From patchwork Thu Dec 5 17:31:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Power, Ciara" X-Patchwork-Id: 63606 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 23474A04F2; Thu, 5 Dec 2019 18:34:49 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DBF721BFA4; Thu, 5 Dec 2019 18:34:18 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id CB27C1BF8B for ; Thu, 5 Dec 2019 18:34:13 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Dec 2019 09:34:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,282,1571727600"; d="scan'208";a="223711848" Received: from silpixa00399953.ir.intel.com (HELO silpixa00399953.ger.corp.intel.com) ([10.237.222.53]) by orsmga002.jf.intel.com with ESMTP; 05 Dec 2019 09:34:12 -0800 From: Ciara Power To: dev@dpdk.org Cc: Bruce Richardson , Ciara Power Date: Thu, 5 Dec 2019 17:31:26 +0000 Message-Id: <20191205173128.64543-5-ciara.power@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191205173128.64543-1-ciara.power@intel.com> References: <20191205173128.64543-1-ciara.power@intel.com> Subject: [dpdk-dev] [RFC 4/6] ethdev: add callback support for process-info X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Bruce Richardson The ethdev library now registers commands with process_info, and implements the callback functions. These commands allow the list of ethdev ports and the stats for a port to be queried. Signed-off-by: Bruce Richardson Signed-off-by: Ciara Power --- lib/librte_ethdev/Makefile | 2 +- lib/librte_ethdev/rte_ethdev.c | 73 ++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/lib/librte_ethdev/Makefile b/lib/librte_ethdev/Makefile index b627e4e23..f586f83de 100644 --- a/lib/librte_ethdev/Makefile +++ b/lib/librte_ethdev/Makefile @@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring -LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_meter +LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_meter -lrte_process_info EXPORT_MAP := rte_ethdev_version.map diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 6e9cb243e..b0b5ceec5 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "rte_ethdev.h" #include "rte_ethdev_driver.h" @@ -5190,9 +5191,81 @@ rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da) return result; } +static int +handle_port_list(const char *cmd __rte_unused, + const char *params __rte_unused, + char *buffer, int buf_len) +{ + int used = 0; + int port_id; + + used = strlcpy(buffer, "[", buf_len); + RTE_ETH_FOREACH_DEV(port_id) + used += snprintf(buffer + used, buf_len - used, "%d,", port_id); + buffer[used - 1] = ']'; + return used; +} + +static int +handle_port_stats(const char *cmd __rte_unused, + const char *params, + char *buffer, int buf_len) +{ + struct rte_eth_xstat *eth_xstats; + struct rte_eth_xstat_name *xstat_names; + int port_id, num_xstats; + int i, ret; + int used = 0; + + if (params == NULL || strlen(params) == 0 || !isdigit(*params)) + return -1; + + port_id = atoi(params); + if (!rte_eth_dev_is_valid_port(port_id)) + return -1; + + used = strlcpy(buffer, "{", buf_len); + + num_xstats = rte_eth_xstats_get(port_id, NULL, 0); + if (num_xstats < 0) + return -1; + + /* use one malloc for both names and stats */ + eth_xstats = malloc((sizeof(struct rte_eth_xstat) + + sizeof(struct rte_eth_xstat_name)) * num_xstats); + if (eth_xstats == NULL) + return -1; + xstat_names = (void *)ð_xstats[num_xstats]; + + ret = rte_eth_xstats_get_names(port_id, xstat_names, num_xstats); + if (ret < 0 || ret > num_xstats) { + free(eth_xstats); + return -1; + } + + ret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats); + if (ret < 0 || ret > num_xstats) { + free(eth_xstats); + return -1; + } + + for (i = 0; i < num_xstats; i++) { + ret = snprintf(buffer + used, buf_len - used, "\"%s\":%"PRIu64",", + xstat_names[i].name, eth_xstats[i].value); + if (ret + used >= buf_len) + break; + used += ret; + } + + buffer[used - 1] = '}'; + return used; +} + RTE_INIT(ethdev_init_log) { rte_eth_dev_logtype = rte_log_register("lib.ethdev"); if (rte_eth_dev_logtype >= 0) rte_log_set_level(rte_eth_dev_logtype, RTE_LOG_INFO); + rte_process_info_register("/ethdev:list", handle_port_list); + rte_process_info_register("/ethdev:stats", handle_port_stats); }