From: Long Li <longli@microsoft.com>
To: "Morten Brørup" <mb@smartsharesystems.com>, "Wei Hu" <weh@microsoft.com>
Cc: "stephen@networkplumber.org" <stephen@networkplumber.org>,
"dev@dpdk.org" <dev@dpdk.org>
Subject: RE: [PATCH] netvsc: optimize stats counters performance
Date: Fri, 2 Aug 2024 16:48:47 +0000 [thread overview]
Message-ID: <DM4PR21MB353607D8B9AF9A7BE3DB2B9FCEB32@DM4PR21MB3536.namprd21.prod.outlook.com> (raw)
In-Reply-To: <20240802144048.270152-1-mb@smartsharesystems.com>
> Subject: [PATCH] netvsc: optimize stats counters performance
>
> 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 <mb@smartsharesystems.com>
> ---
> 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]++;
This part looks good.
>
> 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)]++;
> }
This makes the code a little harder to read. How about just add "unlikely" to rte_is_multicast_ether_addr(ea) and keep the rest unchanged?
Thank you,
Long
next prev parent reply other threads:[~2024-08-02 16:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-02 14:40 Morten Brørup
2024-08-02 16:48 ` Long Li [this message]
2024-08-02 17:28 ` Morten Brørup
2024-08-02 17:33 ` Stephen Hemminger
2024-09-19 13:51 ` Morten Brørup
2024-09-19 18:06 ` Long Li
2024-09-22 2:36 ` Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DM4PR21MB353607D8B9AF9A7BE3DB2B9FCEB32@DM4PR21MB3536.namprd21.prod.outlook.com \
--to=longli@microsoft.com \
--cc=dev@dpdk.org \
--cc=mb@smartsharesystems.com \
--cc=stephen@networkplumber.org \
--cc=weh@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).