From 25f90f47784607799731db215590776fa2d376f9 Mon Sep 17 00:00:00 2001 From: Rafal Stefanowski Date: Mon, 26 Oct 2026 18:21:54 +0100 Subject: [PATCH 1/2] stats: Use cache and core totals for cleaner and prefetcher stats When 'total' variable was used to fill cleaner and prefetcher stats it held the pass-through's total instead of cache's and core's. Rather than relying on a common 'total' variable, save cache and core totals to a separate variables for cleaner and prefetcher totals. Signed-off-by: Rafal Stefanowski --- src/ocf_stats_builder.c | 68 ++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/ocf_stats_builder.c b/src/ocf_stats_builder.c index f50c8e64..23316607 100644 --- a/src/ocf_stats_builder.c +++ b/src/ocf_stats_builder.c @@ -124,7 +124,7 @@ static void _fill_req_part(struct ocf_stats_requests *req, static void _fill_blocks(struct ocf_stats_blocks *blocks, const struct ocf_stats_core *s) { - uint64_t rd, wr, total; + uint64_t rd, wr, total, core_total, cache_total; uint64_t pf_rd, pf_wr; uint64_t cl_rd, cl_wr; ocf_pf_id_t pf_id; @@ -132,28 +132,28 @@ static void _fill_blocks(struct ocf_stats_blocks *blocks, /* Core volume */ rd = _bytes4k(s->core_volume.read); wr = _bytes4k(s->core_volume.write); - total = rd + wr; + core_total = rd + wr; for_each_pf(pf_id) - total += _bytes4k(s->prefetch_blocks[pf_id].read); - total += _bytes4k(s->cleaner_blocks.write); + core_total += _bytes4k(s->prefetch_blocks[pf_id].read); + core_total += _bytes4k(s->cleaner_blocks.write); - _set(&blocks->core_volume_rd, rd, total); - _set(&blocks->core_volume_wr, wr, total); - _set(&blocks->core_volume_total, total, total); + _set(&blocks->core_volume_rd, rd, core_total); + _set(&blocks->core_volume_wr, wr, core_total); + _set(&blocks->core_volume_total, core_total, core_total); /* Cache volume */ rd = _bytes4k(s->cache_volume.read); wr = _bytes4k(s->cache_volume.write); - total = rd + wr; + cache_total = rd + wr; for_each_pf(pf_id) - total += _bytes4k(s->prefetch_blocks[pf_id].write); - total += _bytes4k(s->cleaner_blocks.read); + cache_total += _bytes4k(s->prefetch_blocks[pf_id].write); + cache_total += _bytes4k(s->cleaner_blocks.read); - _set(&blocks->cache_volume_rd, rd, total); - _set(&blocks->cache_volume_wr, wr, total); - _set(&blocks->cache_volume_total, total, total); + _set(&blocks->cache_volume_rd, rd, cache_total); + _set(&blocks->cache_volume_wr, wr, cache_total); + _set(&blocks->cache_volume_total, cache_total, cache_total); /* Core (cache volume) */ rd = _bytes4k(s->core.read); @@ -174,24 +174,24 @@ static void _fill_blocks(struct ocf_stats_blocks *blocks, /* Prefetch */ for_each_pf(pf_id) { pf_rd = _bytes4k(s->prefetch_blocks[pf_id].read); - _set(&blocks->prefetch_core_rd[pf_id], pf_rd, total); + _set(&blocks->prefetch_core_rd[pf_id], pf_rd, core_total); } for_each_pf(pf_id) { pf_wr = _bytes4k(s->prefetch_blocks[pf_id].write); - _set(&blocks->prefetch_cache_wr[pf_id], pf_wr, total); + _set(&blocks->prefetch_cache_wr[pf_id], pf_wr, cache_total); } /* Cleaner */ cl_rd = _bytes4k(s->cleaner_blocks.read); - _set(&blocks->cleaner_cache_rd, cl_rd, total); + _set(&blocks->cleaner_cache_rd, cl_rd, cache_total); cl_wr = _bytes4k(s->cleaner_blocks.write); - _set(&blocks->cleaner_core_wr, cl_wr, total); + _set(&blocks->cleaner_core_wr, cl_wr, core_total); } static void _fill_blocks_part(struct ocf_stats_blocks *blocks, const struct ocf_stats_io_class *s) { - uint64_t rd, wr, total; + uint64_t rd, wr, total, core_total, cache_total; uint64_t pf_rd, pf_wr; uint64_t cl_rd, cl_wr; ocf_pf_id_t pf_id; @@ -199,28 +199,28 @@ static void _fill_blocks_part(struct ocf_stats_blocks *blocks, /* Core volume */ rd = _bytes4k(s->core_blocks.read); wr = _bytes4k(s->core_blocks.write); - total = rd + wr; + core_total = rd + wr; for_each_pf(pf_id) - total += _bytes4k(s->prefetch_blocks[pf_id].read); - total += _bytes4k(s->cleaner_blocks.write); + core_total += _bytes4k(s->prefetch_blocks[pf_id].read); + core_total += _bytes4k(s->cleaner_blocks.write); - _set(&blocks->core_volume_rd, rd, total); - _set(&blocks->core_volume_wr, wr, total); - _set(&blocks->core_volume_total, total, total); + _set(&blocks->core_volume_rd, rd, core_total); + _set(&blocks->core_volume_wr, wr, core_total); + _set(&blocks->core_volume_total, core_total, core_total); /* Cache volume */ rd = _bytes4k(s->cache_blocks.read); wr = _bytes4k(s->cache_blocks.write); - total = rd + wr; + cache_total = rd + wr; for_each_pf(pf_id) - total += _bytes4k(s->prefetch_blocks[pf_id].write); - total += _bytes4k(s->cleaner_blocks.read); + cache_total += _bytes4k(s->prefetch_blocks[pf_id].write); + cache_total += _bytes4k(s->cleaner_blocks.read); - _set(&blocks->cache_volume_rd, rd, total); - _set(&blocks->cache_volume_wr, wr, total); - _set(&blocks->cache_volume_total, total, total); + _set(&blocks->cache_volume_rd, rd, cache_total); + _set(&blocks->cache_volume_wr, wr, cache_total); + _set(&blocks->cache_volume_total, cache_total, cache_total); /* Core (cache volume) */ rd = _bytes4k(s->blocks.read); @@ -241,18 +241,18 @@ static void _fill_blocks_part(struct ocf_stats_blocks *blocks, /* Prefetch */ for_each_pf(pf_id) { pf_rd = _bytes4k(s->prefetch_blocks[pf_id].read); - _set(&blocks->prefetch_core_rd[pf_id], pf_rd, total); + _set(&blocks->prefetch_core_rd[pf_id], pf_rd, core_total); } for_each_pf(pf_id) { pf_wr = _bytes4k(s->prefetch_blocks[pf_id].write); - _set(&blocks->prefetch_cache_wr[pf_id], pf_wr, total); + _set(&blocks->prefetch_cache_wr[pf_id], pf_wr, cache_total); } /* Cleaner */ cl_rd = _bytes4k(s->cleaner_blocks.read); - _set(&blocks->cleaner_cache_rd, cl_rd, total); + _set(&blocks->cleaner_cache_rd, cl_rd, cache_total); cl_wr = _bytes4k(s->cleaner_blocks.write); - _set(&blocks->cleaner_core_wr, cl_wr, total); + _set(&blocks->cleaner_core_wr, cl_wr, core_total); } static void _fill_errors(struct ocf_stats_errors *errors, From 2d1f9dbac2e3e3aefc3b48c92874fb4eb3d93597 Mon Sep 17 00:00:00 2001 From: Rafal Stefanowski Date: Mon, 26 Oct 2026 18:44:23 +0100 Subject: [PATCH 2/2] stats: Use memset instead of an aggregate initializer to zero a struct Use more straightforward and less confusing method for zeroing a struct and do it without allocating additional temporary object. Signed-off-by: Rafal Stefanowski --- src/utils/utils_stats.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/utils/utils_stats.h b/src/utils/utils_stats.h index 72c32ce7..e988556b 100644 --- a/src/utils/utils_stats.h +++ b/src/utils/utils_stats.h @@ -8,10 +8,8 @@ #define _ocf_stats_zero(stats) \ do { \ - if (stats) { \ - typeof(*stats) zero = { { 0 } }; \ - *stats = zero; \ - } \ + if (stats) \ + ENV_BUG_ON(env_memset(stats, sizeof(*stats), 0)); \ } while (0) static inline uint64_t _fraction(uint64_t numerator, uint64_t denominator)