From patchwork Tue May 30 09:05:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 127695 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B857042BE1; Tue, 30 May 2023 11:08:16 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 60BFE42D43; Tue, 30 May 2023 11:07:48 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 21DA542D20 for ; Tue, 30 May 2023 11:07:43 +0200 (CEST) Received: from kwepemi500020.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QVmkY1hWbzSqX8; Tue, 30 May 2023 17:07:33 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by kwepemi500020.china.huawei.com (7.221.188.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 30 May 2023 17:07:41 +0800 From: Jie Hai To: Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko CC: , Subject: [PATCH 07/10] ethdev: support telemetry query DCB info Date: Tue, 30 May 2023 17:05:07 +0800 Message-ID: <20230530090510.56812-8-haijie1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230530090510.56812-1-haijie1@huawei.com> References: <20230530090510.56812-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemi500020.china.huawei.com (7.221.188.8) X-CFilter-Loop: Reflected 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 This patch supports querying DCB info. The command is like: --> /ethdev/dcb,0 { "/ethdev/dcb": { "tc_num": 1, "tc0": { "priority": 0, "bw_percent": "100%", "rxq_base": 0, "txq_base": 0, "nb_rxq": 4, "nb_txq": 4 } } } Signed-off-by: Jie Hai --- lib/ethdev/rte_ethdev.c | 85 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index d906cc66d2f9..dad9c5538149 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -7349,6 +7349,89 @@ eth_dev_handle_port_txq(const char *cmd __rte_unused, return 0; } +static int +eth_dev_add_dcb_tc(struct rte_eth_dcb_info *dcb_info, struct rte_tel_data *d) +{ + struct rte_tel_data *tcds[RTE_ETH_DCB_NUM_TCS] = {NULL}; + struct rte_eth_dcb_tc_queue_mapping *tcq; + char bw_percent[RTE_TEL_MAX_STRING_LEN]; + char name[RTE_TEL_MAX_STRING_LEN]; + struct rte_tel_data *tcd; + uint32_t i; + + for (i = 0; i < dcb_info->nb_tcs; i++) { + tcd = rte_tel_data_alloc(); + if (tcd == NULL) { + while (i-- > 0) + rte_tel_data_free(tcds[i]); + return -ENOMEM; + } + + tcds[i] = tcd; + rte_tel_data_start_dict(tcd); + + rte_tel_data_add_dict_uint(tcd, "priority", dcb_info->prio_tc[i]); + snprintf(bw_percent, RTE_TEL_MAX_STRING_LEN, + "%u%%", dcb_info->tc_bws[i]); + rte_tel_data_add_dict_string(tcd, "bw_percent", bw_percent); + + tcq = &dcb_info->tc_queue; + rte_tel_data_add_dict_uint(tcd, "rxq_base", tcq->tc_rxq[0][i].base); + rte_tel_data_add_dict_uint(tcd, "txq_base", tcq->tc_txq[0][i].base); + rte_tel_data_add_dict_uint(tcd, "nb_rxq", tcq->tc_rxq[0][i].nb_queue); + rte_tel_data_add_dict_uint(tcd, "nb_txq", tcq->tc_txq[0][i].nb_queue); + + snprintf(name, RTE_TEL_MAX_STRING_LEN, "tc%u", i); + rte_tel_data_add_dict_container(d, name, tcd, 0); + } + + return 0; +} + +static int +eth_dev_add_dcb_info(uint16_t port_id, struct rte_tel_data *d) +{ + struct rte_eth_dcb_info dcb_info; + int ret; + + ret = rte_eth_dev_get_dcb_info(port_id, &dcb_info); + if (ret != 0) { + RTE_ETHDEV_LOG(ERR, + "Failed to get dcb info, ret = %d\n", ret); + return ret; + } + + rte_tel_data_start_dict(d); + rte_tel_data_add_dict_uint(d, "tc_num", dcb_info.nb_tcs); + + if (dcb_info.nb_tcs > 0) + return eth_dev_add_dcb_tc(&dcb_info, d); + + return 0; +} + +static int +eth_dev_handle_port_dcb(const char *cmd __rte_unused, + const char *params, + struct rte_tel_data *d) +{ + unsigned long port_id; + char *end_param; + + if (params == NULL || strlen(params) == 0 || !isdigit(*params)) + return -EINVAL; + + port_id = strtoul(params, &end_param, 0); + if (*end_param != '\0') + RTE_ETHDEV_LOG(NOTICE, + "Extra parameters passed to ethdev telemetry command, ignoring\n"); + + if (port_id >= UINT16_MAX || !rte_eth_dev_is_valid_port(port_id)) + return -EINVAL; + + return eth_dev_add_dcb_info(port_id, d); +} + RTE_LOG_REGISTER_DEFAULT(rte_eth_dev_logtype, INFO); RTE_INIT(ethdev_init_telemetry) @@ -7378,4 +7461,6 @@ RTE_INIT(ethdev_init_telemetry) "Returns Rx queue info for a port. Parameters: unsigned port_id, unsigned queue_id (Optional if only one queue)"); rte_telemetry_register_cmd("/ethdev/tx_queue", eth_dev_handle_port_txq, "Returns Tx queue info for a port. Parameters: unsigned port_id, unsigned queue_id (Optional if only one queue)"); + rte_telemetry_register_cmd("/ethdev/dcb", eth_dev_handle_port_dcb, + "Returns DCB info for a port. Parameters: unsigned port_id"); }