Use cleaning ops wrapper functions

Signed-off-by: Michal Mielewczyk <michal.mielewczyk@intel.com>
This commit is contained in:
Michal Mielewczyk 2021-07-19 15:52:04 +02:00
parent 00aa56dd28
commit 26194fc536
11 changed files with 34 additions and 144 deletions

View File

@ -13,7 +13,7 @@
#include "../mngt/ocf_mngt_common.h" #include "../mngt/ocf_mngt_common.h"
#include "../metadata/metadata.h" #include "../metadata/metadata.h"
#include "../ocf_queue_priv.h" #include "../ocf_queue_priv.h"
#include "cleaning_ops.c" #include "cleaning_ops.h"
int ocf_start_cleaner(ocf_cache_t cache) int ocf_start_cleaner(ocf_cache_t cache)
{ {
@ -82,7 +82,6 @@ static void ocf_cleaner_run_complete(ocf_cleaner_t cleaner, uint32_t interval)
void ocf_cleaner_run(ocf_cleaner_t cleaner, ocf_queue_t queue) void ocf_cleaner_run(ocf_cleaner_t cleaner, ocf_queue_t queue)
{ {
ocf_cache_t cache; ocf_cache_t cache;
ocf_cleaning_t clean_type;
OCF_CHECK_NULL(cleaner); OCF_CHECK_NULL(cleaner);
OCF_CHECK_NULL(queue); OCF_CHECK_NULL(queue);
@ -110,13 +109,8 @@ void ocf_cleaner_run(ocf_cleaner_t cleaner, ocf_queue_t queue)
return; return;
} }
clean_type = cache->conf_meta->cleaning_policy_type;
ENV_BUG_ON(clean_type >= ocf_cleaning_max);
ocf_queue_get(queue); ocf_queue_get(queue);
cleaner->io_queue = queue; cleaner->io_queue = queue;
cleaning_policy_ops[clean_type].perform_cleaning(cache, ocf_cleaning_perform_cleaning(cache, ocf_cleaner_run_complete);
ocf_cleaner_run_complete);
} }

View File

@ -38,27 +38,6 @@ struct cleaning_policy_meta {
} meta; } meta;
}; };
struct cleaning_policy_ops {
void (*setup)(ocf_cache_t cache);
int (*initialize)(ocf_cache_t cache, int init_metadata);
void (*deinitialize)(ocf_cache_t cache);
int (*add_core)(ocf_cache_t cache, ocf_core_id_t core_id);
void (*remove_core)(ocf_cache_t cache, ocf_core_id_t core_id);
void (*init_cache_block)(ocf_cache_t cache, uint32_t cache_line);
void (*purge_cache_block)(ocf_cache_t cache, uint32_t cache_line);
int (*purge_range)(ocf_cache_t cache, int core_id,
uint64_t start_byte, uint64_t end_byte);
void (*set_hot_cache_line)(ocf_cache_t cache, uint32_t cache_line);
int (*set_cleaning_param)(ocf_cache_t cache, uint32_t param_id,
uint32_t param_value);
int (*get_cleaning_param)(ocf_cache_t cache, uint32_t param_id,
uint32_t *param_value);
void (*perform_cleaning)(ocf_cache_t cache, ocf_cleaner_end_t cmpl);
const char *name;
};
extern struct cleaning_policy_ops cleaning_policy_ops[ocf_cleaning_max];
struct ocf_cleaner { struct ocf_cleaner {
void *cleaning_policy_context; void *cleaning_policy_context;
ocf_queue_t io_queue; ocf_queue_t io_queue;

View File

@ -300,7 +300,6 @@ void ocf_map_cache_line(struct ocf_request *req,
{ {
ocf_cache_t cache = req->cache; ocf_cache_t cache = req->cache;
ocf_core_id_t core_id = ocf_core_get_id(req->core); ocf_core_id_t core_id = ocf_core_get_id(req->core);
ocf_cleaning_t clean_policy_type;
unsigned int hash_index = req->map[idx].hash; unsigned int hash_index = req->map[idx].hash;
uint64_t core_line = req->core_line_first + idx; uint64_t core_line = req->core_line_first + idx;
@ -311,13 +310,8 @@ void ocf_map_cache_line(struct ocf_request *req,
ocf_metadata_end_collision_shared_access(cache, cache_line); ocf_metadata_end_collision_shared_access(cache, cache_line);
/* Update dirty cache-block list */ /* Update dirty cache-block list */
clean_policy_type = cache->conf_meta->cleaning_policy_type;
ENV_BUG_ON(clean_policy_type >= ocf_cleaning_max); ocf_cleaning_init_cache_block(cache, cache_line);
if (cleaning_policy_ops[clean_policy_type].init_cache_block != NULL)
cleaning_policy_ops[clean_policy_type].
init_cache_block(cache, cache_line);
req->map[idx].coll_idx = cache_line; req->map[idx].coll_idx = cache_line;
} }

View File

@ -1200,19 +1200,12 @@ static void _recovery_invalidate_clean_sec(struct ocf_cache *cache,
static void _recovery_reset_cline_metadata(struct ocf_cache *cache, static void _recovery_reset_cline_metadata(struct ocf_cache *cache,
ocf_cache_line_t cline) ocf_cache_line_t cline)
{ {
ocf_cleaning_t clean_policy_type;
ocf_metadata_set_core_info(cache, cline, OCF_CORE_MAX, ULLONG_MAX); ocf_metadata_set_core_info(cache, cline, OCF_CORE_MAX, ULLONG_MAX);
metadata_clear_valid(cache, cline); metadata_clear_valid(cache, cline);
clean_policy_type = cache->conf_meta->cleaning_policy_type; ocf_cleaning_init_cache_block(cache, cline);
ENV_BUG_ON(clean_policy_type >= ocf_cleaning_max);
if (cleaning_policy_ops[clean_policy_type].init_cache_block != NULL)
cleaning_policy_ops[clean_policy_type].
init_cache_block(cache, cline);
} }
static void _recovery_rebuild_metadata(ocf_pipeline_t pipeline, static void _recovery_rebuild_metadata(ocf_pipeline_t pipeline,

View File

@ -202,29 +202,20 @@ static ocf_error_t __init_cleaning_policy(ocf_cache_t cache)
{ {
ocf_cleaning_t cleaning_policy = ocf_cleaning_default; ocf_cleaning_t cleaning_policy = ocf_cleaning_default;
int i; int i;
ocf_error_t result = 0;
OCF_ASSERT_PLUGGED(cache); OCF_ASSERT_PLUGGED(cache);
for (i = 0; i < ocf_cleaning_max; i++) { for (i = 0; i < ocf_cleaning_max; i++)
if (cleaning_policy_ops[i].setup) ocf_cleaning_setup(cache, i);
cleaning_policy_ops[i].setup(cache);
}
cache->conf_meta->cleaning_policy_type = ocf_cleaning_default; cache->conf_meta->cleaning_policy_type = ocf_cleaning_default;
if (cleaning_policy_ops[cleaning_policy].initialize)
result = cleaning_policy_ops[cleaning_policy].initialize(cache, 1);
return result; return ocf_cleaning_initialize(cache, cleaning_policy, 1);
} }
static void __deinit_cleaning_policy(ocf_cache_t cache) static void __deinit_cleaning_policy(ocf_cache_t cache)
{ {
ocf_cleaning_t cleaning_policy; ocf_cleaning_deinitialize(cache);
cleaning_policy = cache->conf_meta->cleaning_policy_type;
if (cleaning_policy_ops[cleaning_policy].deinitialize)
cleaning_policy_ops[cleaning_policy].deinitialize(cache);
} }
static void __setup_promotion_policy(ocf_cache_t cache) static void __setup_promotion_policy(ocf_cache_t cache)
@ -470,13 +461,11 @@ void _ocf_mngt_load_init_instance_complete(void *priv, int error)
__populate_free(cache); __populate_free(cache);
cleaning_policy = cache->conf_meta->cleaning_policy_type; cleaning_policy = cache->conf_meta->cleaning_policy_type;
if (!cleaning_policy_ops[cleaning_policy].initialize)
goto out;
if (context->metadata.shutdown_status == ocf_metadata_clean_shutdown) if (context->metadata.shutdown_status == ocf_metadata_clean_shutdown)
result = cleaning_policy_ops[cleaning_policy].initialize(cache, 0); result = ocf_cleaning_initialize(cache, cleaning_policy, 0);
else else
result = cleaning_policy_ops[cleaning_policy].initialize(cache, 1); result = ocf_cleaning_initialize(cache, cleaning_policy, 1);
if (result) { if (result) {
ocf_cache_log(cache, log_err, ocf_cache_log(cache, log_err,
@ -484,7 +473,6 @@ void _ocf_mngt_load_init_instance_complete(void *priv, int error)
OCF_PL_FINISH_RET(context->pipeline, result); OCF_PL_FINISH_RET(context->pipeline, result);
} }
out:
ocf_pipeline_next(context->pipeline); ocf_pipeline_next(context->pipeline);
} }
@ -2074,7 +2062,7 @@ static void _ocf_mngt_cache_load_log(ocf_cache_t cache)
ocf_cache_log(cache, log_info, "Cache mode : %s\n", ocf_cache_log(cache, log_info, "Cache mode : %s\n",
_ocf_cache_mode_get_name(cache_mode)); _ocf_cache_mode_get_name(cache_mode));
ocf_cache_log(cache, log_info, "Cleaning policy : %s\n", ocf_cache_log(cache, log_info, "Cleaning policy : %s\n",
cleaning_policy_ops[cleaning_type].name); ocf_cleaning_get_name(cleaning_type));
ocf_cache_log(cache, log_info, "Promotion policy : %s\n", ocf_cache_log(cache, log_info, "Promotion policy : %s\n",
ocf_promotion_policies[promotion_type].name); ocf_promotion_policies[promotion_type].name);
ocf_core_visit(cache, _ocf_mngt_cache_load_core_log, ocf_core_visit(cache, _ocf_mngt_cache_load_core_log,

View File

@ -36,15 +36,10 @@ void cache_mngt_core_remove_from_cleaning_pol(ocf_core_t core)
{ {
ocf_cache_t cache = ocf_core_get_cache(core); ocf_cache_t cache = ocf_core_get_cache(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_metadata_start_exclusive_access(&cache->metadata.lock); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
clean_pol_type = cache->conf_meta->cleaning_policy_type; ocf_cleaning_remove_core(cache, core_id);
if (cleaning_policy_ops[clean_pol_type].remove_core) {
cleaning_policy_ops[clean_pol_type].
remove_core(cache, core_id);
}
ocf_metadata_end_exclusive_access(&cache->metadata.lock); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
} }

View File

@ -12,7 +12,7 @@
#include "../utils/utils_pipeline.h" #include "../utils/utils_pipeline.h"
#include "../ocf_stats_priv.h" #include "../ocf_stats_priv.h"
#include "../ocf_def_priv.h" #include "../ocf_def_priv.h"
#include "../cleaning/cleaning_ops.c" #include "../cleaning/cleaning_ops.h"
static ocf_seq_no_t _ocf_mngt_get_core_seq_no(ocf_cache_t cache) static ocf_seq_no_t _ocf_mngt_get_core_seq_no(ocf_cache_t cache)
{ {
@ -124,14 +124,12 @@ static void _ocf_mngt_cache_add_core_handle_error(
ocf_core_t core = context->core; ocf_core_t core = context->core;
ocf_core_id_t core_id; ocf_core_id_t core_id;
ocf_volume_t volume; ocf_volume_t volume;
ocf_cleaning_t clean_type;
if (!core) if (!core)
return; return;
core_id = ocf_core_get_id(core); core_id = ocf_core_get_id(core);
volume = &core->volume; volume = &core->volume;
clean_type = cache->conf_meta->cleaning_policy_type;
if (context->flags.counters_allocated) { if (context->flags.counters_allocated) {
env_bit_clear(core_id, env_bit_clear(core_id,
@ -144,11 +142,8 @@ static void _ocf_mngt_cache_add_core_handle_error(
core->counters = NULL; core->counters = NULL;
} }
if (context->flags.clean_pol_added) { if (context->flags.clean_pol_added)
if (cleaning_policy_ops[clean_type].remove_core) ocf_cleaning_remove_core(cache, core_id);
cleaning_policy_ops[clean_type].remove_core(cache,
core_id);
}
if (context->flags.cutoff_initialized) if (context->flags.cutoff_initialized)
ocf_core_seq_cutoff_deinit(core); ocf_core_seq_cutoff_deinit(core);
@ -376,7 +371,6 @@ static void ocf_mngt_cache_add_core_insert(ocf_pipeline_t pipeline,
ocf_volume_t volume; ocf_volume_t volume;
ocf_volume_type_t type; ocf_volume_type_t type;
ocf_seq_no_t core_sequence_no; ocf_seq_no_t core_sequence_no;
ocf_cleaning_t clean_type;
uint64_t length; uint64_t length;
int i, result = 0; int i, result = 0;
@ -428,11 +422,8 @@ static void ocf_mngt_cache_add_core_insert(ocf_pipeline_t pipeline,
core->conf_meta->length = length; core->conf_meta->length = length;
clean_type = cache->conf_meta->cleaning_policy_type; if (ocf_cache_is_device_attached(cache)) {
if (ocf_cache_is_device_attached(cache) && result = ocf_cleaning_add_core(cache, core_id);
cleaning_policy_ops[clean_type].add_core) {
result = cleaning_policy_ops[clean_type].add_core(cache,
core_id);
if (result) if (result)
OCF_PL_FINISH_RET(pipeline, result); OCF_PL_FINISH_RET(pipeline, result);

View File

@ -915,17 +915,15 @@ int ocf_mngt_cache_cleaning_set_policy(ocf_cache_t cache, ocf_cleaning_t type)
if (type == old_type) { if (type == old_type) {
ocf_cache_log(cache, log_info, "Cleaning policy %s is already " ocf_cache_log(cache, log_info, "Cleaning policy %s is already "
"set\n", cleaning_policy_ops[old_type].name); "set\n", ocf_cleaning_get_name(old_type));
return 0; return 0;
} }
ocf_metadata_start_exclusive_access(&cache->metadata.lock); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
if (cleaning_policy_ops[old_type].deinitialize) ocf_cleaning_deinitialize(cache);
cleaning_policy_ops[old_type].deinitialize(cache);
if (cleaning_policy_ops[type].initialize) { if (ocf_cleaning_initialize(cache, type, 1)) {
if (cleaning_policy_ops[type].initialize(cache, 1)) {
/* /*
* If initialization of new cleaning policy failed, * If initialization of new cleaning policy failed,
* we set cleaning policy to nop. * we set cleaning policy to nop.
@ -933,15 +931,14 @@ int ocf_mngt_cache_cleaning_set_policy(ocf_cache_t cache, ocf_cleaning_t type)
type = ocf_cleaning_nop; type = ocf_cleaning_nop;
ret = -OCF_ERR_INVAL; ret = -OCF_ERR_INVAL;
} }
}
cache->conf_meta->cleaning_policy_type = type; cache->conf_meta->cleaning_policy_type = type;
ocf_metadata_end_exclusive_access(&cache->metadata.lock); 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", ocf_cleaning_get_name(old_type),
cleaning_policy_ops[type].name); ocf_cleaning_get_name(type));
return ret; return ret;
} }
@ -966,13 +963,9 @@ int ocf_mngt_cache_cleaning_set_param(ocf_cache_t cache, ocf_cleaning_t type,
if (type < 0 || type >= ocf_cleaning_max) if (type < 0 || type >= ocf_cleaning_max)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
if (!cleaning_policy_ops[type].set_cleaning_param)
return -OCF_ERR_INVAL;
ocf_metadata_start_exclusive_access(&cache->metadata.lock); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
ret = cleaning_policy_ops[type].set_cleaning_param(cache, ret = ocf_cleaning_set_param(cache, type, param_id, param_value);
param_id, param_value);
ocf_metadata_end_exclusive_access(&cache->metadata.lock); ocf_metadata_end_exclusive_access(&cache->metadata.lock);
@ -982,19 +975,11 @@ int ocf_mngt_cache_cleaning_set_param(ocf_cache_t cache, ocf_cleaning_t type,
int ocf_mngt_cache_cleaning_get_param(ocf_cache_t cache, ocf_cleaning_t type, int ocf_mngt_cache_cleaning_get_param(ocf_cache_t cache, ocf_cleaning_t type,
uint32_t param_id, uint32_t *param_value) uint32_t param_id, uint32_t *param_value)
{ {
int ret;
OCF_CHECK_NULL(cache); OCF_CHECK_NULL(cache);
OCF_CHECK_NULL(param_value); OCF_CHECK_NULL(param_value);
if (type < 0 || type >= ocf_cleaning_max) if (type < 0 || type >= ocf_cleaning_max)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
if (!cleaning_policy_ops[type].get_cleaning_param) return ocf_cleaning_get_param(cache, type, param_id, param_value);
return -OCF_ERR_INVAL;
ret = cleaning_policy_ops[type].get_cleaning_param(cache,
param_id, param_value);
return ret;
} }

View File

@ -6,19 +6,6 @@
#include "utils_cache_line.h" #include "utils_cache_line.h"
#include "../promotion/promotion.h" #include "../promotion/promotion.h"
void ocf_cleaning_set_hot_cache_line(struct ocf_cache *cache,
ocf_cache_line_t line)
{
ocf_cleaning_t cleaning_type = cache->conf_meta->cleaning_policy_type;
ENV_BUG_ON(cleaning_type >= ocf_cleaning_max);
if (cleaning_policy_ops[cleaning_type].set_hot_cache_line) {
cleaning_policy_ops[cleaning_type].
set_hot_cache_line(cache, line);
}
}
static void __set_cache_line_invalid(struct ocf_cache *cache, uint8_t start_bit, static void __set_cache_line_invalid(struct ocf_cache *cache, uint8_t start_bit,
uint8_t end_bit, ocf_cache_line_t line, uint8_t end_bit, ocf_cache_line_t line,
ocf_core_id_t core_id, ocf_part_id_t part_id) ocf_core_id_t core_id, ocf_part_id_t part_id)
@ -178,6 +165,5 @@ void set_cache_line_dirty(struct ocf_cache *cache, uint8_t start_bit,
} }
} }
ocf_cleaning_set_hot_cache_line(cache, line); ocf_cleaning_set_hot_cache_line(cache, line);
} }

View File

@ -12,7 +12,7 @@
#include "../engine/cache_engine.h" #include "../engine/cache_engine.h"
#include "../ocf_request.h" #include "../ocf_request.h"
#include "../ocf_def_priv.h" #include "../ocf_def_priv.h"
#include "../cleaning/cleaning_ops.c" #include "../cleaning/cleaning_ops.h"
/** /**
* @file utils_cache_line.h * @file utils_cache_line.h
@ -69,9 +69,6 @@ static inline uint64_t ocf_lines_2_bytes(struct ocf_cache *cache,
return lines * ocf_line_size(cache); return lines * ocf_line_size(cache);
} }
void ocf_cleaning_set_hot_cache_line(struct ocf_cache *cache,
ocf_cache_line_t line);
/** /**
* @brief Set cache line invalid * @brief Set cache line invalid
* *
@ -162,13 +159,8 @@ void set_cache_line_dirty(struct ocf_cache *cache, uint8_t start_bit,
static inline void ocf_purge_cleaning_policy(struct ocf_cache *cache, static inline void ocf_purge_cleaning_policy(struct ocf_cache *cache,
ocf_cache_line_t line) ocf_cache_line_t line)
{ {
ocf_cleaning_t clean_type = cache->conf_meta->cleaning_policy_type;
ENV_BUG_ON(clean_type >= ocf_cleaning_max);
/* Remove from cleaning policy */ /* Remove from cleaning policy */
if (cleaning_policy_ops[clean_type].purge_cache_block != NULL) ocf_cleaning_purge_cache_block(cache, line);
cleaning_policy_ops[clean_type].purge_cache_block(cache, line);
} }
/** /**

View File

@ -99,9 +99,6 @@ void ocf_user_part_move(struct ocf_request *req)
ocf_cache_line_t line; ocf_cache_line_t line;
ocf_part_id_t id_old, id_new; ocf_part_id_t id_old, id_new;
uint32_t i; uint32_t i;
ocf_cleaning_t type = cache->conf_meta->cleaning_policy_type;
ENV_BUG_ON(type >= ocf_cleaning_max);
entry = &req->map[0]; entry = &req->map[0];
for (i = 0; i < req->core_line_count; i++, entry++) { for (i = 0; i < req->core_line_count; i++, entry++) {
@ -141,9 +138,7 @@ void ocf_user_part_move(struct ocf_request *req)
* TODO: Consider adding update_cache_line() ops * TODO: Consider adding update_cache_line() ops
* to cleaning policy to let policies handle this. * to cleaning policy to let policies handle this.
*/ */
if (cleaning_policy_ops[type].purge_cache_block) ocf_cleaning_purge_cache_block(cache, line);
cleaning_policy_ops[type].
purge_cache_block(cache, line);
} }
ocf_lru_repart(cache, line, &cache->user_parts[id_old].part, ocf_lru_repart(cache, line, &cache->user_parts[id_old].part,
@ -155,9 +150,7 @@ void ocf_user_part_move(struct ocf_request *req)
*/ */
if (metadata_test_dirty(cache, line)) { if (metadata_test_dirty(cache, line)) {
/* Add cline back to cleaning policy */ /* Add cline back to cleaning policy */
if (cleaning_policy_ops[type].set_hot_cache_line) ocf_cleaning_set_hot_cache_line(cache, line);
cleaning_policy_ops[type].
set_hot_cache_line(cache, line);
env_atomic_inc(&req->core->runtime_meta-> env_atomic_inc(&req->core->runtime_meta->
part_counters[id_new].dirty_clines); part_counters[id_new].dirty_clines);