diff --git a/inc/ocf_ctx.h b/inc/ocf_ctx.h index 4ca4366..b729faf 100644 --- a/inc/ocf_ctx.h +++ b/inc/ocf_ctx.h @@ -145,6 +145,13 @@ struct ocf_cleaner_ops { */ int (*init)(ocf_cleaner_t c); + /** + * @brief Kick cleaner thread. + * + * @param[in] c Descriptor of cleaner to be kicked. + */ + void (*kick)(ocf_cleaner_t c); + /** * @brief Stop cleaner * diff --git a/inc/ocf_def.h b/inc/ocf_def.h index 1ce2eee..740a46f 100644 --- a/inc/ocf_def.h +++ b/inc/ocf_def.h @@ -320,6 +320,15 @@ typedef enum { * @} */ +/** + * @name OCF cleaner definitions + * @{ + */ +#define OCF_CLEANER_DISABLE ~0U +/** + * @} + */ + #define MAX_TRIM_RQ_SIZE (1 * MiB) #endif /* __OCF_DEF_H__ */ diff --git a/src/cleaning/acp.c b/src/cleaning/acp.c index 64abe5e..c5c585f 100644 --- a/src/cleaning/acp.c +++ b/src/cleaning/acp.c @@ -316,6 +316,7 @@ int cleaning_policy_acp_initialize(struct ocf_cache *cache, } _acp_rebuild(cache); + ocf_kick_cleaner(cache); return 0; } @@ -336,6 +337,7 @@ int cleaning_policy_acp_set_cleaning_param(ocf_cache_t cache, config->thread_wakeup_time = param_value; ocf_cache_log(cache, log_info, "Write-back flush thread " "wake-up time: %d\n", config->thread_wakeup_time); + ocf_kick_cleaner(cache); break; case ocf_acp_flush_max_buffers: OCF_CLEANING_CHECK_PARAM(cache, param_value, diff --git a/src/cleaning/alru.c b/src/cleaning/alru.c index e04f98e..10ec27b 100644 --- a/src/cleaning/alru.c +++ b/src/cleaning/alru.c @@ -470,6 +470,8 @@ int cleaning_policy_alru_initialize(ocf_cache_t cache, int init_metadata) if (init_metadata) _alru_rebuild(cache); + ocf_kick_cleaner(cache); + return 0; } @@ -495,6 +497,7 @@ int cleaning_policy_alru_set_cleaning_param(ocf_cache_t cache, config->thread_wakeup_time = param_value; ocf_cache_log(cache, log_info, "Write-back flush thread " "wake-up time: %d\n", config->thread_wakeup_time); + ocf_kick_cleaner(cache); break; case ocf_alru_stale_buffer_time: OCF_CLEANING_CHECK_PARAM(cache, param_value, diff --git a/src/cleaning/cleaning.c b/src/cleaning/cleaning.c index cc53553..f3c200e 100644 --- a/src/cleaning/cleaning.c +++ b/src/cleaning/cleaning.c @@ -59,6 +59,11 @@ void ocf_stop_cleaner(ocf_cache_t cache) ctx_cleaner_stop(cache->owner, &cache->cleaner); } +void ocf_kick_cleaner(ocf_cache_t cache) +{ + ctx_cleaner_kick(cache->owner, &cache->cleaner); +} + void ocf_cleaner_set_cmpl(ocf_cleaner_t cleaner, ocf_cleaner_end_t fn) { cleaner->end = fn; diff --git a/src/cleaning/cleaning.h b/src/cleaning/cleaning.h index e8dcf75..39d7b24 100644 --- a/src/cleaning/cleaning.h +++ b/src/cleaning/cleaning.h @@ -68,6 +68,8 @@ struct ocf_cleaner { int ocf_start_cleaner(ocf_cache_t cache); +void ocf_kick_cleaner(ocf_cache_t cache); + void ocf_stop_cleaner(ocf_cache_t cache); #endif diff --git a/src/cleaning/nop.c b/src/cleaning/nop.c index 0462141..4d88733 100644 --- a/src/cleaning/nop.c +++ b/src/cleaning/nop.c @@ -9,6 +9,5 @@ void cleaning_nop_perform_cleaning(ocf_cache_t cache, ocf_cleaner_end_t cmpl) { - uint32_t interval = SLEEP_TIME_MS; - cmpl(&cache->cleaner, interval); + cmpl(&cache->cleaner, OCF_CLEANER_DISABLE); } diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 578f364..1111444 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -1347,6 +1347,15 @@ static void _ocf_mngt_attach_init_instance(ocf_pipeline_t pipeline, { struct ocf_cache_attach_context *context = priv; ocf_cache_t cache = context->cache; + int result; + + result = ocf_start_cleaner(cache); + if (result) { + ocf_cache_log(cache, log_err, + "Error while starting cleaner\n"); + OCF_PL_FINISH_RET(context->pipeline, result); + } + context->flags.cleaner_started = true; switch (cache->device->init_mode) { case ocf_init_mode_init: @@ -1503,17 +1512,6 @@ static void _ocf_mngt_attach_post_init(ocf_pipeline_t pipeline, { struct ocf_cache_attach_context *context = priv; ocf_cache_t cache = context->cache; - int result; - - if (!context->flags.cleaner_started) { - result = ocf_start_cleaner(cache); - if (result) { - ocf_cache_log(cache, log_err, - "Error while starting cleaner\n"); - OCF_PL_FINISH_RET(context->pipeline, result); - } - context->flags.cleaner_started = true; - } ocf_cleaner_refcnt_unfreeze(cache); ocf_refcnt_unfreeze(&cache->refcnt.metadata); diff --git a/src/ocf_ctx_priv.h b/src/ocf_ctx_priv.h index dca2461..f8f6143 100644 --- a/src/ocf_ctx_priv.h +++ b/src/ocf_ctx_priv.h @@ -146,6 +146,11 @@ static inline void ctx_cleaner_stop(ocf_ctx_t ctx, ocf_cleaner_t cleaner) ctx->ops->cleaner.stop(cleaner); } +static inline void ctx_cleaner_kick(ocf_ctx_t ctx, ocf_cleaner_t cleaner) +{ + ctx->ops->cleaner.kick(cleaner); +} + static inline int ctx_metadata_updater_init(ocf_ctx_t ctx, ocf_metadata_updater_t mu) { diff --git a/tests/functional/pyocf/types/cleaner.py b/tests/functional/pyocf/types/cleaner.py index 45ecb44..df28290 100644 --- a/tests/functional/pyocf/types/cleaner.py +++ b/tests/functional/pyocf/types/cleaner.py @@ -9,9 +9,10 @@ from .shared import SharedOcfObject class CleanerOps(Structure): INIT = CFUNCTYPE(c_int, c_void_p) + KICK = CFUNCTYPE(None, c_void_p) STOP = CFUNCTYPE(None, c_void_p) - _fields_ = [("init", INIT), ("stop", STOP)] + _fields_ = [("init", INIT), ("kick", KICK), ("stop", STOP)] class Cleaner(SharedOcfObject): @@ -24,13 +25,18 @@ class Cleaner(SharedOcfObject): @classmethod def get_ops(cls): - return CleanerOps(init=cls._init, stop=cls._stop) + return CleanerOps(init=cls._init, kick=cls._kick, stop=cls._stop) @staticmethod @CleanerOps.INIT def _init(cleaner): return 0 + @staticmethod + @CleanerOps.KICK + def _kick(cleaner): + pass + @staticmethod @CleanerOps.STOP def _stop(cleaner):