Skip to content

Commit

Permalink
linux-gen: pool: optimize odp_pool_stats() implementation
Browse files Browse the repository at this point in the history
If 'thread_cache_available' is enabled and 'cache_available' is not, it's
enough to read only the selected per thread counters.

Signed-off-by: Matias Elo <matias.elo@nokia.com>
  • Loading branch information
MatiasElo committed Dec 1, 2023
1 parent e4f8674 commit 190a5c3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions platform/linux-generic/odp_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ static inline int cache_available(pool_t *pool, odp_pool_stats_t *stats)
uint64_t cached = 0;
const uint16_t first = stats->thread.first;
const uint16_t last = stats->thread.last;
const odp_bool_t cache_available = pool->params.stats.bit.cache_available;
const odp_bool_t per_thread = pool->params.stats.bit.thread_cache_available;
const int max_threads = odp_thread_count_max();
uint16_t out_idx = 0;
int i, idx_limit;

if (per_thread) {
if (first > last || last >= max_threads) {
Expand All @@ -165,7 +167,15 @@ static inline int cache_available(pool_t *pool, odp_pool_stats_t *stats)
}
}

for (int i = 0; i < max_threads; i++) {
if (cache_available) {
i = 0;
idx_limit = max_threads;
} else {
i = first;
idx_limit = last + 1;
}

for (; i < idx_limit; i++) {
uint32_t cur = odp_atomic_load_u32(&pool->local_cache[i].cache_num);

if (per_thread && i >= first && i <= last)
Expand All @@ -174,7 +184,7 @@ static inline int cache_available(pool_t *pool, odp_pool_stats_t *stats)
cached += cur;
}

if (pool->params.stats.bit.cache_available)
if (cache_available)
stats->cache_available = cached;

return 0;
Expand Down

0 comments on commit 190a5c3

Please sign in to comment.