diff --git a/inc/ocf_cache.h b/inc/ocf_cache.h index 7020e37..1af9329 100644 --- a/inc/ocf_cache.h +++ b/inc/ocf_cache.h @@ -16,6 +16,7 @@ #include "ocf_volume.h" #include "ocf_ctx.h" #include "ocf_def.h" +#include "ocf_stats.h" /** * @brief Cache info: configuration, status @@ -32,10 +33,13 @@ struct ocf_cache_info { /* Statistics of inactive cores */ struct { - uint32_t occupancy; + struct ocf_stat occupancy; /*!< Cache occupancy (in cache lines) */ - uint32_t dirty; + struct ocf_stat clean; + /*!< Clean blocks within cache (in cache lines) */ + + struct ocf_stat dirty; /*!< Dirty blocks within cache (in cache lines) */ } inactive; diff --git a/src/ocf_cache.c b/src/ocf_cache.c index 86ffabb..c4cfabb 100644 --- a/src/ocf_cache.c +++ b/src/ocf_cache.c @@ -11,6 +11,7 @@ #include "utils/utils_part.h" #include "ocf_priv.h" #include "ocf_cache_priv.h" +#include "utils/utils_stats.h" ocf_volume_t ocf_cache_get_volume(ocf_cache_t cache) { @@ -84,6 +85,8 @@ int ocf_cache_get_info(ocf_cache_t cache, struct ocf_cache_info *info) ENV_BUG_ON(env_memset(info, sizeof(*info), 0)); + _ocf_stats_zero(&info->inactive); + info->attached = ocf_cache_is_device_attached(cache); if (info->attached) { info->volume_type = ocf_ctx_get_volume_type_id(cache->owner, @@ -145,8 +148,20 @@ int ocf_cache_get_info(ocf_cache_t cache, struct ocf_cache_info *info) cache->device->metadata_offset / PAGE_SIZE : 0; info->state = cache->cache_state; - info->inactive.occupancy = cache_occupancy_inactive; - info->inactive.dirty = dirty_blocks_inactive; + + if (info->attached) { + _set(&info->inactive.occupancy, + _lines4k(cache_occupancy_inactive, ocf_line_size(cache)), + _lines4k(info->size, ocf_line_size(cache))); + _set(&info->inactive.clean, + _lines4k(cache_occupancy_inactive - dirty_blocks_inactive, + ocf_line_size(cache)), + _lines4k(cache_occupancy_total, ocf_line_size(cache))); + _set(&info->inactive.dirty, + _lines4k(dirty_blocks_inactive, ocf_line_size(cache)), + _lines4k(cache_occupancy_total, ocf_line_size(cache))); + } + info->flushed = (env_atomic_read(&cache->flush_in_progress)) ? flushed_total : 0;