Merge pull request #297 from mmichal10/pp-params-in-sb
Store PP config params in cache superblock.
This commit is contained in:
@@ -41,8 +41,10 @@ struct ocf_superblock_config {
|
||||
ocf_cleaning_t cleaning_policy_type;
|
||||
struct cleaning_policy_config cleaning[CLEANING_POLICY_TYPE_MAX];
|
||||
|
||||
ocf_eviction_t eviction_policy_type;
|
||||
ocf_promotion_t promotion_policy_type;
|
||||
struct promotion_policy_config promotion[PROMOTION_POLICY_TYPE_MAX];
|
||||
|
||||
ocf_eviction_t eviction_policy_type;
|
||||
|
||||
/* Current core sequence number */
|
||||
ocf_core_id_t curr_core_seq_no;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "../ocf_ctx_priv.h"
|
||||
#include "../ocf_freelist.h"
|
||||
#include "../cleaning/cleaning.h"
|
||||
#include "../promotion/ops.h"
|
||||
|
||||
#define OCF_ASSERT_PLUGGED(cache) ENV_BUG_ON(!(cache)->device)
|
||||
|
||||
@@ -116,6 +117,9 @@ struct ocf_cache_attach_context {
|
||||
bool cleaner_started : 1;
|
||||
/*!< Cleaner has been started */
|
||||
|
||||
bool promotion_initialized : 1;
|
||||
/*!< Promotion policy has been started */
|
||||
|
||||
bool cores_opened : 1;
|
||||
/*!< underlying cores are opened (happens only during
|
||||
* load or recovery
|
||||
@@ -243,11 +247,16 @@ static void __init_eviction_policy(ocf_cache_t cache,
|
||||
cache->conf_meta->eviction_policy_type = eviction;
|
||||
}
|
||||
|
||||
static ocf_error_t __init_promotion_policy(ocf_cache_t cache)
|
||||
static void __setup_promotion_policy(ocf_cache_t cache)
|
||||
{
|
||||
ENV_BUG_ON(cache->promotion_policy);
|
||||
int i;
|
||||
|
||||
return ocf_promotion_init(cache, &cache->promotion_policy);
|
||||
OCF_CHECK_NULL(cache);
|
||||
|
||||
for (i = 0; i < ocf_promotion_max; i++) {
|
||||
if (ocf_promotion_policies[i].setup)
|
||||
ocf_promotion_policies[i].setup(cache);
|
||||
}
|
||||
}
|
||||
|
||||
static void __deinit_promotion_policy(ocf_cache_t cache)
|
||||
@@ -309,13 +318,7 @@ static ocf_error_t init_attached_data_structures(ocf_cache_t cache,
|
||||
}
|
||||
|
||||
__init_eviction_policy(cache, eviction_policy);
|
||||
result =__init_promotion_policy(cache);
|
||||
if (result) {
|
||||
ocf_cache_log(cache, log_err,
|
||||
"Cannot initialize promotion policy\n");
|
||||
__deinit_cleaning_policy(cache);
|
||||
return result;
|
||||
}
|
||||
__setup_promotion_policy(cache);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -467,13 +470,6 @@ void _ocf_mngt_init_instance_load_complete(void *priv, int error)
|
||||
|
||||
__init_freelist(cache);
|
||||
|
||||
result = __init_promotion_policy(cache);
|
||||
if (result) {
|
||||
ocf_cache_log(cache, log_err,
|
||||
"Cannot initialize promotion policy\n");
|
||||
OCF_PL_FINISH_RET(context->pipeline, result);
|
||||
}
|
||||
|
||||
cleaning_policy = cache->conf_meta->cleaning_policy_type;
|
||||
if (!cleaning_policy_ops[cleaning_policy].initialize)
|
||||
goto out;
|
||||
@@ -486,7 +482,6 @@ void _ocf_mngt_init_instance_load_complete(void *priv, int error)
|
||||
if (result) {
|
||||
ocf_cache_log(cache, log_err,
|
||||
"Cannot initialize cleaning policy\n");
|
||||
__deinit_promotion_policy(cache);
|
||||
OCF_PL_FINISH_RET(context->pipeline, result);
|
||||
}
|
||||
|
||||
@@ -1135,6 +1130,9 @@ static void _ocf_mngt_attach_handle_error(
|
||||
if (context->flags.cleaner_started)
|
||||
ocf_stop_cleaner(cache);
|
||||
|
||||
if (context->flags.promotion_initialized)
|
||||
__deinit_promotion_policy(cache);
|
||||
|
||||
if (context->flags.cores_opened)
|
||||
_ocf_mngt_close_all_uninitialized_cores(cache);
|
||||
|
||||
@@ -1165,8 +1163,7 @@ static void _ocf_mngt_cache_init(ocf_cache_t cache,
|
||||
*/
|
||||
cache->conf_meta->cache_mode = params->metadata.cache_mode;
|
||||
cache->conf_meta->metadata_layout = params->metadata.layout;
|
||||
cache->conf_meta->promotion_policy_type =
|
||||
params->metadata.promotion_policy;
|
||||
cache->conf_meta->promotion_policy_type = params->metadata.promotion_policy;
|
||||
|
||||
INIT_LIST_HEAD(&cache->io_queues);
|
||||
|
||||
@@ -1353,6 +1350,14 @@ static void _ocf_mngt_attach_init_instance(ocf_pipeline_t pipeline,
|
||||
}
|
||||
context->flags.cleaner_started = true;
|
||||
|
||||
result = ocf_promotion_init(cache, cache->conf_meta->promotion_policy_type);
|
||||
if (result) {
|
||||
ocf_cache_log(cache, log_err,
|
||||
"Cannot initialize promotion policy\n");
|
||||
OCF_PL_FINISH_RET(context->pipeline, result);
|
||||
}
|
||||
context->flags.promotion_initialized = true;
|
||||
|
||||
switch (cache->device->init_mode) {
|
||||
case ocf_init_mode_init:
|
||||
case ocf_init_mode_metadata_volatile:
|
||||
@@ -1823,6 +1828,7 @@ static void _ocf_mngt_cache_load_log(ocf_cache_t cache)
|
||||
ocf_cache_mode_t cache_mode = ocf_cache_get_mode(cache);
|
||||
ocf_eviction_t eviction_type = cache->conf_meta->eviction_policy_type;
|
||||
ocf_cleaning_t cleaning_type = cache->conf_meta->cleaning_policy_type;
|
||||
ocf_promotion_t promotion_type = cache->conf_meta->promotion_policy_type;
|
||||
|
||||
ocf_cache_log(cache, log_info, "Successfully loaded\n");
|
||||
ocf_cache_log(cache, log_info, "Cache mode : %s\n",
|
||||
@@ -1831,6 +1837,8 @@ static void _ocf_mngt_cache_load_log(ocf_cache_t cache)
|
||||
evict_policy_ops[eviction_type].name);
|
||||
ocf_cache_log(cache, log_info, "Cleaning policy : %s\n",
|
||||
cleaning_policy_ops[cleaning_type].name);
|
||||
ocf_cache_log(cache, log_info, "Promotion policy : %s\n",
|
||||
ocf_promotion_policies[promotion_type].name);
|
||||
ocf_core_visit(cache, _ocf_mngt_cache_load_core_log,
|
||||
cache, false);
|
||||
}
|
||||
@@ -2276,32 +2284,30 @@ ocf_promotion_t ocf_mngt_cache_promotion_get_policy(ocf_cache_t cache)
|
||||
return result;
|
||||
}
|
||||
|
||||
int ocf_mngt_cache_promotion_get_param(ocf_cache_t cache, uint8_t param_id,
|
||||
uint32_t *param_value)
|
||||
int ocf_mngt_cache_promotion_get_param(ocf_cache_t cache, ocf_promotion_t type,
|
||||
uint8_t param_id, uint32_t *param_value)
|
||||
{
|
||||
int result;
|
||||
|
||||
ocf_metadata_start_shared_access(&cache->metadata.lock);
|
||||
|
||||
result = ocf_promotion_get_param(cache->promotion_policy, param_id,
|
||||
param_value);
|
||||
result = ocf_promotion_get_param(cache, type, param_id, param_value);
|
||||
|
||||
ocf_metadata_end_shared_access(&cache->metadata.lock);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int ocf_mngt_cache_promotion_set_param(ocf_cache_t cache, uint8_t param_id,
|
||||
uint32_t param_value)
|
||||
int ocf_mngt_cache_promotion_set_param(ocf_cache_t cache, ocf_promotion_t type,
|
||||
uint8_t param_id, uint32_t param_value)
|
||||
{
|
||||
int result;
|
||||
|
||||
ocf_metadata_start_shared_access(&cache->metadata.lock);
|
||||
ocf_metadata_start_exclusive_access(&cache->metadata.lock);
|
||||
|
||||
result = ocf_promotion_set_param(cache->promotion_policy, param_id,
|
||||
param_value);
|
||||
result = ocf_promotion_set_param(cache, type, param_id, param_value);
|
||||
|
||||
ocf_metadata_end_shared_access(&cache->metadata.lock);
|
||||
ocf_metadata_end_exclusive_access(&cache->metadata.lock);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -15,13 +15,19 @@
|
||||
|
||||
struct nhit_policy_context {
|
||||
nhit_hash_t hash_map;
|
||||
|
||||
/* Configurable parameters */
|
||||
env_atomic insertion_threshold;
|
||||
env_atomic trigger_threshold;
|
||||
};
|
||||
|
||||
ocf_error_t nhit_init(ocf_cache_t cache, ocf_promotion_policy_t policy)
|
||||
void nhit_setup(ocf_cache_t cache)
|
||||
{
|
||||
struct nhit_promotion_policy_config *cfg;
|
||||
|
||||
cfg = (void *) &cache->conf_meta->promotion[ocf_promotion_nhit].data;
|
||||
|
||||
cfg->insertion_threshold = OCF_NHIT_THRESHOLD_DEFAULT;
|
||||
cfg->trigger_threshold = OCF_NHIT_TRIGGER_DEFAULT;
|
||||
}
|
||||
|
||||
ocf_error_t nhit_init(ocf_cache_t cache)
|
||||
{
|
||||
struct nhit_policy_context *ctx;
|
||||
int result = 0;
|
||||
@@ -37,9 +43,7 @@ ocf_error_t nhit_init(ocf_cache_t cache, ocf_promotion_policy_t policy)
|
||||
if (result)
|
||||
goto dealloc_ctx;
|
||||
|
||||
env_atomic_set(&ctx->insertion_threshold, OCF_NHIT_THRESHOLD_DEFAULT);
|
||||
env_atomic_set(&ctx->trigger_threshold, OCF_NHIT_TRIGGER_DEFAULT);
|
||||
policy->ctx = ctx;
|
||||
cache->promotion_policy->ctx = ctx;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -60,22 +64,24 @@ void nhit_deinit(ocf_promotion_policy_t policy)
|
||||
policy->ctx = NULL;
|
||||
}
|
||||
|
||||
ocf_error_t nhit_set_param(ocf_promotion_policy_t policy, uint8_t param_id,
|
||||
ocf_error_t nhit_set_param(ocf_cache_t cache, uint8_t param_id,
|
||||
uint32_t param_value)
|
||||
{
|
||||
struct nhit_policy_context *ctx = policy->ctx;
|
||||
struct nhit_promotion_policy_config *cfg;
|
||||
ocf_error_t result = 0;
|
||||
|
||||
cfg = (void *) &cache->conf_meta->promotion[ocf_promotion_nhit].data;
|
||||
|
||||
switch (param_id) {
|
||||
case ocf_nhit_insertion_threshold:
|
||||
if (param_value >= OCF_NHIT_MIN_THRESHOLD &&
|
||||
param_value <= OCF_NHIT_MAX_THRESHOLD) {
|
||||
env_atomic_set(&ctx->insertion_threshold, param_value);
|
||||
ocf_cache_log(policy->owner, log_info,
|
||||
cfg->insertion_threshold = param_value;
|
||||
ocf_cache_log(cache, log_info,
|
||||
"Nhit PP insertion threshold value set to %u",
|
||||
param_value);
|
||||
} else {
|
||||
ocf_cache_log(policy->owner, log_err, "Invalid nhit "
|
||||
ocf_cache_log(cache, log_err, "Invalid nhit "
|
||||
"promotion policy insertion threshold!\n");
|
||||
result = -OCF_ERR_INVAL;
|
||||
}
|
||||
@@ -84,12 +90,12 @@ ocf_error_t nhit_set_param(ocf_promotion_policy_t policy, uint8_t param_id,
|
||||
case ocf_nhit_trigger_threshold:
|
||||
if (param_value >= OCF_NHIT_MIN_TRIGGER &&
|
||||
param_value <= OCF_NHIT_MAX_TRIGGER) {
|
||||
env_atomic_set(&ctx->trigger_threshold, param_value);
|
||||
ocf_cache_log(policy->owner, log_info,
|
||||
cfg->trigger_threshold = param_value;
|
||||
ocf_cache_log(cache, log_info,
|
||||
"Nhit PP trigger threshold value set to %u%%\n",
|
||||
param_value);
|
||||
} else {
|
||||
ocf_cache_log(policy->owner, log_err, "Invalid nhit "
|
||||
ocf_cache_log(cache, log_err, "Invalid nhit "
|
||||
"promotion policy insertion trigger "
|
||||
"threshold!\n");
|
||||
result = -OCF_ERR_INVAL;
|
||||
@@ -97,7 +103,7 @@ ocf_error_t nhit_set_param(ocf_promotion_policy_t policy, uint8_t param_id,
|
||||
break;
|
||||
|
||||
default:
|
||||
ocf_cache_log(policy->owner, log_err, "Invalid nhit "
|
||||
ocf_cache_log(cache, log_err, "Invalid nhit "
|
||||
"promotion policy parameter (%u)!\n",
|
||||
param_id);
|
||||
result = -OCF_ERR_INVAL;
|
||||
@@ -108,23 +114,25 @@ ocf_error_t nhit_set_param(ocf_promotion_policy_t policy, uint8_t param_id,
|
||||
return result;
|
||||
}
|
||||
|
||||
ocf_error_t nhit_get_param(ocf_promotion_policy_t policy, uint8_t param_id,
|
||||
ocf_error_t nhit_get_param(ocf_cache_t cache, uint8_t param_id,
|
||||
uint32_t *param_value)
|
||||
{
|
||||
struct nhit_policy_context *ctx = policy->ctx;
|
||||
struct nhit_promotion_policy_config *cfg;
|
||||
ocf_error_t result = 0;
|
||||
|
||||
cfg = (void *) &cache->conf_meta->promotion[ocf_promotion_nhit].data;
|
||||
|
||||
OCF_CHECK_NULL(param_value);
|
||||
|
||||
switch (param_id) {
|
||||
case ocf_nhit_insertion_threshold:
|
||||
*param_value = env_atomic_read(&ctx->insertion_threshold);
|
||||
*param_value = cfg->insertion_threshold;
|
||||
break;
|
||||
case ocf_nhit_trigger_threshold:
|
||||
*param_value = env_atomic_read(&ctx->trigger_threshold);
|
||||
*param_value = cfg->trigger_threshold;
|
||||
break;
|
||||
default:
|
||||
ocf_cache_log(policy->owner, log_err, "Invalid nhit "
|
||||
ocf_cache_log(cache, log_err, "Invalid nhit "
|
||||
"promotion policy parameter (%u)!\n",
|
||||
param_id);
|
||||
result = -OCF_ERR_INVAL;
|
||||
@@ -156,16 +164,21 @@ void nhit_req_purge(ocf_promotion_policy_t policy,
|
||||
}
|
||||
}
|
||||
|
||||
static bool core_line_should_promote(struct nhit_policy_context *ctx,
|
||||
static bool core_line_should_promote(ocf_promotion_policy_t policy,
|
||||
ocf_core_id_t core_id, uint64_t core_lba)
|
||||
{
|
||||
struct nhit_promotion_policy_config *cfg;
|
||||
struct nhit_policy_context *ctx;
|
||||
bool hit;
|
||||
int32_t counter;
|
||||
|
||||
cfg = (struct nhit_promotion_policy_config*)policy->config;
|
||||
ctx = policy->ctx;
|
||||
|
||||
hit = nhit_hash_query(ctx->hash_map, core_id, core_lba, &counter);
|
||||
if (hit) {
|
||||
/* we have a hit, return now */
|
||||
return env_atomic_read(&ctx->insertion_threshold) <= counter;
|
||||
return cfg->insertion_threshold <= counter;
|
||||
}
|
||||
|
||||
nhit_hash_insert(ctx->hash_map, core_id, core_lba);
|
||||
@@ -176,7 +189,7 @@ static bool core_line_should_promote(struct nhit_policy_context *ctx,
|
||||
bool nhit_req_should_promote(ocf_promotion_policy_t policy,
|
||||
struct ocf_request *req)
|
||||
{
|
||||
struct nhit_policy_context *ctx = policy->ctx;
|
||||
struct nhit_promotion_policy_config *cfg;
|
||||
bool result = true;
|
||||
uint32_t i;
|
||||
uint64_t core_line;
|
||||
@@ -184,8 +197,10 @@ 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 = (struct nhit_promotion_policy_config*)policy->config;
|
||||
|
||||
if (occupied_cachelines < OCF_DIV_ROUND_UP(
|
||||
((uint64_t) env_atomic_read(&ctx->trigger_threshold) *
|
||||
((uint64_t)cfg->trigger_threshold *
|
||||
ocf_metadata_get_cachelines_count(policy->owner)), 100))
|
||||
return true;
|
||||
|
||||
@@ -193,7 +208,7 @@ bool nhit_req_should_promote(ocf_promotion_policy_t policy,
|
||||
core_line <= req->core_line_last; core_line++, i++) {
|
||||
struct ocf_map_info *entry = &(req->map[i]);
|
||||
|
||||
if (!core_line_should_promote(ctx, entry->core_id,
|
||||
if (!core_line_should_promote(policy, entry->core_id,
|
||||
entry->core_line)) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
@@ -9,15 +9,18 @@
|
||||
#include "ocf/ocf.h"
|
||||
#include "../../ocf_request.h"
|
||||
#include "../promotion.h"
|
||||
#include "nhit_structs.h"
|
||||
|
||||
ocf_error_t nhit_init(ocf_cache_t cache, ocf_promotion_policy_t policy);
|
||||
void nhit_setup(ocf_cache_t cache);
|
||||
|
||||
ocf_error_t nhit_init(ocf_cache_t cache);
|
||||
|
||||
void nhit_deinit(ocf_promotion_policy_t policy);
|
||||
|
||||
ocf_error_t nhit_set_param(ocf_promotion_policy_t policy, uint8_t param_id,
|
||||
ocf_error_t nhit_set_param(ocf_cache_t cache, uint8_t param_id,
|
||||
uint32_t param_value);
|
||||
|
||||
ocf_error_t nhit_get_param(ocf_promotion_policy_t policy, uint8_t param_id,
|
||||
ocf_error_t nhit_get_param(ocf_cache_t cache, uint8_t param_id,
|
||||
uint32_t *param_value);
|
||||
|
||||
void nhit_req_purge(ocf_promotion_policy_t policy,
|
||||
|
||||
16
src/promotion/nhit/nhit_structs.h
Normal file
16
src/promotion/nhit/nhit_structs.h
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright(c) 2012-2019 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
#ifndef __PROMOTION_NHIT_STRUCTS_H_
|
||||
#define __PROMOTION_NHIT_STRUCTS_H_
|
||||
|
||||
struct nhit_promotion_policy_config {
|
||||
uint32_t insertion_threshold;
|
||||
/*!< Number of hits */
|
||||
|
||||
uint32_t trigger_threshold;
|
||||
/*!< Cache occupancy (percentage value) */
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -20,17 +24,20 @@ struct promotion_policy_ops {
|
||||
const char *name;
|
||||
/*!< Promotion policy name */
|
||||
|
||||
ocf_error_t (*init)(ocf_cache_t cache, ocf_promotion_policy_t policy);
|
||||
void (*setup)(ocf_cache_t cache);
|
||||
/*!< initialize promotion policy default config */
|
||||
|
||||
ocf_error_t (*init)(ocf_cache_t cache);
|
||||
/*!< Allocate and initialize promotion policy */
|
||||
|
||||
void (*deinit)(ocf_promotion_policy_t policy);
|
||||
/*!< Deinit and free promotion policy */
|
||||
|
||||
ocf_error_t (*set_param)(ocf_promotion_policy_t policy, uint8_t param_id,
|
||||
ocf_error_t (*set_param)(ocf_cache_t cache, uint8_t param_id,
|
||||
uint32_t param_value);
|
||||
/*!< Set promotion policy parameter */
|
||||
|
||||
ocf_error_t (*get_param)(ocf_promotion_policy_t policy, uint8_t param_id,
|
||||
ocf_error_t (*get_param)(ocf_cache_t cache, uint8_t param_id,
|
||||
uint32_t *param_value);
|
||||
/*!< Get promotion policy parameter */
|
||||
|
||||
@@ -44,5 +51,7 @@ struct promotion_policy_ops {
|
||||
/*!< Should request lines be inserted into cache */
|
||||
};
|
||||
|
||||
extern struct promotion_policy_ops ocf_promotion_policies[ocf_promotion_max];
|
||||
|
||||
#endif /* PROMOTION_OPS_H_ */
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ struct promotion_policy_ops ocf_promotion_policies[ocf_promotion_max] = {
|
||||
},
|
||||
[ocf_promotion_nhit] = {
|
||||
.name = "nhit",
|
||||
.setup = nhit_setup,
|
||||
.init = nhit_init,
|
||||
.deinit = nhit_deinit,
|
||||
.set_param = nhit_set_param,
|
||||
@@ -24,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;
|
||||
}
|
||||
@@ -81,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,
|
||||
@@ -95,32 +104,30 @@ ocf_error_t ocf_promotion_set_policy(ocf_promotion_policy_t policy,
|
||||
return result;
|
||||
}
|
||||
|
||||
ocf_error_t ocf_promotion_set_param(ocf_promotion_policy_t policy,
|
||||
ocf_error_t ocf_promotion_set_param(ocf_cache_t cache, ocf_promotion_t type,
|
||||
uint8_t param_id, uint32_t param_value)
|
||||
{
|
||||
ocf_promotion_t type = policy->type;
|
||||
ocf_error_t result = -OCF_ERR_INVAL;
|
||||
|
||||
ENV_BUG_ON(type >= ocf_promotion_max);
|
||||
|
||||
if (ocf_promotion_policies[type].set_param) {
|
||||
result = ocf_promotion_policies[type].set_param(policy, param_id,
|
||||
result = ocf_promotion_policies[type].set_param(cache, param_id,
|
||||
param_value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ocf_error_t ocf_promotion_get_param(ocf_promotion_policy_t policy,
|
||||
ocf_error_t ocf_promotion_get_param(ocf_cache_t cache, ocf_promotion_t type,
|
||||
uint8_t param_id, uint32_t *param_value)
|
||||
{
|
||||
ocf_promotion_t type = policy->type;
|
||||
ocf_error_t result = -OCF_ERR_INVAL;
|
||||
|
||||
ENV_BUG_ON(type >= ocf_promotion_max);
|
||||
|
||||
if (ocf_promotion_policies[type].get_param) {
|
||||
result = ocf_promotion_policies[type].get_param(policy, param_id,
|
||||
result = ocf_promotion_policies[type].get_param(cache, param_id,
|
||||
param_value);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,18 +9,36 @@
|
||||
#include "ocf/ocf.h"
|
||||
#include "../ocf_request.h"
|
||||
|
||||
#define PROMOTION_POLICY_CONFIG_BYTES 256
|
||||
#define PROMOTION_POLICY_TYPE_MAX 2
|
||||
|
||||
|
||||
struct promotion_policy_config {
|
||||
uint8_t data[PROMOTION_POLICY_CONFIG_BYTES];
|
||||
};
|
||||
|
||||
typedef struct ocf_promotion_policy *ocf_promotion_policy_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize promotion policy default values. Should be called after
|
||||
* cache metadata has been allocated and cache->conf_meta->promotion_policy_type
|
||||
* has been set.
|
||||
*
|
||||
* @param[in] cache OCF cache instance
|
||||
*/
|
||||
void ocf_promotion_setup(ocf_cache_t cache);
|
||||
|
||||
/**
|
||||
* @brief Allocate and initialize promotion policy. Should be called after cache
|
||||
* metadata has been allocated and cache->conf_meta->promotion_policy_type has
|
||||
* 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.
|
||||
@@ -44,25 +62,27 @@ ocf_error_t ocf_promotion_set_policy(ocf_promotion_policy_t policy,
|
||||
/**
|
||||
* @brief Set promotion policy parameter
|
||||
*
|
||||
* @param[in] policy promotion policy handle
|
||||
* @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] param_value value of parameter to be set
|
||||
*
|
||||
* @retval ocf_error_t
|
||||
*/
|
||||
ocf_error_t ocf_promotion_set_param(ocf_promotion_policy_t policy,
|
||||
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] policy promotion policy handle
|
||||
* @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[out] param_value value of parameter to be set
|
||||
*
|
||||
* @retval ocf_error_t
|
||||
*/
|
||||
ocf_error_t ocf_promotion_get_param(ocf_promotion_policy_t policy,
|
||||
ocf_error_t ocf_promotion_get_param(ocf_cache_t cache, ocf_promotion_t type,
|
||||
uint8_t param_id, uint32_t *param_value);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user