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 08/10] app/dma-perf: refactor load config function
Date: Tue, 12 Aug 2025 10:07:06 +0800	[thread overview]
Message-ID: <20250812020708.16186-9-fengchengwen@huawei.com> (raw)
In-Reply-To: <20250812020708.16186-1-fengchengwen@huawei.com>

The load_configs() function has 198 lines, and hard to understand.
This commit split it to three functions.

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test-dma-perf/main.c | 212 ++++++++++++++++++++-------------------
 1 file changed, 109 insertions(+), 103 deletions(-)

diff --git a/app/test-dma-perf/main.c b/app/test-dma-perf/main.c
index e630d2980a..d8d1e3d3f8 100644
--- a/app/test-dma-perf/main.c
+++ b/app/test-dma-perf/main.c
@@ -191,6 +191,20 @@ parse_lcore(struct test_configure *test_case, const char *value)
 	return 0;
 }
 
+static void
+parse_cpu_config(struct test_configure *test_case, int case_id,
+		     struct rte_cfgfile *cfgfile, char *section_name)
+{
+	const char *lcore;
+
+	lcore = rte_cfgfile_get_entry(cfgfile, section_name, "lcore");
+	int lcore_ret = parse_lcore(test_case, lcore);
+	if (lcore_ret < 0) {
+		printf("parse lcore error in case %d.\n", case_id);
+		test_case->is_valid = false;
+	}
+}
+
 static int
 parse_entry(const char *value, struct test_configure_entry *entry)
 {
@@ -269,6 +283,91 @@ static int populate_dma_dev_config(const char *key, const char *value, void *tes
 	return ret;
 }
 
+static void
+parse_dma_config(struct test_configure *test_case, int case_id,
+		     struct rte_cfgfile *cfgfile, char *section_name, int *nb_vp)
+{
+	const char *ring_size_str, *kick_batch_str, *src_sges_str, *dst_sges_str;
+	char lc_dma[RTE_DEV_NAME_MAX_LEN];
+	struct rte_kvargs *kvlist;
+	const char *lcore_dma;
+	int args_nr;
+	int i;
+
+	ring_size_str = rte_cfgfile_get_entry(cfgfile, section_name, "dma_ring_size");
+	args_nr = parse_entry(ring_size_str, &test_case->ring_size);
+	if (args_nr < 0) {
+		printf("parse error in case %d.\n", case_id);
+		test_case->is_valid = false;
+		return;
+	} else if (args_nr == 4)
+		*nb_vp += 1;
+
+	src_sges_str = rte_cfgfile_get_entry(cfgfile, section_name, "dma_src_sge");
+	if (src_sges_str != NULL)
+		test_case->nb_src_sges = (int)atoi(rte_cfgfile_get_entry(cfgfile,
+						section_name, "dma_src_sge"));
+
+	dst_sges_str = rte_cfgfile_get_entry(cfgfile, section_name, "dma_dst_sge");
+	if (dst_sges_str != NULL)
+		test_case->nb_dst_sges = (int)atoi(rte_cfgfile_get_entry(cfgfile,
+						section_name, "dma_dst_sge"));
+
+	if ((src_sges_str != NULL && dst_sges_str == NULL) ||
+	    (src_sges_str == NULL && dst_sges_str != NULL)) {
+		printf("parse dma_src_sge, dma_dst_sge error in case %d.\n", case_id);
+		test_case->is_valid = false;
+		return;
+	} else if (src_sges_str != NULL && dst_sges_str != NULL) {
+		if (test_case->nb_src_sges == 0 || test_case->nb_dst_sges == 0) {
+			printf("dma_src_sge and dma_dst_sge can not be 0 in case %d.\n", case_id);
+			test_case->is_valid = false;
+			return;
+		}
+		test_case->is_sg = true;
+	}
+
+	kick_batch_str = rte_cfgfile_get_entry(cfgfile, section_name, "kick_batch");
+	args_nr = parse_entry(kick_batch_str, &test_case->kick_batch);
+	if (args_nr < 0) {
+		printf("parse error in case %d.\n", case_id);
+		test_case->is_valid = false;
+		return;
+	} else if (args_nr == 4)
+		*nb_vp += 1;
+
+	i = 0;
+	while (1) {
+		snprintf(lc_dma, RTE_DEV_NAME_MAX_LEN, "lcore_dma%d", i);
+		lcore_dma = rte_cfgfile_get_entry(cfgfile, section_name, lc_dma);
+		if (lcore_dma == NULL)
+			break;
+
+		kvlist = rte_kvargs_parse(lcore_dma, NULL);
+		if (kvlist == NULL) {
+			printf("rte_kvargs_parse() error");
+			test_case->is_valid = false;
+			break;
+		}
+
+		if (rte_kvargs_process(kvlist, NULL, populate_dma_dev_config,
+				       (void *)&test_case->dma_config[i]) < 0) {
+			printf("rte_kvargs_process() error\n");
+			rte_kvargs_free(kvlist);
+			test_case->is_valid = false;
+			break;
+		}
+		i++;
+		test_case->num_worker++;
+		rte_kvargs_free(kvlist);
+	}
+
+	if (test_case->num_worker == 0) {
+		printf("Error: Parsing %s Failed\n", lc_dma);
+		test_case->is_valid = false;
+	}
+}
+
 static int
 parse_global_config(struct rte_cfgfile *cfgfile)
 {
@@ -320,17 +419,14 @@ parse_global_config(struct rte_cfgfile *cfgfile)
 static uint16_t
 load_configs(const char *path)
 {
-	struct rte_cfgfile *cfgfile;
-	int nb_sections, i;
+	const char *mem_size_str, *buf_size_str;
 	struct test_configure *test_case;
 	char section_name[CFG_NAME_LEN];
+	struct rte_cfgfile *cfgfile;
 	const char *case_type;
-	const char *lcore_dma;
-	const char *mem_size_str, *buf_size_str, *ring_size_str, *kick_batch_str,
-		*src_sges_str, *dst_sges_str;
-	const char *skip;
-	struct rte_kvargs *kvlist;
+	int nb_sections, i;
 	int args_nr, nb_vp;
+	const char *skip;
 
 	printf("config file parsing...\n");
 	cfgfile = rte_cfgfile_load(path, 0);
@@ -358,6 +454,7 @@ load_configs(const char *path)
 			continue;
 		}
 
+		test_case->is_valid = true;
 		case_type = rte_cfgfile_get_entry(cfgfile, section_name, "type");
 		if (case_type == NULL) {
 			printf("Error: No case type in case %d, the test will be finished here.\n",
@@ -399,108 +496,17 @@ load_configs(const char *path)
 		} else if (args_nr == 4)
 			nb_vp++;
 
-		if (test_case->test_type == TEST_TYPE_DMA_MEM_COPY) {
-			ring_size_str = rte_cfgfile_get_entry(cfgfile, section_name,
-								"dma_ring_size");
-			args_nr = parse_entry(ring_size_str, &test_case->ring_size);
-			if (args_nr < 0) {
-				printf("parse error in case %d.\n", i + 1);
-				test_case->is_valid = false;
-				continue;
-			} else if (args_nr == 4)
-				nb_vp++;
-
-			src_sges_str = rte_cfgfile_get_entry(cfgfile, section_name,
-								"dma_src_sge");
-			if (src_sges_str != NULL) {
-				test_case->nb_src_sges = (int)atoi(rte_cfgfile_get_entry(cfgfile,
-								section_name, "dma_src_sge"));
-			}
-
-			dst_sges_str = rte_cfgfile_get_entry(cfgfile, section_name,
-								"dma_dst_sge");
-			if (dst_sges_str != NULL) {
-				test_case->nb_dst_sges = (int)atoi(rte_cfgfile_get_entry(cfgfile,
-								section_name, "dma_dst_sge"));
-			}
-
-			if ((src_sges_str != NULL && dst_sges_str == NULL) ||
-			    (src_sges_str == NULL && dst_sges_str != NULL)) {
-				printf("parse dma_src_sge, dma_dst_sge error in case %d.\n",
-					i + 1);
-				test_case->is_valid = false;
-				continue;
-			} else if (src_sges_str != NULL && dst_sges_str != NULL) {
-				test_case->is_sg = true;
-
-				if (test_case->nb_src_sges == 0 || test_case->nb_dst_sges == 0) {
-					printf("dma_src_sge and dma_dst_sge can not be 0 in case %d.\n",
-						i + 1);
-					test_case->is_valid = false;
-					continue;
-				}
-			} else {
-				test_case->is_sg = false;
-			}
-
-			kick_batch_str = rte_cfgfile_get_entry(cfgfile, section_name, "kick_batch");
-			args_nr = parse_entry(kick_batch_str, &test_case->kick_batch);
-			if (args_nr < 0) {
-				printf("parse error in case %d.\n", i + 1);
-				test_case->is_valid = false;
-				continue;
-			} else if (args_nr == 4)
-				nb_vp++;
-
-			char lc_dma[RTE_DEV_NAME_MAX_LEN];
-			int i = 0;
-			while (1) {
-				snprintf(lc_dma, RTE_DEV_NAME_MAX_LEN, "lcore_dma%d", i);
-				lcore_dma = rte_cfgfile_get_entry(cfgfile, section_name, lc_dma);
-				if (lcore_dma == NULL)
-					break;
-
-				kvlist = rte_kvargs_parse(lcore_dma, NULL);
-				if (kvlist == NULL) {
-					printf("rte_kvargs_parse() error");
-					test_case->is_valid = false;
-					break;
-				}
-
-				if (rte_kvargs_process(kvlist, NULL, populate_dma_dev_config,
-						       (void *)&test_case->dma_config[i]) < 0) {
-					printf("rte_kvargs_process() error\n");
-					rte_kvargs_free(kvlist);
-					test_case->is_valid = false;
-					break;
-				}
-				i++;
-				test_case->num_worker++;
-				rte_kvargs_free(kvlist);
-			}
-
-			if (test_case->num_worker == 0) {
-				printf("Error: Parsing %s Failed\n", lc_dma);
-				continue;
-			}
-		} else {
-			lcore_dma = rte_cfgfile_get_entry(cfgfile, section_name, "lcore");
-			int lcore_ret = parse_lcore(test_case, lcore_dma);
-			if (lcore_ret < 0) {
-				printf("parse lcore error in case %d.\n", i + 1);
-				test_case->is_valid = false;
-				continue;
-			}
-		}
+		if (test_case->test_type == TEST_TYPE_DMA_MEM_COPY)
+			parse_dma_config(test_case, i + 1, cfgfile, section_name, &nb_vp);
+		else
+			parse_cpu_config(test_case, i + 1, cfgfile, section_name);
 
-		if (nb_vp > 1) {
+		if (test_case->is_valid && nb_vp > 1) {
 			printf("Case %d error, each section can only have a single variable parameter.\n",
 					i + 1);
 			test_case->is_valid = false;
 			continue;
 		}
-
-		test_case->is_valid = true;
 	}
 
 	rte_cfgfile_close(cfgfile);
-- 
2.17.1


  parent reply	other threads:[~2025-08-12  2:08 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   ` Chengwen Feng [this message]
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

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-9-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).