Adding synchronization primitives destroyers

Environment should provide calls for destroying primitives (i.e. env_mutex_destroy()) and OCF should call these functions in its cleanup paths.

Signed-off-by: Firas Medini <mdnfiras@yahoo.com>
This commit is contained in:
Firas Medini 2019-08-13 05:13:11 -07:00
parent 34c8d135c2
commit 1f979f630b
16 changed files with 58 additions and 189 deletions

5
env/posix/ocf_env.c vendored
View File

@ -110,11 +110,6 @@ void env_allocator_destroy(env_allocator *allocator)
} }
} }
uint32_t env_allocator_item_count(env_allocator *allocator)
{
return env_atomic_read(&allocator->count);
}
/* *** DEBUGING *** */ /* *** DEBUGING *** */
#define ENV_TRACE_DEPTH 16 #define ENV_TRACE_DEPTH 16

110
env/posix/ocf_env.h vendored
View File

@ -169,8 +169,6 @@ void *env_allocator_new(env_allocator *allocator);
void env_allocator_del(env_allocator *allocator, void *item); void env_allocator_del(env_allocator *allocator, void *item);
uint32_t env_allocator_item_count(env_allocator *allocator);
/* *** MUTEX *** */ /* *** MUTEX *** */
typedef struct { typedef struct {
@ -198,22 +196,15 @@ static inline int env_mutex_lock_interruptible(env_mutex *mutex)
return 0; return 0;
} }
static inline int env_mutex_trylock(env_mutex *mutex)
{
return pthread_mutex_trylock(&mutex->m) ? -OCF_ERR_NO_LOCK : 0;
}
static inline void env_mutex_unlock(env_mutex *mutex) static inline void env_mutex_unlock(env_mutex *mutex)
{ {
ENV_BUG_ON(pthread_mutex_unlock(&mutex->m)); ENV_BUG_ON(pthread_mutex_unlock(&mutex->m));
} }
static inline int env_mutex_is_locked(env_mutex *mutex) static inline int env_mutex_destroy(env_mutex *mutex)
{ {
if (env_mutex_trylock(mutex) == 0) { if(pthread_mutex_destroy(&mutex->m))
env_mutex_unlock(mutex);
return 1; return 1;
}
return 0; return 0;
} }
@ -243,19 +234,17 @@ static inline int env_rmutex_lock_interruptible(env_rmutex *rmutex)
return env_mutex_lock_interruptible(rmutex); return env_mutex_lock_interruptible(rmutex);
} }
static inline int env_rmutex_trylock(env_rmutex *rmutex)
{
return env_mutex_trylock(rmutex);
}
static inline void env_rmutex_unlock(env_rmutex *rmutex) static inline void env_rmutex_unlock(env_rmutex *rmutex)
{ {
env_mutex_unlock(rmutex); env_mutex_unlock(rmutex);
} }
static inline int env_rmutex_is_locked(env_rmutex *rmutex) static inline int env_rmutex_destroy(env_rmutex *rmutex)
{ {
return env_mutex_is_locked(rmutex); if(pthread_mutex_destroy(&rmutex->m))
return 1;
return 0;
} }
/* *** RW SEMAPHORE *** */ /* *** RW SEMAPHORE *** */
@ -298,26 +287,9 @@ static inline int env_rwsem_down_write_trylock(env_rwsem *s)
return pthread_rwlock_trywrlock(&s->lock) ? -OCF_ERR_NO_LOCK : 0; return pthread_rwlock_trywrlock(&s->lock) ? -OCF_ERR_NO_LOCK : 0;
} }
static inline int env_rwsem_is_locked(env_rwsem *s) static inline int env_rwsem_destroy(env_rwsem *s)
{ {
if (env_rwsem_down_read_trylock(s) == 0) { return pthread_rwlock_destroy(&s->lock);
env_rwsem_up_read(s);
return 0;
}
return 1;
}
static inline int env_rwsem_down_write_interruptible(env_rwsem *s)
{
env_rwsem_down_write(s);
return 0;
}
static inline int env_rwsem_down_read_interruptible(env_rwsem *s)
{
env_rwsem_down_read(s);
return 0;
} }
/* *** COMPLETION *** */ /* *** COMPLETION *** */
@ -342,10 +314,9 @@ static inline void env_completion_complete(env_completion *completion)
sem_post(&completion->sem); sem_post(&completion->sem);
} }
static inline void env_completion_complete_and_exit( static inline void env_completion_destroy(env_completion *completion)
env_completion *completion, int ret)
{ {
env_completion_complete(completion); /* TODO */ sem_destroy(&completion->sem);
} }
/* *** ATOMIC VARIABLES *** */ /* *** ATOMIC VARIABLES *** */
@ -378,11 +349,6 @@ static inline void env_atomic_sub(int i, env_atomic *a)
__sync_sub_and_fetch(&a->counter, i); __sync_sub_and_fetch(&a->counter, i);
} }
static inline bool env_atomic_sub_and_test(int i, env_atomic *a)
{
return __sync_sub_and_fetch(&a->counter, i) == 0;
}
static inline void env_atomic_inc(env_atomic *a) static inline void env_atomic_inc(env_atomic *a)
{ {
env_atomic_add(1, a); env_atomic_add(1, a);
@ -398,11 +364,6 @@ static inline bool env_atomic_dec_and_test(env_atomic *a)
return __sync_sub_and_fetch(&a->counter, 1) == 0; return __sync_sub_and_fetch(&a->counter, 1) == 0;
} }
static inline bool env_atomic_inc_and_test(env_atomic *a)
{
return __sync_add_and_fetch(&a->counter, 1) == 0;
}
static inline int env_atomic_add_return(int i, env_atomic *a) static inline int env_atomic_add_return(int i, env_atomic *a)
{ {
return __sync_add_and_fetch(&a->counter, i); return __sync_add_and_fetch(&a->counter, i);
@ -504,16 +465,6 @@ static inline void env_spinlock_unlock(env_spinlock *l)
ENV_BUG_ON(pthread_spin_unlock(&l->lock)); ENV_BUG_ON(pthread_spin_unlock(&l->lock));
} }
static inline void env_spinlock_lock_irq(env_spinlock *l)
{
env_spinlock_lock(l);
}
static inline void env_spinlock_unlock_irq(env_spinlock *l)
{
env_spinlock_unlock(l);
}
#define env_spinlock_lock_irqsave(l, flags) \ #define env_spinlock_lock_irqsave(l, flags) \
(void)flags; \ (void)flags; \
env_spinlock_lock(l) env_spinlock_lock(l)
@ -522,6 +473,11 @@ static inline void env_spinlock_unlock_irq(env_spinlock *l)
(void)flags; \ (void)flags; \
env_spinlock_unlock(l) env_spinlock_unlock(l)
static inline void env_spinlock_destroy(env_spinlock *l)
{
ENV_BUG_ON(pthread_spin_destroy(&l->lock));
}
/* *** RW LOCKS *** */ /* *** RW LOCKS *** */
typedef struct { typedef struct {
@ -553,22 +509,17 @@ static inline void env_rwlock_write_unlock(env_rwlock *l)
ENV_BUG_ON(pthread_rwlock_unlock(&l->lock)); ENV_BUG_ON(pthread_rwlock_unlock(&l->lock));
} }
static inline void env_rwlock_destroy(env_rwlock *l)
{
ENV_BUG_ON(pthread_rwlock_destroy(&l->lock));
}
/* *** WAITQUEUE *** */ /* *** WAITQUEUE *** */
typedef struct { typedef struct {
sem_t sem; sem_t sem;
} env_waitqueue; } env_waitqueue;
static inline void env_waitqueue_init(env_waitqueue *w)
{
sem_init(&w->sem, 0, 0);
}
static inline void env_waitqueue_wake_up(env_waitqueue *w)
{
sem_post(&w->sem);
}
#define env_waitqueue_wait(w, condition) \ #define env_waitqueue_wait(w, condition) \
({ \ ({ \
int __ret = 0; \ int __ret = 0; \
@ -577,6 +528,11 @@ static inline void env_waitqueue_wake_up(env_waitqueue *w)
__ret = __ret; \ __ret = __ret; \
}) })
static inline void env_waitqueue_destroy(env_waitqueue *w)
{
sem_destroy(&w->sem);
}
/* *** BIT OPERATIONS *** */ /* *** BIT OPERATIONS *** */
static inline void env_bit_set(int nr, volatile void *addr) static inline void env_bit_set(int nr, volatile void *addr)
@ -604,12 +560,6 @@ static inline bool env_bit_test(int nr, const volatile unsigned long *addr)
return !!(*byte & mask); return !!(*byte & mask);
} }
/* *** SCHEDULING *** */
static inline void env_schedule(void)
{
sched_yield();
}
static inline int env_in_interrupt(void) static inline int env_in_interrupt(void)
{ {
return 0; return 0;
@ -689,14 +639,6 @@ struct env_timeval {
uint64_t sec, usec; uint64_t sec, usec;
}; };
static inline void env_gettimeofday(struct env_timeval *tv)
{
struct timeval t;
gettimeofday(&t, NULL);
tv->sec = t.tv_sec;
tv->usec = t.tv_usec;
}
uint32_t env_crc32(uint32_t crc, uint8_t const *data, size_t len); uint32_t env_crc32(uint32_t crc, uint8_t const *data, size_t len);
#define ENV_PRIu64 "lu" #define ENV_PRIu64 "lu"

View File

@ -233,8 +233,13 @@ void cleaning_policy_acp_init_cache_block(struct ocf_cache *cache,
void cleaning_policy_acp_deinitialize(struct ocf_cache *cache) void cleaning_policy_acp_deinitialize(struct ocf_cache *cache)
{ {
struct acp_context *acp;
_acp_remove_cores(cache); _acp_remove_cores(cache);
acp = cache->cleaner.cleaning_policy_context;
env_rwsem_destroy(&acp->chunks_lock);
env_vfree(cache->cleaner.cleaning_policy_context); env_vfree(cache->cleaner.cleaning_policy_context);
cache->cleaner.cleaning_policy_context = NULL; cache->cleaner.cleaning_policy_context = NULL;
} }

View File

@ -134,6 +134,7 @@ ocf_cache_line_concurrency_init:
*/ */
void ocf_cache_line_concurrency_deinit(struct ocf_cache *cache) void ocf_cache_line_concurrency_deinit(struct ocf_cache *cache)
{ {
int i;
struct ocf_cache_line_concurrency *concurrency; struct ocf_cache_line_concurrency *concurrency;
if (!cache->device->concurrency.cache_line) if (!cache->device->concurrency.cache_line)
@ -143,6 +144,11 @@ 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);
for (i = 0; i < _WAITERS_LIST_ENTRIES; i++)
env_spinlock_destroy(&concurrency->waiters_lsts[i].lock);
if (concurrency->access) if (concurrency->access)
OCF_REALLOC_DEINIT(&concurrency->access, OCF_REALLOC_DEINIT(&concurrency->access,
&concurrency->access_limit); &concurrency->access_limit);

View File

@ -12,6 +12,13 @@ void ocf_metadata_concurrency_init(struct ocf_cache *cache)
env_rwsem_init(&cache->metadata.lock.collision); env_rwsem_init(&cache->metadata.lock.collision);
} }
void ocf_metadata_concurrency_deinit(struct ocf_cache *cache)
{
env_spinlock_destroy(&cache->metadata.lock.eviction);
env_rwlock_destroy(&cache->metadata.lock.status);
env_rwsem_destroy(&cache->metadata.lock.collision);
}
int ocf_metadata_concurrency_attached_init(struct ocf_cache *cache) int ocf_metadata_concurrency_attached_init(struct ocf_cache *cache)
{ {
return 0; return 0;

View File

@ -12,6 +12,8 @@
void ocf_metadata_concurrency_init(struct ocf_cache *cache); void ocf_metadata_concurrency_init(struct ocf_cache *cache);
void ocf_metadata_concurrency_deinit(struct ocf_cache *cache);
int ocf_metadata_concurrency_attached_init(struct ocf_cache *cache); int ocf_metadata_concurrency_attached_init(struct ocf_cache *cache);
static inline void ocf_metadata_eviction_lock(struct ocf_cache *cache) static inline void ocf_metadata_eviction_lock(struct ocf_cache *cache)

View File

@ -73,6 +73,8 @@ void ocf_metadata_deinit(struct ocf_cache *cache)
cache->metadata.iface.deinit(cache); cache->metadata.iface.deinit(cache);
} }
ocf_metadata_concurrency_deinit(cache);
ocf_metadata_io_deinit(cache); ocf_metadata_io_deinit(cache);
} }

View File

@ -129,6 +129,8 @@ int raw_dynamic_deinit(ocf_cache_t cache,
for (i = 0; i < raw->ssd_pages; i++) for (i = 0; i < raw->ssd_pages; i++)
env_secure_free(ctrl->pages[i], PAGE_SIZE); env_secure_free(ctrl->pages[i], PAGE_SIZE);
env_mutex_destroy(&ctrl->lock);
env_vfree(ctrl); env_vfree(ctrl);
raw->priv = NULL; raw->priv = NULL;

View File

@ -33,6 +33,7 @@ void ocf_metadata_updater_kick(ocf_cache_t cache)
void ocf_metadata_updater_stop(ocf_cache_t cache) void ocf_metadata_updater_stop(ocf_cache_t cache)
{ {
ctx_metadata_updater_stop(cache->owner, &cache->metadata_updater); ctx_metadata_updater_stop(cache->owner, &cache->metadata_updater);
env_mutex_destroy(&cache->metadata_updater.syncher.lock);
} }
void ocf_metadata_updater_set_priv(ocf_metadata_updater_t mu, void *priv) void ocf_metadata_updater_set_priv(ocf_metadata_updater_t mu, void *priv)

View File

@ -135,6 +135,7 @@ void ocf_mngt_cache_put(ocf_cache_t cache)
ctx = cache->owner; ctx = cache->owner;
ocf_metadata_deinit(cache); ocf_metadata_deinit(cache);
ocf_mngt_cache_lock_deinit(cache); ocf_mngt_cache_lock_deinit(cache);
env_mutex_destroy(&cache->flush_mutex);
env_vfree(cache); env_vfree(cache);
ocf_ctx_put(ctx); ocf_ctx_put(ctx);
} }

View File

@ -233,6 +233,8 @@ void ocf_ctx_put(ocf_ctx_t ctx)
ocf_mngt_core_pool_deinit(ctx); ocf_mngt_core_pool_deinit(ctx);
ocf_ctx_unregister_volume_types(ctx); ocf_ctx_unregister_volume_types(ctx);
env_rmutex_destroy(&ctx->lock);
ocf_req_allocator_deinit(ctx); ocf_req_allocator_deinit(ctx);
ocf_logger_close(&ctx->logger); ocf_logger_close(&ctx->logger);
env_free(ctx); env_free(ctx);

View File

@ -60,6 +60,7 @@ void ocf_queue_put(ocf_queue_t queue)
list_del(&queue->list); list_del(&queue->list);
queue->ops->stop(queue); queue->ops->stop(queue);
ocf_mngt_cache_put(queue->cache); ocf_mngt_cache_put(queue->cache);
env_spinlock_destroy(&queue->io_list_lock);
env_free(queue); env_free(queue);
} }
} }

View File

@ -308,6 +308,7 @@ static void ocf_volume_close_end(void *ctx)
env_completion *cmpl = ctx; env_completion *cmpl = ctx;
env_completion_complete(cmpl); env_completion_complete(cmpl);
env_completion_destroy(cmpl);
} }
void ocf_volume_close(ocf_volume_t volume) void ocf_volume_close(ocf_volume_t volume)

View File

@ -72,6 +72,8 @@ void ocf_async_lock_deinit(struct ocf_async_lock *lock)
list_for_each_entry_safe(iter, temp, &lock->waiters, list) list_for_each_entry_safe(iter, temp, &lock->waiters, list)
list_move_tail(&iter->list, &waiters); list_move_tail(&iter->list, &waiters);
env_mutex_unlock(&lock->mutex); env_mutex_unlock(&lock->mutex);
env_mutex_destroy(&lock->mutex);
_ocf_async_lock_run_waiters(lock, &waiters, -OCF_ERR_NO_LOCK); _ocf_async_lock_run_waiters(lock, &waiters, -OCF_ERR_NO_LOCK);
} }

View File

@ -127,11 +127,6 @@ void env_allocator_destroy(env_allocator *allocator)
} }
} }
uint32_t env_allocator_item_count(env_allocator *allocator)
{
return env_atomic_read(&allocator->count);
}
/* *** COMPLETION *** */ /* *** COMPLETION *** */
void env_completion_init(env_completion *completion) void env_completion_init(env_completion *completion)
@ -173,26 +168,12 @@ int env_mutex_lock_interruptible(env_mutex *mutex)
return mock(); return mock();
} }
int env_mutex_trylock(env_mutex *mutex)
{
function_called();
check_expected_ptr(mutex);
return mock();
}
void env_mutex_unlock(env_mutex *mutex) void env_mutex_unlock(env_mutex *mutex)
{ {
function_called(); function_called();
check_expected_ptr(mutex); check_expected_ptr(mutex);
} }
int env_mutex_is_locked(env_mutex *mutex)
{
function_called();
check_expected_ptr(mutex);
return mock();
}
int env_rmutex_init(env_rmutex *rmutex) int env_rmutex_init(env_rmutex *rmutex)
{ {
function_called(); function_called();
@ -213,26 +194,12 @@ int env_rmutex_lock_interruptible(env_rmutex *rmutex)
return mock(); return mock();
} }
int env_rmutex_trylock(env_rmutex *rmutex)
{
function_called();
check_expected_ptr(rmutex);
return mock();
}
void env_rmutex_unlock(env_rmutex *rmutex) void env_rmutex_unlock(env_rmutex *rmutex)
{ {
function_called(); function_called();
check_expected_ptr(rmutex); check_expected_ptr(rmutex);
} }
int env_rmutex_is_locked(env_rmutex *rmutex)
{
function_called();
check_expected_ptr(rmutex);
return mock();
}
int env_rwsem_init(env_rwsem *s) int env_rwsem_init(env_rwsem *s)
{ {
function_called(); function_called();
@ -298,11 +265,6 @@ void env_atomic_sub(int i, env_atomic *a)
*a -= i; *a -= i;
} }
bool env_atomic_sub_and_test(int i, env_atomic *a)
{
return *a-=i == 0;
}
void env_atomic_inc(env_atomic *a) void env_atomic_inc(env_atomic *a)
{ {
++*a; ++*a;
@ -318,11 +280,6 @@ bool env_atomic_dec_and_test(env_atomic *a)
return --*a == 0; return --*a == 0;
} }
bool env_atomic_inc_and_test(env_atomic *a)
{
return ++*a == 0;
}
int env_atomic_add_return(int i, env_atomic *a) int env_atomic_add_return(int i, env_atomic *a)
{ {
return *a+=i; return *a+=i;
@ -422,18 +379,6 @@ void env_spinlock_unlock(env_spinlock *l)
check_expected_ptr(l); check_expected_ptr(l);
} }
void env_spinlock_lock_irq(env_spinlock *l)
{
function_called();
check_expected_ptr(l);
}
void env_spinlock_unlock_irq(env_spinlock *l)
{
function_called();
check_expected_ptr(l);
}
void env_rwlock_init(env_rwlock *l) void env_rwlock_init(env_rwlock *l)
{ {
function_called(); function_called();
@ -464,20 +409,6 @@ void env_rwlock_write_unlock(env_rwlock *l)
check_expected_ptr(l); check_expected_ptr(l);
} }
void env_waitqueue_init(env_waitqueue *w)
{
w->completed = false;
w->waiting = false;
w->co = NULL;
}
void env_waitqueue_wake_up(env_waitqueue *w)
{
w->completed = true;
if (!w->waiting || !w->co)
return;
}
void env_bit_set(int nr, volatile void *addr) void env_bit_set(int nr, volatile void *addr)
{ {
char *byte = (char *) addr + (nr >> 3); char *byte = (char *) addr + (nr >> 3);
@ -510,11 +441,6 @@ void env_touch_softlockup_wd(void)
function_called(); function_called();
} }
void env_schedule(void)
{
function_called();
}
int env_in_interrupt(void) int env_in_interrupt(void)
{ {
function_called(); function_called();

View File

@ -120,8 +120,6 @@ void *env_allocator_new(env_allocator *allocator);
void env_allocator_del(env_allocator *allocator, void *item); void env_allocator_del(env_allocator *allocator, void *item);
uint32_t env_allocator_item_count(env_allocator *allocator);
/* *** MUTEX *** */ /* *** MUTEX *** */
typedef struct { typedef struct {
@ -134,12 +132,8 @@ void env_mutex_lock(env_mutex *mutex);
int env_mutex_lock_interruptible(env_mutex *mutex); int env_mutex_lock_interruptible(env_mutex *mutex);
int env_mutex_trylock(env_mutex *mutex);
void env_mutex_unlock(env_mutex *mutex); void env_mutex_unlock(env_mutex *mutex);
int env_mutex_is_locked(env_mutex *mutex);
/* *** RECURSIVE MUTEX *** */ /* *** RECURSIVE MUTEX *** */
typedef env_mutex env_rmutex; typedef env_mutex env_rmutex;
@ -150,12 +144,8 @@ void env_rmutex_lock(env_rmutex *rmutex);
int env_rmutex_lock_interruptible(env_rmutex *rmutex); int env_rmutex_lock_interruptible(env_rmutex *rmutex);
int env_rmutex_trylock(env_rmutex *rmutex);
void env_rmutex_unlock(env_rmutex *rmutex); void env_rmutex_unlock(env_rmutex *rmutex);
int env_rmutex_is_locked(env_rmutex *rmutex);
/* *** RW SEMAPHORE *** */ /* *** RW SEMAPHORE *** */
typedef struct { typedef struct {
pthread_rwlock_t lock; pthread_rwlock_t lock;
@ -175,8 +165,6 @@ void env_rwsem_down_write(env_rwsem *s);
int env_rwsem_down_write_trylock(env_rwsem *s); int env_rwsem_down_write_trylock(env_rwsem *s);
int env_rwsem_is_locked(env_rwsem *s);
/* *** ATOMIC VARIABLES *** */ /* *** ATOMIC VARIABLES *** */
typedef int env_atomic; typedef int env_atomic;
@ -191,16 +179,12 @@ void env_atomic_add(int i, env_atomic *a);
void env_atomic_sub(int i, env_atomic *a); void env_atomic_sub(int i, env_atomic *a);
bool env_atomic_sub_and_test(int i, env_atomic *a);
void env_atomic_inc(env_atomic *a); void env_atomic_inc(env_atomic *a);
void env_atomic_dec(env_atomic *a); void env_atomic_dec(env_atomic *a);
bool env_atomic_dec_and_test(env_atomic *a); bool env_atomic_dec_and_test(env_atomic *a);
bool env_atomic_inc_and_test(env_atomic *a);
int env_atomic_add_return(int i, env_atomic *a); int env_atomic_add_return(int i, env_atomic *a);
int env_atomic_sub_return(int i, env_atomic *a); int env_atomic_sub_return(int i, env_atomic *a);
@ -253,10 +237,6 @@ void env_spinlock_lock(env_spinlock *l);
void env_spinlock_unlock(env_spinlock *l); void env_spinlock_unlock(env_spinlock *l);
void env_spinlock_lock_irq(env_spinlock *l);
void env_spinlock_unlock_irq(env_spinlock *l);
#define env_spinlock_lock_irqsave(l, flags) \ #define env_spinlock_lock_irqsave(l, flags) \
env_spinlock_lock(l); (void)flags; env_spinlock_lock(l); (void)flags;
@ -286,10 +266,6 @@ typedef struct {
Coroutine *co; Coroutine *co;
} env_waitqueue; } env_waitqueue;
void env_waitqueue_init(env_waitqueue *w);
void env_waitqueue_wake_up(env_waitqueue *w);
#define env_waitqueue_wait(w, condition) \ #define env_waitqueue_wait(w, condition) \
({ \ ({ \
int __ret = 0; \ int __ret = 0; \
@ -314,8 +290,6 @@ bool env_bit_test(int nr, const volatile unsigned long *addr);
void env_touch_softlockup_wd(void); void env_touch_softlockup_wd(void);
void env_schedule(void);
int env_in_interrupt(void); int env_in_interrupt(void);
uint64_t env_get_tick_count(void); uint64_t env_get_tick_count(void);