Skip to content

Commit

Permalink
test: dmafwd: reorder cache size calculations
Browse files Browse the repository at this point in the history
Move pool and stash cache calculations inside branches where related
logic resides, preventing uninitialized value usage. The actual
uninitialized usage is prevented later and does not cause any runtime
issues. Nevertheless, this is now properly handled during startup.

Signed-off-by: Tuomas Taipale <tuomas.taipale@nokia.com>
Reviewed-by: Matias Elo <matias.elo@nokia.com>
  • Loading branch information
TuomasTaipale committed Sep 29, 2023
1 parent 0248805 commit 95cc30d
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions test/performance/odp_dmafwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,22 @@ static parse_result_t check_options(prog_config_t *config)

config->num_inflight = dma_capa.max_transfers;

if (odp_pool_capability(&pool_capa) < 0) {
ODPH_ERR("Error querying pool capabilities\n");
return PRS_NOK;
}

if (config->cache_size < pool_capa.pkt.min_cache_size ||
config->cache_size > pool_capa.pkt.max_cache_size) {
ODPH_ERR("Invalid pool cache size: %u (min: %u, max: %u)\n", config->cache_size,
pool_capa.pkt.min_cache_size, pool_capa.pkt.max_cache_size);
return PRS_NOK;
}

if (config->copy_type != SW_COPY)
config->trs_cache_size = MIN(MAX(config->cache_size, pool_capa.buf.min_cache_size),
pool_capa.buf.max_cache_size);

if (config->copy_type == DMA_COPY_EV) {
if ((dma_capa.compl_mode_mask & ODP_DMA_COMPL_EVENT) == 0U ||
!dma_capa.queue_type_sched) {
Expand All @@ -377,6 +393,10 @@ static parse_result_t check_options(prog_config_t *config)
config->num_inflight, dma_capa.pool.max_num);
return PRS_NOK;
}

config->compl_cache_size = MIN(MAX(config->cache_size,
dma_capa.pool.min_cache_size),
dma_capa.pool.max_cache_size);
} else if (config->copy_type == DMA_COPY_POLL) {
if ((dma_capa.compl_mode_mask & ODP_DMA_COMPL_POLL) == 0U) {
ODPH_ERR("Unsupported DMA completion mode: poll (mode support: %x)\n",
Expand Down Expand Up @@ -417,11 +437,7 @@ static parse_result_t check_options(prog_config_t *config)
}

config->inflight_obj_size = obj_size;
}

if (odp_pool_capability(&pool_capa) < 0) {
ODPH_ERR("Error querying pool capabilities\n");
return PRS_NOK;
config->stash_cache_size = MIN(config->cache_size, stash_capa.max_cache_size);
}

if (config->num_pkts == 0U ||
Expand All @@ -438,25 +454,12 @@ static parse_result_t check_options(prog_config_t *config)
return PRS_NOK;
}

if (config->cache_size < pool_capa.pkt.min_cache_size ||
config->cache_size > pool_capa.pkt.max_cache_size) {
ODPH_ERR("Invalid pool cache size: %u (min: %u, max: %u)\n", config->cache_size,
pool_capa.pkt.min_cache_size, pool_capa.pkt.max_cache_size);
return PRS_NOK;
}

if (config->num_inflight > pool_capa.buf.max_num) {
ODPH_ERR("Invalid pool buffer count: %u (max: %u)\n", config->num_inflight,
pool_capa.buf.max_num);
return PRS_NOK;
}

config->trs_cache_size = MIN(MAX(config->cache_size, pool_capa.buf.min_cache_size),
pool_capa.buf.max_cache_size);
config->compl_cache_size = MIN(MAX(config->cache_size, dma_capa.pool.min_cache_size),
dma_capa.pool.max_cache_size);
config->stash_cache_size = MIN(config->cache_size, stash_capa.max_cache_size);

return PRS_OK;
}

Expand Down

0 comments on commit 95cc30d

Please sign in to comment.