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 0559AA0542; Fri, 2 Dec 2022 08:57:07 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E075340687; Fri, 2 Dec 2022 08:57:06 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 2A073400D6 for ; Fri, 2 Dec 2022 08:57:05 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B1NIGEP024669; Thu, 1 Dec 2022 23:57:04 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=KV6jNgHdsyjHQRWayYfio0AVsgyPh4yKoAfcGK1hO3s=; b=bJk90Gisx6P4vTiaT5nRyO4TeZE/rRO/celxT6CTOI3w74yb1KM3qXcILfK2nVVig5Ak /yvHtpFJM5Pjt7KB/xAB+NpIvV5KFWKbtRYzpNtWVLHlaJueKZMKpFb66Q2fTHFBzQwh qXG25VzmbkjCEdhsZ/8tZ1tcaASEtE7yDB9tIOGjp20u/C6LaCdWssGuQGn1wB8BOwGW gc9xL7lGceFVxHeCVqBz9Ck+Tf8ipdZaEZZFRb5yAh5VaaPeJZafzeW4f8tsI+12ONCs 2XDx9HT1yZKymzA3ZWtPlZKGpX7KNZpuoJZm4lmFgG4zo5SFM2rkYd26A/nhLgA//Jge dQ== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3m6k8k5h4y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 01 Dec 2022 23:57:04 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 1 Dec 2022 23:57:02 -0800 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 1 Dec 2022 23:56:51 -0800 Received: from localhost.localdomain (unknown [10.28.34.25]) by maili.marvell.com (Postfix) with ESMTP id 5FF443F706D; Thu, 1 Dec 2022 23:56:50 -0800 (PST) From: To: Aman Singh , Yuying Zhang CC: , Sunil Kumar Kori Subject: [PATCH v4 1/1] app/testpmd: support congestion management CLIs Date: Fri, 2 Dec 2022 13:26:47 +0530 Message-ID: <20221202075647.2804081-1-skori@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221129080436.2318877-1-skori@marvell.com> References: <20221129080436.2318877-1-skori@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: Al2k7vzIj7Oy9HHPZtJ7_Ov0rqGvTnpo X-Proofpoint-ORIG-GUID: Al2k7vzIj7Oy9HHPZtJ7_Ov0rqGvTnpo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-02_04,2022-12-01_01,2022-06-22_01 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 From: Sunil Kumar Kori Support congestion management CLIs. Signed-off-by: Sunil Kumar Kori Acked-by: Aman Singh --- v3..v4: - Fix build error v2..v3: - Move Congestion management document section near TM section - Rebase on top of the dpdk/main v1..v2: - Rebase on top of the dpdk-next-net-mrvl/for-next-net app/test-pmd/cmdline.c | 15 + app/test-pmd/cmdline_cman.c | 392 ++++++++++++++++++++ app/test-pmd/cmdline_cman.h | 12 + app/test-pmd/meson.build | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 26 ++ 5 files changed, 446 insertions(+) create mode 100644 app/test-pmd/cmdline_cman.c create mode 100644 app/test-pmd/cmdline_cman.h diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index b32dc8bfd4..cb8c174020 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -61,6 +61,7 @@ #include #endif #include "testpmd.h" +#include "cmdline_cman.h" #include "cmdline_mtr.h" #include "cmdline_tm.h" #include "bpf_cmd.h" @@ -610,6 +611,17 @@ static void cmd_help_long_parsed(void *parsed_result, "set port (port_id) fec_mode auto|off|rs|baser\n" " set fec mode for a specific port\n\n" + "show port cman capa (port_id)\n" + " Show congestion management capabilities\n\n" + + "show port cman config (port_id)\n" + " Show congestion management configuration\n\n" + + "set port cman config (port_id) (queue_id) default | " + "[obj (queue|queue_mempool) mode red (min_thresh) " + "(max_thresh) (prob_inv)]\n" + " Set congestion management configuration\n\n" + , list_pkt_forwarding_modes() ); } @@ -12851,6 +12863,9 @@ static cmdline_parse_ctx_t builtin_ctx[] = { (cmdline_parse_inst_t *)&cmd_show_capability, (cmdline_parse_inst_t *)&cmd_set_flex_is_pattern, (cmdline_parse_inst_t *)&cmd_set_flex_spec_pattern, + (cmdline_parse_inst_t *)&cmd_show_port_cman_capa, + (cmdline_parse_inst_t *)&cmd_show_port_cman_config, + (cmdline_parse_inst_t *)&cmd_set_port_cman_config, NULL, }; diff --git a/app/test-pmd/cmdline_cman.c b/app/test-pmd/cmdline_cman.c new file mode 100644 index 0000000000..1a34172f1f --- /dev/null +++ b/app/test-pmd/cmdline_cman.c @@ -0,0 +1,392 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2022 Marvell International Ltd. + */ + +#include + +#include +#include +#include + +#include + +#include "testpmd.h" + +#define PARSE_DELIMITER " \f\n\r\t\v" + +static int +parse_uint(uint64_t *value, const char *str) +{ + char *next = NULL; + uint64_t n; + + errno = 0; + /* Parse number string */ + n = strtol(str, &next, 10); + if (errno != 0 || str == next || *next != '\0') + return -1; + + *value = n; + + return 0; +} + +static int +parse_cman_obj_str(char *str, uint64_t *obj) +{ + char *token; + + token = strtok_r(str, PARSE_DELIMITER, &str); + if (token == NULL) + return 0; + + if (strcasecmp(token, "queue") == 0) + *obj = RTE_ETH_CMAN_OBJ_RX_QUEUE; + else if (strcasecmp(token, "queue_mempool") == 0) + *obj = RTE_ETH_CMAN_OBJ_RX_QUEUE_MEMPOOL; + else + return -1; + + return 0; +} + +static int +parse_cman_mode_str(char *str, uint64_t *mode) +{ + char *token; + + token = strtok_r(str, PARSE_DELIMITER, &str); + if (token == NULL) + return 0; + + if (strcasecmp(token, "red") == 0) + *mode = RTE_CMAN_RED; + else + return -1; + + return 0; +} + +static int +parse_cman_params_str(uint16_t port_id, char *str, + struct rte_eth_cman_config *cfg) +{ + uint64_t obj = 0, mode = 0, min_th = 0, max_th = 0, maxp_inv = 0; + struct rte_eth_cman_info info; + char *token; + int ret; + + token = strtok_r(str, PARSE_DELIMITER, &str); + if (!strcasecmp(token, "default")) { + ret = rte_eth_cman_config_init(port_id, cfg); + if (ret) { + fprintf(stderr, "error in default initialization\n"); + return ret; + } + return 0; + } + + /* First token: obj name */ + token = strtok_r(str, PARSE_DELIMITER, &str); + if (token == NULL) { + fprintf(stderr, "Object param parse error\n"); + goto error; + } + + ret = parse_cman_obj_str(token, &obj); + if (ret) { + fprintf(stderr, "Object value is invalid\n"); + goto error; + } + + /* Second token: mode name */ + token = strtok_r(str, PARSE_DELIMITER, &str); + if (token == NULL) { + fprintf(stderr, " Mode param is invalid\n"); + goto error; + } + + token = strtok_r(str, PARSE_DELIMITER, &str); + if (token == NULL) { + fprintf(stderr, " Mode value is invalid\n"); + goto error; + } + + ret = parse_cman_mode_str(token, &mode); + if (ret) { + fprintf(stderr, "mode string parse error\n"); + goto error; + } + + /* Third token: minimum threshold */ + token = strtok_r(str, PARSE_DELIMITER, &str); + if (token == NULL) { + fprintf(stderr, "Minimum threshold parse error\n"); + goto error; + } + + ret = parse_uint(&min_th, token); + if (ret != 0 || min_th > UINT8_MAX) { + fprintf(stderr, "Minimum threshold is invalid\n"); + goto error; + } + + /* Fourth token: maximum threshold */ + token = strtok_r(str, PARSE_DELIMITER, &str); + if (token == NULL) { + fprintf(stderr, "Maximum threshold parse error\n"); + goto error; + } + + ret = parse_uint(&max_th, token); + if (ret != 0 || max_th > UINT8_MAX) { + fprintf(stderr, "Maximum threshold is invalid\n"); + goto error; + } + + /* Fifth token: probability inversion */ + token = strtok_r(str, PARSE_DELIMITER, &str); + if (token == NULL) { + fprintf(stderr, "Maximum probability inversion parse error\n"); + goto error; + } + + ret = parse_uint(&maxp_inv, token); + if (ret != 0 || maxp_inv == 0 || maxp_inv > UINT16_MAX) { + fprintf(stderr, "Maximum probability inversion is invalid\n"); + goto error; + } + + memset(&info, 0, sizeof(struct rte_eth_cman_info)); + ret = rte_eth_cman_info_get(port_id, &info); + if (ret) { + fprintf(stderr, "Congestion management capa get error\n"); + goto error; + } + + if (!(info.objs_supported & obj)) { + fprintf(stderr, "Object type is not supported by driver\n"); + goto error; + } + + if (!(info.modes_supported & mode)) { + fprintf(stderr, "Mode is not supported by driver\n"); + goto error; + } + + cfg->obj = obj; + cfg->mode = mode; + cfg->mode_param.red.min_th = min_th; + cfg->mode_param.red.max_th = max_th; + cfg->mode_param.red.maxp_inv = maxp_inv; + + return 0; + +error: + return -EINVAL; +} + +/* *** Show Port Congestion Management Capabilities *** */ +struct cmd_show_port_cman_capa_result { + cmdline_fixed_string_t show; + cmdline_fixed_string_t port; + cmdline_fixed_string_t cman; + cmdline_fixed_string_t capa; + uint16_t port_id; +}; + +static cmdline_parse_token_string_t cmd_show_port_cman_capa_show = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_cman_capa_result, show, "show"); + +static cmdline_parse_token_string_t cmd_show_port_cman_capa_port = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_cman_capa_result, port, "port"); + +static cmdline_parse_token_string_t cmd_show_port_cman_capa_cman = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_cman_capa_result, cman, "cman"); + +static cmdline_parse_token_string_t cmd_show_port_cman_capa_capa = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_cman_capa_result, capa, "capa"); + +static cmdline_parse_token_num_t cmd_show_port_cman_capa_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_show_port_cman_capa_result, port_id, RTE_UINT16); + +static void cmd_show_port_cman_capa_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_show_port_cman_capa_result *res = parsed_result; + uint16_t port_id = res->port_id; + struct rte_eth_cman_info info; + int ret; + + memset(&info, 0, sizeof(struct rte_eth_cman_info)); + ret = rte_eth_cman_info_get(port_id, &info); + if (ret) + return; + + printf("\n**** Port Congestion Management Capabilities ****\n\n"); + printf("modes_supported 0x%" PRIx64 "\n", info.modes_supported); + printf("objs_supported 0x%" PRIx64 "\n", info.objs_supported); +} + +cmdline_parse_inst_t cmd_show_port_cman_capa = { + .f = cmd_show_port_cman_capa_parsed, + .data = NULL, + .help_str = "show port cman capa ", + .tokens = { + (void *)&cmd_show_port_cman_capa_show, + (void *)&cmd_show_port_cman_capa_port, + (void *)&cmd_show_port_cman_capa_cman, + (void *)&cmd_show_port_cman_capa_capa, + (void *)&cmd_show_port_cman_capa_port_id, + NULL, + }, +}; + +/* *** Show Port Congestion Management configuration *** */ +struct cmd_show_port_cman_cfg_result { + cmdline_fixed_string_t show; + cmdline_fixed_string_t port; + cmdline_fixed_string_t cman; + cmdline_fixed_string_t cfg; + uint16_t port_id; +}; + +static cmdline_parse_token_string_t cmd_show_port_cman_cfg_show = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_cman_cfg_result, show, "show"); + +static cmdline_parse_token_string_t cmd_show_port_cman_cfg_port = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_cman_cfg_result, port, "port"); + +static cmdline_parse_token_string_t cmd_show_port_cman_cfg_cman = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_cman_cfg_result, cman, "cman"); + +static cmdline_parse_token_string_t cmd_show_port_cman_cfg_cfg = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_cman_cfg_result, cfg, "config"); + +static cmdline_parse_token_num_t cmd_show_port_cman_cfg_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_show_port_cman_cfg_result, port_id, RTE_UINT16); + +static void cmd_show_port_cman_cfg_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_show_port_cman_cfg_result *res = parsed_result; + uint16_t port_id = res->port_id; + struct rte_eth_cman_config cfg; + int ret; + + memset(&cfg, 0, sizeof(struct rte_eth_cman_config)); + ret = rte_eth_cman_config_get(port_id, &cfg); + if (ret) + return; + + printf("\n**** Port Congestion Management Configuration ****\n\n"); + printf("cman object 0x%" PRIx32 "\n", cfg.obj); + printf("cman Rx queue %" PRIx16 "\n", cfg.obj_param.rx_queue); + printf("cman mode 0x%" PRIx32 "\n", cfg.mode); + printf("cman RED min thresh %" PRIx8 "\n", cfg.mode_param.red.min_th); + printf("cman RED max thresh %" PRIx8 "\n", cfg.mode_param.red.max_th); + printf("cman RED Prob inversion %" PRIx16 "\n", + cfg.mode_param.red.maxp_inv); +} + +cmdline_parse_inst_t cmd_show_port_cman_config = { + .f = cmd_show_port_cman_cfg_parsed, + .data = NULL, + .help_str = "show port cman config ", + .tokens = { + (void *)&cmd_show_port_cman_cfg_show, + (void *)&cmd_show_port_cman_cfg_port, + (void *)&cmd_show_port_cman_cfg_cman, + (void *)&cmd_show_port_cman_cfg_cfg, + (void *)&cmd_show_port_cman_cfg_port_id, + NULL, + }, +}; + +/* *** Set Port Congestion Management configuration *** */ +struct cmd_set_port_cman_cfg_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t port; + cmdline_fixed_string_t cman; + cmdline_fixed_string_t cfg; + uint16_t port_id; + uint16_t qid; + cmdline_multi_string_t params; +}; + +static cmdline_parse_token_string_t cmd_set_port_cman_cfg_set = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_cman_cfg_result, set, "set"); + +static cmdline_parse_token_string_t cmd_set_port_cman_cfg_port = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_cman_cfg_result, port, "port"); + +static cmdline_parse_token_string_t cmd_set_port_cman_cfg_cman = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_cman_cfg_result, cman, "cman"); + +static cmdline_parse_token_string_t cmd_set_port_cman_cfg_cfg = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_cman_cfg_result, cfg, "config"); + +static cmdline_parse_token_num_t cmd_set_port_cman_cfg_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_cman_cfg_result, port_id, RTE_UINT16); + +static cmdline_parse_token_num_t cmd_set_port_cman_cfg_qid = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_cman_cfg_result, qid, RTE_UINT16); + +static cmdline_parse_token_string_t cmd_set_port_cman_cfg_params = + TOKEN_STRING_INITIALIZER(struct cmd_set_port_cman_cfg_result, + params, TOKEN_STRING_MULTI); + +static void cmd_set_port_cman_cfg_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_set_port_cman_cfg_result *res = parsed_result; + uint16_t port_id = res->port_id; + struct rte_eth_cman_config cfg; + int ret; + + ret = parse_cman_params_str(port_id, res->params, &cfg); + if (ret) { + fprintf(stderr, "params string parse error\n"); + return; + } + + cfg.obj_param.rx_queue = res->qid; + rte_eth_cman_config_set(port_id, &cfg); +} + +cmdline_parse_inst_t cmd_set_port_cman_config = { + .f = cmd_set_port_cman_cfg_parsed, + .data = NULL, + .help_str = "set port cman config " + "default | [obj mode red " + " ]", + .tokens = { + (void *)&cmd_set_port_cman_cfg_set, + (void *)&cmd_set_port_cman_cfg_port, + (void *)&cmd_set_port_cman_cfg_cman, + (void *)&cmd_set_port_cman_cfg_cfg, + (void *)&cmd_set_port_cman_cfg_port_id, + (void *)&cmd_set_port_cman_cfg_qid, + (void *)&cmd_set_port_cman_cfg_params, + NULL, + }, +}; diff --git a/app/test-pmd/cmdline_cman.h b/app/test-pmd/cmdline_cman.h new file mode 100644 index 0000000000..bd6c99ce35 --- /dev/null +++ b/app/test-pmd/cmdline_cman.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2022 Marvell International Ltd. + */ + +#ifndef _CMDLINE_CMAN_H_ +#define _CMDLINE_CMAN_H_ + +extern cmdline_parse_inst_t cmd_show_port_cman_capa; +extern cmdline_parse_inst_t cmd_show_port_cman_config; +extern cmdline_parse_inst_t cmd_set_port_cman_config; + +#endif /* _CMDLINE_CMAN_H_ */ diff --git a/app/test-pmd/meson.build b/app/test-pmd/meson.build index 8488efc138..d2e3f60892 100644 --- a/app/test-pmd/meson.build +++ b/app/test-pmd/meson.build @@ -7,6 +7,7 @@ cflags += '-Wno-deprecated-declarations' sources = files( '5tswap.c', 'cmdline.c', + 'cmdline_cman.c', 'cmdline_flow.c', 'cmdline_mtr.c', 'cmdline_tm.c', diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index 0037506a79..03663866ac 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -2843,6 +2843,32 @@ where: * ``red`` enable 1, disable 0 marking IP ecn for yellow marked packets with ecn of 2'b01 or 2'b10 to ecn of 2'b11 when IP is caring TCP or SCTP +Congestion Management +--------------------- + +Get capabilities +~~~~~~~~~~~~~~~~ + +Retrieve congestion management capabilities supported by driver for given port. +Below example command retrieves capabilities for port 0:: + + testpmd> show port cman capa 0 + +Get configuration +~~~~~~~~~~~~~~~~~ +Retrieve congestion management configuration for given port. Below example +command retrieves configuration for port 0:: + + testpmd> show port cman config 0 + +Set configuration +~~~~~~~~~~~~~~~~~ +Configures congestion management settings on given queue or mempool associated +with queue. Below example command configures RED as congestion management algo +for port 0 and queue 0:: + + testpmd> set port cman config 0 0 obj queue mode red 10 100 1 + Filter Functions ---------------- -- 2.25.1