Async wait for cleaner completion

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski
2019-04-11 13:16:16 -04:00
parent 0e15c693fd
commit 348b0f9ab8
7 changed files with 281 additions and 144 deletions

View File

@@ -8,6 +8,7 @@
#include "../engine/engine_common.h"
#include "../concurrency/ocf_concurrency.h"
#include "utils_cleaner.h"
#include "utils_part.h"
#include "utils_req.h"
#include "utils_io.h"
#include "utils_cache_line.h"
@@ -1014,3 +1015,49 @@ void ocf_cleaner_sort_flush_containers(struct flush_container *fctbl,
_ocf_cleaner_swap);
}
}
void ocf_cleaner_refcnt_freeze(ocf_cache_t cache)
{
struct ocf_user_part *curr_part;
ocf_part_id_t part_id;
for_each_part(cache, curr_part, part_id)
ocf_refcnt_freeze(&cache->refcnt.cleaning[part_id]);
}
void ocf_cleaner_refcnt_unfreeze(ocf_cache_t cache)
{
struct ocf_user_part *curr_part;
ocf_part_id_t part_id;
for_each_part(cache, curr_part, part_id)
ocf_refcnt_unfreeze(&cache->refcnt.cleaning[part_id]);
}
static void ocf_cleaner_refcnt_register_zero_cb_finish(void *priv)
{
struct ocf_cleaner_wait_context *ctx = priv;
if (!env_atomic_dec_return(&ctx->waiting))
ctx->cb(ctx->priv);
}
void ocf_cleaner_refcnt_register_zero_cb(ocf_cache_t cache,
struct ocf_cleaner_wait_context *ctx,
ocf_cleaner_refcnt_zero_cb_t cb, void *priv)
{
struct ocf_user_part *curr_part;
ocf_part_id_t part_id;
env_atomic_set(&ctx->waiting, 1);
ctx->cb = cb;
ctx->priv = priv;
for_each_part(cache, curr_part, part_id) {
env_atomic_inc(&ctx->waiting);
ocf_refcnt_register_zero_cb(&cache->refcnt.cleaning[part_id],
ocf_cleaner_refcnt_register_zero_cb_finish, ctx);
}
ocf_cleaner_refcnt_register_zero_cb_finish(ctx);
}

View File

@@ -79,6 +79,18 @@ struct flush_container {
struct ocf_mngt_cache_flush_context *context;
};
typedef void (*ocf_cleaner_refcnt_zero_cb_t)(void *priv);
/**
* @brief Context for ocf_cleaner_refcnt_register_zero_cb
*/
struct ocf_cleaner_wait_context
{
env_atomic waiting;
ocf_cleaner_refcnt_zero_cb_t cb;
void *priv;
};
/**
* @brief Run cleaning procedure
*
@@ -119,4 +131,30 @@ void ocf_cleaner_sort_sectors(struct flush_data *tbl, uint32_t num);
void ocf_cleaner_sort_flush_containers(struct flush_container *fctbl,
uint32_t num);
/**
* @brief Disable incrementing of cleaner reference counters
*
* @param cache - Cache instance
*/
void ocf_cleaner_refcnt_freeze(ocf_cache_t cache);
/**
* @brief Enable incrementing of cleaner reference counters
*
* @param cache - Cache instance
*/
void ocf_cleaner_refcnt_unfreeze(ocf_cache_t cache);
/**
* @brief Register callback for cleaner reference counters dropping to 0
*
* @param cache - Cache instance
* @param ctx - Routine private context, allocated by caller to avoid ENOMEM
* @param cb - Caller callback
* @param priv - Caller callback private data
*/
void ocf_cleaner_refcnt_register_zero_cb(ocf_cache_t cache,
struct ocf_cleaner_wait_context *ctx,
ocf_cleaner_refcnt_zero_cb_t cb, void *priv);
#endif /* UTILS_CLEANER_H_ */