From patchwork Tue Feb 7 10:16:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liu, Mingxia" X-Patchwork-Id: 123243 X-Patchwork-Delegate: qi.z.zhang@intel.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 531EA41C2D; Tue, 7 Feb 2023 12:14:42 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 866D8410F6; Tue, 7 Feb 2023 12:14:30 +0100 (CET) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id 7BA5A42D32 for ; Tue, 7 Feb 2023 12:14:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675768468; x=1707304468; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5SpgYB3FmHaN8tZnXwxErbDxeI6/hbr+hGCN+xz2meE=; b=eOTU3O0imzG4hPMMljvsUyO/MNK2hQ1xcwhx58gtiqFXKqoCdRj3GMMS y+qMHNG2xtJJQlA836u6+oFLqx2tqKtLNhHAldB/GsYE2qAh2xmGA+xbT pOHaC1PLK9mWDDdOsyo1q/AsM8+QQ7vg5zqHvDNGMvzPQdyvKq4Lp5SfR uesZg/u29LCIYqsugp3kvAVs438Y+poAuibShVE5EpCfb298DQvmf8Cj3 4xJa3NCdIaCVRxZKemY2tD6bLOjFd5kOybS29LKy9P2A1nMK3G5aJgg+2 eikQN2nubmwqLUCh38TEfZq/LLgJxxGp1IcXD/w1N4qzIBJulTsZBmpWp A==; X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="415699081" X-IronPort-AV: E=Sophos;i="5.97,278,1669104000"; d="scan'208";a="415699081" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2023 03:14:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="809486983" X-IronPort-AV: E=Sophos;i="5.97,278,1669104000"; d="scan'208";a="809486983" Received: from dpdk-mingxial-01.sh.intel.com ([10.67.119.167]) by fmsmga001.fm.intel.com with ESMTP; 07 Feb 2023 03:14:26 -0800 From: Mingxia Liu To: dev@dpdk.org, qi.z.zhang@intel.com, jingjing.wu@intel.com, beilei.xing@intel.com Cc: Mingxia Liu Subject: [PATCH v6 6/6] common/idpf: add xstats ops Date: Tue, 7 Feb 2023 10:16:50 +0000 Message-Id: <20230207101650.2402452-7-mingxia.liu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230207101650.2402452-1-mingxia.liu@intel.com> References: <20230207100859.2401709-2-mingxia.liu@intel.com> <20230207101650.2402452-1-mingxia.liu@intel.com> MIME-Version: 1.0 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 Add support for these device ops: -idpf_dev_xstats_get -idpf_dev_xstats_get_names -idpf_dev_xstats_reset Signed-off-by: Mingxia Liu --- drivers/net/idpf/idpf_ethdev.c | 80 ++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/drivers/net/idpf/idpf_ethdev.c b/drivers/net/idpf/idpf_ethdev.c index 751c0d8717..38cbbf369d 100644 --- a/drivers/net/idpf/idpf_ethdev.c +++ b/drivers/net/idpf/idpf_ethdev.c @@ -80,6 +80,30 @@ static const uint64_t idpf_ipv6_rss = RTE_ETH_RSS_NONFRAG_IPV6_UDP | RTE_ETH_RSS_NONFRAG_IPV6_OTHER | RTE_ETH_RSS_FRAG_IPV6; +struct rte_idpf_xstats_name_off { + char name[RTE_ETH_XSTATS_NAME_SIZE]; + unsigned int offset; +}; + +static const struct rte_idpf_xstats_name_off rte_idpf_stats_strings[] = { + {"rx_bytes", offsetof(struct virtchnl2_vport_stats, rx_bytes)}, + {"rx_unicast_packets", offsetof(struct virtchnl2_vport_stats, rx_unicast)}, + {"rx_multicast_packets", offsetof(struct virtchnl2_vport_stats, rx_multicast)}, + {"rx_broadcast_packets", offsetof(struct virtchnl2_vport_stats, rx_broadcast)}, + {"rx_dropped_packets", offsetof(struct virtchnl2_vport_stats, rx_discards)}, + {"rx_errors", offsetof(struct virtchnl2_vport_stats, rx_errors)}, + {"rx_unknown_protocol_packets", offsetof(struct virtchnl2_vport_stats, + rx_unknown_protocol)}, + {"tx_bytes", offsetof(struct virtchnl2_vport_stats, tx_bytes)}, + {"tx_unicast_packets", offsetof(struct virtchnl2_vport_stats, tx_unicast)}, + {"tx_multicast_packets", offsetof(struct virtchnl2_vport_stats, tx_multicast)}, + {"tx_broadcast_packets", offsetof(struct virtchnl2_vport_stats, tx_broadcast)}, + {"tx_dropped_packets", offsetof(struct virtchnl2_vport_stats, tx_discards)}, + {"tx_error_packets", offsetof(struct virtchnl2_vport_stats, tx_errors)}}; + +#define IDPF_NB_XSTATS (sizeof(rte_idpf_stats_strings) / \ + sizeof(rte_idpf_stats_strings[0])) + static int idpf_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete) @@ -313,6 +337,59 @@ idpf_dev_stats_reset(struct rte_eth_dev *dev) return 0; } +static int idpf_dev_xstats_reset(struct rte_eth_dev *dev) +{ + idpf_dev_stats_reset(dev); + return 0; +} + +static int idpf_dev_xstats_get(struct rte_eth_dev *dev, + struct rte_eth_xstat *xstats, unsigned int n) +{ + struct idpf_vport *vport = + (struct idpf_vport *)dev->data->dev_private; + struct virtchnl2_vport_stats *pstats = NULL; + unsigned int i; + int ret; + + if (n < IDPF_NB_XSTATS) + return IDPF_NB_XSTATS; + + if (!xstats) + return 0; + + ret = idpf_vc_stats_query(vport, &pstats); + if (ret) { + PMD_DRV_LOG(ERR, "Get statistics failed"); + return 0; + } + + idpf_vport_stats_update(&vport->eth_stats_offset, pstats); + + /* loop over xstats array and values from pstats */ + for (i = 0; i < IDPF_NB_XSTATS; i++) { + xstats[i].id = i; + xstats[i].value = *(uint64_t *)(((char *)pstats) + + rte_idpf_stats_strings[i].offset); + } + return IDPF_NB_XSTATS; +} + +static int idpf_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) + for (i = 0; i < IDPF_NB_XSTATS; i++) { + snprintf(xstats_names[i].name, + sizeof(xstats_names[i].name), + "%s", rte_idpf_stats_strings[i].name); + } + return IDPF_NB_XSTATS; +} + static int idpf_config_rss_hf(struct idpf_vport *vport, uint64_t rss_hf) { uint64_t hena = 0; @@ -1122,6 +1199,9 @@ static const struct eth_dev_ops idpf_eth_dev_ops = { .reta_query = idpf_rss_reta_query, .rss_hash_update = idpf_rss_hash_update, .rss_hash_conf_get = idpf_rss_hash_conf_get, + .xstats_get = idpf_dev_xstats_get, + .xstats_get_names = idpf_dev_xstats_get_names, + .xstats_reset = idpf_dev_xstats_reset, }; static uint16_t