From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B838246CFC; Mon, 11 Aug 2025 12:55:08 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C252640DD5; Mon, 11 Aug 2025 12:54:43 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 14DE640A80 for ; Mon, 11 Aug 2025 12:54:35 +0200 (CEST) Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4c0rxC3bfyz14MQV; Mon, 11 Aug 2025 18:49:35 +0800 (CST) Received: from kwepemk500009.china.huawei.com (unknown [7.202.194.94]) by mail.maildlp.com (Postfix) with ESMTPS id 07EC21402DB; Mon, 11 Aug 2025 18:54:34 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by kwepemk500009.china.huawei.com (7.202.194.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 11 Aug 2025 18:54:33 +0800 From: Chengwen Feng To: CC: , Subject: [PATCH 8/9] app/dma-perf: refactor load config function Date: Mon, 11 Aug 2025 18:54:29 +0800 Message-ID: <20250811105430.55791-9-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20250811105430.55791-1-fengchengwen@huawei.com> References: <20250811105430.55791-1-fengchengwen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: kwepems100002.china.huawei.com (7.221.188.206) To kwepemk500009.china.huawei.com (7.202.194.94) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The load_configs() function has 198 lines, and hard to understand. This commit split it to three functions. Signed-off-by: Chengwen Feng --- 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 27d2af46f8..a4f9aeb859 100644 --- a/app/test-dma-perf/main.c +++ b/app/test-dma-perf/main.c @@ -190,6 +190,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) { @@ -268,6 +282,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) { @@ -319,17 +418,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); @@ -357,6 +453,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", @@ -398,108 +495,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