From patchwork Tue Aug 3 16:42:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 12416809 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43AA9C4338F for ; Tue, 3 Aug 2021 16:42:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B50F61103 for ; Tue, 3 Aug 2021 16:42:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234751AbhHCQnG (ORCPT ); Tue, 3 Aug 2021 12:43:06 -0400 Received: from mga01.intel.com ([192.55.52.88]:28280 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234675AbhHCQnE (ORCPT ); Tue, 3 Aug 2021 12:43:04 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10065"; a="235674742" X-IronPort-AV: E=Sophos;i="5.84,292,1620716400"; d="scan'208";a="235674742" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Aug 2021 09:42:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,292,1620716400"; d="scan'208";a="670509401" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by fmsmga005.fm.intel.com with ESMTP; 03 Aug 2021 09:42:33 -0700 Received: from alobakin-mobl.ger.corp.intel.com (lkalica-MOBL.ger.corp.intel.com [10.213.13.182]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 173GgTIX032348; Tue, 3 Aug 2021 17:42:29 +0100 From: Alexander Lobakin To: "David S. Miller" , Jakub Kicinski Cc: Alexander Lobakin , Jesse Brandeburg , Lukasz Czapnik , Marcin Kubiak , Michal Kubiak , Michal Swiatkowski , Jonathan Corbet , Netanel Belgazal , Arthur Kiyanovski , Guy Tzalik , Saeed Bishara , Ioana Ciornei , Claudiu Manoil , Thomas Petazzoni , Marcin Wojtas , Russell King , Edward Cree , Martin Habets , "Michael S. Tsirkin" , Jason Wang , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Shay Agroskin , Sameeh Jubran , Alexander Duyck , Danielle Ratson , Ido Schimmel , Andrew Lunn , Vladyslav Tarasiuk , Arnd Bergmann , Andrew Morton , Jian Shen , Petr Vorel , Dan Murphy , Yangbo Lu , Michal Kubecek , Zheng Yongjun , Heiner Kallweit , YueHaibing , Johannes Berg , netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, bpf@vger.kernel.org Subject: [PATCH net-next 20/21] virtio-net: convert to standard XDP stats Date: Tue, 3 Aug 2021 18:42:28 +0200 Message-Id: <20210803164228.4342-1-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210803163641.3743-1-alexandr.lobakin@intel.com> References: <20210803163641.3743-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Now that we have 1:1 correspondence between the driver XDP stats and the standard XDP stats, we can go forth and convert the driver to expose XDP statistics via our standard interface. Signed-off-by: Alexander Lobakin Reviewed-by: Jesse Brandeburg --- drivers/net/virtio_net.c | 52 ++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index acad099006cd..df1fe36cf089 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -101,8 +101,6 @@ struct virtnet_rq_stats { static const struct virtnet_stat_desc virtnet_sq_stats_desc[] = { { "packets", VIRTNET_SQ_STAT(packets) }, { "bytes", VIRTNET_SQ_STAT(bytes) }, - { "xdp_xmit", VIRTNET_SQ_STAT(xdp_xmit) }, - { "xdp_xmit_drops", VIRTNET_SQ_STAT(xdp_xmit_drops) }, { "kicks", VIRTNET_SQ_STAT(kicks) }, }; @@ -110,11 +108,6 @@ static const struct virtnet_stat_desc virtnet_rq_stats_desc[] = { { "packets", VIRTNET_RQ_STAT(packets) }, { "bytes", VIRTNET_RQ_STAT(bytes) }, { "drops", VIRTNET_RQ_STAT(drops) }, - { "xdp_packets", VIRTNET_RQ_STAT(xdp_packets) }, - { "xdp_tx", VIRTNET_RQ_STAT(xdp_tx) }, - { "xdp_redirects", VIRTNET_RQ_STAT(xdp_redirects) }, - { "xdp_drops", VIRTNET_RQ_STAT(xdp_drops) }, - { "xdp_errors", VIRTNET_RQ_STAT(xdp_errors) }, { "kicks", VIRTNET_RQ_STAT(kicks) }, }; @@ -2295,6 +2288,49 @@ static void virtnet_get_ethtool_stats(struct net_device *dev, } } +static int virtnet_get_std_stats_channels(struct net_device *dev, u32 sset) +{ + const struct virtnet_info *vi = netdev_priv(dev); + + switch (sset) { + case ETH_SS_STATS_XDP: + return vi->curr_queue_pairs; + default: + return -EOPNOTSUPP; + } +} + +static void virtnet_get_xdp_stats(struct net_device *dev, + struct ethtool_xdp_stats *xdp_stats) +{ + const struct virtnet_info *vi = netdev_priv(dev); + u32 i; + + for (i = 0; i < vi->curr_queue_pairs; i++) { + const struct virtnet_rq_stats *rqs = &vi->rq[i].stats; + const struct virtnet_sq_stats *sqs = &vi->sq[i].stats; + struct ethtool_xdp_stats *iter = xdp_stats + i; + u32 start; + + do { + start = u64_stats_fetch_begin_irq(&rqs->syncp); + + iter->packets = rqs->xdp_packets; + iter->tx = rqs->xdp_tx; + iter->redirect = rqs->xdp_redirects; + iter->drop = rqs->xdp_drops; + iter->errors = rqs->xdp_errors; + } while (u64_stats_fetch_retry_irq(&rqs->syncp, start)); + + do { + start = u64_stats_fetch_begin_irq(&sqs->syncp); + + iter->xmit = sqs->xdp_xmit; + iter->xmit_drops = sqs->xdp_xmit_drops; + } while (u64_stats_fetch_retry_irq(&sqs->syncp, start)); + } +} + static void virtnet_get_channels(struct net_device *dev, struct ethtool_channels *channels) { @@ -2409,6 +2445,8 @@ static const struct ethtool_ops virtnet_ethtool_ops = { .set_link_ksettings = virtnet_set_link_ksettings, .set_coalesce = virtnet_set_coalesce, .get_coalesce = virtnet_get_coalesce, + .get_std_stats_channels = virtnet_get_std_stats_channels, + .get_xdp_stats = virtnet_get_xdp_stats, }; static void virtnet_freeze_down(struct virtio_device *vdev)