From 89de6038c19130e314747c2a710b5033e81a53d0 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Mon, 2 Sep 2019 09:07:19 -0400 Subject: [PATCH] Split retrieving core stats and config info into two functions. Signed-off-by: Michal Mielewczyk --- inc/ocf_core.h | 37 +++++++++++++++++++++++++++++++++++++ inc/ocf_stats.h | 18 ------------------ src/ocf_core.c | 35 +++++++++++++++++++++++++++++++++++ src/ocf_stats.c | 27 --------------------------- 4 files changed, 72 insertions(+), 45 deletions(-) diff --git a/inc/ocf_core.h b/inc/ocf_core.h index 24b099c..435dd74 100644 --- a/inc/ocf_core.h +++ b/inc/ocf_core.h @@ -16,6 +16,32 @@ #include "ocf_io.h" #include "ocf_mngt.h" +struct ocf_core_info { + /** Core size in cache line size unit */ + uint64_t core_size; + + /** Core size in bytes unit */ + uint64_t core_size_bytes; + + /** Fields refers ongoing flush operation */ + struct { + /** Number of blocks flushed in ongoing flush operation */ + uint32_t flushed; + + /** Number of blocks left to flush in ongoing flush operation */ + uint32_t dirty; + }; + + /** How long core is dirty in seconds unit */ + uint32_t dirty_for; + + /** Sequential cutoff threshold (in bytes) */ + uint32_t seq_cutoff_threshold; + + /** Sequential cutoff policy */ + ocf_seq_cutoff_policy seq_cutoff_policy; +}; + /** * @brief Get OCF core by name * @@ -202,4 +228,15 @@ typedef int (*ocf_core_visitor_t)(ocf_core_t core, void *cntx); int ocf_core_visit(ocf_cache_t cache, ocf_core_visitor_t visitor, void *cntx, bool only_opened); +/** + * @brief Get info of given core object + * + * @param[in] core Core object + * @param[out] info Core info structure + * + * @retval 0 Success + * @retval Non-zero Fail + */ +int ocf_core_get_info(ocf_core_t core, struct ocf_core_info *info); + #endif /* __OCF_CORE_H__ */ diff --git a/inc/ocf_stats.h b/inc/ocf_stats.h index f792d1a..4906023 100644 --- a/inc/ocf_stats.h +++ b/inc/ocf_stats.h @@ -111,24 +111,12 @@ struct ocf_stats_core_debug { * @brief OCF core statistics */ struct ocf_stats_core { - /** Core size in cache line size unit */ - uint64_t core_size; - - /** Core size in bytes unit */ - uint64_t core_size_bytes; - /** Number of cache lines allocated in the cache for this core */ uint32_t cache_occupancy; /** Number of dirty cache lines allocated in the cache for this core */ uint32_t dirty; - /** Number of block flushed in ongoing flush operation */ - uint32_t flushed; - - /** How long core is dirty in seconds unit */ - uint32_t dirty_for; - /** Read requests statistics */ struct ocf_stats_req read_reqs; @@ -152,12 +140,6 @@ struct ocf_stats_core { /** Debug statistics */ struct ocf_stats_core_debug debug_stat; - - /** Sequential cutoff threshold (in bytes) */ - uint32_t seq_cutoff_threshold; - - /** Sequential cutoff policy */ - ocf_seq_cutoff_policy seq_cutoff_policy; }; /** diff --git a/src/ocf_core.c b/src/ocf_core.c index c346aee..5c8dcfe 100644 --- a/src/ocf_core.c +++ b/src/ocf_core.c @@ -143,6 +143,13 @@ int ocf_core_visit(ocf_cache_t cache, ocf_core_visitor_t visitor, void *cntx, /* *** HELPER FUNCTIONS *** */ +static uint32_t _calc_dirty_for(uint64_t dirty_since) +{ + return dirty_since ? + (env_ticks_to_msecs(env_get_tick_count() - dirty_since) / 1000) + : 0; +} + static inline struct ocf_request *ocf_io_to_req(struct ocf_io *io) { struct ocf_io_internal *ioi; @@ -585,3 +592,31 @@ int ocf_core_volume_type_init(ocf_ctx_t ctx) &ocf_core_volume_properties, &ocf_core_volume_extended); } + +int ocf_core_get_info(ocf_core_t core, struct ocf_core_info *info) +{ + ocf_cache_t cache; + + OCF_CHECK_NULL(core); + + cache = ocf_core_get_cache(core); + + if (!info) + return -OCF_ERR_INVAL; + + ENV_BUG_ON(env_memset(info, sizeof(*info), 0)); + + info->core_size_bytes = ocf_volume_get_length(&core->volume); + info->core_size = ocf_bytes_2_lines_round_up(cache, + info->core_size_bytes); + info->seq_cutoff_threshold = ocf_core_get_seq_cutoff_threshold(core); + info->seq_cutoff_policy = ocf_core_get_seq_cutoff_policy(core); + + info->flushed = env_atomic_read(&core->flushed); + info->dirty = env_atomic_read(&core->runtime_meta->dirty_clines); + + info->dirty_for = _calc_dirty_for( + env_atomic64_read(&core->runtime_meta->dirty_since)); + + return 0; +} diff --git a/src/ocf_stats.c b/src/ocf_stats.c index b7f8880..b670149 100644 --- a/src/ocf_stats.c +++ b/src/ocf_stats.c @@ -204,26 +204,14 @@ int ocf_core_io_class_get_stats(ocf_core_t core, ocf_part_id_t part_id, return 0; } -static uint32_t _calc_dirty_for(uint64_t dirty_since) -{ - return dirty_since ? - (env_ticks_to_msecs(env_get_tick_count() - dirty_since) / 1000) - : 0; -} - int ocf_core_get_stats(ocf_core_t core, struct ocf_stats_core *stats) { uint32_t i; - ocf_core_id_t core_id; - ocf_cache_t cache; struct ocf_counters_core *core_stats = NULL; struct ocf_counters_part *curr = NULL; OCF_CHECK_NULL(core); - core_id = ocf_core_get_id(core); - cache = ocf_core_get_cache(core); - if (!stats) return -OCF_ERR_INVAL; @@ -231,16 +219,6 @@ int ocf_core_get_stats(ocf_core_t core, struct ocf_stats_core *stats) ENV_BUG_ON(env_memset(stats, sizeof(*stats), 0)); - stats->core_size_bytes = ocf_volume_get_length( - &cache->core[core_id].volume); - stats->core_size = ocf_bytes_2_lines_round_up(cache, - stats->core_size_bytes); - stats->seq_cutoff_threshold = ocf_core_get_seq_cutoff_threshold(core); - stats->seq_cutoff_policy = ocf_core_get_seq_cutoff_policy(core); - - - env_atomic_read(&core->runtime_meta->cached_clines); - copy_error_stats(&stats->core_errors, &core_stats->core_errors); copy_error_stats(&stats->cache_errors, @@ -269,11 +247,6 @@ int ocf_core_get_stats(ocf_core_t core, struct ocf_stats_core *stats) part_counters[i].dirty_clines); } - stats->flushed = env_atomic_read(&core->flushed); - - stats->dirty_for = _calc_dirty_for( - env_atomic64_read(&core->runtime_meta->dirty_since)); - return 0; }