DPDK patches and discussions
 help / color / mirror / Atom feed
From: Chengwen Feng <fengchengwen@huawei.com>
To: <thomas@monjalon.net>, <honest.jiang@foxmail.com>
Cc: <dev@dpdk.org>, <liuyonglong@huawei.com>
Subject: [PATCH 09/10] app/dma-perf: refactor benchmark function
Date: Tue, 12 Aug 2025 10:07:07 +0800	[thread overview]
Message-ID: <20250812020708.16186-10-fengchengwen@huawei.com> (raw)
In-Reply-To: <20250812020708.16186-1-fengchengwen@huawei.com>

This commit refactor mem_copy_benchmark() function by splitting the
data verification part into an independent function.

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-dma-perf/benchmark.c | 153 +++++++++++++++++++---------------
 1 file changed, 84 insertions(+), 69 deletions(-)

diff --git a/app/test-dma-perf/benchmark.c b/app/test-dma-perf/benchmark.c
index 663f81ef5c..1145493152 100644
--- a/app/test-dma-perf/benchmark.c
+++ b/app/test-dma-perf/benchmark.c
@@ -669,27 +669,100 @@ attach_ext_buffer(struct vchan_dev_config *vchan_dev, struct lcore_params *lcore
 	return 0;
 }
 
+static int
+verify_data(struct test_configure *cfg, struct rte_mbuf **srcs, struct rte_mbuf **dsts,
+	    uint32_t nr_buf)
+{
+	struct rte_mbuf **src_buf = NULL, **dst_buf = NULL;
+	uint32_t nr_buf_pt = nr_buf / cfg->num_worker;
+	struct vchan_dev_config *vchan_dev = NULL;
+	unsigned int buf_size = cfg->buf_size.cur;
+	uint32_t offset, work_idx, i, j;
+
+	for (work_idx = 0; work_idx < cfg->num_worker; work_idx++)  {
+		vchan_dev = &cfg->dma_config[work_idx].vchan_dev;
+		offset = nr_buf / cfg->num_worker * work_idx;
+		src_buf = srcs + offset;
+		dst_buf = dsts + offset;
+
+		if (vchan_dev->tdir == RTE_DMA_DIR_MEM_TO_MEM && !cfg->is_sg) {
+			for (i = 0; i < nr_buf_pt; i++) {
+				if (memcmp(rte_pktmbuf_mtod(src_buf[i], void *),
+							    rte_pktmbuf_mtod(dst_buf[i], void *),
+							    cfg->buf_size.cur) != 0) {
+					printf("Copy validation fails for buffer number %d\n", i);
+					return -1;
+				}
+			}
+			continue;
+		}
+
+		if (vchan_dev->tdir == RTE_DMA_DIR_MEM_TO_MEM && cfg->is_sg) {
+			size_t src_remsz = buf_size % cfg->nb_src_sges;
+			size_t dst_remsz = buf_size % cfg->nb_dst_sges;
+			size_t src_sz = buf_size / cfg->nb_src_sges;
+			size_t dst_sz = buf_size / cfg->nb_dst_sges;
+			uint8_t src[buf_size], dst[buf_size];
+			uint8_t *sbuf, *dbuf, *ptr;
+
+			for (i = 0; i < (nr_buf_pt / RTE_MAX(cfg->nb_src_sges, cfg->nb_dst_sges));
+				i++) {
+				sbuf = src;
+				dbuf = dst;
+				ptr = NULL;
+
+				for (j = 0; j < cfg->nb_src_sges; j++) {
+					ptr = rte_pktmbuf_mtod(src_buf[i * cfg->nb_src_sges + j],
+						uint8_t *);
+					memcpy(sbuf, ptr, src_sz);
+					sbuf += src_sz;
+				}
+				if (src_remsz)
+					memcpy(sbuf, ptr + src_sz, src_remsz);
+
+				for (j = 0; j < cfg->nb_dst_sges; j++) {
+					ptr = rte_pktmbuf_mtod(dst_buf[i * cfg->nb_dst_sges + j],
+						uint8_t *);
+					memcpy(dbuf, ptr, dst_sz);
+					dbuf += dst_sz;
+				}
+				if (dst_remsz)
+					memcpy(dbuf, ptr + dst_sz, dst_remsz);
+
+				if (memcmp(src, dst, buf_size) != 0) {
+					printf("SG Copy validation fails for buffer number %d\n",
+						i * cfg->nb_src_sges);
+					return -1;
+				}
+			}
+			continue;
+		}
+	}
+
+	return 0;
+}
+
 int
 mem_copy_benchmark(struct test_configure *cfg)
 {
-	uint32_t i, j, k;
-	uint32_t offset;
-	unsigned int lcore_id = 0;
 	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;
 	unsigned int buf_size = cfg->buf_size.cur;
 	uint16_t kick_batch = cfg->kick_batch.cur;
-	uint16_t nb_workers = cfg->num_worker;
 	uint16_t test_secs = global_cfg.test_secs;
-	float memory = 0;
-	uint32_t avg_cycles = 0;
+	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;
+	uint32_t avg_cycles = 0;
 	float mops, mops_total;
-	float bandwidth, bandwidth_total;
-	uint32_t nr_sgsrc = 0, nr_sgdst = 0;
+	float memory = 0;
 	uint32_t nr_buf;
+	uint32_t offset;
+	uint32_t i, k;
 	int ret = 0;
 
 	nr_buf = align_buffer_count(cfg, &nr_sgsrc, &nr_sgdst);
@@ -781,67 +854,9 @@ mem_copy_benchmark(struct test_configure *cfg)
 
 	rte_eal_mp_wait_lcore();
 
-	for (k = 0; k < nb_workers; k++) {
-		struct rte_mbuf **src_buf = NULL, **dst_buf = NULL;
-		uint32_t nr_buf_pt = nr_buf / nb_workers;
-		vchan_dev = &cfg->dma_config[k].vchan_dev;
-		offset = nr_buf / nb_workers * k;
-		src_buf = srcs + offset;
-		dst_buf = dsts + offset;
-
-		if (vchan_dev->tdir == RTE_DMA_DIR_MEM_TO_MEM && !cfg->is_sg) {
-			for (i = 0; i < nr_buf_pt; i++) {
-				if (memcmp(rte_pktmbuf_mtod(src_buf[i], void *),
-							    rte_pktmbuf_mtod(dst_buf[i], void *),
-							    cfg->buf_size.cur) != 0) {
-					printf("Copy validation fails for buffer number %d\n", i);
-					ret = -1;
-					goto out;
-				}
-			}
-		} else if (vchan_dev->tdir == RTE_DMA_DIR_MEM_TO_MEM && cfg->is_sg) {
-			size_t src_remsz = buf_size % cfg->nb_src_sges;
-			size_t dst_remsz = buf_size % cfg->nb_dst_sges;
-			size_t src_sz = buf_size / cfg->nb_src_sges;
-			size_t dst_sz = buf_size / cfg->nb_dst_sges;
-			uint8_t src[buf_size], dst[buf_size];
-			uint8_t *sbuf, *dbuf, *ptr;
-
-			for (i = 0; i < (nr_buf_pt / RTE_MAX(cfg->nb_src_sges, cfg->nb_dst_sges));
-			     i++) {
-				sbuf = src;
-				dbuf = dst;
-				ptr = NULL;
-
-				for (j = 0; j < cfg->nb_src_sges; j++) {
-					ptr = rte_pktmbuf_mtod(src_buf[i * cfg->nb_src_sges + j],
-							       uint8_t *);
-					memcpy(sbuf, ptr, src_sz);
-					sbuf += src_sz;
-				}
-
-				if (src_remsz)
-					memcpy(sbuf, ptr + src_sz, src_remsz);
-
-				for (j = 0; j < cfg->nb_dst_sges; j++) {
-					ptr = rte_pktmbuf_mtod(dst_buf[i * cfg->nb_dst_sges + j],
-							       uint8_t *);
-					memcpy(dbuf, ptr, dst_sz);
-					dbuf += dst_sz;
-				}
-
-				if (dst_remsz)
-					memcpy(dbuf, ptr + dst_sz, dst_remsz);
-
-				if (memcmp(src, dst, buf_size) != 0) {
-					printf("SG Copy validation fails for buffer number %d\n",
-							i * cfg->nb_src_sges);
-					ret = -1;
-					goto out;
-				}
-			}
-		}
-	}
+	ret = verify_data(cfg, srcs, dsts, nr_buf);
+	if (ret != 0)
+		goto out;
 
 	mops_total = 0;
 	bandwidth_total = 0;
-- 
2.17.1


  parent reply	other threads:[~2025-08-12  2:07 UTC|newest]

Thread overview: 21+ 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   ` Chengwen Feng [this message]
2025-08-12  2:07   ` [PATCH 10/10] app/dma-perf: support specific error info Chengwen Feng

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=20250812020708.16186-10-fengchengwen@huawei.com \
    --to=fengchengwen@huawei.com \
    --cc=dev@dpdk.org \
    --cc=honest.jiang@foxmail.com \
    --cc=liuyonglong@huawei.com \
    --cc=thomas@monjalon.net \
    /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).