Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH v2] linux-gen: pool: optimize odp_pool_stats() implementation #1962

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions platform/linux-generic/odp_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,14 @@ 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 >= odp_thread_count_max()) {
if (first > last || last >= max_threads) {
_ODP_ERR("Bad thread ids: first=%" PRIu16 " last=%" PRIu16 "\n",
first, last);
return -1;
Expand All @@ -164,7 +167,15 @@ static inline int cache_available(pool_t *pool, odp_pool_stats_t *stats)
}
}

for (int i = 0; i < ODP_THREAD_COUNT_MAX; 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 @@ -173,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 All @@ -182,8 +193,9 @@ static inline int cache_available(pool_t *pool, odp_pool_stats_t *stats)
static inline uint64_t cache_total_available(pool_t *pool)
{
uint64_t cached = 0;
const int max_threads = odp_thread_count_max();

for (int i = 0; i < ODP_THREAD_COUNT_MAX; i++)
for (int i = 0; i < max_threads; i++)
cached += odp_atomic_load_u32(&pool->local_cache[i].cache_num);

return cached;
Expand Down Expand Up @@ -1169,6 +1181,7 @@ odp_pool_t odp_pool_create(const char *name, const odp_pool_param_t *params)
int odp_pool_destroy(odp_pool_t pool_hdl)
{
pool_t *pool = _odp_pool_entry(pool_hdl);
const int max_threads = odp_thread_count_max();
int i;

if (pool == NULL)
Expand All @@ -1186,7 +1199,7 @@ int odp_pool_destroy(odp_pool_t pool_hdl)
pool->mem_src_ops->unbind(pool->mem_src_data);

/* Make sure local caches are empty */
for (i = 0; i < ODP_THREAD_COUNT_MAX; i++)
for (i = 0; i < max_threads; i++)
cache_flush(&pool->local_cache[i], pool);

if (pool->pool_ext == 0)
Expand Down