diff --git a/src/utils/utils_alock.c b/src/utils/utils_alock.c index 1c5690b..d00a5f4 100644 --- a/src/utils/utils_alock.c +++ b/src/utils/utils_alock.c @@ -15,8 +15,8 @@ ocf_cache_log(cache, log_info, "[Concurrency][Cache] %s\n", __func__) #define OCF_DEBUG_RQ(req, format, ...) \ - ocf_cache_log(req->cache, log_info, "[Concurrency][Cache][%s] %s - " \ - format"\n", OCF_READ == (req)->rw ? "RD" : "WR", \ + ocf_cache_log(req->cache, log_info, "[Concurrency][Cache][%s][%p] %s - " \ + format"\n", OCF_READ == (req)->rw ? "RD" : "WR", req, \ __func__, ##__VA_ARGS__) #else diff --git a/tests/unit/tests/concurrency/ocf_cache_line_concurrency.c/ocf_cache_line_concurrency.c b/tests/unit/tests/concurrency/ocf_cache_line_concurrency.c/ocf_cache_line_concurrency.c index c797bf3..e9c39f7 100644 --- a/tests/unit/tests/concurrency/ocf_cache_line_concurrency.c/ocf_cache_line_concurrency.c +++ b/tests/unit/tests/concurrency/ocf_cache_line_concurrency.c/ocf_cache_line_concurrency.c @@ -39,6 +39,11 @@ * _ocf_req_trylock_wr * _req_on_lock * ocf_cache_line_are_waiters + * ocf_cl_lock_line_needs_lock + * ocf_cl_lock_line_get_entry + * ocf_cl_lock_line_is_acting + * ocf_cl_lock_line_slow + * ocf_cl_lock_line_fast * */ @@ -64,8 +69,100 @@ #include "concurrency/ocf_cache_line_concurrency.c/ocf_cache_line_concurrency_generated_wraps.c" +#include "../utils/utils_alock.c" + #define LOCK_WAIT_TIMEOUT 5 +int __wrap_ocf_alock_init(struct ocf_alock **self, unsigned num_entries, + const char* name, struct ocf_alock_lock_cbs *cbs, ocf_cache_t cache) +{ + return ocf_alock_init(self, num_entries, name, cbs, cache); +} + +void __wrap_ocf_alock_waitlist_remove_entry(struct ocf_alock *alock, + struct ocf_request *req, ocf_cache_line_t entry, int i, int rw) +{ + ocf_alock_waitlist_remove_entry(alock, req, entry, i, rw); +} + +void __wrap_ocf_alock_deinit(struct ocf_alock **self) +{ + ocf_alock_deinit(self); +} + +void __wrap_ocf_alock_mark_index_locked(struct ocf_alock *alock, + struct ocf_request *req, unsigned index, _Bool locked) +{ + ocf_alock_mark_index_locked(alock, req, index, locked); +} + +void __wrap_ocf_alock_unlock_one_wr(struct ocf_alock *alock, + const ocf_cache_line_t entry_idx) +{ + ocf_alock_unlock_one_wr(alock, entry_idx); +} + +int __wrap_ocf_alock_lock_wr(struct ocf_alock *alock, + struct ocf_request *req, ocf_req_async_lock_cb cmpl) +{ + return ocf_alock_lock_wr(alock, req, cmpl); +} + +int __wrap_ocf_alock_lock_rd(struct ocf_alock *alock, + struct ocf_request *req, ocf_req_async_lock_cb cmpl) +{ + return ocf_alock_lock_rd(alock, req, cmpl); +} + + +void __wrap_ocf_alock_unlock_one_rd(struct ocf_alock *alock, + const ocf_cache_line_t entry) +{ + ocf_alock_unlock_one_rd(alock, entry); +} + +void __wrap_ocf_alock_is_index_locked(struct ocf_alock *alock, + struct ocf_request *req, unsigned index) +{ + ocf_alock_is_index_locked(alock, req, index); +} + +bool __wrap_ocf_alock_lock_one_wr(struct ocf_alock *alock, + const ocf_cache_line_t entry, ocf_req_async_lock_cb cmpl, + void *req, uint32_t idx) +{ + usleep(rand() % 100); + return ocf_alock_lock_one_wr(alock, entry, cmpl, req, idx); +} + +bool __wrap_ocf_alock_trylock_entry_rd_idle(struct ocf_alock *alock, + ocf_cache_line_t entry) +{ + return ocf_alock_trylock_entry_rd_idle(alock, entry); +} + +bool __wrap_ocf_alock_lock_one_rd(struct ocf_alock *alock, const ocf_cache_line_t entry, ocf_req_async_lock_cb cmpl, + void *req, uint32_t idx) +{ + usleep(rand() % 100); + return ocf_alock_lock_one_rd(alock, entry, cmpl, req, idx); +} + +bool __wrap_ocf_alock_waitlist_is_empty(struct ocf_alock *alock, ocf_cache_line_t entry) +{ + return ocf_alock_waitlist_is_empty(alock, entry); +} + +bool __wrap_ocf_alock_trylock_one_rd(struct ocf_alock *alock, ocf_cache_line_t entry) +{ + return ocf_alock_trylock_one_rd(alock, entry); +} + +bool __wrap_ocf_alock_trylock_entry_wr(struct ocf_alock *alock, ocf_cache_line_t entry) +{ + return ocf_alock_trylock_entry_wr(alock, entry); +} + void __wrap___assert_fail (const char *__assertion, const char *__file, unsigned int __line, const char *__function) { @@ -125,32 +222,14 @@ int __wrap_snprintf (char *__restrict __s, size_t __maxlen, return ret; } -static inline bool __wrap___lock_cache_line_wr(struct ocf_cache_line_concurrency *c, - const ocf_cache_line_t line, ocf_req_async_lock_cb cb, - void *ctx, uint32_t ctx_id) +ocf_ctx_t ocf_cache_get_ctx(ocf_cache_t cache) { - usleep(rand() % 100); - return __real___lock_cache_line_wr(c, line, cb, ctx, ctx_id); + return NULL; } -static inline bool __wrap___lock_cache_line_rd(struct ocf_cache_line_concurrency *c, - const ocf_cache_line_t line, ocf_req_async_lock_cb cb, - void *ctx, uint32_t ctx_id) +int __wrap_ocf_log_raw(ocf_logger_t logger, ocf_logger_lvl_t lvl, const char *fmt, ...) { - usleep(rand() % 100); - return __real___lock_cache_line_rd(c, line, cb, ctx, ctx_id); -} - -int __wrap__ocf_req_lock_wr(struct ocf_request *req, ocf_req_async_lock_cb cb) -{ - usleep(rand() % 500); - return __real__ocf_req_lock_wr(req, cb); -} - -int __wrap__ocf_req_lock_rd(struct ocf_request *req, ocf_req_async_lock_cb cb) -{ - usleep(rand() % 500); - return __real__ocf_req_lock_wr(req, cb); + function_called(); } unsigned long long progress; @@ -263,7 +342,7 @@ void thread(void *_ctx) while (i-- && !ctx->terminated) { rw = rand() % 2; - single = (rand() % 4 == 0); + single = (rand() % 5 == 0); if (!single) { shuffle(permutation, ctx->clines);