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 A6E44A00C5; Wed, 3 Aug 2022 13:32:42 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7364B42BC4; Wed, 3 Aug 2022 13:31:41 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id D856742BCE for ; Wed, 3 Aug 2022 13:31:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659526299; x=1691062299; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2oH9dJCDLfK/E5TNIKGDiuDRg0pkClQdxkIGqvsscoU=; b=OULmOG+7LllPjoMGfVRyxly3DJ92u1mt1XYKCGUVNkUVzTXMzbqUoVvz 1iRPHh3UaTHfVZQNteNSc651Hd2vpdjC8hS7hVn9Dv0dcMtY8uftClBdd tIYMD9rWj4VBX5NUEB+r6IRwBrdbh259ZI9/UDb5s5WRXsmKCRt+jPrA8 yr4+LgBSmZRssTn+4N5H0vkA8GxxALQgBcTqUfyvnqsAoNd+CSimN/tso qiI/OBylpz6JgCQL+gqEhefWAMEmXsP8twq3rdyVQPK0hpXHNU7aWQ84p 7bIa5vPm66O3jzLfVIq3GUNc0vxuaFszdia3Xzx9ueK/OYov4m5XKo/go A==; X-IronPort-AV: E=McAfee;i="6400,9594,10427"; a="375948539" X-IronPort-AV: E=Sophos;i="5.93,214,1654585200"; d="scan'208";a="375948539" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2022 04:31:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,214,1654585200"; d="scan'208";a="692211123" Received: from dpdk-jf-ntb-v2.sh.intel.com ([10.67.118.246]) by FMSMGA003.fm.intel.com with ESMTP; 03 Aug 2022 04:31:36 -0700 From: Junfeng Guo To: qi.z.zhang@intel.com, jingjing.wu@intel.com, beilei.xing@intel.com Cc: dev@dpdk.org, junfeng.guo@intel.com, Mingxia Liu Subject: [PATCH 11/13] net/idpf: add hw statistics Date: Wed, 3 Aug 2022 19:31:02 +0800 Message-Id: <20220803113104.1184059-12-junfeng.guo@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220803113104.1184059-1-junfeng.guo@intel.com> References: <20220803113104.1184059-1-junfeng.guo@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 Add hardware packets/bytes statisticsi query and reset. Signed-off-by: Mingxia Liu Signed-off-by: Junfeng Guo --- drivers/net/idpf/idpf_ethdev.c | 82 +++++++++++++++++++++++++++++++++- drivers/net/idpf/idpf_ethdev.h | 2 + drivers/net/idpf/idpf_vchnl.c | 26 +++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/drivers/net/idpf/idpf_ethdev.c b/drivers/net/idpf/idpf_ethdev.c index 4b8e3c4d5b..b934488d0b 100644 --- a/drivers/net/idpf/idpf_ethdev.c +++ b/drivers/net/idpf/idpf_ethdev.c @@ -35,6 +35,9 @@ static int idpf_dev_close(struct rte_eth_dev *dev); static int idpf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info); static int idpf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu); +static int idpf_dev_stats_get(struct rte_eth_dev *dev, + struct rte_eth_stats *stats); +static int idpf_dev_stats_reset(struct rte_eth_dev *dev); int idpf_dev_link_update(struct rte_eth_dev *dev, @@ -74,6 +77,8 @@ static const struct eth_dev_ops idpf_eth_dev_ops = { .dev_infos_get = idpf_dev_info_get, .link_update = idpf_dev_link_update, .mtu_set = idpf_dev_mtu_set, + .stats_get = idpf_dev_stats_get, + .stats_reset = idpf_dev_stats_reset, }; static int @@ -157,8 +162,79 @@ idpf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused) return 0; } +static void +idpf_stat_update(uint64_t *offset, uint64_t *stat) +{ + *stat = *stat - *offset; +} + + +static void +idpf_update_stats(struct virtchnl2_vport_stats *oes, struct virtchnl2_vport_stats *nes) +{ + idpf_stat_update(&oes->rx_bytes, &nes->rx_bytes); + idpf_stat_update(&oes->rx_unicast, &nes->rx_unicast); + idpf_stat_update(&oes->rx_multicast, &nes->rx_multicast); + idpf_stat_update(&oes->rx_broadcast, &nes->rx_broadcast); + idpf_stat_update(&oes->rx_discards, &nes->rx_discards); + idpf_stat_update(&oes->tx_bytes, &nes->tx_bytes); + idpf_stat_update(&oes->tx_unicast, &nes->tx_unicast); + idpf_stat_update(&oes->tx_multicast, &nes->tx_multicast); + idpf_stat_update(&oes->tx_broadcast, &nes->tx_broadcast); + idpf_stat_update(&oes->tx_errors, &nes->tx_errors); + idpf_stat_update(&oes->tx_discards, &nes->tx_discards); +} + static int -idpf_init_vport_req_info(__rte_unused struct rte_eth_dev *dev) +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; + } else { + PMD_DRV_LOG(ERR, "Get statistics failed"); + } + return ret; +} + + +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; + + return 0; +} + +static int +idpf_init_vport_req_info(struct rte_eth_dev *dev) { struct virtchnl2_create_vport *vport_info; uint16_t idx = adapter->next_vport_idx; @@ -499,6 +575,10 @@ 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; + } return 0; err_vport: diff --git a/drivers/net/idpf/idpf_ethdev.h b/drivers/net/idpf/idpf_ethdev.h index 22096c4185..c0cbf4c3c6 100644 --- a/drivers/net/idpf/idpf_ethdev.h +++ b/drivers/net/idpf/idpf_ethdev.h @@ -227,6 +227,8 @@ int idpf_switch_queue(struct idpf_vport *vport, uint16_t qid, bool rx, bool on); int idpf_ena_dis_queues(struct idpf_vport *vport, bool enable); int idpf_ena_dis_vport(struct idpf_vport *vport, bool enable); +int idpf_query_stats(struct idpf_vport *vport, + struct virtchnl2_vport_stats **pstats); #endif /* _IDPF_ETHDEV_H_ */ diff --git a/drivers/net/idpf/idpf_vchnl.c b/drivers/net/idpf/idpf_vchnl.c index 07b220016f..563f8f649e 100644 --- a/drivers/net/idpf/idpf_vchnl.c +++ b/drivers/net/idpf/idpf_vchnl.c @@ -219,6 +219,7 @@ idpf_execute_vc_cmd(struct idpf_adapter *adapter, struct idpf_cmd_info *args) case VIRTCHNL2_OP_DISABLE_QUEUES: case VIRTCHNL2_OP_ENABLE_VPORT: case VIRTCHNL2_OP_DISABLE_VPORT: + case VIRTCHNL2_OP_GET_STATS: /* for init virtchnl ops, need to poll the response */ do { result = idpf_read_msg_from_ipf(adapter, @@ -1070,3 +1071,28 @@ idpf_ena_dis_vport(struct idpf_vport *vport, bool enable) return err; } +int +idpf_query_stats(struct idpf_vport *vport, + struct virtchnl2_vport_stats **pstats) +{ + struct virtchnl2_vport vc_vport; + struct idpf_cmd_info args; + int err; + + vc_vport.vport_id = vport->vport_id; + args.ops = VIRTCHNL2_OP_GET_STATS; + args.in_args = (u8 *)&vc_vport; + args.in_args_size = sizeof(vc_vport); + args.out_buffer = adapter->mbx_resp; + args.out_size = IDPF_DFLT_MBX_BUF_SIZE; + + err = idpf_execute_vc_cmd(adapter, &args); + if (err) { + PMD_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; +} + -- 2.25.1