From d2bd807e49d776fb115ccc9fe724e85bd449f098 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Thu, 1 Aug 2019 16:54:26 -0400 Subject: [PATCH] Remove calls to OCF_METADATA_(UN)LOCK_WR(RD) Signed-off-by: Adam Rutkowski --- src/cleaning/acp.c | 4 ++-- src/cleaning/alru.c | 6 ++--- src/concurrency/ocf_metadata_concurrency.h | 18 -------------- src/metadata/metadata.c | 8 +++---- src/metadata/metadata_hash.c | 4 ++-- src/metadata/metadata_io.c | 4 ++-- src/mngt/ocf_mngt_cache.c | 23 +++++++----------- src/mngt/ocf_mngt_common.c | 17 ++++++------- src/mngt/ocf_mngt_flush.c | 28 +++++++++++----------- src/mngt/ocf_mngt_io_class.c | 4 ++-- src/utils/utils_cleaner.c | 4 ++-- 11 files changed, 48 insertions(+), 72 deletions(-) diff --git a/src/cleaning/acp.c b/src/cleaning/acp.c index 533f4e6..1a1d1d9 100644 --- a/src/cleaning/acp.c +++ b/src/cleaning/acp.c @@ -392,7 +392,7 @@ static ocf_cache_line_t _acp_trylock_dirty(struct ocf_cache *cache, struct ocf_map_info info; 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, core_line); @@ -403,7 +403,7 @@ static ocf_cache_line_t _acp_trylock_dirty(struct ocf_cache *cache, 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; } diff --git a/src/cleaning/alru.c b/src/cleaning/alru.c index 91c6781..e3e08f4 100644 --- a/src/cleaning/alru.c +++ b/src/cleaning/alru.c @@ -779,7 +779,7 @@ static void alru_clean(struct alru_flush_ctx *fctx) return; } - if (OCF_METADATA_LOCK_WR_TRY()) { + if (ocf_metadata_try_start_exclusive_access(&cache->metadata.lock)) { alru_clean_complete(fctx, 0); return; } @@ -797,7 +797,7 @@ static void alru_clean(struct alru_flush_ctx *fctx) fctx->flush_perfomed = true; ocf_cleaner_do_flush_data_async(cache, fctx->flush_data, to_clean, &fctx->attribs); - OCF_METADATA_UNLOCK_WR(); + ocf_metadata_end_exclusive_access(&cache->metadata.lock); return; } @@ -806,7 +806,7 @@ static void alru_clean(struct alru_flush_ctx *fctx) env_ticks_to_secs(env_get_tick_count()); end: - OCF_METADATA_UNLOCK_WR(); + ocf_metadata_end_exclusive_access(&cache->metadata.lock); alru_clean_complete(fctx, 0); } diff --git a/src/concurrency/ocf_metadata_concurrency.h b/src/concurrency/ocf_metadata_concurrency.h index c085c97..0875237 100644 --- a/src/concurrency/ocf_metadata_concurrency.h +++ b/src/concurrency/ocf_metadata_concurrency.h @@ -79,24 +79,6 @@ static inline void ocf_metadata_status_bits_unlock( 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() \ ocf_metadata_status_bits_lock(&cache->metadata.lock, \ OCF_METADATA_RD) diff --git a/src/metadata/metadata.c b/src/metadata/metadata.c index 5e5d02f..ddcd247 100644 --- a/src/metadata/metadata.c +++ b/src/metadata/metadata.c @@ -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, 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); - OCF_METADATA_UNLOCK_WR(); + ocf_metadata_end_exclusive_access(&cache->metadata.lock); } void ocf_metadata_load_all(ocf_cache_t cache, 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); - OCF_METADATA_UNLOCK_WR(); + ocf_metadata_end_exclusive_access(&cache->metadata.lock); } void ocf_metadata_load_recovery(ocf_cache_t cache, diff --git a/src/metadata/metadata_hash.c b/src/metadata/metadata_hash.c index 628df6d..8bb59f3 100644 --- a/src/metadata/metadata_hash.c +++ b/src/metadata/metadata_hash.c @@ -1903,7 +1903,7 @@ static void _recovery_rebuild_metadata(ocf_pipeline_t pipeline, const uint64_t collision_table_entries = 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++) { 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_METADATA_UNLOCK_WR(); + ocf_metadata_end_exclusive_access(&cache->metadata.lock); ocf_pipeline_next(pipeline); } diff --git a/src/metadata/metadata_io.c b/src/metadata/metadata_io.c index 35183a3..859c5e2 100644 --- a/src/metadata/metadata_io.c +++ b/src/metadata/metadata_io.c @@ -226,9 +226,9 @@ static int ocf_restart_meta_io(struct ocf_request *req) int ret; /* 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); - OCF_METADATA_UNLOCK_RD(); io = ocf_new_cache_io(cache, req->io_queue, PAGES_TO_BYTES(meta_io_req->page), diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 22b8558..84e2084 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -292,7 +292,6 @@ static ocf_error_t init_attached_data_structures(ocf_cache_t cache, ocf_error_t result; /* Lock to ensure consistency */ - OCF_METADATA_LOCK_WR(); ocf_metadata_init_hash_table(cache); ocf_metadata_init_collision(cache); @@ -303,7 +302,6 @@ static ocf_error_t init_attached_data_structures(ocf_cache_t cache, if (result) { ocf_cache_log(cache, log_err, "Cannot initialize cleaning policy\n"); - OCF_METADATA_UNLOCK_WR(); return result; } @@ -313,24 +311,19 @@ static ocf_error_t init_attached_data_structures(ocf_cache_t cache, ocf_cache_log(cache, log_err, "Cannot initialize promotion policy\n"); __deinit_cleaning_policy(cache); - OCF_METADATA_UNLOCK_WR(); return result; } - OCF_METADATA_UNLOCK_WR(); - return 0; } static void init_attached_data_structures_recovery(ocf_cache_t cache) { - OCF_METADATA_LOCK_WR(); ocf_metadata_init_hash_table(cache); ocf_metadata_init_collision(cache); __init_partitions_attached(cache); __reset_stats(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; - OCF_METADATA_LOCK_WR(); + ocf_metadata_start_exclusive_access(&cache->metadata.lock); result = ocf_promotion_set_policy(cache->promotion_policy, type); - OCF_METADATA_UNLOCK_WR(); + ocf_metadata_end_exclusive_access(&cache->metadata.lock); return result; } @@ -2255,11 +2248,11 @@ ocf_promotion_t ocf_mngt_cache_promotion_get_policy(ocf_cache_t cache) { ocf_promotion_t result; - OCF_METADATA_LOCK_RD(); + ocf_metadata_start_shared_access(&cache->metadata.lock); result = cache->conf_meta->promotion_policy_type; - OCF_METADATA_UNLOCK_RD(); + ocf_metadata_end_shared_access(&cache->metadata.lock); return result; } @@ -2269,12 +2262,12 @@ int ocf_mngt_cache_promotion_get_param(ocf_cache_t cache, uint8_t param_id, { int result; - OCF_METADATA_LOCK_RD(); + ocf_metadata_start_shared_access(&cache->metadata.lock); result = ocf_promotion_get_param(cache->promotion_policy, param_id, param_value); - OCF_METADATA_UNLOCK_RD(); + ocf_metadata_end_shared_access(&cache->metadata.lock); return result; } @@ -2284,12 +2277,12 @@ int ocf_mngt_cache_promotion_set_param(ocf_cache_t cache, uint8_t param_id, { int result; - OCF_METADATA_LOCK_RD(); + ocf_metadata_start_shared_access(&cache->metadata.lock); result = ocf_promotion_set_param(cache->promotion_policy, param_id, param_value); - OCF_METADATA_UNLOCK_RD(); + ocf_metadata_end_shared_access(&cache->metadata.lock); return result; } diff --git a/src/mngt/ocf_mngt_common.c b/src/mngt/ocf_mngt_common.c index bc21cd0..2ab6118 100644 --- a/src/mngt/ocf_mngt_common.c +++ b/src/mngt/ocf_mngt_common.c @@ -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_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; 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 */ @@ -65,7 +65,7 @@ void cache_mngt_core_deinit_attached_meta(ocf_core_t core) if (!core_size) core_size = ~0ULL; - OCF_METADATA_LOCK_WR(); + ocf_metadata_start_exclusive_access(&cache->metadata.lock); clean_pol_type = cache->conf_meta->cleaning_policy_type; while (retry) { @@ -82,13 +82,14 @@ void cache_mngt_core_deinit_attached_meta(ocf_core_t core) } if (retry) { - OCF_METADATA_UNLOCK_WR(); + ocf_metadata_end_exclusive_access(&cache->metadata.lock); 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 */ @@ -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_METADATA_LOCK_WR(); + ocf_metadata_start_exclusive_access(&cache->metadata.lock); /* In metadata mark data this core was removed from cache */ 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); 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 */ diff --git a/src/mngt/ocf_mngt_flush.c b/src/mngt/ocf_mngt_flush.c index 237e80e..3bfdee4 100644 --- a/src/mngt/ocf_mngt_flush.c +++ b/src/mngt/ocf_mngt_flush.c @@ -385,9 +385,9 @@ static int _ofc_flush_container_step(struct ocf_request *req) struct flush_container *fc = req->priv; ocf_cache_t cache = fc->cache; - OCF_METADATA_LOCK_WR(); + ocf_metadata_start_exclusive_access(&cache->metadata.lock); _ocf_mngt_flush_portion(fc); - OCF_METADATA_UNLOCK_WR(); + ocf_metadata_end_exclusive_access(&cache->metadata.lock); return 0; } @@ -501,7 +501,7 @@ static void _ocf_mngt_flush_core( return; } - OCF_METADATA_LOCK_WR(); + ocf_metadata_start_exclusive_access(&cache->metadata.lock); ret = _ocf_mngt_get_sectors(cache, core_id, &fc->flush_data, &fc->count); @@ -509,7 +509,7 @@ static void _ocf_mngt_flush_core( ocf_core_log(core, log_err, "Flushing operation aborted, " "no memory\n"); env_vfree(fc); - OCF_METADATA_UNLOCK_WR(); + ocf_metadata_end_exclusive_access(&cache->metadata.lock); complete(context, -OCF_ERR_NO_MEM); return; } @@ -519,7 +519,7 @@ static void _ocf_mngt_flush_core( _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( @@ -538,21 +538,21 @@ static void _ocf_mngt_flush_all_cores( 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 */ ret = _ocf_mngt_get_flush_containers(cache, &fctbl, &fcnum); if (ret) { ocf_cache_log(cache, log_err, "Flushing operation aborted, " "no memory\n"); - OCF_METADATA_UNLOCK_WR(); + ocf_metadata_end_exclusive_access(&cache->metadata.lock); complete(context, ret); return; } _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( @@ -774,10 +774,10 @@ static void _ocf_mngt_cache_invalidate(ocf_pipeline_t pipeline, void *priv, ocf_cache_t cache = context->cache; 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, 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); } @@ -907,7 +907,7 @@ int ocf_mngt_cache_cleaning_set_policy(ocf_cache_t cache, ocf_cleaning_t type) return 0; } - OCF_METADATA_LOCK_WR(); + ocf_metadata_start_exclusive_access(&cache->metadata.lock); if (cleaning_policy_ops[old_type].deinitialize) 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; - OCF_METADATA_UNLOCK_WR(); + ocf_metadata_end_exclusive_access(&cache->metadata.lock); ocf_cache_log(cache, log_info, "Changing cleaning policy from " "%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) 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, param_id, param_value); - OCF_METADATA_UNLOCK_WR(); + ocf_metadata_end_exclusive_access(&cache->metadata.lock); return ret; } diff --git a/src/mngt/ocf_mngt_io_class.c b/src/mngt/ocf_mngt_io_class.c index ae0f086..cb42f93 100644 --- a/src/mngt/ocf_mngt_io_class.c +++ b/src/mngt/ocf_mngt_io_class.c @@ -275,7 +275,7 @@ int ocf_mngt_cache_io_classes_configure(ocf_cache_t cache, if (!old_config) 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), cache->user_parts, sizeof(cache->user_parts)); @@ -300,7 +300,7 @@ out_edit: } out_cpy: - OCF_METADATA_UNLOCK_WR(); + ocf_metadata_end_exclusive_access(&cache->metadata.lock); env_free(old_config); return result; diff --git a/src/utils/utils_cleaner.c b/src/utils/utils_cleaner.c index 6f9aa23..41b425e 100644 --- a/src/utils/utils_cleaner.c +++ b/src/utils/utils_cleaner.c @@ -320,7 +320,7 @@ static int _ocf_cleaner_update_metadata(struct ocf_request *req) OCF_DEBUG_TRACE(req->cache); - OCF_METADATA_LOCK_WR(); + ocf_metadata_start_exclusive_access(&cache->metadata.lock); /* Update metadata */ for (i = 0; i < req->core_line_count; i++, iter++) { 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_UNLOCK_WR(); + ocf_metadata_end_exclusive_access(&cache->metadata.lock); return 0; }