From 494a1ccc7989e45e8906033de7c0d6c5a9f7209a Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Thu, 12 Sep 2019 04:41:59 -0400 Subject: [PATCH 1/3] Extract stats builder utils to separate file. Signed-off-by: Michal Mielewczyk --- src/ocf_stats_builder.c | 41 +-------------------------------- src/utils/utils_stats.h | 50 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 40 deletions(-) create mode 100644 src/utils/utils_stats.h diff --git a/src/ocf_stats_builder.c b/src/ocf_stats_builder.c index 5f8125a..bdc2a6f 100644 --- a/src/ocf_stats_builder.c +++ b/src/ocf_stats_builder.c @@ -9,46 +9,7 @@ #include "engine/cache_engine.h" #include "utils/utils_part.h" #include "utils/utils_cache_line.h" - -#define _ocf_stats_zero(stats) \ - do { \ - if (stats) { \ - typeof(*stats) zero = { { 0 } }; \ - *stats = zero; \ - } \ - } while (0) - -static uint64_t _fraction(uint64_t numerator, uint64_t denominator) -{ - uint64_t result; - if (denominator) { - result = 10000 * numerator / denominator; - } else { - result = 0; - } - return result; -} - -static uint64_t _lines4k(uint64_t size, - ocf_cache_line_size_t cache_line_size) -{ - long unsigned int result; - - result = size * (cache_line_size / 4096); - - return result; -} - -static uint64_t _bytes4k(uint64_t bytes) -{ - return (bytes + 4095UL) >> 12; -} - -static void _set(struct ocf_stat *stat, uint64_t value, uint64_t denominator) -{ - stat->value = value; - stat->fraction = _fraction(value, denominator); -} +#include "utils/utils_stats.h" static void _fill_req(struct ocf_stats_requests *req, struct ocf_stats_core *s) { diff --git a/src/utils/utils_stats.h b/src/utils/utils_stats.h new file mode 100644 index 0000000..d0c9fac --- /dev/null +++ b/src/utils/utils_stats.h @@ -0,0 +1,50 @@ +/* + * Copyright(c) 2012-2019 Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause-Clear + */ + +#ifndef UTILS_STATS_H_ +#define UTILS_STATS_H_ + +#define _ocf_stats_zero(stats) \ + do { \ + if (stats) { \ + typeof(*stats) zero = { { 0 } }; \ + *stats = zero; \ + } \ + } while (0) + +static inline uint64_t _fraction(uint64_t numerator, uint64_t denominator) +{ + uint64_t result; + if (denominator) { + result = 10000 * numerator / denominator; + } else { + result = 0; + } + return result; +} + +static inline uint64_t _lines4k(uint64_t size, + ocf_cache_line_size_t cache_line_size) +{ + long unsigned int result; + + result = size * (cache_line_size / 4096); + + return result; +} + +static inline uint64_t _bytes4k(uint64_t bytes) +{ + return (bytes + 4095UL) >> 12; +} + +static inline void _set(struct ocf_stat *stat, uint64_t value, + uint64_t denominator) +{ + stat->value = value; + stat->fraction = _fraction(value, denominator); +} + +#endif From f226f978f0c4f51c245397f2701965650a73df7a Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Thu, 12 Sep 2019 05:11:47 -0400 Subject: [PATCH 2/3] Unify inactive cores stats. Inactive core stats should be caluculated and returned to adapter in unified from, just like all stats are. Signed-off-by: Michal Mielewczyk --- inc/ocf_cache.h | 8 ++++++-- src/ocf_cache.c | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) 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; From 5042c5fc437bb6b4a57951901290b1bd9246b127 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Thu, 12 Sep 2019 09:20:12 -0400 Subject: [PATCH 3/3] pyocf: adapt tests to new inactive cores stats. Signed-off-by: Michal Mielewczyk --- tests/functional/pyocf/types/cache.py | 9 +++++++-- tests/functional/pyocf/types/stats/cache.py | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/functional/pyocf/types/cache.py b/tests/functional/pyocf/types/cache.py index c8fcf7c..995356a 100644 --- a/tests/functional/pyocf/types/cache.py +++ b/tests/functional/pyocf/types/cache.py @@ -468,9 +468,14 @@ class Cache: "size": CacheLines(cache_info.size, line_size), "inactive": { "occupancy": CacheLines( - cache_info.inactive.occupancy, line_size + cache_info.inactive.occupancy.value, line_size + ), + "dirty": CacheLines( + cache_info.inactive.dirty.value, line_size + ), + "clean": CacheLines( + cache_info.inactive.clean.value, line_size ), - "dirty": CacheLines(cache_info.inactive.dirty, line_size), }, "occupancy": CacheLines(cache_info.occupancy, line_size), "dirty": CacheLines(cache_info.dirty, line_size), diff --git a/tests/functional/pyocf/types/stats/cache.py b/tests/functional/pyocf/types/stats/cache.py index ae85de5..b9b192f 100644 --- a/tests/functional/pyocf/types/stats/cache.py +++ b/tests/functional/pyocf/types/stats/cache.py @@ -4,10 +4,11 @@ # from ctypes import c_uint8, c_uint32, c_uint64, c_bool, c_int, Structure +from pyocf.types.stats.shared import _Stat class _Inactive(Structure): - _fields_ = [("occupancy", c_uint32), ("dirty", c_uint32)] + _fields_ = [("occupancy", _Stat), ("clean", _Stat), ("dirty", _Stat)] class _FallbackPt(Structure):