DPDK patches and discussions
 help / color / mirror / Atom feed
From: Chengwen Feng <fengchengwen@huawei.com>
To: <thomas@monjalon.net>, <stephen@networkplumber.org>
Cc: <dev@dpdk.org>, <aman.deep.singh@intel.com>,
	<liuyonglong@huawei.com>, <yangxingui@huawei.com>,
	<lihuisong@huawei.com>
Subject: [PATCH v3] app/testpmd: support specify TCs when DCB forward
Date: Thu, 6 Nov 2025 20:49:59 +0800	[thread overview]
Message-ID: <20251106124959.2592-1-fengchengwen@huawei.com> (raw)
In-Reply-To: <20251104040916.25864-1-fengchengwen@huawei.com>

This commit supports specify TCs when DCB forwarding, the command:

  set dcb fwd_tc (tc_mask)

The background of this command: only some TCs are expected to generate
traffic when the DCB function is tested based on txonly forwarding, we
could use this command to specify TCs to be used.

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
Depends-on: series-2682 ("two bugfix for testpmd DCB")
---
v3: use new way to impl and fix comment from Stephen.
v2: introduce pause/resume lcore's forwarding.

---
 app/test-pmd/cmdline.c                      | 57 +++++++++++++++++++++
 app/test-pmd/config.c                       | 50 +++++++++++++++++-
 app/test-pmd/testpmd.c                      |  6 +++
 app/test-pmd/testpmd.h                      |  3 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  7 +++
 5 files changed, 121 insertions(+), 2 deletions(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 22afbdbad3..0400c8356e 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -511,6 +511,9 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"set fwd (%s)\n"
 			"    Set packet forwarding mode.\n\n"
 
+			"set dcb fwd_tc (tc_mask)\n"
+			"    Set dcb forwarding on specify TCs, if bit-n in tc-mask is 1, then TC-n's forwarding is enabled\n\n"
+
 			"mac_addr add (port_id) (XX:XX:XX:XX:XX:XX)\n"
 			"    Add a MAC address on port_id.\n\n"
 
@@ -6224,6 +6227,59 @@ static void cmd_set_fwd_retry_mode_init(void)
 	token_struct->string_data.str = token;
 }
 
+/* *** set dcb forward TCs *** */
+struct cmd_set_dcb_fwd_tc_result {
+	cmdline_fixed_string_t set;
+	cmdline_fixed_string_t dcb;
+	cmdline_fixed_string_t fwd_tc;
+	uint8_t                tc_mask;
+};
+
+static void cmd_set_dcb_fwd_tc_parsed(void *parsed_result,
+				      __rte_unused struct cmdline *cl,
+				      __rte_unused void *data)
+{
+	struct cmd_set_dcb_fwd_tc_result *res = parsed_result;
+	int i;
+	if (res->tc_mask == 0) {
+		fprintf(stderr, "TC mask should not be zero!\n");
+		return;
+	}
+	printf("Enabled DCB forwarding TC list:");
+	dcb_fwd_tc_mask = res->tc_mask;
+	for (i = 0; i < RTE_ETH_8_TCS; i++) {
+		if (dcb_fwd_tc_mask & (1u << i))
+			printf(" %d", i);
+	}
+	printf("\n");
+}
+
+static cmdline_parse_token_string_t cmd_set_dcb_fwd_tc_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_set_dcb_fwd_tc_result,
+			set, "set");
+static cmdline_parse_token_string_t cmd_set_dcb_fwd_tc_dcb =
+	TOKEN_STRING_INITIALIZER(struct cmd_set_dcb_fwd_tc_result,
+			dcb, "dcb");
+static cmdline_parse_token_string_t cmd_set_dcb_fwd_tc_fwdtc =
+	TOKEN_STRING_INITIALIZER(struct cmd_set_dcb_fwd_tc_result,
+			fwd_tc, "fwd_tc");
+static cmdline_parse_token_string_t cmd_set_dcb_fwd_tc_tcmask =
+	TOKEN_NUM_INITIALIZER(struct cmd_set_dcb_fwd_tc_result,
+			tc_mask, RTE_UINT8);
+
+static cmdline_parse_inst_t cmd_set_dcb_fwd_tc = {
+	.f = cmd_set_dcb_fwd_tc_parsed,
+	.data = NULL,
+	.help_str = "config DCB forwarding on specify TCs, if bit-n in tc-mask is 1, then TC-n's forwarding is enabled, and vice versa.",
+	.tokens = {
+		(void *)&cmd_set_dcb_fwd_tc_set,
+		(void *)&cmd_set_dcb_fwd_tc_dcb,
+		(void *)&cmd_set_dcb_fwd_tc_fwdtc,
+		(void *)&cmd_set_dcb_fwd_tc_tcmask,
+		NULL,
+	},
+};
+
 /* *** SET BURST TX DELAY TIME RETRY NUMBER *** */
 struct cmd_set_burst_tx_retry_result {
 	cmdline_fixed_string_t set;
@@ -14003,6 +14059,7 @@ static cmdline_parse_ctx_t builtin_ctx[] = {
 	&cmd_set_fwd_mask,
 	&cmd_set_fwd_mode,
 	&cmd_set_fwd_retry_mode,
+	&cmd_set_dcb_fwd_tc,
 	&cmd_set_burst_tx_retry,
 	&cmd_set_promisc_mode_one,
 	&cmd_set_promisc_mode_all,
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 8557371488..ca40a03b40 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -5121,12 +5121,48 @@ get_fwd_port_total_tc_num(void)
 
 	for (i = 0; i < nb_fwd_ports; i++) {
 		(void)rte_eth_dev_get_dcb_info(fwd_ports_ids[i], &dcb_info);
-		total_tc_num += dcb_info.nb_tcs;
+		total_tc_num += rte_popcount32(dcb_fwd_tc_mask & ((1u << dcb_info.nb_tcs) - 1));
 	}
 
 	return total_tc_num;
 }
 
+static void
+dcb_forward_tc_update_dcb_info(struct rte_eth_dcb_info *org_dcb_info)
+{
+	struct rte_eth_dcb_info dcb_info = {0};
+	uint32_t i, vmdq_idx;
+	uint32_t tc = 0;
+
+	if (dcb_fwd_tc_mask == DEFAULT_DCB_FWD_TC_MASK)
+		return;
+
+	/*
+	 * Use compress scheme to update dcb-info.
+	 * E.g. If org_dcb_info->nb_tcs is 4 and dcb_fwd_tc_mask is 0x8, it
+	 *      means only enable TC3, then the new dcb-info's nb_tcs is set to
+	 *      1, and also move corresponding tc_rxq and tc_txq info to new
+	 *      index.
+	 */
+	for (i = 0; i < org_dcb_info->nb_tcs; i++) {
+		if (!(dcb_fwd_tc_mask & (1u << i)))
+			continue;
+		for (vmdq_idx = 0; vmdq_idx < RTE_ETH_MAX_VMDQ_POOL; vmdq_idx++) {
+			dcb_info.tc_queue.tc_rxq[vmdq_idx][tc].base =
+				org_dcb_info->tc_queue.tc_rxq[vmdq_idx][i].base;
+			dcb_info.tc_queue.tc_rxq[vmdq_idx][tc].nb_queue =
+				org_dcb_info->tc_queue.tc_rxq[vmdq_idx][i].nb_queue;
+			dcb_info.tc_queue.tc_txq[vmdq_idx][tc].base =
+				org_dcb_info->tc_queue.tc_txq[vmdq_idx][i].base;
+			dcb_info.tc_queue.tc_txq[vmdq_idx][tc].nb_queue =
+				org_dcb_info->tc_queue.tc_txq[vmdq_idx][i].nb_queue;
+		}
+		tc++;
+	}
+	dcb_info.nb_tcs = tc;
+	memcpy(org_dcb_info, &dcb_info, sizeof(struct rte_eth_dcb_info));
+}
+
 /**
  * For the DCB forwarding test, each core is assigned on each traffic class.
  *
@@ -5176,11 +5212,17 @@ dcb_fwd_config_setup(void)
 		}
 	}
 
+	total_tc_num = get_fwd_port_total_tc_num();
+	if (total_tc_num == 0) {
+		fprintf(stderr, "Error: total forwarding TC num is zero!\n");
+		cur_fwd_config.nb_fwd_lcores = 0;
+		return;
+	}
+
 	cur_fwd_config.nb_fwd_lcores = (lcoreid_t) nb_fwd_lcores;
 	cur_fwd_config.nb_fwd_ports = nb_fwd_ports;
 	cur_fwd_config.nb_fwd_streams =
 		(streamid_t) (nb_rxq * cur_fwd_config.nb_fwd_ports);
-	total_tc_num = get_fwd_port_total_tc_num();
 	if (cur_fwd_config.nb_fwd_lcores > total_tc_num)
 		cur_fwd_config.nb_fwd_lcores = total_tc_num;
 
@@ -5190,7 +5232,9 @@ dcb_fwd_config_setup(void)
 	txp = fwd_topology_tx_port_get(rxp);
 	/* get the dcb info on the first RX and TX ports */
 	(void)rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
+	dcb_forward_tc_update_dcb_info(&rxp_dcb_info);
 	(void)rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
+	dcb_forward_tc_update_dcb_info(&txp_dcb_info);
 
 	for (lc_id = 0; lc_id < cur_fwd_config.nb_fwd_lcores; lc_id++) {
 		fwd_lcores[lc_id]->stream_nb = 0;
@@ -5238,7 +5282,9 @@ dcb_fwd_config_setup(void)
 		txp = fwd_topology_tx_port_get(rxp);
 		/* get the dcb information on next RX and TX ports */
 		rte_eth_dev_get_dcb_info(fwd_ports_ids[rxp], &rxp_dcb_info);
+		dcb_forward_tc_update_dcb_info(&rxp_dcb_info);
 		rte_eth_dev_get_dcb_info(fwd_ports_ids[txp], &txp_dcb_info);
+		dcb_forward_tc_update_dcb_info(&txp_dcb_info);
 	}
 }
 
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 2360da3a48..9d0ce5660c 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -211,6 +211,12 @@ struct fwd_engine * fwd_engines[] = {
 	NULL,
 };
 
+/*
+ * Bitmask for control DCB forwarding for TCs.
+ * If bit-n in tc-mask is 1, then TC-n's forwarding is enabled, and vice versa.
+ */
+uint8_t dcb_fwd_tc_mask = DEFAULT_DCB_FWD_TC_MASK;
+
 struct rte_mempool *mempools[RTE_MAX_NUMA_NODES * MAX_SEGS_BUFFER_SPLIT];
 uint16_t mempool_flags;
 
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index fa46865c67..1ada0de450 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -484,6 +484,9 @@ extern cmdline_parse_inst_t cmd_show_set_raw_all;
 extern cmdline_parse_inst_t cmd_set_flex_is_pattern;
 extern cmdline_parse_inst_t cmd_set_flex_spec_pattern;
 
+#define DEFAULT_DCB_FWD_TC_MASK	0xFF
+extern uint8_t dcb_fwd_tc_mask;
+
 extern uint16_t mempool_flags;
 
 /**
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index e423abd40e..d263734a11 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -1877,6 +1877,13 @@ Set a controllable LED associated with a certain port on or off::
 
    testpmd> set port (port_id) led (on|off)
 
+set dcb fwd_tc
+~~~~~~~~~~~~~~
+
+Config DCB forwarding on specify TCs, if bit-n in tc-mask is 1, then TC-n's forwarding is enabled, and vice versa::
+
+   testpmd> set dcb fwd_tc (tc_mask)
+
 Port Functions
 --------------
 
-- 
2.17.1


  parent reply	other threads:[~2025-11-06 12:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-04  4:09 [PATCH 0/3] testpmd support stop specify lcore Chengwen Feng
2025-11-04  4:09 ` [PATCH 1/3] app/testpmd: fix invalid txp when setup DCB forward Chengwen Feng
2025-11-04  4:09 ` [PATCH 2/3] app/testpmd: fix wrong Rx queues " Chengwen Feng
2025-11-04  4:09 ` [PATCH 3/3] app/testpmd: support stop specify lcore Chengwen Feng
2025-11-05  0:21 ` [PATCH 0/3] testpmd " Stephen Hemminger
2025-11-05  0:43   ` fengchengwen
2025-11-05  9:47 ` [PATCH v2 0/3] testpmd support pause/resume specify lcore's fwd Chengwen Feng
2025-11-05  9:47   ` [PATCH v2 1/3] app/testpmd: fix invalid txp when setup DCB forward Chengwen Feng
2025-11-05  9:47   ` [PATCH v2 2/3] app/testpmd: fix wrong Rx queues " Chengwen Feng
2025-11-05  9:47   ` [PATCH v2 3/3] app/testpmd: support pause/resume specify lcore Chengwen Feng
2025-11-05 18:59   ` [PATCH v2 0/3] testpmd support pause/resume specify lcore's fwd Stephen Hemminger
2025-11-06  0:34     ` fengchengwen
2025-11-06 12:49 ` Chengwen Feng [this message]
2025-11-06 19:24   ` [PATCH v3] app/testpmd: support specify TCs when DCB forward Stephen Hemminger

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=20251106124959.2592-1-fengchengwen@huawei.com \
    --to=fengchengwen@huawei.com \
    --cc=aman.deep.singh@intel.com \
    --cc=dev@dpdk.org \
    --cc=lihuisong@huawei.com \
    --cc=liuyonglong@huawei.com \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    --cc=yangxingui@huawei.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).