From: Chengwen Feng <fengchengwen@huawei.com>
To: <thomas@monjalon.net>, <stephen@networkplumber.org>,
<aman.deep.singh@intel.com>
Cc: <dev@dpdk.org>
Subject: [PATCH 2/4] app/testpmd: support config prio-tc map in DCB command
Date: Tue, 25 Feb 2025 17:19:27 +0800 [thread overview]
Message-ID: <20250225091929.25072-3-fengchengwen@huawei.com> (raw)
In-Reply-To: <20250225091929.25072-1-fengchengwen@huawei.com>
Currently, the "port config 0 dcb ..." command config the prio-tc map
by remainder operation, which means the prio-tc = prio % nb_tcs.
This commit introduces an optional parameter "prio-tc" which is the same
as kernel dcb ets tool. The new command:
port config 0 dcb vt off 4 pfc off prio-tc 0:1 1:2 2:3 ...
If this parameter is not specified, the prio-tc map is configured by
default.
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
app/test-pmd/cmdline.c | 119 ++++++++++++++++++--
app/test-pmd/testpmd.c | 21 ++--
app/test-pmd/testpmd.h | 4 +-
doc/guides/testpmd_app_ug/testpmd_funcs.rst | 3 +-
4 files changed, 125 insertions(+), 22 deletions(-)
diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index c23b811764..a8aa948c81 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -3447,19 +3447,111 @@ struct cmd_config_dcb {
cmdline_fixed_string_t vt_en;
uint8_t num_tcs;
cmdline_fixed_string_t pfc;
- cmdline_fixed_string_t pfc_en;
+ cmdline_multi_string_t token_str;
};
+static int
+parse_dcb_token_prio_tc(char *param_str[], int param_num,
+ uint8_t prio_tc[RTE_ETH_DCB_NUM_USER_PRIORITIES],
+ uint8_t *prio_tc_en)
+{
+ unsigned long prio, tc;
+ int prio_tc_maps = 0;
+ char *param, *end;
+ int i;
+
+ for (i = 0; i < param_num; i++) {
+ param = param_str[i];
+ prio = strtoul(param, &end, 10);
+ if (prio >= RTE_ETH_DCB_NUM_USER_PRIORITIES) {
+ fprintf(stderr, "Bad Argument: invalid PRIO %lu\n", prio);
+ return -1;
+ }
+ if ((*end != ':') || (strlen(end + 1) == 0)) {
+ fprintf(stderr, "Bad Argument: invalid PRIO:TC format %s\n", param);
+ return -1;
+ }
+ tc = strtoul(end + 1, &end, 10);
+ if (tc >= RTE_ETH_8_TCS) {
+ fprintf(stderr, "Bad Argument: invalid TC %lu\n", tc);
+ return -1;
+ }
+ if (*end != '\0') {
+ fprintf(stderr, "Bad Argument: invalid PRIO:TC format %s\n", param);
+ return -1;
+ }
+ prio_tc[prio] = tc;
+ prio_tc_maps++;
+ } while (0);
+
+ if (prio_tc_maps == 0) {
+ fprintf(stderr, "Bad Argument: no PRIO:TC provided\n");
+ return -1;
+ }
+ *prio_tc_en = 1;
+
+ return 0;
+}
+
+static int
+parse_dcb_token_value(char *token_str,
+ uint8_t *pfc_en,
+ uint8_t prio_tc[RTE_ETH_DCB_NUM_USER_PRIORITIES],
+ uint8_t *prio_tc_en)
+{
+#define MAX_TOKEN_NUM 128
+ char *split_str[MAX_TOKEN_NUM];
+ int split_num = 0;
+ char *token;
+
+ /* split multiple token to split str. */
+ do {
+ token = strtok_r(token_str, " \f\n\r\t\v", &token_str);
+ if (token == NULL)
+ break;
+ if (split_num >= MAX_TOKEN_NUM) {
+ fprintf(stderr, "Bad Argument: too much argument\n");
+ return -1;
+ }
+ split_str[split_num++] = token;
+ } while (1);
+
+ /* parse fixed parameter "pfc-en" first. */
+ token = split_str[0];
+ if (strcmp(token, "on") == 0)
+ *pfc_en = 1;
+ else if (strcmp(token, "off") == 0)
+ *pfc_en = 0;
+ else {
+ fprintf(stderr, "Bad Argument: pfc-en must be on or off\n");
+ return -EINVAL;
+ }
+
+ if (split_num == 1)
+ return 0;
+
+ /* start parse optional parameter. */
+ token = split_str[1];
+ if (strcmp(token, "prio-tc") != 0) {
+ fprintf(stderr, "Bad Argument: unknown token %s\n", token);
+ return -1;
+ }
+
+ return parse_dcb_token_prio_tc(&split_str[2], split_num - 2, prio_tc, prio_tc_en);
+}
+
static void
cmd_config_dcb_parsed(void *parsed_result,
__rte_unused struct cmdline *cl,
__rte_unused void *data)
{
+ uint8_t prio_tc[RTE_ETH_DCB_NUM_USER_PRIORITIES] = {0};
struct cmd_config_dcb *res = parsed_result;
struct rte_eth_dcb_info dcb_info;
portid_t port_id = res->port_id;
+ uint8_t prio_tc_en = 0;
struct rte_port *port;
- uint8_t pfc_en;
+ uint8_t pfc_en = 0;
int ret;
port = &ports[port_id];
@@ -3488,20 +3580,19 @@ cmd_config_dcb_parsed(void *parsed_result,
return;
}
- if (!strncmp(res->pfc_en, "on", 2))
- pfc_en = 1;
- else
- pfc_en = 0;
+ ret = parse_dcb_token_value(res->token_str, &pfc_en, prio_tc, &prio_tc_en);
+ if (ret != 0)
+ return;
/* DCB in VT mode */
if (!strncmp(res->vt_en, "on", 2))
ret = init_port_dcb_config(port_id, DCB_VT_ENABLED,
(enum rte_eth_nb_tcs)res->num_tcs,
- pfc_en);
+ pfc_en, prio_tc, prio_tc_en);
else
ret = init_port_dcb_config(port_id, DCB_ENABLED,
(enum rte_eth_nb_tcs)res->num_tcs,
- pfc_en);
+ pfc_en, prio_tc, prio_tc_en);
if (ret != 0) {
fprintf(stderr, "Cannot initialize network ports.\n");
return;
@@ -3528,13 +3619,17 @@ static cmdline_parse_token_num_t cmd_config_dcb_num_tcs =
TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, num_tcs, RTE_UINT8);
static cmdline_parse_token_string_t cmd_config_dcb_pfc =
TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc, "pfc");
-static cmdline_parse_token_string_t cmd_config_dcb_pfc_en =
- TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, pfc_en, "on#off");
+static cmdline_parse_token_string_t cmd_config_dcb_token_str =
+ TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, token_str, TOKEN_STRING_MULTI);
static cmdline_parse_inst_t cmd_config_dcb = {
.f = cmd_config_dcb_parsed,
.data = NULL,
- .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off",
+ .help_str = "port config <port-id> dcb vt on|off <num_tcs> pfc on|off prio-tc PRIO-MAP\n"
+ "where PRIO-MAP: [ PRIO-MAP ] PRIO-MAPPING\n"
+ " PRIO-MAPPING := PRIO:TC\n"
+ " PRIO: { 0 .. 7 }\n"
+ " TC: { 0 .. 7 }",
.tokens = {
(void *)&cmd_config_dcb_port,
(void *)&cmd_config_dcb_config,
@@ -3544,7 +3639,7 @@ static cmdline_parse_inst_t cmd_config_dcb = {
(void *)&cmd_config_dcb_vt_en,
(void *)&cmd_config_dcb_num_tcs,
(void *)&cmd_config_dcb_pfc,
- (void *)&cmd_config_dcb_pfc_en,
+ (void *)&cmd_config_dcb_token_str,
NULL,
},
};
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 0520aba0db..f4c23fd896 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -4126,9 +4126,10 @@ const uint16_t vlan_tags[] = {
static void
get_eth_dcb_conf(struct rte_eth_conf *eth_conf, enum dcb_mode_enable dcb_mode,
- enum rte_eth_nb_tcs num_tcs, uint8_t pfc_en)
+ enum rte_eth_nb_tcs num_tcs, uint8_t pfc_en,
+ uint8_t prio_tc[RTE_ETH_DCB_NUM_USER_PRIORITIES], uint8_t prio_tc_en)
{
- uint8_t i;
+ uint8_t dcb_tc_val, i;
/*
* Builds up the correct configuration for dcb+vt based on the vlan tags array
@@ -4155,8 +4156,9 @@ get_eth_dcb_conf(struct rte_eth_conf *eth_conf, enum dcb_mode_enable dcb_mode,
1 << (i % vmdq_rx_conf->nb_queue_pools);
}
for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
- vmdq_rx_conf->dcb_tc[i] = i % num_tcs;
- vmdq_tx_conf->dcb_tc[i] = i % num_tcs;
+ dcb_tc_val = prio_tc_en ? prio_tc[i] : i % num_tcs;
+ vmdq_rx_conf->dcb_tc[i] = dcb_tc_val;
+ vmdq_tx_conf->dcb_tc[i] = dcb_tc_val;
}
/* set DCB mode of RX and TX of multiple queues */
@@ -4174,8 +4176,9 @@ get_eth_dcb_conf(struct rte_eth_conf *eth_conf, enum dcb_mode_enable dcb_mode,
tx_conf->nb_tcs = num_tcs;
for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
- rx_conf->dcb_tc[i] = i % num_tcs;
- tx_conf->dcb_tc[i] = i % num_tcs;
+ dcb_tc_val = prio_tc_en ? prio_tc[i] : i % num_tcs;
+ rx_conf->dcb_tc[i] = dcb_tc_val;
+ tx_conf->dcb_tc[i] = dcb_tc_val;
}
eth_conf->rxmode.mq_mode =
@@ -4195,7 +4198,9 @@ int
init_port_dcb_config(portid_t pid,
enum dcb_mode_enable dcb_mode,
enum rte_eth_nb_tcs num_tcs,
- uint8_t pfc_en)
+ uint8_t pfc_en,
+ uint8_t prio_tc[RTE_ETH_DCB_NUM_USER_PRIORITIES],
+ uint8_t prio_tc_en)
{
struct rte_eth_conf port_conf;
struct rte_port *rte_port;
@@ -4212,7 +4217,7 @@ init_port_dcb_config(portid_t pid,
memcpy(&port_conf, &rte_port->dev_conf, sizeof(struct rte_eth_conf));
/* set configuration of DCB in vt mode and DCB in non-vt mode */
- get_eth_dcb_conf(&port_conf, dcb_mode, num_tcs, pfc_en);
+ get_eth_dcb_conf(&port_conf, dcb_mode, num_tcs, pfc_en, prio_tc, prio_tc_en);
port_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
/* remove RSS HASH offload for DCB in vt mode */
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index a933fb433a..671641dac5 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -1150,7 +1150,9 @@ uint8_t port_is_bonding_member(portid_t member_pid);
int init_port_dcb_config(portid_t pid, enum dcb_mode_enable dcb_mode,
enum rte_eth_nb_tcs num_tcs,
- uint8_t pfc_en);
+ uint8_t pfc_en,
+ uint8_t prio_tc[RTE_ETH_DCB_NUM_USER_PRIORITIES],
+ uint8_t prio_tc_en);
int start_port(portid_t pid);
void stop_port(portid_t pid);
void close_port(portid_t pid);
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 38bc00705f..3cbc377271 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -2165,9 +2165,10 @@ port config - DCB
Set the DCB mode for an individual port::
- testpmd> port config (port_id) dcb vt (on|off) (traffic_class) pfc (on|off)
+ testpmd> port config (port_id) dcb vt (on|off) (traffic_class) pfc (on|off) prio-tc (prio-tc)
The traffic class could be 2~8.
+The prio-tc field here is optional, if not specified then the prio-tc use default configuration.
port config - Burst
~~~~~~~~~~~~~~~~~~~
--
2.17.1
next prev parent reply other threads:[~2025-02-25 9:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-25 9:19 [PATCH 0/4] enhance testpmd " Chengwen Feng
2025-02-25 9:19 ` [PATCH 1/4] app/testpmd: remove restrict of number of TCs in " Chengwen Feng
2025-02-25 9:19 ` Chengwen Feng [this message]
2025-02-25 9:19 ` [PATCH 3/4] app/testpmd: support don't adjust queue num " Chengwen Feng
2025-02-25 9:19 ` [PATCH 4/4] app/testpmd: support disable " Chengwen Feng
2025-02-25 14:42 ` [PATCH 0/4] enhance testpmd " 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=20250225091929.25072-3-fengchengwen@huawei.com \
--to=fengchengwen@huawei.com \
--cc=aman.deep.singh@intel.com \
--cc=dev@dpdk.org \
--cc=stephen@networkplumber.org \
--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).