From: Chengwen Feng <fengchengwen@huawei.com>
To: <thomas@monjalon.net>, <honest.jiang@foxmail.com>
Cc: <dev@dpdk.org>, <liuyonglong@huawei.com>, <vattunuru@marvell.com>
Subject: [PATCH v4 14/14] app/dma-perf: refactor benchmark function
Date: Mon, 20 Oct 2025 12:11:05 +0800 [thread overview]
Message-ID: <20251020041105.1590-15-fengchengwen@huawei.com> (raw)
In-Reply-To: <20251020041105.1590-1-fengchengwen@huawei.com>
Refactor benchmark function by splitting the resource alloc/free to
different subfunctions.
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
app/test-dma-perf/benchmark.c | 217 ++++++++++++++++++++--------------
1 file changed, 130 insertions(+), 87 deletions(-)
diff --git a/app/test-dma-perf/benchmark.c b/app/test-dma-perf/benchmark.c
index 7512018e38..b6125d86f9 100644
--- a/app/test-dma-perf/benchmark.c
+++ b/app/test-dma-perf/benchmark.c
@@ -240,6 +240,9 @@ config_dmadevs(struct test_configure *cfg)
uint8_t nb_sges = 0;
char *dma_name;
+ if (cfg->test_type != TEST_TYPE_DMA_MEM_COPY)
+ return 0;
+
if (cfg->is_sg)
nb_sges = RTE_MAX(cfg->nb_src_sges, cfg->nb_dst_sges);
@@ -540,7 +543,7 @@ dummy_free_ext_buf(void *addr, void *opaque)
static int
setup_memory_env(struct test_configure *cfg, uint32_t nr_buf,
- struct rte_mbuf ***srcs, struct rte_mbuf ***dsts,
+ struct rte_mbuf ***srcs, struct rte_mbuf ***dsts,
struct rte_dma_sge **src_sges, struct rte_dma_sge **dst_sges,
struct rte_dma_op ***dma_ops)
{
@@ -681,6 +684,39 @@ setup_memory_env(struct test_configure *cfg, uint32_t nr_buf,
return 0;
}
+static void
+teardown_memory_env(uint32_t nr_buf, struct rte_mbuf **srcs, struct rte_mbuf **dsts,
+ struct rte_dma_sge *src_sges, struct rte_dma_sge *dst_sges,
+ struct rte_dma_op **dma_ops)
+{
+ /* free mbufs used in the test */
+ if (srcs != NULL)
+ rte_pktmbuf_free_bulk(srcs, nr_buf);
+ if (dsts != NULL)
+ rte_pktmbuf_free_bulk(dsts, nr_buf);
+
+ /* free the points for the mbufs */
+ rte_free(srcs);
+ srcs = NULL;
+ rte_free(dsts);
+ dsts = NULL;
+
+ rte_mempool_free(src_pool);
+ src_pool = NULL;
+
+ rte_mempool_free(dst_pool);
+ dst_pool = NULL;
+
+ /* free sges for mbufs */
+ rte_free(src_sges);
+ src_sges = NULL;
+
+ rte_free(dst_sges);
+ dst_sges = NULL;
+
+ rte_free(dma_ops);
+}
+
static uint32_t
align_buffer_count(struct test_configure *cfg, uint32_t *nr_sgsrc, uint32_t *nr_sgdst)
{
@@ -883,48 +919,23 @@ verify_data(struct test_configure *cfg, struct rte_mbuf **srcs, struct rte_mbuf
return 0;
}
-int
-mem_copy_benchmark(struct test_configure *cfg)
+static int
+setup_worker(struct test_configure *cfg, uint32_t nr_buf,
+ struct rte_mbuf **srcs, struct rte_mbuf **dsts,
+ struct rte_dma_sge *src_sges, struct rte_dma_sge *dst_sges,
+ struct rte_dma_op **dma_ops,
+ uint32_t nr_sgsrc, uint32_t nr_sgdst)
{
- struct rte_mbuf **srcs = NULL, **dsts = NULL, **m = NULL;
- struct rte_dma_sge *src_sges = NULL, *dst_sges = NULL;
- struct vchan_dev_config *vchan_dev = NULL;
struct lcore_dma_map_t *lcore_dma_map = NULL;
- struct rte_dma_op **dma_ops = NULL;
+ struct vchan_dev_config *vchan_dev = NULL;
unsigned int buf_size = cfg->buf_size.cur;
uint16_t kick_batch = cfg->kick_batch.cur;
uint16_t test_secs = global_cfg.test_secs;
uint16_t nb_workers = cfg->num_worker;
- uint32_t nr_sgsrc = 0, nr_sgdst = 0;
- float bandwidth, bandwidth_total;
unsigned int lcore_id = 0;
- uint32_t avg_cycles_total;
- bool dev_stopped = false;
- uint32_t avg_cycles = 0;
- float mops, mops_total;
- float memory = 0;
uint32_t i, j, k;
- uint32_t nr_buf;
uint32_t nr_ops;
uint32_t offset;
- int ret = 0;
-
- nr_buf = align_buffer_count(cfg, &nr_sgsrc, &nr_sgdst);
-
- if (setup_memory_env(cfg, nr_buf, &srcs, &dsts, &src_sges, &dst_sges, &dma_ops) < 0)
- goto out;
-
- if (cfg->test_type == TEST_TYPE_DMA_MEM_COPY)
- if (config_dmadevs(cfg) < 0)
- goto out;
-
- if (global_cfg.cache_flush > 0) {
- cache_flush_buf(srcs, buf_size, nr_buf);
- cache_flush_buf(dsts, buf_size, nr_buf);
- rte_mb();
- }
-
- printf("Start testing....\n");
for (i = 0; i < nb_workers; i++) {
lcore_dma_map = &cfg->dma_config[i].lcore_dma_map;
@@ -935,7 +946,7 @@ mem_copy_benchmark(struct test_configure *cfg)
lcores[i] = rte_malloc(NULL, sizeof(struct lcore_params), 0);
if (lcores[i] == NULL) {
printf("lcore parameters malloc failure for lcore %d\n", lcore_id);
- break;
+ return -1;
}
if (cfg->test_type == TEST_TYPE_DMA_MEM_COPY) {
lcores[i]->dma_name = lcore_dma_map->dma_names;
@@ -963,7 +974,7 @@ mem_copy_benchmark(struct test_configure *cfg)
vchan_dev->tdir == RTE_DMA_DIR_MEM_TO_DEV) {
if (attach_ext_buffer(vchan_dev, lcores[i], cfg->is_sg,
(nr_sgsrc/nb_workers), (nr_sgdst/nb_workers)) < 0)
- goto stop_dmadev;
+ return -1;
}
if (cfg->is_sg && cfg->use_ops) {
@@ -988,6 +999,88 @@ mem_copy_benchmark(struct test_configure *cfg)
rte_eal_remote_launch(get_work_function(cfg), (void *)(lcores[i]), lcore_id);
}
+ return 0;
+}
+
+static void
+teardown_worker_res(struct test_configure *cfg, uint32_t nr_buf,
+ struct rte_mbuf **srcs, struct rte_mbuf **dsts)
+{
+ uint16_t nb_workers = cfg->num_worker;
+ struct vchan_dev_config *vchan_dev;
+ struct rte_mbuf **m;
+ uint32_t offset;
+ uint32_t i, j;
+
+ for (i = 0; i < nb_workers; i++) {
+ struct rte_mbuf **sbuf = NULL, **dbuf = NULL;
+ vchan_dev = &cfg->dma_config[i].vchan_dev;
+ offset = nr_buf / nb_workers * i;
+ m = NULL;
+ if (vchan_dev->tdir == RTE_DMA_DIR_DEV_TO_MEM) {
+ sbuf = srcs + offset;
+ m = sbuf;
+ } else if (vchan_dev->tdir == RTE_DMA_DIR_MEM_TO_DEV) {
+ dbuf = dsts + offset;
+ m = dbuf;
+ }
+
+ if (m) {
+ for (j = 0; j < (nr_buf / nb_workers); j++)
+ rte_pktmbuf_detach_extbuf(m[j]);
+
+ if (m[0]->shinfo && rte_mbuf_ext_refcnt_read(m[0]->shinfo) == 0)
+ rte_free(m[0]->shinfo);
+ }
+
+ rte_free(lcores[i]);
+ lcores[i] = NULL;
+ }
+}
+
+int
+mem_copy_benchmark(struct test_configure *cfg)
+{
+ struct rte_mbuf **srcs = NULL, **dsts = NULL;
+ struct rte_dma_sge *src_sges = NULL, *dst_sges = NULL;
+ struct vchan_dev_config *vchan_dev = NULL;
+ unsigned int buf_size = cfg->buf_size.cur;
+ uint16_t kick_batch = cfg->kick_batch.cur;
+ uint16_t test_secs = global_cfg.test_secs;
+ uint16_t nb_workers = cfg->num_worker;
+ uint32_t nr_sgsrc = 0, nr_sgdst = 0;
+ struct rte_dma_op **dma_ops = NULL;
+ float bandwidth, bandwidth_total;
+ uint32_t avg_cycles_total;
+ bool dev_stopped = false;
+ uint32_t avg_cycles = 0;
+ float mops, mops_total;
+ float memory = 0;
+ uint32_t nr_buf;
+ int ret = -1;
+ uint32_t i;
+
+ nr_buf = align_buffer_count(cfg, &nr_sgsrc, &nr_sgdst);
+
+ if (setup_memory_env(cfg, nr_buf, &srcs, &dsts, &src_sges, &dst_sges, &dma_ops) < 0)
+ goto out;
+
+ if (config_dmadevs(cfg) < 0)
+ goto out;
+
+ if (global_cfg.cache_flush > 0) {
+ cache_flush_buf(srcs, buf_size, nr_buf);
+ cache_flush_buf(dsts, buf_size, nr_buf);
+ rte_mb();
+ }
+
+ printf("Start testing....\n");
+
+ ret = setup_worker(cfg, nr_buf, srcs, dsts, src_sges, dst_sges, dma_ops,
+ nr_sgsrc, nr_sgdst);
+ if (ret != 0)
+ goto stop_dmadev;
+
while (1) {
bool ready = true;
for (i = 0; i < nb_workers; i++) {
@@ -1048,58 +1141,8 @@ mem_copy_benchmark(struct test_configure *cfg)
stop_dmadev(cfg, &dev_stopped);
out:
- for (k = 0; k < nb_workers; k++) {
- struct rte_mbuf **sbuf = NULL, **dbuf = NULL;
- vchan_dev = &cfg->dma_config[k].vchan_dev;
- offset = nr_buf / nb_workers * k;
- m = NULL;
- if (vchan_dev->tdir == RTE_DMA_DIR_DEV_TO_MEM) {
- sbuf = srcs + offset;
- m = sbuf;
- } else if (vchan_dev->tdir == RTE_DMA_DIR_MEM_TO_DEV) {
- dbuf = dsts + offset;
- m = dbuf;
- }
-
- if (m) {
- for (i = 0; i < (nr_buf / nb_workers); i++)
- rte_pktmbuf_detach_extbuf(m[i]);
-
- if (m[0]->shinfo && rte_mbuf_ext_refcnt_read(m[0]->shinfo) == 0)
- rte_free(m[0]->shinfo);
- }
- }
-
- /* free mbufs used in the test */
- if (srcs != NULL)
- rte_pktmbuf_free_bulk(srcs, nr_buf);
- if (dsts != NULL)
- rte_pktmbuf_free_bulk(dsts, nr_buf);
-
- /* free the points for the mbufs */
- rte_free(srcs);
- srcs = NULL;
- rte_free(dsts);
- dsts = NULL;
-
- rte_mempool_free(src_pool);
- src_pool = NULL;
-
- rte_mempool_free(dst_pool);
- dst_pool = NULL;
-
- /* free sges for mbufs */
- rte_free(src_sges);
- src_sges = NULL;
-
- rte_free(dst_sges);
- dst_sges = NULL;
-
- /* free the worker parameters */
- for (i = 0; i < nb_workers; i++) {
- rte_free(lcores[i]);
- lcores[i] = NULL;
- }
+ teardown_worker_res(cfg, nr_buf, srcs, dsts);
+ teardown_memory_env(nr_buf, srcs, dsts, src_sges, dst_sges, dma_ops);
return ret;
}
--
2.17.1
prev parent reply other threads:[~2025-10-20 4:12 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-11 10:54 [PATCH 0/9] bugfix and refactor of dma-perf Chengwen Feng
2025-08-11 10:54 ` [PATCH 1/9] app/dma-perf: fix use-after-free Chengwen Feng
2025-08-11 10:54 ` [PATCH 2/9] app/dma-perf: add global section for config file Chengwen Feng
2025-08-11 10:54 ` [PATCH 3/9] app/dma-perf: use argparse lib to parse argument Chengwen Feng
2025-08-11 10:54 ` [PATCH 4/9] app/dma-perf: refactor output csv Chengwen Feng
2025-08-11 10:54 ` [PATCH 5/9] app/dma-perf: support list DMA devices Chengwen Feng
2025-08-11 10:54 ` [PATCH 6/9] app/dma-perf: add more global config Chengwen Feng
2025-08-11 10:54 ` [PATCH 7/9] app/dma-perf: remove invalid or redundant field Chengwen Feng
2025-08-11 10:54 ` [PATCH 8/9] app/dma-perf: refactor load config function Chengwen Feng
2025-08-11 10:54 ` [PATCH 9/9] app/dma-perf: refactor benchmark function Chengwen Feng
2025-08-12 2:06 ` [PATCH 00/10] bugfix and refactor of dma-perf Chengwen Feng
2025-08-12 2:06 ` [PATCH 01/10] app/dma-perf: fix use-after-free Chengwen Feng
2025-08-12 2:07 ` [PATCH 02/10] app/dma-perf: add global section for config file Chengwen Feng
2025-08-12 2:07 ` [PATCH 03/10] app/dma-perf: use argparse lib to parse argument Chengwen Feng
2025-08-12 2:07 ` [PATCH 04/10] app/dma-perf: refactor output csv Chengwen Feng
2025-08-12 2:07 ` [PATCH 05/10] app/dma-perf: support list DMA devices Chengwen Feng
2025-08-12 2:07 ` [PATCH 06/10] app/dma-perf: add more global config Chengwen Feng
2025-08-12 2:07 ` [PATCH 07/10] app/dma-perf: remove invalid or redundant field Chengwen Feng
2025-08-12 2:07 ` [PATCH 08/10] app/dma-perf: refactor load config function Chengwen Feng
2025-08-12 2:07 ` [PATCH 09/10] app/dma-perf: refactor benchmark function Chengwen Feng
2025-08-12 2:07 ` [PATCH 10/10] app/dma-perf: support specific error info Chengwen Feng
2025-09-11 14:53 ` [EXTERNAL] [PATCH 00/10] bugfix and refactor of dma-perf Vamsi Krishna Attunuru
2025-09-17 3:33 ` [PATCH v2 " Chengwen Feng
2025-09-17 3:33 ` [PATCH v2 01/10] app/dma-perf: fix use-after-free Chengwen Feng
2025-09-17 3:33 ` [PATCH v2 02/10] app/dma-perf: add global section for config file Chengwen Feng
2025-09-17 3:33 ` [PATCH v2 03/10] app/dma-perf: use argparse lib to parse argument Chengwen Feng
2025-09-17 3:33 ` [PATCH v2 04/10] app/dma-perf: refactor output csv Chengwen Feng
2025-09-17 3:33 ` [PATCH v2 05/10] app/dma-perf: support list DMA devices Chengwen Feng
2025-09-17 3:33 ` [PATCH v2 06/10] app/dma-perf: add more global config Chengwen Feng
2025-09-17 3:33 ` [PATCH v2 07/10] app/dma-perf: remove invalid or redundant field Chengwen Feng
2025-09-17 3:33 ` [PATCH v2 08/10] app/dma-perf: refactor load config function Chengwen Feng
2025-09-17 3:33 ` [PATCH v2 09/10] app/dma-perf: refactor benchmark function Chengwen Feng
2025-09-17 3:33 ` [PATCH v2 10/10] app/dma-perf: support specific error info Chengwen Feng
2025-10-13 3:02 ` [PATCH v3 00/13] bugfix and refactor of dma-perf Chengwen Feng
2025-10-13 3:02 ` [PATCH v3 01/13] app/dma-perf: fix use-after-free Chengwen Feng
2025-10-13 7:55 ` Bruce Richardson
2025-10-13 8:15 ` fengchengwen
2025-10-13 3:02 ` [PATCH v3 02/13] app/dma-perf: add global section for config file Chengwen Feng
2025-10-13 3:02 ` [PATCH v3 03/13] app/dma-perf: use argparse lib to parse argument Chengwen Feng
2025-10-13 3:02 ` [PATCH v3 04/13] app/dma-perf: refactor output csv Chengwen Feng
2025-10-13 3:02 ` [PATCH v3 05/13] app/dma-perf: support list DMA devices Chengwen Feng
2025-10-13 3:02 ` [PATCH v3 06/13] app/dma-perf: add more global config Chengwen Feng
2025-10-13 3:02 ` [PATCH v3 07/13] app/dma-perf: remove invalid or redundant field Chengwen Feng
2025-10-13 3:02 ` [PATCH v3 08/13] app/dma-perf: refactor load config function Chengwen Feng
2025-10-13 3:02 ` [PATCH v3 09/13] app/dma-perf: refactor benchmark function Chengwen Feng
2025-10-13 3:02 ` [PATCH v3 10/13] app/dma-perf: support specific error info Chengwen Feng
2025-10-13 3:02 ` [PATCH v3 11/13] app/dma-perf: fix segment fault with large size Chengwen Feng
2025-10-13 3:02 ` [PATCH v3 12/13] app/dma-perf: fix on-flight DMA when verify data Chengwen Feng
2025-10-13 3:02 ` [PATCH v3 13/13] app/dma-perf: fix wrong stage to stop dmadev Chengwen Feng
2025-10-20 4:10 ` [PATCH v4 00/14] bugfix and refactor of dma-perf Chengwen Feng
2025-10-20 4:10 ` [PATCH v4 01/14] app/dma-perf: fix use-after-free Chengwen Feng
2025-10-20 4:10 ` [PATCH v4 02/14] app/dma-perf: add global section for config file Chengwen Feng
2025-10-20 4:10 ` [PATCH v4 03/14] app/dma-perf: use argparse lib to parse argument Chengwen Feng
2025-10-20 4:10 ` [PATCH v4 04/14] app/dma-perf: refactor output csv Chengwen Feng
2025-10-20 4:10 ` [PATCH v4 05/14] app/dma-perf: support list DMA devices Chengwen Feng
2025-10-20 4:10 ` [PATCH v4 06/14] app/dma-perf: add more global config Chengwen Feng
2025-10-20 4:10 ` [PATCH v4 07/14] app/dma-perf: remove invalid or redundant field Chengwen Feng
2025-10-20 4:10 ` [PATCH v4 08/14] app/dma-perf: refactor load config function Chengwen Feng
2025-10-20 4:11 ` [PATCH v4 09/14] app/dma-perf: refactor benchmark function Chengwen Feng
2025-10-20 4:11 ` [PATCH v4 10/14] app/dma-perf: support specific error info Chengwen Feng
2025-10-20 4:11 ` [PATCH v4 11/14] app/dma-perf: fix segment fault with large size Chengwen Feng
2025-10-20 4:11 ` [PATCH v4 12/14] app/dma-perf: fix on-flight DMA when verify data Chengwen Feng
2025-10-20 4:11 ` [PATCH v4 13/14] app/dma-perf: fix wrong stage to stop dmadev Chengwen Feng
2025-10-20 4:11 ` Chengwen Feng [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251020041105.1590-15-fengchengwen@huawei.com \
--to=fengchengwen@huawei.com \
--cc=dev@dpdk.org \
--cc=honest.jiang@foxmail.com \
--cc=liuyonglong@huawei.com \
--cc=thomas@monjalon.net \
--cc=vattunuru@marvell.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).