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 EEC064571C; Fri, 2 Aug 2024 16:40:51 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E3DB240E20; Fri, 2 Aug 2024 16:40:51 +0200 (CEST) Received: from dkmailrelay1.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 9708F40696 for ; Fri, 2 Aug 2024 16:40:50 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesys.local [192.168.4.10]) by dkmailrelay1.smartsharesystems.com (Postfix) with ESMTP id 6DAE22099B; Fri, 2 Aug 2024 16:40:50 +0200 (CEST) Received: from dkrd4.smartsharesys.local ([192.168.4.26]) by smartserver.smartsharesystems.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 2 Aug 2024 16:40:49 +0200 From: =?UTF-8?q?Morten=20Br=C3=B8rup?= To: longli@microsoft.com, weh@microsoft.com Cc: stephen@networkplumber.org, dev@dpdk.org, =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [PATCH] netvsc: optimize stats counters performance Date: Fri, 2 Aug 2024 14:40:48 +0000 Message-ID: <20240802144048.270152-1-mb@smartsharesystems.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-OriginalArrivalTime: 02 Aug 2024 14:40:49.0823 (UTC) FILETIME=[F7E342F0:01DAE4E9] 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 statistics counters by reducing the number of branches. Ordered the packet size comparisons according to the probability with typical internet traffic mix. Signed-off-by: Morten Brørup --- drivers/net/netvsc/hn_rxtx.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/drivers/net/netvsc/hn_rxtx.c b/drivers/net/netvsc/hn_rxtx.c index 9bf1ec5509..b704b2c971 100644 --- a/drivers/net/netvsc/hn_rxtx.c +++ b/drivers/net/netvsc/hn_rxtx.c @@ -110,30 +110,18 @@ hn_update_packet_stats(struct hn_stats *stats, const struct rte_mbuf *m) uint32_t s = m->pkt_len; const struct rte_ether_addr *ea; - 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]++; - } + if (s >= 1024) + stats->size_bins[6 + (s > 1518)]++; + else if (s <= 64) + stats->size_bins[s >> 6]++; + else + stats->size_bins[32UL - rte_clz32(s) - 5]++; ea = rte_pktmbuf_mtod(m, const struct rte_ether_addr *); - if (rte_is_multicast_ether_addr(ea)) { - if (rte_is_broadcast_ether_addr(ea)) - stats->broadcast++; - else - stats->multicast++; - } + RTE_BUILD_BUG_ON(offsetof(struct hn_stats, broadcast) != + offsetof(struct hn_stats, multicast) + sizeof(uint64_t)); + if (unlikely(rte_is_multicast_ether_addr(ea))) + (&stats->multicast)[rte_is_broadcast_ether_addr(ea)]++; } static inline unsigned int hn_rndis_pktlen(const struct rndis_packet_msg *pkt) -- 2.43.0