Remove calls to OCF_METADATA_(UN)LOCK_WR(RD)

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski 2019-08-01 16:54:26 -04:00
parent 2333d837fb
commit d2bd807e49
11 changed files with 48 additions and 72 deletions

View File

@ -392,7 +392,7 @@ static ocf_cache_line_t _acp_trylock_dirty(struct ocf_cache *cache,
struct ocf_map_info info; struct ocf_map_info info;
bool locked = false; bool locked = false;
OCF_METADATA_LOCK_RD(); ocf_metadata_hash_lock_rd(&cache->metadata.lock, core_id, core_line);
ocf_engine_lookup_map_entry(cache, &info, core_id, ocf_engine_lookup_map_entry(cache, &info, core_id,
core_line); core_line);
@ -403,7 +403,7 @@ static ocf_cache_line_t _acp_trylock_dirty(struct ocf_cache *cache,
locked = true; locked = true;
} }
OCF_METADATA_UNLOCK_RD(); ocf_metadata_hash_unlock_rd(&cache->metadata.lock, core_id, core_line);
return locked ? info.coll_idx : cache->device->collision_table_entries; return locked ? info.coll_idx : cache->device->collision_table_entries;
} }

View File

@ -779,7 +779,7 @@ static void alru_clean(struct alru_flush_ctx *fctx)
return; return;
} }
if (OCF_METADATA_LOCK_WR_TRY()) { if (ocf_metadata_try_start_exclusive_access(&cache->metadata.lock)) {
alru_clean_complete(fctx, 0); alru_clean_complete(fctx, 0);
return; return;
} }
@ -797,7 +797,7 @@ static void alru_clean(struct alru_flush_ctx *fctx)
fctx->flush_perfomed = true; fctx->flush_perfomed = true;
ocf_cleaner_do_flush_data_async(cache, fctx->flush_data, to_clean, ocf_cleaner_do_flush_data_async(cache, fctx->flush_data, to_clean,
&fctx->attribs); &fctx->attribs);
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
return; return;
} }
@ -806,7 +806,7 @@ static void alru_clean(struct alru_flush_ctx *fctx)
env_ticks_to_secs(env_get_tick_count()); env_ticks_to_secs(env_get_tick_count());
end: end:
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
alru_clean_complete(fctx, 0); alru_clean_complete(fctx, 0);
} }

View File

@ -79,24 +79,6 @@ static inline void ocf_metadata_status_bits_unlock(
ENV_BUG(); ENV_BUG();
} }
#define OCF_METADATA_LOCK_RD() ocf_metadata_start_shared_access( \
&cache->metadata.lock)
#define OCF_METADATA_UNLOCK_RD() ocf_metadata_end_shared_access( \
&cache->metadata.lock)
#define OCF_METADATA_LOCK_RD_TRY() ocf_metadata_try_start_shared_access( \
&cache->metadata.lock)
#define OCF_METADATA_LOCK_WR() ocf_metadata_start_exclusive_access( \
&cache->metadata.lock)
#define OCF_METADATA_LOCK_WR_TRY() \
ocf_metadata_try_start_exclusive_access(&cache->metadata.lock)
#define OCF_METADATA_UNLOCK_WR() ocf_metadata_end_exclusive_access( \
&cache->metadata.lock)
#define OCF_METADATA_BITS_LOCK_RD() \ #define OCF_METADATA_BITS_LOCK_RD() \
ocf_metadata_status_bits_lock(&cache->metadata.lock, \ ocf_metadata_status_bits_lock(&cache->metadata.lock, \
OCF_METADATA_RD) OCF_METADATA_RD)

View File

@ -113,17 +113,17 @@ ocf_cache_line_t ocf_metadata_get_cachelines_count(ocf_cache_t cache)
void ocf_metadata_flush_all(ocf_cache_t cache, void ocf_metadata_flush_all(ocf_cache_t cache,
ocf_metadata_end_t cmpl, void *priv) ocf_metadata_end_t cmpl, void *priv)
{ {
OCF_METADATA_LOCK_WR(); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
cache->metadata.iface.flush_all(cache, cmpl, priv); cache->metadata.iface.flush_all(cache, cmpl, priv);
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
} }
void ocf_metadata_load_all(ocf_cache_t cache, void ocf_metadata_load_all(ocf_cache_t cache,
ocf_metadata_end_t cmpl, void *priv) ocf_metadata_end_t cmpl, void *priv)
{ {
OCF_METADATA_LOCK_WR(); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
cache->metadata.iface.load_all(cache, cmpl, priv); cache->metadata.iface.load_all(cache, cmpl, priv);
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
} }
void ocf_metadata_load_recovery(ocf_cache_t cache, void ocf_metadata_load_recovery(ocf_cache_t cache,

View File

@ -1903,7 +1903,7 @@ static void _recovery_rebuild_metadata(ocf_pipeline_t pipeline,
const uint64_t collision_table_entries = const uint64_t collision_table_entries =
ocf_metadata_collision_table_entries(cache); ocf_metadata_collision_table_entries(cache);
OCF_METADATA_LOCK_WR(); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
for (cline = 0; cline < collision_table_entries; cline++) { for (cline = 0; cline < collision_table_entries; cline++) {
ocf_metadata_get_core_info(cache, cline, &core_id, &core_line); ocf_metadata_get_core_info(cache, cline, &core_id, &core_line);
@ -1923,7 +1923,7 @@ static void _recovery_rebuild_metadata(ocf_pipeline_t pipeline,
OCF_COND_RESCHED(step, 128); OCF_COND_RESCHED(step, 128);
} }
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
ocf_pipeline_next(pipeline); ocf_pipeline_next(pipeline);
} }

View File

@ -226,9 +226,9 @@ static int ocf_restart_meta_io(struct ocf_request *req)
int ret; int ret;
/* Fill with the latest metadata. */ /* Fill with the latest metadata. */
OCF_METADATA_LOCK_RD(); /* TODO: synchronize with concurrent metadata io and hash bucket locks
*/
metadata_io_req_fill(meta_io_req); metadata_io_req_fill(meta_io_req);
OCF_METADATA_UNLOCK_RD();
io = ocf_new_cache_io(cache, req->io_queue, io = ocf_new_cache_io(cache, req->io_queue,
PAGES_TO_BYTES(meta_io_req->page), PAGES_TO_BYTES(meta_io_req->page),

View File

@ -292,7 +292,6 @@ static ocf_error_t init_attached_data_structures(ocf_cache_t cache,
ocf_error_t result; ocf_error_t result;
/* Lock to ensure consistency */ /* Lock to ensure consistency */
OCF_METADATA_LOCK_WR();
ocf_metadata_init_hash_table(cache); ocf_metadata_init_hash_table(cache);
ocf_metadata_init_collision(cache); ocf_metadata_init_collision(cache);
@ -303,7 +302,6 @@ static ocf_error_t init_attached_data_structures(ocf_cache_t cache,
if (result) { if (result) {
ocf_cache_log(cache, log_err, ocf_cache_log(cache, log_err,
"Cannot initialize cleaning policy\n"); "Cannot initialize cleaning policy\n");
OCF_METADATA_UNLOCK_WR();
return result; return result;
} }
@ -313,24 +311,19 @@ static ocf_error_t init_attached_data_structures(ocf_cache_t cache,
ocf_cache_log(cache, log_err, ocf_cache_log(cache, log_err,
"Cannot initialize promotion policy\n"); "Cannot initialize promotion policy\n");
__deinit_cleaning_policy(cache); __deinit_cleaning_policy(cache);
OCF_METADATA_UNLOCK_WR();
return result; return result;
} }
OCF_METADATA_UNLOCK_WR();
return 0; return 0;
} }
static void init_attached_data_structures_recovery(ocf_cache_t cache) static void init_attached_data_structures_recovery(ocf_cache_t cache)
{ {
OCF_METADATA_LOCK_WR();
ocf_metadata_init_hash_table(cache); ocf_metadata_init_hash_table(cache);
ocf_metadata_init_collision(cache); ocf_metadata_init_collision(cache);
__init_partitions_attached(cache); __init_partitions_attached(cache);
__reset_stats(cache); __reset_stats(cache);
__init_metadata_version(cache); __init_metadata_version(cache);
OCF_METADATA_UNLOCK_WR();
} }
/**************************************************************** /****************************************************************
@ -2242,11 +2235,11 @@ int ocf_mngt_cache_promotion_set_policy(ocf_cache_t cache, ocf_promotion_t type)
{ {
int result; int result;
OCF_METADATA_LOCK_WR(); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
result = ocf_promotion_set_policy(cache->promotion_policy, type); result = ocf_promotion_set_policy(cache->promotion_policy, type);
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
return result; return result;
} }
@ -2255,11 +2248,11 @@ ocf_promotion_t ocf_mngt_cache_promotion_get_policy(ocf_cache_t cache)
{ {
ocf_promotion_t result; ocf_promotion_t result;
OCF_METADATA_LOCK_RD(); ocf_metadata_start_shared_access(&cache->metadata.lock);
result = cache->conf_meta->promotion_policy_type; result = cache->conf_meta->promotion_policy_type;
OCF_METADATA_UNLOCK_RD(); ocf_metadata_end_shared_access(&cache->metadata.lock);
return result; return result;
} }
@ -2269,12 +2262,12 @@ int ocf_mngt_cache_promotion_get_param(ocf_cache_t cache, uint8_t param_id,
{ {
int result; int result;
OCF_METADATA_LOCK_RD(); ocf_metadata_start_shared_access(&cache->metadata.lock);
result = ocf_promotion_get_param(cache->promotion_policy, param_id, result = ocf_promotion_get_param(cache->promotion_policy, param_id,
param_value); param_value);
OCF_METADATA_UNLOCK_RD(); ocf_metadata_end_shared_access(&cache->metadata.lock);
return result; return result;
} }
@ -2284,12 +2277,12 @@ int ocf_mngt_cache_promotion_set_param(ocf_cache_t cache, uint8_t param_id,
{ {
int result; int result;
OCF_METADATA_LOCK_RD(); ocf_metadata_start_shared_access(&cache->metadata.lock);
result = ocf_promotion_set_param(cache->promotion_policy, param_id, result = ocf_promotion_set_param(cache->promotion_policy, param_id,
param_value); param_value);
OCF_METADATA_UNLOCK_RD(); ocf_metadata_end_shared_access(&cache->metadata.lock);
return result; return result;
} }

View File

@ -39,7 +39,7 @@ void cache_mngt_core_remove_from_cleaning_pol(ocf_core_t core)
ocf_core_id_t core_id = ocf_core_get_id(core); ocf_core_id_t core_id = ocf_core_get_id(core);
ocf_cleaning_t clean_pol_type; ocf_cleaning_t clean_pol_type;
OCF_METADATA_LOCK_WR(); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
clean_pol_type = cache->conf_meta->cleaning_policy_type; clean_pol_type = cache->conf_meta->cleaning_policy_type;
if (cache->core[core_id].opened) { if (cache->core[core_id].opened) {
@ -49,7 +49,7 @@ void cache_mngt_core_remove_from_cleaning_pol(ocf_core_t core)
} }
} }
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
} }
/* Deinitialize core metadata in attached metadata */ /* Deinitialize core metadata in attached metadata */
@ -65,7 +65,7 @@ void cache_mngt_core_deinit_attached_meta(ocf_core_t core)
if (!core_size) if (!core_size)
core_size = ~0ULL; core_size = ~0ULL;
OCF_METADATA_LOCK_WR(); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
clean_pol_type = cache->conf_meta->cleaning_policy_type; clean_pol_type = cache->conf_meta->cleaning_policy_type;
while (retry) { while (retry) {
@ -82,13 +82,14 @@ void cache_mngt_core_deinit_attached_meta(ocf_core_t core)
} }
if (retry) { if (retry) {
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
env_msleep(100); env_msleep(100);
OCF_METADATA_LOCK_WR(); ocf_metadata_start_exclusive_access(
&cache->metadata.lock);
} }
} }
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
} }
/* Mark core as removed in metadata */ /* Mark core as removed in metadata */
@ -96,7 +97,7 @@ void cache_mngt_core_remove_from_meta(ocf_core_t core)
{ {
ocf_cache_t cache = ocf_core_get_cache(core); ocf_cache_t cache = ocf_core_get_cache(core);
OCF_METADATA_LOCK_WR(); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
/* In metadata mark data this core was removed from cache */ /* In metadata mark data this core was removed from cache */
core->conf_meta->valid = false; core->conf_meta->valid = false;
@ -105,7 +106,7 @@ void cache_mngt_core_remove_from_meta(ocf_core_t core)
ocf_mngt_core_clear_uuid_metadata(core); ocf_mngt_core_clear_uuid_metadata(core);
core->conf_meta->seq_no = OCF_SEQ_NO_INVALID; core->conf_meta->seq_no = OCF_SEQ_NO_INVALID;
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
} }
/* Deinit in-memory structures related to this core */ /* Deinit in-memory structures related to this core */

View File

@ -385,9 +385,9 @@ static int _ofc_flush_container_step(struct ocf_request *req)
struct flush_container *fc = req->priv; struct flush_container *fc = req->priv;
ocf_cache_t cache = fc->cache; ocf_cache_t cache = fc->cache;
OCF_METADATA_LOCK_WR(); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
_ocf_mngt_flush_portion(fc); _ocf_mngt_flush_portion(fc);
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
return 0; return 0;
} }
@ -501,7 +501,7 @@ static void _ocf_mngt_flush_core(
return; return;
} }
OCF_METADATA_LOCK_WR(); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
ret = _ocf_mngt_get_sectors(cache, core_id, ret = _ocf_mngt_get_sectors(cache, core_id,
&fc->flush_data, &fc->count); &fc->flush_data, &fc->count);
@ -509,7 +509,7 @@ static void _ocf_mngt_flush_core(
ocf_core_log(core, log_err, "Flushing operation aborted, " ocf_core_log(core, log_err, "Flushing operation aborted, "
"no memory\n"); "no memory\n");
env_vfree(fc); env_vfree(fc);
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
complete(context, -OCF_ERR_NO_MEM); complete(context, -OCF_ERR_NO_MEM);
return; return;
} }
@ -519,7 +519,7 @@ static void _ocf_mngt_flush_core(
_ocf_mngt_flush_containers(context, fc, 1, complete); _ocf_mngt_flush_containers(context, fc, 1, complete);
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
} }
static void _ocf_mngt_flush_all_cores( static void _ocf_mngt_flush_all_cores(
@ -538,21 +538,21 @@ static void _ocf_mngt_flush_all_cores(
env_atomic_set(&cache->flush_in_progress, 1); env_atomic_set(&cache->flush_in_progress, 1);
OCF_METADATA_LOCK_WR(); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
/* Get all 'dirty' sectors for all cores */ /* Get all 'dirty' sectors for all cores */
ret = _ocf_mngt_get_flush_containers(cache, &fctbl, &fcnum); ret = _ocf_mngt_get_flush_containers(cache, &fctbl, &fcnum);
if (ret) { if (ret) {
ocf_cache_log(cache, log_err, "Flushing operation aborted, " ocf_cache_log(cache, log_err, "Flushing operation aborted, "
"no memory\n"); "no memory\n");
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
complete(context, ret); complete(context, ret);
return; return;
} }
_ocf_mngt_flush_containers(context, fctbl, fcnum, complete); _ocf_mngt_flush_containers(context, fctbl, fcnum, complete);
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
} }
static void _ocf_mngt_flush_all_cores_complete( static void _ocf_mngt_flush_all_cores_complete(
@ -774,10 +774,10 @@ static void _ocf_mngt_cache_invalidate(ocf_pipeline_t pipeline, void *priv,
ocf_cache_t cache = context->cache; ocf_cache_t cache = context->cache;
int result; int result;
OCF_METADATA_LOCK_WR(); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
result = ocf_metadata_sparse_range(cache, context->purge.core_id, 0, result = ocf_metadata_sparse_range(cache, context->purge.core_id, 0,
context->purge.end_byte); context->purge.end_byte);
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
OCF_PL_NEXT_ON_SUCCESS_RET(context->pipeline, result); OCF_PL_NEXT_ON_SUCCESS_RET(context->pipeline, result);
} }
@ -907,7 +907,7 @@ int ocf_mngt_cache_cleaning_set_policy(ocf_cache_t cache, ocf_cleaning_t type)
return 0; return 0;
} }
OCF_METADATA_LOCK_WR(); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
if (cleaning_policy_ops[old_type].deinitialize) if (cleaning_policy_ops[old_type].deinitialize)
cleaning_policy_ops[old_type].deinitialize(cache); cleaning_policy_ops[old_type].deinitialize(cache);
@ -925,7 +925,7 @@ int ocf_mngt_cache_cleaning_set_policy(ocf_cache_t cache, ocf_cleaning_t type)
cache->conf_meta->cleaning_policy_type = type; cache->conf_meta->cleaning_policy_type = type;
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
ocf_cache_log(cache, log_info, "Changing cleaning policy from " ocf_cache_log(cache, log_info, "Changing cleaning policy from "
"%s to %s\n", cleaning_policy_ops[old_type].name, "%s to %s\n", cleaning_policy_ops[old_type].name,
@ -957,12 +957,12 @@ int ocf_mngt_cache_cleaning_set_param(ocf_cache_t cache, ocf_cleaning_t type,
if (!cleaning_policy_ops[type].set_cleaning_param) if (!cleaning_policy_ops[type].set_cleaning_param)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
OCF_METADATA_LOCK_WR(); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
ret = cleaning_policy_ops[type].set_cleaning_param(cache, ret = cleaning_policy_ops[type].set_cleaning_param(cache,
param_id, param_value); param_id, param_value);
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
return ret; return ret;
} }

View File

@ -275,7 +275,7 @@ int ocf_mngt_cache_io_classes_configure(ocf_cache_t cache,
if (!old_config) if (!old_config)
return -OCF_ERR_NO_MEM; return -OCF_ERR_NO_MEM;
OCF_METADATA_LOCK_WR(); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
result = env_memcpy(old_config, sizeof(cache->user_parts), result = env_memcpy(old_config, sizeof(cache->user_parts),
cache->user_parts, sizeof(cache->user_parts)); cache->user_parts, sizeof(cache->user_parts));
@ -300,7 +300,7 @@ out_edit:
} }
out_cpy: out_cpy:
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
env_free(old_config); env_free(old_config);
return result; return result;

View File

@ -320,7 +320,7 @@ static int _ocf_cleaner_update_metadata(struct ocf_request *req)
OCF_DEBUG_TRACE(req->cache); OCF_DEBUG_TRACE(req->cache);
OCF_METADATA_LOCK_WR(); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
/* Update metadata */ /* Update metadata */
for (i = 0; i < req->core_line_count; i++, iter++) { for (i = 0; i < req->core_line_count; i++, iter++) {
if (iter->status == LOOKUP_MISS) if (iter->status == LOOKUP_MISS)
@ -345,7 +345,7 @@ static int _ocf_cleaner_update_metadata(struct ocf_request *req)
} }
ocf_metadata_flush_do_asynch(cache, req, _ocf_cleaner_metadata_io_end); ocf_metadata_flush_do_asynch(cache, req, _ocf_cleaner_metadata_io_end);
OCF_METADATA_UNLOCK_WR(); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
return 0; return 0;
} }