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 0879145702; Wed, 31 Jul 2024 16:06:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 83707410F9; Wed, 31 Jul 2024 16:06:18 +0200 (CEST) Received: from dkmailrelay1.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 9B1AB4065A for ; Wed, 31 Jul 2024 16:05:03 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesys.local [192.168.4.10]) by dkmailrelay1.smartsharesystems.com (Postfix) with ESMTP id 6CF002099B; Wed, 31 Jul 2024 16:05:03 +0200 (CEST) Received: from dkrd4.smartsharesys.local ([192.168.4.26]) by smartserver.smartsharesystems.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 31 Jul 2024 16:05:00 +0200 From: =?UTF-8?q?Morten=20Br=C3=B8rup?= To: maxime.coquelin@redhat.com, chenbox@nvidia.com Cc: dev@dpdk.org, =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [PATCH v2] virtio: optimize stats counters performance Date: Wed, 31 Jul 2024 14:04:45 +0000 Message-ID: <20240731140446.36735-1-mb@smartsharesystems.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240731131744.36448-1-mb@smartsharesystems.com> References: <20240731131744.36448-1-mb@smartsharesystems.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-OriginalArrivalTime: 31 Jul 2024 14:05:00.0955 (UTC) FILETIME=[A23C86B0:01DAE352] 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 Optimized the performance of updating the virtio statistics counters by reducing the number of branches and inlining the function. Ordered the packet size comparisons according to the probability with typical internet traffic mix. Signed-off-by: Morten Brørup --- v2: * Fixed checkpatch warning about line length. --- drivers/net/virtio/virtio_rxtx.c | 34 -------------------------------- drivers/net/virtio/virtio_rxtx.h | 26 ++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c index f69b9453a2..bb04fd7d43 100644 --- a/drivers/net/virtio/virtio_rxtx.c +++ b/drivers/net/virtio/virtio_rxtx.c @@ -81,40 +81,6 @@ vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) dp->next = VQ_RING_DESC_CHAIN_END; } -void -virtio_update_packet_stats(struct virtnet_stats *stats, struct rte_mbuf *mbuf) -{ - uint32_t s = mbuf->pkt_len; - struct rte_ether_addr *ea; - - stats->bytes += s; - - if (s == 64) { - stats->size_bins[1]++; - } else if (s > 64 && s < 1024) { - uint32_t bin; - - /* count zeros, and offset into correct bin */ - bin = (sizeof(s) * 8) - rte_clz32(s) - 5; - stats->size_bins[bin]++; - } else { - if (s < 64) - stats->size_bins[0]++; - else if (s < 1519) - stats->size_bins[6]++; - else - stats->size_bins[7]++; - } - - ea = rte_pktmbuf_mtod(mbuf, struct rte_ether_addr *); - if (rte_is_multicast_ether_addr(ea)) { - if (rte_is_broadcast_ether_addr(ea)) - stats->broadcast++; - else - stats->multicast++; - } -} - static inline void virtio_rx_stats_updated(struct virtnet_rx *rxvq, struct rte_mbuf *m) { diff --git a/drivers/net/virtio/virtio_rxtx.h b/drivers/net/virtio/virtio_rxtx.h index afc4b74534..81325ed842 100644 --- a/drivers/net/virtio/virtio_rxtx.h +++ b/drivers/net/virtio/virtio_rxtx.h @@ -35,7 +35,29 @@ struct virtnet_tx { }; int virtio_rxq_vec_setup(struct virtnet_rx *rxvq); -void virtio_update_packet_stats(struct virtnet_stats *stats, - struct rte_mbuf *mbuf); + +static inline void +virtio_update_packet_stats(struct virtnet_stats *const stats, const struct rte_mbuf *const mbuf) +{ + uint32_t s = mbuf->pkt_len; + const struct rte_ether_addr *ea = rte_pktmbuf_mtod(mbuf, const struct rte_ether_addr *); + + stats->bytes += s; + + if (s >= 1024) { + stats->size_bins[6 + (s > 1518)]++; + } else if (s <= 64) { + stats->size_bins[s >> 6]++; + } else { + /* count zeros, and offset into correct bin */ + uint32_t bin = (sizeof(s) * 8) - rte_clz32(s) - 5; + stats->size_bins[bin]++; + } + + RTE_BUILD_BUG_ON(offsetof(struct virtnet_stats, broadcast) != + offsetof(struct virtnet_stats, multicast) + sizeof(uint64_t)); + if (rte_is_multicast_ether_addr(ea)) + (&stats->multicast)[rte_is_broadcast_ether_addr(ea)]++; +} #endif /* _VIRTIO_RXTX_H_ */ -- 2.43.0