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 095D7423AA; Wed, 11 Jan 2023 09:13:05 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2DB9F42D1F; Wed, 11 Jan 2023 09:13:03 +0100 (CET) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 7363F41611 for ; Wed, 11 Jan 2023 09:13:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673424780; x=1704960780; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ErbpORnGNFqL8iHqzyES7MIFC9bilyJzYYBJGsrQobg=; b=E0O/dSUGYBHx7SH8aoujhvp22XuebssGULFJvgmg6CVnZoFYLm3oRWcI Ipqf8HkWnmQyPI+XKqpzZX9m+ALk1xxpHY85eb/yF3INIAiTaH1cZRyPy zDeQDQzFA/KdrFJ7EXbe+7Y0F20zB9sbpFjRwyrLSMAtH/DI568asNxf7 z2wPVjm70YbD+kAi2AwJdwzmygTg6aD97Ed7ZS8Q2RWxKAQgOVQ7WsF8p XsjilMq2EYzEc+TB3MNDr/qW6sZY5mB6oeryc68hCsOvRqLPXz/RCpCXN 2LD07rSPqRyY9AMhxYBMr+7u9InXyhizo/rMdxPErjko723Dbp7VkJWK5 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="311167467" X-IronPort-AV: E=Sophos;i="5.96,315,1665471600"; d="scan'208";a="311167467" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2023 00:13:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="831271375" X-IronPort-AV: E=Sophos;i="5.96,315,1665471600"; d="scan'208";a="831271375" Received: from dpdk-mingxial-01.sh.intel.com ([10.67.119.112]) by orsmga005.jf.intel.com with ESMTP; 11 Jan 2023 00:12:58 -0800 From: Mingxia Liu To: dev@dpdk.org Cc: jingjing.wu@intel.com, beilei.xing@intel.com, Mingxia Liu Subject: [PATCH v2 1/6] common/idpf: add hw statistics Date: Wed, 11 Jan 2023 07:15:40 +0000 Message-Id: <20230111071545.504706-2-mingxia.liu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230111071545.504706-1-mingxia.liu@intel.com> References: <20221216093706.2453812-1-mingxia.liu@intel.com> <20230111071545.504706-1-mingxia.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 add hardware packets/bytes statistics. Signed-off-by: Mingxia Liu --- drivers/common/idpf/idpf_common_device.c | 17 +++++ drivers/common/idpf/idpf_common_device.h | 5 +- drivers/common/idpf/idpf_common_virtchnl.c | 27 +++++++ drivers/common/idpf/idpf_common_virtchnl.h | 3 + drivers/common/idpf/version.map | 2 + drivers/net/idpf/idpf_ethdev.c | 87 ++++++++++++++++++++++ 6 files changed, 140 insertions(+), 1 deletion(-) diff --git a/drivers/common/idpf/idpf_common_device.c b/drivers/common/idpf/idpf_common_device.c index 4e257a68fd..4adbb6f399 100644 --- a/drivers/common/idpf/idpf_common_device.c +++ b/drivers/common/idpf/idpf_common_device.c @@ -661,4 +661,21 @@ idpf_create_vport_info_init(struct idpf_vport *vport, return 0; } +void +idpf_update_stats(struct virtchnl2_vport_stats *oes, struct virtchnl2_vport_stats *nes) +{ + nes->rx_bytes = nes->rx_bytes - oes->rx_bytes; + nes->rx_unicast = nes->rx_unicast - oes->rx_unicast; + nes->rx_multicast = nes->rx_multicast - oes->rx_multicast; + nes->rx_broadcast = nes->rx_broadcast - oes->rx_broadcast; + nes->rx_errors = nes->rx_errors - oes->rx_errors; + nes->rx_discards = nes->rx_discards - oes->rx_discards; + nes->tx_bytes = nes->tx_bytes - oes->tx_bytes; + nes->tx_unicast = nes->tx_unicast - oes->tx_unicast; + nes->tx_multicast = nes->tx_multicast - oes->tx_multicast; + nes->tx_broadcast = nes->tx_broadcast - oes->tx_broadcast; + nes->tx_errors = nes->tx_errors - oes->tx_errors; + nes->tx_discards = nes->tx_discards - oes->tx_discards; +} + RTE_LOG_REGISTER_SUFFIX(idpf_common_logtype, common, NOTICE); diff --git a/drivers/common/idpf/idpf_common_device.h b/drivers/common/idpf/idpf_common_device.h index 6c9a65ae3b..5184dcee9f 100644 --- a/drivers/common/idpf/idpf_common_device.h +++ b/drivers/common/idpf/idpf_common_device.h @@ -112,6 +112,8 @@ struct idpf_vport { bool tx_vec_allowed; bool rx_use_avx512; bool tx_use_avx512; + + struct virtchnl2_vport_stats eth_stats_offset; }; /* Message type read in virtual channel from PF */ @@ -188,5 +190,6 @@ int idpf_config_irq_unmap(struct idpf_vport *vport, uint16_t nb_rx_queues); __rte_internal int idpf_create_vport_info_init(struct idpf_vport *vport, struct virtchnl2_create_vport *vport_info); - +__rte_internal +void idpf_update_stats(struct virtchnl2_vport_stats *oes, struct virtchnl2_vport_stats *nes); #endif /* _IDPF_COMMON_DEVICE_H_ */ diff --git a/drivers/common/idpf/idpf_common_virtchnl.c b/drivers/common/idpf/idpf_common_virtchnl.c index 324214caa1..80351d15de 100644 --- a/drivers/common/idpf/idpf_common_virtchnl.c +++ b/drivers/common/idpf/idpf_common_virtchnl.c @@ -217,6 +217,7 @@ idpf_execute_vc_cmd(struct idpf_adapter *adapter, struct idpf_cmd_info *args) case VIRTCHNL2_OP_UNMAP_QUEUE_VECTOR: case VIRTCHNL2_OP_ALLOC_VECTORS: case VIRTCHNL2_OP_DEALLOC_VECTORS: + case VIRTCHNL2_OP_GET_STATS: /* for init virtchnl ops, need to poll the response */ err = idpf_read_one_msg(adapter, args->ops, args->out_size, args->out_buffer); clear_cmd(adapter); @@ -806,6 +807,32 @@ idpf_vc_query_ptype_info(struct idpf_adapter *adapter) return err; } +int +idpf_query_stats(struct idpf_vport *vport, + struct virtchnl2_vport_stats **pstats) +{ + struct idpf_adapter *adapter = vport->adapter; + struct virtchnl2_vport_stats vport_stats; + struct idpf_cmd_info args; + int err; + + vport_stats.vport_id = vport->vport_id; + args.ops = VIRTCHNL2_OP_GET_STATS; + args.in_args = (u8 *)&vport_stats; + args.in_args_size = sizeof(vport_stats); + args.out_buffer = adapter->mbx_resp; + args.out_size = IDPF_DFLT_MBX_BUF_SIZE; + + err = idpf_execute_vc_cmd(adapter, &args); + if (err) { + DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_GET_STATS"); + *pstats = NULL; + return err; + } + *pstats = (struct virtchnl2_vport_stats *)args.out_buffer; + return 0; +} + #define IDPF_RX_BUF_STRIDE 64 int idpf_vc_config_rxq(struct idpf_vport *vport, struct idpf_rx_queue *rxq) diff --git a/drivers/common/idpf/idpf_common_virtchnl.h b/drivers/common/idpf/idpf_common_virtchnl.h index d16b6b66f4..60347fe571 100644 --- a/drivers/common/idpf/idpf_common_virtchnl.h +++ b/drivers/common/idpf/idpf_common_virtchnl.h @@ -38,4 +38,7 @@ __rte_internal int idpf_vc_config_rxq(struct idpf_vport *vport, struct idpf_rx_queue *rxq); __rte_internal int idpf_vc_config_txq(struct idpf_vport *vport, struct idpf_tx_queue *txq); +__rte_internal +int idpf_query_stats(struct idpf_vport *vport, + struct virtchnl2_vport_stats **pstats); #endif /* _IDPF_COMMON_VIRTCHNL_H_ */ diff --git a/drivers/common/idpf/version.map b/drivers/common/idpf/version.map index 7018a1d695..6a1dc13302 100644 --- a/drivers/common/idpf/version.map +++ b/drivers/common/idpf/version.map @@ -50,6 +50,8 @@ INTERNAL { idpf_splitq_recv_pkts_avx512; idpf_singleq_xmit_pkts_avx512; idpf_splitq_xmit_pkts_avx512; + idpf_update_stats; + idpf_query_stats; local: *; }; diff --git a/drivers/net/idpf/idpf_ethdev.c b/drivers/net/idpf/idpf_ethdev.c index ee2dec7c7c..e8bb097c78 100644 --- a/drivers/net/idpf/idpf_ethdev.c +++ b/drivers/net/idpf/idpf_ethdev.c @@ -140,6 +140,86 @@ idpf_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused) return ptypes; } +static uint64_t +idpf_get_mbuf_alloc_failed_stats(struct rte_eth_dev *dev) +{ + uint64_t mbuf_alloc_failed = 0; + struct idpf_rx_queue *rxq; + int i = 0; + + for (i = 0; i < dev->data->nb_rx_queues; i++) { + rxq = dev->data->rx_queues[i]; + mbuf_alloc_failed += rte_atomic64_read(&(rxq->rx_stats.mbuf_alloc_failed)); + } + + return mbuf_alloc_failed; +} + +static int +idpf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) +{ + struct idpf_vport *vport = + (struct idpf_vport *)dev->data->dev_private; + struct virtchnl2_vport_stats *pstats = NULL; + int ret; + + ret = idpf_query_stats(vport, &pstats); + if (ret == 0) { + uint8_t crc_stats_len = (dev->data->dev_conf.rxmode.offloads & + RTE_ETH_RX_OFFLOAD_KEEP_CRC) ? 0 : + RTE_ETHER_CRC_LEN; + + idpf_update_stats(&vport->eth_stats_offset, pstats); + stats->ipackets = pstats->rx_unicast + pstats->rx_multicast + + pstats->rx_broadcast - pstats->rx_discards; + stats->opackets = pstats->tx_broadcast + pstats->tx_multicast + + pstats->tx_unicast; + stats->imissed = pstats->rx_discards; + stats->oerrors = pstats->tx_errors + pstats->tx_discards; + stats->ibytes = pstats->rx_bytes; + stats->ibytes -= stats->ipackets * crc_stats_len; + stats->obytes = pstats->tx_bytes; + + dev->data->rx_mbuf_alloc_failed = idpf_get_mbuf_alloc_failed_stats(dev); + stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed; + } else { + PMD_DRV_LOG(ERR, "Get statistics failed"); + } + return ret; +} + +static void +idpf_reset_mbuf_alloc_failed_stats(struct rte_eth_dev *dev) +{ + struct idpf_rx_queue *rxq; + int i; + + for (i = 0; i < dev->data->nb_rx_queues; i++) { + rxq = dev->data->rx_queues[i]; + rte_atomic64_set(&(rxq->rx_stats.mbuf_alloc_failed), 0); + } +} + +static int +idpf_dev_stats_reset(struct rte_eth_dev *dev) +{ + struct idpf_vport *vport = + (struct idpf_vport *)dev->data->dev_private; + struct virtchnl2_vport_stats *pstats = NULL; + int ret; + + ret = idpf_query_stats(vport, &pstats); + if (ret != 0) + return ret; + + /* set stats offset base on current values */ + vport->eth_stats_offset = *pstats; + + idpf_reset_mbuf_alloc_failed_stats(dev); + + return 0; +} + static int idpf_init_rss(struct idpf_vport *vport) { @@ -327,6 +407,11 @@ idpf_dev_start(struct rte_eth_dev *dev) goto err_vport; } + if (idpf_dev_stats_reset(dev)) { + PMD_DRV_LOG(ERR, "Failed to reset stats"); + goto err_vport; + } + vport->stopped = 0; return 0; @@ -606,6 +691,8 @@ static const struct eth_dev_ops idpf_eth_dev_ops = { .tx_queue_release = idpf_dev_tx_queue_release, .mtu_set = idpf_dev_mtu_set, .dev_supported_ptypes_get = idpf_dev_supported_ptypes_get, + .stats_get = idpf_dev_stats_get, + .stats_reset = idpf_dev_stats_reset, }; static uint16_t -- 2.25.1