Replace global concurrency rw spinlock with rw semaphore
Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
parent
9e515e0271
commit
07b1f0c064
@ -50,7 +50,7 @@ struct __waiters_list {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ocf_cache_line_concurrency {
|
struct ocf_cache_line_concurrency {
|
||||||
env_rwlock lock;
|
env_rwsem lock;
|
||||||
env_atomic *access;
|
env_atomic *access;
|
||||||
env_atomic waiting;
|
env_atomic waiting;
|
||||||
size_t access_limit;
|
size_t access_limit;
|
||||||
@ -85,6 +85,13 @@ int ocf_cache_line_concurrency_init(struct ocf_cache *cache)
|
|||||||
goto ocf_cache_line_concurrency_init;
|
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;
|
cache->device->concurrency.cache_line = c;
|
||||||
|
|
||||||
OCF_REALLOC_INIT(&c->access, &c->access_limit);
|
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;
|
goto spinlock_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
env_rwlock_init(&c->lock);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
spinlock_err:
|
spinlock_err:
|
||||||
@ -127,6 +132,7 @@ ocf_cache_line_concurrency_init:
|
|||||||
ocf_cache_log(cache, log_err, "Cannot initialize cache concurrency, "
|
ocf_cache_log(cache, log_err, "Cannot initialize cache concurrency, "
|
||||||
"ERROR %d", error);
|
"ERROR %d", error);
|
||||||
|
|
||||||
|
if (cache->device->concurrency.cache_line)
|
||||||
ocf_cache_line_concurrency_deinit(cache);
|
ocf_cache_line_concurrency_deinit(cache);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@ -147,7 +153,7 @@ void ocf_cache_line_concurrency_deinit(struct ocf_cache *cache)
|
|||||||
|
|
||||||
concurrency = cache->device->concurrency.cache_line;
|
concurrency = cache->device->concurrency.cache_line;
|
||||||
|
|
||||||
env_rwlock_destroy(&concurrency->lock);
|
env_rwsem_destroy(&concurrency->lock);
|
||||||
|
|
||||||
for (i = 0; i < _WAITERS_LIST_ENTRIES; i++)
|
for (i = 0; i < _WAITERS_LIST_ENTRIES; i++)
|
||||||
env_spinlock_destroy(&concurrency->waiters_lsts[i].lock);
|
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;
|
req->cache->device->concurrency.cache_line;
|
||||||
int lock;
|
int lock;
|
||||||
|
|
||||||
env_rwlock_read_lock(&c->lock);
|
env_rwsem_down_read(&c->lock);
|
||||||
lock = _ocf_req_trylock_rd(req);
|
lock = _ocf_req_trylock_rd(req);
|
||||||
env_rwlock_read_unlock(&c->lock);
|
env_rwsem_up_read(&c->lock);
|
||||||
|
|
||||||
if (lock != OCF_LOCK_ACQUIRED) {
|
if (lock != OCF_LOCK_ACQUIRED) {
|
||||||
env_rwlock_write_lock(&c->lock);
|
env_rwsem_down_write(&c->lock);
|
||||||
lock = _ocf_req_lock_rd(req, cb);
|
lock = _ocf_req_lock_rd(req, cb);
|
||||||
env_rwlock_write_unlock(&c->lock);
|
env_rwsem_up_write(&c->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 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;
|
req->cache->device->concurrency.cache_line;
|
||||||
int lock;
|
int lock;
|
||||||
|
|
||||||
env_rwlock_read_lock(&c->lock);
|
env_rwsem_down_read(&c->lock);
|
||||||
lock = _ocf_req_trylock_wr(req);
|
lock = _ocf_req_trylock_wr(req);
|
||||||
env_rwlock_read_unlock(&c->lock);
|
env_rwsem_up_read(&c->lock);
|
||||||
|
|
||||||
if (lock != OCF_LOCK_ACQUIRED) {
|
if (lock != OCF_LOCK_ACQUIRED) {
|
||||||
env_rwlock_write_lock(&c->lock);
|
env_rwsem_down_write(&c->lock);
|
||||||
lock = _ocf_req_lock_wr(req, cb);
|
lock = _ocf_req_lock_wr(req, cb);
|
||||||
env_rwlock_write_unlock(&c->lock);
|
env_rwsem_up_write(&c->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
return lock;
|
return lock;
|
||||||
|
Loading…
Reference in New Issue
Block a user