DPDK patches and discussions
 help / color / mirror / Atom feed
From: Chenbo Xia <chenbox@nvidia.com>
To: "Morten Brørup" <mb@smartsharesystems.com>
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>,
	"stephen@networkplumber.org" <stephen@networkplumber.org>,
	"dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [PATCH v5] virtio: optimize stats counters performance
Date: Tue, 6 Aug 2024 08:23:57 +0000	[thread overview]
Message-ID: <B5A8682F-4396-4D72-8A9B-F0A087E3A3FE@nvidia.com> (raw)
In-Reply-To: <20240801160312.205281-1-mb@smartsharesystems.com>



> On Aug 2, 2024, at 00:03, Morten Brørup <mb@smartsharesystems.com> wrote:
> 
> External email: Use caution opening links or attachments
> 
> 
> Optimized the performance of updating the virtio 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>
> ---
> v5:
> * Do not inline the function. (Stephen)
> v4:
> * Consider multicast/broadcast packets unlikely.
> v3:
> * Eliminated a local variable.
> * Note: Substituted sizeof(uint32_t)*4 by 32UL, using unsigned long type
>  to keep optimal offsetting in generated assembler output.
> * Removed unnecessary curly braces.
> v2:
> * Fixed checkpatch warning about line length.
> ---
> drivers/net/virtio/virtio_rxtx.c | 39 ++++++++++++--------------------
> drivers/net/virtio/virtio_rxtx.h |  4 ++--
> 2 files changed, 16 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
> index f69b9453a2..b67f063b31 100644
> --- a/drivers/net/virtio/virtio_rxtx.c
> +++ b/drivers/net/virtio/virtio_rxtx.c
> @@ -82,37 +82,26 @@ vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx)
> }
> 
> void
> -virtio_update_packet_stats(struct virtnet_stats *stats, struct rte_mbuf *mbuf)
> +virtio_update_packet_stats(struct virtnet_stats *const stats,
> +               const struct rte_mbuf *const mbuf)
> {
>        uint32_t s = mbuf->pkt_len;
> -       struct rte_ether_addr *ea;
> +       const struct rte_ether_addr *const ea =
> +                       rte_pktmbuf_mtod(mbuf, const struct rte_ether_addr *);
> 
>        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]++;
> -       }
> +       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(mbuf, 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 virtnet_stats, broadcast) !=
> +                       offsetof(struct virtnet_stats, multicast) + sizeof(uint64_t));
> +       if (unlikely(rte_is_multicast_ether_addr(ea)))
> +               (&stats->multicast)[rte_is_broadcast_ether_addr(ea)]++;
> }
> 
> static inline void
> diff --git a/drivers/net/virtio/virtio_rxtx.h b/drivers/net/virtio/virtio_rxtx.h
> index afc4b74534..68034c914b 100644
> --- a/drivers/net/virtio/virtio_rxtx.h
> +++ b/drivers/net/virtio/virtio_rxtx.h
> @@ -35,7 +35,7 @@ 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);
> +void virtio_update_packet_stats(struct virtnet_stats *const stats,
> +               const struct rte_mbuf *const mbuf);
> 
> #endif /* _VIRTIO_RXTX_H_ */
> —
> 2.43.0
> 

Reviewed-by: Chenbo Xia <chenbox@nvidia.com>

  parent reply	other threads:[~2024-08-06  8:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-31 13:17 [PATCH] " Morten Brørup
2024-07-31 14:04 ` [PATCH v2] " Morten Brørup
2024-07-31 15:13 ` [PATCH v3] " Morten Brørup
2024-07-31 22:58 ` [PATCH v4] " Morten Brørup
2024-07-31 23:45   ` Stephen Hemminger
2024-07-31 23:51     ` Morten Brørup
2024-08-01 16:03 ` [PATCH v5] " Morten Brørup
2024-08-01 16:17   ` Stephen Hemminger
2024-08-01 20:38     ` Morten Brørup
2024-08-02 14:49       ` Morten Brørup
2024-08-02  2:23   ` lihuisong (C)
2024-08-02  2:42     ` Stephen Hemminger
2024-08-02  3:17       ` lihuisong (C)
2024-08-02 11:27     ` Morten Brørup
2024-08-05  1:14       ` lihuisong (C)
2024-08-05  1:19   ` lihuisong (C)
2024-08-06  8:23   ` Chenbo Xia [this message]
2024-09-10 15:01   ` Maxime Coquelin
2024-09-19 12:04   ` Maxime Coquelin

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=B5A8682F-4396-4D72-8A9B-F0A087E3A3FE@nvidia.com \
    --to=chenbox@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@redhat.com \
    --cc=mb@smartsharesystems.com \
    --cc=stephen@networkplumber.org \
    /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).