From eeda1f3f0fd742e530ee7f5857314fa7be91729b Mon Sep 17 00:00:00 2001 From: Slawomir Jankowski Date: Fri, 12 Feb 2021 15:44:52 +0100 Subject: [PATCH] Unify type of `dirty_for` in info structs Reformat function that calculates how long cache/core is dirty Update `dirty_for` types in functional tests Values stored in info structs fields (both in cache and core structs) are unsigned 64-bits ints but `dirty_for`s were unsigned 32-bits ints. Use existing function to transform returned value to seconds. Replace seconds stored in metadata with seconds. Replacement was done if old value of replaced field was equal to zero. Acquiring monotonic high precission timestamp is potentially slow and it makes sense to compare the field's value to zero before calling atomic function. Signed-off-by: Slawomir Jankowski --- inc/ocf_cache.h | 2 +- inc/ocf_core.h | 2 +- src/metadata/metadata.c | 5 +++-- src/ocf_cache.c | 8 ++++---- src/ocf_core.c | 8 ++++---- src/utils/utils_cache_line.c | 6 ++++-- tests/functional/pyocf/types/stats/cache.py | 2 +- tests/functional/pyocf/types/stats/core.py | 2 +- 8 files changed, 19 insertions(+), 16 deletions(-) diff --git a/inc/ocf_cache.h b/inc/ocf_cache.h index 098e1d3..dc96487 100644 --- a/inc/ocf_cache.h +++ b/inc/ocf_cache.h @@ -53,7 +53,7 @@ struct ocf_cache_info { * out of WB mode */ - uint32_t dirty_for; + uint64_t dirty_for; /*!< How long there are dirty cache lines (in seconds) */ ocf_cache_mode_t cache_mode; diff --git a/inc/ocf_core.h b/inc/ocf_core.h index 700a3bb..f1e95ed 100644 --- a/inc/ocf_core.h +++ b/inc/ocf_core.h @@ -32,7 +32,7 @@ struct ocf_core_info { }; /** How long core is dirty in seconds unit */ - uint32_t dirty_for; + uint64_t dirty_for; /** Sequential cutoff threshold (in bytes) */ uint32_t seq_cutoff_threshold; diff --git a/src/metadata/metadata.c b/src/metadata/metadata.c index 4874a13..271d01d 100644 --- a/src/metadata/metadata.c +++ b/src/metadata/metadata.c @@ -1192,8 +1192,9 @@ static void _recovery_rebuild_cline_metadata(ocf_cache_t cache, env_atomic_inc(&core->runtime_meta->dirty_clines); env_atomic_inc(&core->runtime_meta-> part_counters[part_id].dirty_clines); - env_atomic64_cmpxchg(&core->runtime_meta->dirty_since, - 0, env_get_tick_count()); + if (!env_atomic64_read(&core->runtime_meta->dirty_since)) + env_atomic64_cmpxchg(&core->runtime_meta->dirty_since, 0, + env_ticks_to_secs(env_get_tick_count())); } } diff --git a/src/ocf_cache.c b/src/ocf_cache.c index 99cdae1..8c15327 100644 --- a/src/ocf_cache.c +++ b/src/ocf_cache.c @@ -56,11 +56,11 @@ ocf_cache_mode_t ocf_cache_get_mode(ocf_cache_t cache) return cache->conf_meta->cache_mode; } -static uint32_t _calc_dirty_for(uint64_t dirty_since) +static uint64_t _calc_dirty_for(uint64_t dirty_since) { - return dirty_since ? - (env_ticks_to_msecs(env_get_tick_count() - dirty_since) / 1000) - : 0; + uint64_t current_time = env_ticks_to_secs(env_get_tick_count()); + + return dirty_since ? (current_time - dirty_since) : 0; } int ocf_cache_get_info(ocf_cache_t cache, struct ocf_cache_info *info) diff --git a/src/ocf_core.c b/src/ocf_core.c index b351250..9a2cf2a 100644 --- a/src/ocf_core.c +++ b/src/ocf_core.c @@ -142,11 +142,11 @@ 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) +static uint64_t _calc_dirty_for(uint64_t dirty_since) { - return dirty_since ? - (env_ticks_to_msecs(env_get_tick_count() - dirty_since) / 1000) - : 0; + uint64_t current_time = env_ticks_to_secs(env_get_tick_count()); + + return dirty_since ? (current_time - dirty_since) : 0; } static inline struct ocf_request *ocf_io_to_req(struct ocf_io *io) diff --git a/src/utils/utils_cache_line.c b/src/utils/utils_cache_line.c index 02d2d36..e022181 100644 --- a/src/utils/utils_cache_line.c +++ b/src/utils/utils_cache_line.c @@ -156,8 +156,10 @@ void set_cache_line_dirty(struct ocf_cache *cache, uint8_t start_bit, /* * If this is first dirty cline set dirty timestamp */ - env_atomic64_cmpxchg(&req->core->runtime_meta->dirty_since, - 0, env_get_tick_count()); + if (!env_atomic64_read(&req->core->runtime_meta->dirty_since)) + env_atomic64_cmpxchg( + &req->core->runtime_meta->dirty_since, 0, + env_ticks_to_secs(env_get_tick_count())); /* * Update the number of dirty cached data for that diff --git a/tests/functional/pyocf/types/stats/cache.py b/tests/functional/pyocf/types/stats/cache.py index b57ea21..d4ef4ff 100644 --- a/tests/functional/pyocf/types/stats/cache.py +++ b/tests/functional/pyocf/types/stats/cache.py @@ -24,7 +24,7 @@ class CacheInfo(Structure): ("occupancy", c_uint32), ("dirty", c_uint32), ("dirty_initial", c_uint32), - ("dirty_for", c_uint32), + ("dirty_for", c_uint64), ("cache_mode", c_uint32), ("fallback_pt", _FallbackPt), ("state", c_uint8), diff --git a/tests/functional/pyocf/types/stats/core.py b/tests/functional/pyocf/types/stats/core.py index f02b72d..1ba4bab 100644 --- a/tests/functional/pyocf/types/stats/core.py +++ b/tests/functional/pyocf/types/stats/core.py @@ -15,7 +15,7 @@ class CoreInfo(Structure): ("core_size_bytes", c_uint64), ("dirty", c_uint32), ("flushed", c_uint32), - ("dirty_for", c_uint32), + ("dirty_for", c_uint64), ("seq_cutoff_threshold", c_uint32), ("seq_cutoff_policy", c_uint32), ]