From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id EAD10A04BC; Sun, 27 Sep 2020 09:49:17 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7167E1D98B; Sun, 27 Sep 2020 09:47:40 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id D950F1D8D5 for ; Sun, 27 Sep 2020 09:47:36 +0200 (CEST) IronPort-SDR: cn8R4zXrq9HTqauXd6R//w4cyNeYlavN/3NaPSOul66+un9NticcW/o1Bfpu+J2yi6VIF+x5iE adBx/wBVZl8A== X-IronPort-AV: E=McAfee;i="6000,8403,9756"; a="223438306" X-IronPort-AV: E=Sophos;i="5.77,309,1596524400"; d="scan'208";a="223438306" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2020 00:47:36 -0700 IronPort-SDR: 1ydZuWdCwcVd2kqR7JzWIY2/uda887Uef5brKAIwfgtyT0fOZTyKxwB5LMMQTC1rJg9Ijsa/DO MSOO06VnDjBQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,309,1596524400"; d="scan'208";a="323939516" Received: from intel-npg-odc-srv03.cd.intel.com ([10.240.178.138]) by orsmga002.jf.intel.com with ESMTP; 27 Sep 2020 00:47:34 -0700 From: Robin Zhang To: dev@dpdk.org Cc: beilei.xing@intel.com, jingjing.wu@intel.com, qiming.yang@intel.com, stevex.yang@intel.com, Robin Zhang Date: Sun, 27 Sep 2020 07:26:25 +0000 Message-Id: <20200927072626.28374-8-robinx.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200927072626.28374-1-robinx.zhang@intel.com> References: <20200927072626.28374-1-robinx.zhang@intel.com> Subject: [dpdk-dev] [PATCH 7/8] net/iavf: add extended stats 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" Add implementation of xstats() functions in iavf PMD. Signed-off-by: Robin Zhang --- drivers/net/iavf/iavf_ethdev.c | 81 ++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/drivers/net/iavf/iavf_ethdev.c b/drivers/net/iavf/iavf_ethdev.c index 5b3c68f2e..836c09f58 100644 --- a/drivers/net/iavf/iavf_ethdev.c +++ b/drivers/net/iavf/iavf_ethdev.c @@ -40,6 +40,11 @@ static const uint32_t *iavf_dev_supported_ptypes_get(struct rte_eth_dev *dev); static int iavf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats); static int iavf_dev_stats_reset(struct rte_eth_dev *dev); +static int iavf_dev_xstats_get(struct rte_eth_dev *dev, + struct rte_eth_xstat *xstats, unsigned int n); +static int iavf_dev_xstats_get_names(struct rte_eth_dev *dev, + struct rte_eth_xstat_name *xstats_names, + unsigned int limit); static int iavf_dev_promiscuous_enable(struct rte_eth_dev *dev); static int iavf_dev_promiscuous_disable(struct rte_eth_dev *dev); static int iavf_dev_allmulticast_enable(struct rte_eth_dev *dev); @@ -82,6 +87,30 @@ static const struct rte_pci_id pci_id_iavf_map[] = { { .vendor_id = 0, /* sentinel */ }, }; +struct rte_iavf_xstats_name_off { + char name[RTE_ETH_XSTATS_NAME_SIZE]; + unsigned int offset; +}; + +static const struct rte_iavf_xstats_name_off rte_iavf_stats_strings[] = { + {"rx_bytes", offsetof(struct iavf_eth_stats, rx_bytes)}, + {"rx_unicast_packets", offsetof(struct iavf_eth_stats, rx_unicast)}, + {"rx_multicast_packets", offsetof(struct iavf_eth_stats, rx_multicast)}, + {"rx_broadcast_packets", offsetof(struct iavf_eth_stats, rx_broadcast)}, + {"rx_dropped_packets", offsetof(struct iavf_eth_stats, rx_discards)}, + {"rx_unknown_protocol_packets", offsetof(struct iavf_eth_stats, + rx_unknown_protocol)}, + {"tx_bytes", offsetof(struct iavf_eth_stats, tx_bytes)}, + {"tx_unicast_packets", offsetof(struct iavf_eth_stats, tx_unicast)}, + {"tx_multicast_packets", offsetof(struct iavf_eth_stats, tx_multicast)}, + {"tx_broadcast_packets", offsetof(struct iavf_eth_stats, tx_broadcast)}, + {"tx_dropped_packets", offsetof(struct iavf_eth_stats, tx_discards)}, + {"tx_error_packets", offsetof(struct iavf_eth_stats, tx_errors)}, +}; + +#define IAVF_NB_XSTATS (sizeof(rte_iavf_stats_strings) / \ + sizeof(rte_iavf_stats_strings[0])) + static const struct eth_dev_ops iavf_eth_dev_ops = { .dev_configure = iavf_dev_configure, .dev_start = iavf_dev_start, @@ -93,6 +122,9 @@ static const struct eth_dev_ops iavf_eth_dev_ops = { .link_update = iavf_dev_link_update, .stats_get = iavf_dev_stats_get, .stats_reset = iavf_dev_stats_reset, + .xstats_get = iavf_dev_xstats_get, + .xstats_get_names = iavf_dev_xstats_get_names, + .xstats_reset = iavf_dev_stats_reset, .promiscuous_enable = iavf_dev_promiscuous_enable, .promiscuous_disable = iavf_dev_promiscuous_disable, .allmulticast_enable = iavf_dev_allmulticast_enable, @@ -1092,6 +1124,55 @@ iavf_dev_stats_reset(struct rte_eth_dev *dev) return 0; } +static int iavf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev, + struct rte_eth_xstat_name *xstats_names, + __rte_unused unsigned int limit) +{ + unsigned int i; + + if (xstats_names != NULL) + for (i = 0; i < IAVF_NB_XSTATS; i++) { + snprintf(xstats_names[i].name, + sizeof(xstats_names[i].name), + "%s", rte_iavf_stats_strings[i].name); + } + return IAVF_NB_XSTATS; +} + +static int iavf_dev_xstats_get(struct rte_eth_dev *dev, + struct rte_eth_xstat *xstats, unsigned int n) +{ + int ret; + unsigned int i; + struct iavf_adapter *adapter = + IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private); + struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(dev->data->dev_private); + struct iavf_vsi *vsi = &vf->vsi; + struct virtchnl_eth_stats *pstats = NULL; + + if (n < IAVF_NB_XSTATS) + return IAVF_NB_XSTATS; + + ret = iavf_query_stats(adapter, &pstats); + if (ret != 0) + return 0; + + if (!xstats) + return 0; + + iavf_update_stats(vsi, pstats); + + /* loop over xstats array and values from pstats */ + for (i = 0; i < IAVF_NB_XSTATS; i++) { + xstats[i].id = i; + xstats[i].value = *(uint64_t *)(((char *)pstats) + + rte_iavf_stats_strings[i].offset); + } + + return IAVF_NB_XSTATS; +} + + static int iavf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id) { -- 2.17.1