From 0b39711b8b0ac4f29dc366d9051c9c28e40ddd87 Mon Sep 17 00:00:00 2001 From: Rafal Stefanowski Date: Fri, 29 Oct 2021 13:23:06 +0200 Subject: [PATCH] Add promote-on-threshold sequential cutoff switch Decide whether to promote sequential cutoff stream to global structures when threshold is reached Signed-off-by: Rafal Stefanowski --- inc/ocf_core.h | 10 +++++++ inc/ocf_mngt.h | 49 ++++++++++++++++++++++++++++++++++ src/mngt/ocf_mngt_core.c | 57 ++++++++++++++++++++++++++++++++++++++++ src/ocf_core.c | 5 ++++ src/ocf_core_priv.h | 3 +++ src/ocf_seq_cutoff.c | 6 +++-- 6 files changed, 128 insertions(+), 2 deletions(-) diff --git a/inc/ocf_core.h b/inc/ocf_core.h index cd3fe4a..04fff9b 100644 --- a/inc/ocf_core.h +++ b/inc/ocf_core.h @@ -118,6 +118,16 @@ ocf_seq_cutoff_policy ocf_core_get_seq_cutoff_policy(ocf_core_t core); */ uint32_t ocf_core_get_seq_cutoff_promotion_count(ocf_core_t core); +/** + * @brief Whether to promote sequential cutoff stream + * to global structures when threshold is reached + * + * @param[in] core Core object + * + * @retval Sequential cutoff stream promote_on_threshold switch value + */ +bool ocf_core_get_seq_cutoff_promote_on_threshold(ocf_core_t core); + /** * @brief Get name of given core object * diff --git a/inc/ocf_mngt.h b/inc/ocf_mngt.h index c8a0f96..9a65dfb 100644 --- a/inc/ocf_mngt.h +++ b/inc/ocf_mngt.h @@ -45,6 +45,9 @@ struct ocf_mngt_core_config { uint32_t seq_cutoff_promotion_count; /*!< Sequential cutoff promotion request count */ + bool seq_cutoff_promote_on_threshold; + /*!< Sequential cutoff promote on threshold */ + struct { void *data; size_t size; @@ -65,6 +68,7 @@ static inline void ocf_mngt_core_config_set_default( cfg->try_add = false; cfg->seq_cutoff_threshold = 1024; cfg->seq_cutoff_promotion_count = 8; + cfg->seq_cutoff_promote_on_threshold = false; cfg->user_metadata.data = NULL; cfg->user_metadata.size = 0; } @@ -1109,6 +1113,7 @@ int ocf_mngt_core_set_seq_cutoff_promotion_count(ocf_core_t core, */ int ocf_mngt_core_set_seq_cutoff_promotion_count_all(ocf_cache_t cache, uint32_t count); + /** * @brief Get core sequential cutoff promotion threshold * @@ -1121,6 +1126,50 @@ int ocf_mngt_core_set_seq_cutoff_promotion_count_all(ocf_cache_t cache, int ocf_mngt_core_get_seq_cutoff_promotion_count(ocf_core_t core, uint32_t *count); +/** + * @brief Set whether to promote core sequential cutoff stream + * to global structures when threshold is reached + * + * @attention This changes only runtime state. To make changes persistent + * use function ocf_mngt_cache_save(). + * + * @param[in] core Core handle + * @param[in] promote Whether to promote or not + * + * @retval 0 Sequential cutoff promote on threshold has been set successfully + * @retval Non-zero Error occured and promote on threshold hasn't been updated + */ +int ocf_mngt_core_set_seq_cutoff_promote_on_threshold(ocf_core_t core, + bool promote); + +/** + * @brief Set whether to promote sequential cutoff stream + * to global structures when threshold is reached for all cores in cache + * + * @attention This changes only runtime state. To make changes persistent + * use function ocf_mngt_cache_save(). + * + * @param[in] cache Cache handle + * @param[in] promote Whether to promote or not + * + * @retval 0 Sequential cutoff promote on threshold has been set successfully + * @retval Non-zero Error occured and promote on threshold hasn't been updated + */ +int ocf_mngt_core_set_seq_cutoff_promote_on_threshold_all(ocf_cache_t cache, + bool promote); + +/** + * @brief Get core sequential cutoff promote on threshold switch value + * + * @param[in] core Core handle + * @param[out] promote Promote on threshold + * + * @retval 0 Sequential cutoff promote on threshold retrieved successfully + * @retval Non-zero Error occured and value could not be retrieved + */ +int ocf_mngt_core_get_seq_cutoff_promote_on_threshold(ocf_core_t core, + bool *promote); + /** * @brief Set cache fallback Pass Through error threshold * diff --git a/src/mngt/ocf_mngt_core.c b/src/mngt/ocf_mngt_core.c index 6890249..b535068 100644 --- a/src/mngt/ocf_mngt_core.c +++ b/src/mngt/ocf_mngt_core.c @@ -472,6 +472,8 @@ static void ocf_mngt_cache_add_core_insert(ocf_pipeline_t pipeline, cfg->seq_cutoff_threshold); env_atomic_set(&core->conf_meta->seq_cutoff_promo_count, cfg->seq_cutoff_promotion_count); + env_atomic_set(&core->conf_meta->seq_cutoff_promote_on_threshold, + cfg->seq_cutoff_promote_on_threshold); /* Add core sequence number for atomic metadata matching */ core_sequence_no = _ocf_mngt_get_core_seq_no(cache); @@ -1103,3 +1105,58 @@ int ocf_mngt_core_get_seq_cutoff_promotion_count(ocf_core_t core, return 0; } + +static int _cache_mngt_set_core_seq_cutoff_promote_on_threshold( + ocf_core_t core, void *cntx) +{ + bool promote = *(bool*) cntx; + bool promote_old = ocf_core_get_seq_cutoff_promote_on_threshold(core); + + if (promote_old == promote) { + ocf_core_log(core, log_info, + "Sequential cutoff promote on threshold " + "is already set to %s\n", promote ? "true" : "false"); + return 0; + } + + env_atomic_set(&core->conf_meta->seq_cutoff_promote_on_threshold, + promote); + + ocf_core_log(core, log_info, "Changing sequential cutoff promote " + "on threshold from %s to %s successful\n", + promote_old ? "true" : "false", promote ? "true" : "false"); + + return 0; +} + +int ocf_mngt_core_set_seq_cutoff_promote_on_threshold(ocf_core_t core, + bool promote) +{ + OCF_CHECK_NULL(core); + + return _cache_mngt_set_core_seq_cutoff_promote_on_threshold(core, &promote); +} + +int ocf_mngt_core_set_seq_cutoff_promote_on_threshold_all(ocf_cache_t cache, + bool promote) +{ + OCF_CHECK_NULL(cache); + + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; + + return ocf_core_visit(cache, + _cache_mngt_set_core_seq_cutoff_promote_on_threshold, + &promote, true); +} + +int ocf_mngt_core_get_seq_cutoff_promote_on_threshold(ocf_core_t core, + bool *promote) +{ + OCF_CHECK_NULL(core); + OCF_CHECK_NULL(promote); + + *promote = ocf_core_get_seq_cutoff_promote_on_threshold(core); + + return 0; +} diff --git a/src/ocf_core.c b/src/ocf_core.c index 56cb054..0c327f6 100644 --- a/src/ocf_core.c +++ b/src/ocf_core.c @@ -121,6 +121,11 @@ uint32_t ocf_core_get_seq_cutoff_promotion_count(ocf_core_t core) return env_atomic_read(&core->conf_meta->seq_cutoff_promo_count); } +bool ocf_core_get_seq_cutoff_promote_on_threshold(ocf_core_t core) +{ + return env_atomic_read(&core->conf_meta->seq_cutoff_promote_on_threshold); +} + int ocf_core_visit(ocf_cache_t cache, ocf_core_visitor_t visitor, void *cntx, bool only_opened) { diff --git a/src/ocf_core_priv.h b/src/ocf_core_priv.h index 68bb879..879d93c 100644 --- a/src/ocf_core_priv.h +++ b/src/ocf_core_priv.h @@ -47,6 +47,9 @@ struct ocf_core_meta_config { /* Sequential cutoff stream promotion request count */ env_atomic seq_cutoff_promo_count; + /* Sequential cutoff stream promote on threshold */ + env_atomic seq_cutoff_promote_on_threshold; + /* core object size in bytes */ uint64_t length; diff --git a/src/ocf_seq_cutoff.c b/src/ocf_seq_cutoff.c index 1c8e811..a85bf97 100644 --- a/src/ocf_seq_cutoff.c +++ b/src/ocf_seq_cutoff.c @@ -300,13 +300,15 @@ void ocf_core_seq_cutoff_update(ocf_core_t core, struct ocf_request *req) uint32_t threshold = ocf_core_get_seq_cutoff_threshold(core); uint32_t promotion_count = ocf_core_get_seq_cutoff_promotion_count(core); + bool promote_on_threshold = + ocf_core_get_seq_cutoff_promote_on_threshold(core); struct ocf_seq_cutoff_stream *stream; bool promote = false; if (policy == ocf_seq_cutoff_policy_never) return; - if (req->byte_length >= threshold) + if (req->byte_length >= threshold && promote_on_threshold) promote = true; if (promotion_count == 1) @@ -328,7 +330,7 @@ void ocf_core_seq_cutoff_update(ocf_core_t core, struct ocf_request *req) req->byte_position, req->byte_length, req->rw, true); env_rwlock_write_unlock(&req->io_queue->seq_cutoff->lock); - if (stream->bytes >= threshold) + if (stream->bytes >= threshold && promote_on_threshold) promote = true; if (stream->req_count >= promotion_count)