Move metadata concurrency to a separate file
Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
parent
aa02f56b05
commit
e5bed8825c
18
src/concurrency/ocf_metadata_concurrency.c
Normal file
18
src/concurrency/ocf_metadata_concurrency.c
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright(c) 2019-2019 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
|
||||
#include "ocf_metadata_concurrency.h"
|
||||
|
||||
void ocf_metadata_concurrency_init(struct ocf_cache *cache)
|
||||
{
|
||||
env_spinlock_init(&cache->metadata.lock.eviction);
|
||||
env_rwlock_init(&cache->metadata.lock.status);
|
||||
env_rwsem_init(&cache->metadata.lock.collision);
|
||||
}
|
||||
|
||||
int ocf_metadata_concurrency_attached_init(struct ocf_cache *cache)
|
||||
{
|
||||
return 0;
|
||||
}
|
132
src/concurrency/ocf_metadata_concurrency.h
Normal file
132
src/concurrency/ocf_metadata_concurrency.h
Normal file
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright(c) 2019-2019 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
#include "../ocf_cache_priv.h"
|
||||
|
||||
#ifndef __OCF_METADATA_CONCURRENCY_H__
|
||||
#define __OCF_METADATA_CONCURRENCY_H__
|
||||
|
||||
#define OCF_METADATA_RD 0
|
||||
#define OCF_METADATA_WR 1
|
||||
|
||||
void ocf_metadata_concurrency_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)
|
||||
{
|
||||
env_spinlock_lock(&cache->metadata.lock.eviction);
|
||||
}
|
||||
|
||||
static inline void ocf_metadata_eviction_unlock(struct ocf_cache *cache)
|
||||
{
|
||||
env_spinlock_unlock(&cache->metadata.lock.eviction);
|
||||
}
|
||||
|
||||
#define OCF_METADATA_EVICTION_LOCK() \
|
||||
ocf_metadata_eviction_lock(cache)
|
||||
|
||||
#define OCF_METADATA_EVICTION_UNLOCK() \
|
||||
ocf_metadata_eviction_unlock(cache)
|
||||
|
||||
static inline void ocf_metadata_lock(struct ocf_cache *cache, int rw)
|
||||
{
|
||||
if (rw == OCF_METADATA_WR)
|
||||
env_rwsem_down_write(&cache->metadata.lock.collision);
|
||||
else if (rw == OCF_METADATA_RD)
|
||||
env_rwsem_down_read(&cache->metadata.lock.collision);
|
||||
else
|
||||
ENV_BUG();
|
||||
}
|
||||
|
||||
|
||||
static inline void ocf_metadata_unlock(struct ocf_cache *cache, int rw)
|
||||
{
|
||||
if (rw == OCF_METADATA_WR)
|
||||
env_rwsem_up_write(&cache->metadata.lock.collision);
|
||||
else if (rw == OCF_METADATA_RD)
|
||||
env_rwsem_up_read(&cache->metadata.lock.collision);
|
||||
else
|
||||
ENV_BUG();
|
||||
}
|
||||
|
||||
static inline int ocf_metadata_try_lock(struct ocf_cache *cache, int rw)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (rw == OCF_METADATA_WR) {
|
||||
result = env_rwsem_down_write_trylock(
|
||||
&cache->metadata.lock.collision);
|
||||
} else if (rw == OCF_METADATA_RD) {
|
||||
result = env_rwsem_down_read_trylock(
|
||||
&cache->metadata.lock.collision);
|
||||
} else {
|
||||
ENV_BUG();
|
||||
}
|
||||
|
||||
if (result)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void ocf_metadata_status_bits_lock(
|
||||
struct ocf_cache *cache, int rw)
|
||||
{
|
||||
if (rw == OCF_METADATA_WR)
|
||||
env_rwlock_write_lock(&cache->metadata.lock.status);
|
||||
else if (rw == OCF_METADATA_RD)
|
||||
env_rwlock_read_lock(&cache->metadata.lock.status);
|
||||
else
|
||||
ENV_BUG();
|
||||
}
|
||||
|
||||
static inline void ocf_metadata_status_bits_unlock(
|
||||
struct ocf_cache *cache, int rw)
|
||||
{
|
||||
if (rw == OCF_METADATA_WR)
|
||||
env_rwlock_write_unlock(&cache->metadata.lock.status);
|
||||
else if (rw == OCF_METADATA_RD)
|
||||
env_rwlock_read_unlock(&cache->metadata.lock.status);
|
||||
else
|
||||
ENV_BUG();
|
||||
}
|
||||
|
||||
#define OCF_METADATA_LOCK_RD() \
|
||||
ocf_metadata_lock(cache, OCF_METADATA_RD)
|
||||
|
||||
#define OCF_METADATA_UNLOCK_RD() \
|
||||
ocf_metadata_unlock(cache, OCF_METADATA_RD)
|
||||
|
||||
#define OCF_METADATA_LOCK_RD_TRY() \
|
||||
ocf_metadata_try_lock(cache, OCF_METADATA_RD)
|
||||
|
||||
#define OCF_METADATA_LOCK_WR() \
|
||||
ocf_metadata_lock(cache, OCF_METADATA_WR)
|
||||
|
||||
#define OCF_METADATA_LOCK_WR_TRY() \
|
||||
ocf_metadata_try_lock(cache, OCF_METADATA_WR)
|
||||
|
||||
#define OCF_METADATA_UNLOCK_WR() \
|
||||
ocf_metadata_unlock(cache, OCF_METADATA_WR)
|
||||
|
||||
#define OCF_METADATA_BITS_LOCK_RD() \
|
||||
ocf_metadata_status_bits_lock(cache, OCF_METADATA_RD)
|
||||
|
||||
#define OCF_METADATA_BITS_UNLOCK_RD() \
|
||||
ocf_metadata_status_bits_unlock(cache, OCF_METADATA_RD)
|
||||
|
||||
#define OCF_METADATA_BITS_LOCK_WR() \
|
||||
ocf_metadata_status_bits_lock(cache, OCF_METADATA_WR)
|
||||
|
||||
#define OCF_METADATA_BITS_UNLOCK_WR() \
|
||||
ocf_metadata_status_bits_unlock(cache, OCF_METADATA_WR)
|
||||
|
||||
#define OCF_METADATA_FLUSH_LOCK() \
|
||||
ocf_metadata_flush_lock(cache)
|
||||
|
||||
#define OCF_METADATA_FLUSH_UNLOCK() \
|
||||
ocf_metadata_flush_unlock(cache)
|
||||
|
||||
#endif
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "eviction.h"
|
||||
#include "../metadata/metadata.h"
|
||||
#include "../concurrency/ocf_metadata_concurrency.h"
|
||||
|
||||
/**
|
||||
* @brief Initialize cache line before adding it into eviction
|
||||
|
@ -41,6 +41,8 @@ int ocf_metadata_init(struct ocf_cache *cache,
|
||||
if (ret)
|
||||
ocf_metadata_io_deinit(cache);
|
||||
|
||||
ocf_metadata_concurrency_init(cache);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -9,122 +9,6 @@
|
||||
#include "metadata_common.h"
|
||||
#include "../ocf_cache_priv.h"
|
||||
#include "../ocf_ctx_priv.h"
|
||||
|
||||
static inline void ocf_metadata_eviction_lock(struct ocf_cache *cache)
|
||||
{
|
||||
env_spinlock_lock(&cache->metadata.lock.eviction);
|
||||
}
|
||||
|
||||
static inline void ocf_metadata_eviction_unlock(struct ocf_cache *cache)
|
||||
{
|
||||
env_spinlock_unlock(&cache->metadata.lock.eviction);
|
||||
}
|
||||
|
||||
#define OCF_METADATA_EVICTION_LOCK() \
|
||||
ocf_metadata_eviction_lock(cache)
|
||||
|
||||
#define OCF_METADATA_EVICTION_UNLOCK() \
|
||||
ocf_metadata_eviction_unlock(cache)
|
||||
|
||||
static inline void ocf_metadata_lock(struct ocf_cache *cache, int rw)
|
||||
{
|
||||
if (rw == OCF_METADATA_WR)
|
||||
env_rwsem_down_write(&cache->metadata.lock.collision);
|
||||
else if (rw == OCF_METADATA_RD)
|
||||
env_rwsem_down_read(&cache->metadata.lock.collision);
|
||||
else
|
||||
ENV_BUG();
|
||||
}
|
||||
|
||||
|
||||
static inline void ocf_metadata_unlock(struct ocf_cache *cache, int rw)
|
||||
{
|
||||
if (rw == OCF_METADATA_WR)
|
||||
env_rwsem_up_write(&cache->metadata.lock.collision);
|
||||
else if (rw == OCF_METADATA_RD)
|
||||
env_rwsem_up_read(&cache->metadata.lock.collision);
|
||||
else
|
||||
ENV_BUG();
|
||||
}
|
||||
|
||||
static inline int ocf_metadata_try_lock(struct ocf_cache *cache, int rw)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (rw == OCF_METADATA_WR) {
|
||||
result = env_rwsem_down_write_trylock(
|
||||
&cache->metadata.lock.collision);
|
||||
} else if (rw == OCF_METADATA_RD) {
|
||||
result = env_rwsem_down_read_trylock(
|
||||
&cache->metadata.lock.collision);
|
||||
} else {
|
||||
ENV_BUG();
|
||||
}
|
||||
|
||||
if (result)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void ocf_metadata_status_bits_lock(
|
||||
struct ocf_cache *cache, int rw)
|
||||
{
|
||||
if (rw == OCF_METADATA_WR)
|
||||
env_rwlock_write_lock(&cache->metadata.lock.status);
|
||||
else if (rw == OCF_METADATA_RD)
|
||||
env_rwlock_read_lock(&cache->metadata.lock.status);
|
||||
else
|
||||
ENV_BUG();
|
||||
}
|
||||
|
||||
static inline void ocf_metadata_status_bits_unlock(
|
||||
struct ocf_cache *cache, int rw)
|
||||
{
|
||||
if (rw == OCF_METADATA_WR)
|
||||
env_rwlock_write_unlock(&cache->metadata.lock.status);
|
||||
else if (rw == OCF_METADATA_RD)
|
||||
env_rwlock_read_unlock(&cache->metadata.lock.status);
|
||||
else
|
||||
ENV_BUG();
|
||||
}
|
||||
|
||||
#define OCF_METADATA_LOCK_RD() \
|
||||
ocf_metadata_lock(cache, OCF_METADATA_RD)
|
||||
|
||||
#define OCF_METADATA_UNLOCK_RD() \
|
||||
ocf_metadata_unlock(cache, OCF_METADATA_RD)
|
||||
|
||||
#define OCF_METADATA_LOCK_RD_TRY() \
|
||||
ocf_metadata_try_lock(cache, OCF_METADATA_RD)
|
||||
|
||||
#define OCF_METADATA_LOCK_WR() \
|
||||
ocf_metadata_lock(cache, OCF_METADATA_WR)
|
||||
|
||||
#define OCF_METADATA_LOCK_WR_TRY() \
|
||||
ocf_metadata_try_lock(cache, OCF_METADATA_WR)
|
||||
|
||||
#define OCF_METADATA_UNLOCK_WR() \
|
||||
ocf_metadata_unlock(cache, OCF_METADATA_WR)
|
||||
|
||||
#define OCF_METADATA_BITS_LOCK_RD() \
|
||||
ocf_metadata_status_bits_lock(cache, OCF_METADATA_RD)
|
||||
|
||||
#define OCF_METADATA_BITS_UNLOCK_RD() \
|
||||
ocf_metadata_status_bits_unlock(cache, OCF_METADATA_RD)
|
||||
|
||||
#define OCF_METADATA_BITS_LOCK_WR() \
|
||||
ocf_metadata_status_bits_lock(cache, OCF_METADATA_WR)
|
||||
|
||||
#define OCF_METADATA_BITS_UNLOCK_WR() \
|
||||
ocf_metadata_status_bits_unlock(cache, OCF_METADATA_WR)
|
||||
|
||||
#define OCF_METADATA_FLUSH_LOCK() \
|
||||
ocf_metadata_flush_lock(cache)
|
||||
|
||||
#define OCF_METADATA_FLUSH_UNLOCK() \
|
||||
ocf_metadata_flush_unlock(cache)
|
||||
|
||||
#include "metadata_cleaning_policy.h"
|
||||
#include "metadata_eviction_policy.h"
|
||||
#include "metadata_partition.h"
|
||||
|
@ -546,10 +546,6 @@ int ocf_metadata_hash_init(struct ocf_cache *cache,
|
||||
core->runtime_meta = &core_meta_runtime[core_id];
|
||||
}
|
||||
|
||||
env_spinlock_init(&cache->metadata.lock.eviction);
|
||||
env_rwlock_init(&cache->metadata.lock.status);
|
||||
env_rwsem_init(&cache->metadata.lock.collision);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,8 @@
|
||||
#ifndef __METADATA_STATUS_H__
|
||||
#define __METADATA_STATUS_H__
|
||||
|
||||
#include "../ocf_request.h"
|
||||
#include "../concurrency/ocf_metadata_concurrency.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Dirty
|
||||
******************************************************************************/
|
||||
|
@ -470,8 +470,4 @@ struct ocf_metadata {
|
||||
} lock;
|
||||
};
|
||||
|
||||
|
||||
#define OCF_METADATA_RD 0
|
||||
#define OCF_METADATA_WR 1
|
||||
|
||||
#endif /* __METADATA_STRUCTS_H__ */
|
||||
|
@ -1053,9 +1053,15 @@ static void _ocf_mngt_attach_prepare_metadata(ocf_pipeline_t pipeline,
|
||||
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_START_CACHE_FAIL);
|
||||
}
|
||||
|
||||
ocf_cache_log(cache, log_debug, "Cache attached\n");
|
||||
context->flags.attached_metadata_inited = true;
|
||||
|
||||
if (ocf_metadata_concurrency_attached_init(cache)) {
|
||||
ocf_cache_log(cache, log_err, "Failed to initialize attached "
|
||||
"metadata concurrency\n");
|
||||
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_START_CACHE_FAIL);
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < OCF_IO_CLASS_MAX + 1; ++i) {
|
||||
cache->user_parts[i].runtime =
|
||||
&cache->device->runtime_meta->user_parts[i];
|
||||
@ -1538,6 +1544,8 @@ static void _ocf_mngt_attach_post_init(ocf_pipeline_t pipeline,
|
||||
ocf_cleaner_refcnt_unfreeze(cache);
|
||||
ocf_refcnt_unfreeze(&cache->refcnt.metadata);
|
||||
|
||||
ocf_cache_log(cache, log_debug, "Cache attached\n");
|
||||
|
||||
ocf_pipeline_next(context->pipeline);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user