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 CCA74A054F; Mon, 5 Sep 2022 12:59:53 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4A0B642B95; Mon, 5 Sep 2022 12:59:02 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id 22CAE42B79 for ; Mon, 5 Sep 2022 12:59:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662375541; x=1693911541; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ChYCjnP6tI7nyViY2eUWveFJGmkisKAWB3kXgEa7d10=; b=NJVfi1rLWkR7BC31SvhF5m1H0S0QcJHFxhHuUjDjPsJR7XhVdffuj6YR kw/qQWIwBxFntMFVdgck8B3T5fYFN+Uzc4v5+pMzn9g984se/C3lNBxgv va5qc28uwz/mBT6RwhZXDqLdkPl/nwam7u+B7UJ2eN8prlRhprHW+h74b sshfIRhQ1UE6PpM7213bsuDecC2g/5SyTdZzQvtsS59aasPCM7lX4L3uW v8pT+XU7I0QFEinJ0hKz0o7u0TYzddT6d7U/efG44DJFykbrMoOrlTZX6 8rC0mYyv6jyFBPTWTUusvHOplObQlrSLEOuIUrs7BasKNihWvTfa4S8AI w==; X-IronPort-AV: E=McAfee;i="6500,9779,10460"; a="297676344" X-IronPort-AV: E=Sophos;i="5.93,291,1654585200"; d="scan'208";a="297676344" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2022 03:58:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,291,1654585200"; d="scan'208";a="682023936" Received: from dpdk-jf-ntb-v2.sh.intel.com ([10.67.118.246]) by fmsmga004.fm.intel.com with ESMTP; 05 Sep 2022 03:58:58 -0700 From: Junfeng Guo To: qi.z.zhang@intel.com, jingjing.wu@intel.com, beilei.xing@intel.com Cc: dev@dpdk.org, xiao.w.wang@intel.com, junfeng.guo@intel.com, Mingxia Liu Subject: [PATCH v2 11/14] net/idpf: add support for hw statistics Date: Mon, 5 Sep 2022 18:58:25 +0800 Message-Id: <20220905105828.3190335-12-junfeng.guo@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220905105828.3190335-1-junfeng.guo@intel.com> References: <20220803113104.1184059-1-junfeng.guo@intel.com> <20220905105828.3190335-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 | 78 ++++++++++++++++++++++++++++++++++ drivers/net/idpf/idpf_ethdev.h | 2 + drivers/net/idpf/idpf_vchnl.c | 27 ++++++++++++ 3 files changed, 107 insertions(+) diff --git a/drivers/net/idpf/idpf_ethdev.c b/drivers/net/idpf/idpf_ethdev.c index 6b3e7eff89..9fee7a783f 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, @@ -73,6 +76,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 @@ -165,6 +170,75 @@ 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_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) +{ + struct idpf_vport *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 = 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) { @@ -508,6 +582,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 a37582d7b9..2657b75c95 100644 --- a/drivers/net/idpf/idpf_ethdev.h +++ b/drivers/net/idpf/idpf_ethdev.h @@ -250,6 +250,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); int idpf_query_ptype_info(struct idpf_adapter *adapter); int idpf_read_one_msg(struct idpf_adapter *adapter, uint32_t ops, uint16_t buf_len, uint8_t *buf); diff --git a/drivers/net/idpf/idpf_vchnl.c b/drivers/net/idpf/idpf_vchnl.c index 6f9b24ab62..49572dc83c 100644 --- a/drivers/net/idpf/idpf_vchnl.c +++ b/drivers/net/idpf/idpf_vchnl.c @@ -1307,6 +1307,33 @@ 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 idpf_adapter *adapter = vport->adapter; + 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; +} + int idpf_query_ptype_info(struct idpf_adapter *adapter) { -- 2.25.1