Initialize promotion policy on cache attach.
Signed-off-by: Michal Mielewczyk <michal.mielewczyk@intel.com>
This commit is contained in:
@@ -27,7 +27,7 @@ void nhit_setup(ocf_cache_t cache)
|
||||
cfg->trigger_threshold = OCF_NHIT_TRIGGER_DEFAULT;
|
||||
}
|
||||
|
||||
ocf_error_t nhit_init(ocf_cache_t cache, ocf_promotion_policy_t policy)
|
||||
ocf_error_t nhit_init(ocf_cache_t cache)
|
||||
{
|
||||
struct nhit_policy_context *ctx;
|
||||
int result = 0;
|
||||
@@ -43,7 +43,7 @@ ocf_error_t nhit_init(ocf_cache_t cache, ocf_promotion_policy_t policy)
|
||||
if (result)
|
||||
goto dealloc_ctx;
|
||||
|
||||
policy->ctx = ctx;
|
||||
cache->promotion_policy->ctx = ctx;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -172,7 +172,7 @@ static bool core_line_should_promote(ocf_promotion_policy_t policy,
|
||||
bool hit;
|
||||
int32_t counter;
|
||||
|
||||
cfg = (void *)&policy->owner->conf_meta->promotion[ocf_promotion_nhit].data;
|
||||
cfg = (struct nhit_promotion_policy_config*)policy->config;
|
||||
ctx = policy->ctx;
|
||||
|
||||
hit = nhit_hash_query(ctx->hash_map, core_id, core_lba, &counter);
|
||||
@@ -197,7 +197,7 @@ bool nhit_req_should_promote(ocf_promotion_policy_t policy,
|
||||
ocf_metadata_collision_table_entries(policy->owner) -
|
||||
ocf_freelist_num_free(policy->owner->freelist);
|
||||
|
||||
cfg = (void *)&policy->owner->conf_meta->promotion[ocf_promotion_nhit].data;
|
||||
cfg = (struct nhit_promotion_policy_config*)policy->config;
|
||||
|
||||
if (occupied_cachelines < OCF_DIV_ROUND_UP(
|
||||
((uint64_t)cfg->trigger_threshold *
|
||||
|
@@ -13,7 +13,7 @@
|
||||
|
||||
void nhit_setup(ocf_cache_t cache);
|
||||
|
||||
ocf_error_t nhit_init(ocf_cache_t cache, ocf_promotion_policy_t policy);
|
||||
ocf_error_t nhit_init(ocf_cache_t cache);
|
||||
|
||||
void nhit_deinit(ocf_promotion_policy_t policy);
|
||||
|
||||
|
@@ -13,6 +13,10 @@ struct ocf_promotion_policy {
|
||||
ocf_cache_t owner;
|
||||
|
||||
ocf_promotion_t type;
|
||||
|
||||
void *config;
|
||||
/* Pointer to config values stored in cache superblock */
|
||||
|
||||
void *ctx;
|
||||
};
|
||||
|
||||
@@ -23,7 +27,7 @@ struct promotion_policy_ops {
|
||||
void (*setup)(ocf_cache_t cache);
|
||||
/*!< initialize promotion policy default config */
|
||||
|
||||
ocf_error_t (*init)(ocf_cache_t cache, ocf_promotion_policy_t policy);
|
||||
ocf_error_t (*init)(ocf_cache_t cache);
|
||||
/*!< Allocate and initialize promotion policy */
|
||||
|
||||
void (*deinit)(ocf_promotion_policy_t policy);
|
||||
|
@@ -25,22 +25,30 @@ struct promotion_policy_ops ocf_promotion_policies[ocf_promotion_max] = {
|
||||
},
|
||||
};
|
||||
|
||||
ocf_error_t ocf_promotion_init(ocf_cache_t cache, ocf_promotion_policy_t *policy)
|
||||
ocf_error_t ocf_promotion_init(ocf_cache_t cache, ocf_promotion_t type)
|
||||
{
|
||||
ocf_promotion_t type = cache->conf_meta->promotion_policy_type;
|
||||
ocf_promotion_policy_t policy;
|
||||
ocf_error_t result = 0;
|
||||
|
||||
ENV_BUG_ON(type >= ocf_promotion_max);
|
||||
|
||||
*policy = env_vmalloc(sizeof(**policy));
|
||||
if (!*policy)
|
||||
policy = env_vmalloc(sizeof(*policy));
|
||||
if (!policy)
|
||||
return -OCF_ERR_NO_MEM;
|
||||
|
||||
(*policy)->type = type;
|
||||
(*policy)->owner = cache;
|
||||
policy->type = type;
|
||||
policy->owner = cache;
|
||||
policy->config =
|
||||
(void *)&cache->conf_meta->promotion[type].data;
|
||||
cache->promotion_policy = policy;
|
||||
|
||||
if (ocf_promotion_policies[type].init)
|
||||
result = ocf_promotion_policies[type].init(cache, *policy);
|
||||
result = ocf_promotion_policies[type].init(cache);
|
||||
|
||||
if (result) {
|
||||
env_vfree(cache->promotion_policy);
|
||||
cache->promotion_policy = NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -82,7 +90,7 @@ ocf_error_t ocf_promotion_set_policy(ocf_promotion_policy_t policy,
|
||||
policy->type = type;
|
||||
|
||||
if (ocf_promotion_policies[type].init)
|
||||
result = ocf_promotion_policies[type].init(cache, policy);
|
||||
result = ocf_promotion_policies[type].init(cache);
|
||||
|
||||
if (result) {
|
||||
ocf_cache_log(cache, log_err,
|
||||
@@ -96,8 +104,8 @@ ocf_error_t ocf_promotion_set_policy(ocf_promotion_policy_t policy,
|
||||
return result;
|
||||
}
|
||||
|
||||
ocf_error_t ocf_promotion_set_param(ocf_cache_t cache, uint8_t param_id,
|
||||
ocf_promotion_t type, uint32_t param_value)
|
||||
ocf_error_t ocf_promotion_set_param(ocf_cache_t cache, ocf_promotion_t type,
|
||||
uint8_t param_id, uint32_t param_value)
|
||||
{
|
||||
ocf_error_t result = -OCF_ERR_INVAL;
|
||||
|
||||
@@ -111,8 +119,8 @@ ocf_error_t ocf_promotion_set_param(ocf_cache_t cache, uint8_t param_id,
|
||||
return result;
|
||||
}
|
||||
|
||||
ocf_error_t ocf_promotion_get_param(ocf_cache_t cache, uint8_t param_id,
|
||||
ocf_promotion_t type, uint32_t *param_value)
|
||||
ocf_error_t ocf_promotion_get_param(ocf_cache_t cache, ocf_promotion_t type,
|
||||
uint8_t param_id, uint32_t *param_value)
|
||||
{
|
||||
ocf_error_t result = -OCF_ERR_INVAL;
|
||||
|
||||
|
@@ -34,11 +34,11 @@ void ocf_promotion_setup(ocf_cache_t cache);
|
||||
* been set.
|
||||
*
|
||||
* @param[in] cache OCF cache instance
|
||||
* @param[out] param initialized policy handle
|
||||
* @param[in] type type of promotion policy to initialize
|
||||
*
|
||||
* @retval ocf_error_t
|
||||
*/
|
||||
ocf_error_t ocf_promotion_init(ocf_cache_t cache, ocf_promotion_policy_t *policy);
|
||||
ocf_error_t ocf_promotion_init(ocf_cache_t cache, ocf_promotion_t type);
|
||||
|
||||
/**
|
||||
* @brief Stop, deinitialize and free promotion policy structures.
|
||||
@@ -63,27 +63,27 @@ ocf_error_t ocf_promotion_set_policy(ocf_promotion_policy_t policy,
|
||||
* @brief Set promotion policy parameter
|
||||
*
|
||||
* @param[in] cache cache handle
|
||||
* @param[in] type id of promotion policy to be configured
|
||||
* @param[in] param_id id of parameter to be set
|
||||
* @param[in] type id of propmotion policy to be configured
|
||||
* @param[in] param_value value of parameter to be set
|
||||
*
|
||||
* @retval ocf_error_t
|
||||
*/
|
||||
ocf_error_t ocf_promotion_set_param(ocf_cache_t cache, uint8_t param_id,
|
||||
ocf_promotion_t type, uint32_t param_value);
|
||||
ocf_error_t ocf_promotion_set_param(ocf_cache_t cache, ocf_promotion_t type,
|
||||
uint8_t param_id, uint32_t param_value);
|
||||
|
||||
/**
|
||||
* @brief Get promotion policy parameter
|
||||
*
|
||||
* @param[in] cache cache handle
|
||||
* @param[in] type id of promotion policy to be configured
|
||||
* @param[in] param_id id of parameter to be set
|
||||
* @param[in] type id of propmotion policy to be configured
|
||||
* @param[out] param_value value of parameter to be set
|
||||
*
|
||||
* @retval ocf_error_t
|
||||
*/
|
||||
ocf_error_t ocf_promotion_get_param(ocf_cache_t cache, uint8_t param_id,
|
||||
ocf_promotion_t type, uint32_t *param_value);
|
||||
ocf_error_t ocf_promotion_get_param(ocf_cache_t cache, ocf_promotion_t type,
|
||||
uint8_t param_id, uint32_t *param_value);
|
||||
|
||||
/**
|
||||
* @brief Update promotion policy after cache lines have been promoted to cache
|
||||
|
Reference in New Issue
Block a user