From 07b1f0c064dee2d29c231f8538be25c0fd144edb Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Fri, 18 Oct 2019 18:19:05 -0400 Subject: [PATCH] Replace global concurrency rw spinlock with rw semaphore Signed-off-by: Adam Rutkowski --- src/concurrency/ocf_cache_line_concurrency.c | 32 ++++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/concurrency/ocf_cache_line_concurrency.c b/src/concurrency/ocf_cache_line_concurrency.c index de2f20e..3f29c7f 100644 --- a/src/concurrency/ocf_cache_line_concurrency.c +++ b/src/concurrency/ocf_cache_line_concurrency.c @@ -50,7 +50,7 @@ struct __waiters_list { }; struct ocf_cache_line_concurrency { - env_rwlock lock; + env_rwsem lock; env_atomic *access; env_atomic waiting; size_t access_limit; @@ -85,6 +85,13 @@ int ocf_cache_line_concurrency_init(struct ocf_cache *cache) goto ocf_cache_line_concurrency_init; } + error = env_rwsem_init(&c->lock); + if (error) { + env_vfree(c); + error = __LINE__; + goto ocf_cache_line_concurrency_init; + } + cache->device->concurrency.cache_line = c; OCF_REALLOC_INIT(&c->access, &c->access_limit); @@ -116,8 +123,6 @@ int ocf_cache_line_concurrency_init(struct ocf_cache *cache) goto spinlock_err; } - env_rwlock_init(&c->lock); - return 0; spinlock_err: @@ -127,7 +132,8 @@ ocf_cache_line_concurrency_init: ocf_cache_log(cache, log_err, "Cannot initialize cache concurrency, " "ERROR %d", error); - ocf_cache_line_concurrency_deinit(cache); + if (cache->device->concurrency.cache_line) + ocf_cache_line_concurrency_deinit(cache); return -1; } @@ -147,7 +153,7 @@ void ocf_cache_line_concurrency_deinit(struct ocf_cache *cache) concurrency = cache->device->concurrency.cache_line; - env_rwlock_destroy(&concurrency->lock); + env_rwsem_destroy(&concurrency->lock); for (i = 0; i < _WAITERS_LIST_ENTRIES; i++) env_spinlock_destroy(&concurrency->waiters_lsts[i].lock); @@ -813,14 +819,14 @@ int ocf_req_async_lock_rd(struct ocf_request *req, ocf_req_async_lock_cb cb) req->cache->device->concurrency.cache_line; int lock; - env_rwlock_read_lock(&c->lock); + env_rwsem_down_read(&c->lock); lock = _ocf_req_trylock_rd(req); - env_rwlock_read_unlock(&c->lock); + env_rwsem_up_read(&c->lock); if (lock != OCF_LOCK_ACQUIRED) { - env_rwlock_write_lock(&c->lock); + env_rwsem_down_write(&c->lock); lock = _ocf_req_lock_rd(req, cb); - env_rwlock_write_unlock(&c->lock); + env_rwsem_up_write(&c->lock); } return lock; @@ -940,14 +946,14 @@ int ocf_req_async_lock_wr(struct ocf_request *req, ocf_req_async_lock_cb cb) req->cache->device->concurrency.cache_line; int lock; - env_rwlock_read_lock(&c->lock); + env_rwsem_down_read(&c->lock); lock = _ocf_req_trylock_wr(req); - env_rwlock_read_unlock(&c->lock); + env_rwsem_up_read(&c->lock); if (lock != OCF_LOCK_ACQUIRED) { - env_rwlock_write_lock(&c->lock); + env_rwsem_down_write(&c->lock); lock = _ocf_req_lock_wr(req, cb); - env_rwlock_write_unlock(&c->lock); + env_rwsem_up_write(&c->lock); } return lock;