From 96e527049a52ccbfbaa16f561797120a910c93ee Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Fri, 21 Mar 2025 11:51:01 +0100 Subject: [PATCH] Refactor __set_cache_line_invalid() pt.2 Get rid of nested ifs Signed-off-by: Michal Mielewczyk --- src/utils/utils_cache_line.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/utils/utils_cache_line.c b/src/utils/utils_cache_line.c index 54a16ac..8668966 100644 --- a/src/utils/utils_cache_line.c +++ b/src/utils/utils_cache_line.c @@ -20,20 +20,26 @@ static void __set_cache_line_invalid(struct ocf_cache *cache, uint8_t start_bit, line_became_invalid = metadata_clear_valid_sec_changed(cache, line, start_bit, end_bit, &line_remains_valid); - /* If we have waiters, do not remove cache line - * for this cache line which will use one, clear - * only valid bits - */ - if (!line_remains_valid && !ocf_cache_line_are_waiters( - ocf_cache_line_concurrency(cache), line)) { - if (line_became_invalid) { - env_atomic_dec(&core->runtime_meta->cached_clines); - env_atomic_dec(&core->runtime_meta-> - part_counters[part_id].cached_clines); - } - ocf_lru_rm_cline(cache, line); - ocf_metadata_remove_cache_line(cache, line); + if (line_remains_valid) { + ENV_BUG_ON(line_became_invalid); + return; } + + /* If there are any waiters, don't transfer the line to the freelist. + * The new owner will take care about the repart anyways + */ + if (ocf_cache_line_are_waiters(ocf_cache_line_concurrency(cache), line)) + return; + + ocf_lru_rm_cline(cache, line); + ocf_metadata_remove_cache_line(cache, line); + + if (!line_became_invalid) + return; + + env_atomic_dec(&core->runtime_meta->cached_clines); + env_atomic_dec(&core->runtime_meta-> + part_counters[part_id].cached_clines); } void set_cache_line_invalid(struct ocf_cache *cache, uint8_t start_bit,