Initial commit
Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
1125
src/concurrency/ocf_cache_concurrency.c
Normal file
1125
src/concurrency/ocf_cache_concurrency.c
Normal file
File diff suppressed because it is too large
Load Diff
176
src/concurrency/ocf_cache_concurrency.h
Normal file
176
src/concurrency/ocf_cache_concurrency.h
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright(c) 2012-2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
|
||||
#ifndef OCF_CACHE_CONCURRENCY_H_
|
||||
#define OCF_CACHE_CONCURRENCY_H_
|
||||
|
||||
/**
|
||||
* @file utils_rq.h
|
||||
* @brief OCF cache concurrency module
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief OCF cache concurrency module handle
|
||||
*/
|
||||
struct ocf_cache_concurrency;
|
||||
|
||||
/**
|
||||
* @brief Initialize OCF cache concurrency module
|
||||
*
|
||||
* @param cache - OCF cache instance
|
||||
* @return 0 - Initialization successful, otherwise ERROR
|
||||
*/
|
||||
int ocf_cache_concurrency_init(struct ocf_cache *cache);
|
||||
|
||||
/**
|
||||
* @biref De-Initialize OCF cache concurrency module
|
||||
*
|
||||
* @param cache - OCF cache instance
|
||||
*/
|
||||
void ocf_cache_concurrency_deinit(struct ocf_cache *cache);
|
||||
|
||||
/**
|
||||
* @brief Get number of waiting (suspended) OCF requests in due to cache
|
||||
* overlapping
|
||||
*
|
||||
* @param cache - OCF cache instance
|
||||
*
|
||||
* @return Number of suspended OCF requests
|
||||
*/
|
||||
uint32_t ocf_cache_concurrency_suspended_no(struct ocf_cache *cache);
|
||||
|
||||
/**
|
||||
* @brief Return memory footprint conusmed by cache concurrency module
|
||||
*
|
||||
* @param cache - OCF cache instance
|
||||
*
|
||||
* @return Memory footprint of cache concurrency module
|
||||
*/
|
||||
size_t ocf_cache_concurrency_size_of(struct ocf_cache *cache);
|
||||
|
||||
/**
|
||||
* @brief Lock OCF request for WRITE access (Lock all cache lines in map info)
|
||||
*
|
||||
* @note rq->resume callback has to be set
|
||||
*
|
||||
* @param rq - OCF request
|
||||
*
|
||||
* @retval OCF_LOCK_ACQUIRED - OCF request has been locked and can be processed
|
||||
*
|
||||
* @retval OCF_LOCK_NOT_ACQUIRED - OCF request lock not acquired, request was
|
||||
* added into waiting list. When lock will be acquired rq->resume be called
|
||||
*/
|
||||
int ocf_rq_trylock_wr(struct ocf_request *rq);
|
||||
|
||||
/**
|
||||
* @brief Try complete lock of OCF request for WRITE access (Lock cache lines
|
||||
* that marked as invalid)
|
||||
*
|
||||
* @param rq - OCF request
|
||||
*
|
||||
* @note If request not locked it will be added into waiting list
|
||||
*
|
||||
* @retval OCF_LOCK_ACQUIRED - OCF request has been locked and can be processed
|
||||
*
|
||||
* @retval OCF_LOCK_NOT_ACQUIRED - OCF request lock not acquired, request was
|
||||
* added into waiting list. When lock will be acquired rq->resume be called
|
||||
*/
|
||||
int ocf_rq_retrylock_wr(struct ocf_request *rq);
|
||||
|
||||
/**
|
||||
* @brief Lock OCF request for READ access (Lock all cache lines in map info)
|
||||
*
|
||||
* @note rq->resume callback has to be set
|
||||
*
|
||||
* @param rq - OCF request
|
||||
*
|
||||
* @retval OCF_LOCK_ACQUIRED - OCF request has been locked and can be processed
|
||||
*
|
||||
* @retval OCF_LOCK_NOT_ACQUIRED - OCF request lock not acquired, request was
|
||||
* added into waiting list. When lock will be acquired rq->resume be called
|
||||
*/
|
||||
int ocf_rq_trylock_rd(struct ocf_request *rq);
|
||||
|
||||
/**
|
||||
* @brief Unlock OCF request from WRITE access
|
||||
*
|
||||
* @param rq - OCF request
|
||||
*/
|
||||
void ocf_rq_unlock_wr(struct ocf_request *rq);
|
||||
|
||||
/**
|
||||
* @brief Unlock OCF request from READ access
|
||||
*
|
||||
* @param rq - OCF request
|
||||
*/
|
||||
void ocf_rq_unlock_rd(struct ocf_request *rq);
|
||||
|
||||
/**
|
||||
* @brief Unlock OCF request from READ or WRITE access
|
||||
*
|
||||
* @param rq - OCF request
|
||||
*/
|
||||
void ocf_rq_unlock(struct ocf_request *rq);
|
||||
|
||||
/**
|
||||
* @Check if cache line is used.
|
||||
*
|
||||
* Cache line is used when:
|
||||
* 1. It is locked for write or read access
|
||||
* or
|
||||
* 2. There is set locked bit in metadata
|
||||
*
|
||||
* @param cache - OCF cache instance
|
||||
* @param line - Cache line to be unlocked
|
||||
*
|
||||
* @retval true - cache line is used
|
||||
* @retval false - cache line is not used
|
||||
*/
|
||||
bool ocf_cache_line_is_used(struct ocf_cache *cache,
|
||||
ocf_cache_line_t line);
|
||||
|
||||
/**
|
||||
* @brief Check if for specified cache line there are waiters
|
||||
* on the waiting list
|
||||
*
|
||||
* @param cache - OCF cache instance
|
||||
* @param line - Cache line to be checked for waiters
|
||||
*
|
||||
* @retval true - there are waiters
|
||||
* @retval false - No waiters
|
||||
*/
|
||||
bool ocf_cache_line_are_waiters(struct ocf_cache *cache,
|
||||
ocf_cache_line_t line);
|
||||
|
||||
/**
|
||||
* @brief un_lock request map info entry from from WRITE or READ access.
|
||||
*
|
||||
* @param cache - OCF cache instance
|
||||
* @param rq - OCF request
|
||||
* @param entry - request map entry number
|
||||
*/
|
||||
void ocf_rq_unlock_entry(struct ocf_cache *cache,
|
||||
struct ocf_request *rq, uint32_t entry);
|
||||
|
||||
/**
|
||||
* @brief Release cache line read lock
|
||||
*
|
||||
* @param cache - OCF cache instance
|
||||
* @param line - Cache line to be unlocked
|
||||
*/
|
||||
void ocf_cache_line_unlock_rd(struct ocf_cache *cache, ocf_cache_line_t line);
|
||||
|
||||
/**
|
||||
* @brief Attempt to lock cache line for read
|
||||
*
|
||||
* @param cache - OCF cache instance
|
||||
* @param line - Cache line to be checked for waiters
|
||||
*
|
||||
* @retval true - read lock successfully acquired
|
||||
* @retval false - failed to acquire read lock
|
||||
*/
|
||||
bool ocf_cache_line_try_lock_rd(struct ocf_cache *cache, ocf_cache_line_t line);
|
||||
|
||||
#endif /* OCF_CONCURRENCY_H_ */
|
24
src/concurrency/ocf_concurrency.c
Normal file
24
src/concurrency/ocf_concurrency.c
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright(c) 2012-2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
|
||||
#include "ocf_concurrency.h"
|
||||
|
||||
int ocf_concurrency_init(struct ocf_cache *cache)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
result = ocf_cache_concurrency_init(cache);
|
||||
|
||||
if (result)
|
||||
ocf_concurrency_deinit(cache);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ocf_concurrency_deinit(struct ocf_cache *cache)
|
||||
{
|
||||
ocf_cache_concurrency_deinit(cache);
|
||||
}
|
||||
|
43
src/concurrency/ocf_concurrency.h
Normal file
43
src/concurrency/ocf_concurrency.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright(c) 2012-2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
|
||||
#ifndef OCF_CONCURRENCY_H_
|
||||
#define OCF_CONCURRENCY_H_
|
||||
|
||||
#include "../ocf_cache_priv.h"
|
||||
|
||||
/**
|
||||
* @file utils_rq.h
|
||||
* @brief OCF concurrency
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Lock result - Lock acquired successfully
|
||||
*/
|
||||
#define OCF_LOCK_ACQUIRED 0
|
||||
|
||||
/**
|
||||
* @brief Lock result - Lock not acquired, lock request added into waiting list
|
||||
*/
|
||||
#define OCF_LOCK_NOT_ACQUIRED 1
|
||||
|
||||
/**
|
||||
* @brief Initialize OCF concurrency module
|
||||
*
|
||||
* @param cache - OCF cache instance
|
||||
* @return 0 - Initialization successful, otherwise ERROR
|
||||
*/
|
||||
int ocf_concurrency_init(struct ocf_cache *cache);
|
||||
|
||||
/**
|
||||
* @biref De-Initialize OCF concurrency module
|
||||
*
|
||||
* @param cache - OCF cache instance
|
||||
*/
|
||||
void ocf_concurrency_deinit(struct ocf_cache *cache);
|
||||
|
||||
#include "ocf_cache_concurrency.h"
|
||||
|
||||
#endif /* OCF_CONCURRENCY_H_ */
|
Reference in New Issue
Block a user