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>,
	"dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [PATCH] vhost-user: optimize stats counters performance
Date: Tue, 6 Aug 2024 08:24:52 +0000	[thread overview]
Message-ID: <EFAA0B24-FB98-4215-937C-A9C26956BE21@nvidia.com> (raw)
In-Reply-To: <20240802143259.269827-1-mb@smartsharesystems.com>



> On Aug 2, 2024, at 22:32, Morten Brørup <mb@smartsharesystems.com> wrote:
> 
> External email: Use caution opening links or attachments
> 
> 
> 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>
> ---
> lib/vhost/virtio_net.c | 40 ++++++++++++++--------------------------
> 1 file changed, 14 insertions(+), 26 deletions(-)
> 
> diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
> index 370402d849..25a495df56 100644
> --- a/lib/vhost/virtio_net.c
> +++ b/lib/vhost/virtio_net.c
> @@ -53,7 +53,7 @@ is_valid_virt_queue_idx(uint32_t idx, int is_tx, uint32_t nr_vring)
> }
> 
> static inline void
> -vhost_queue_stats_update(struct virtio_net *dev, struct vhost_virtqueue *vq,
> +vhost_queue_stats_update(const struct virtio_net *dev, struct vhost_virtqueue *vq,
>                struct rte_mbuf **pkts, uint16_t count)
>        __rte_shared_locks_required(&vq->access_lock)
> {
> @@ -64,37 +64,25 @@ vhost_queue_stats_update(struct virtio_net *dev, struct vhost_virtqueue *vq,
>                return;
> 
>        for (i = 0; i < count; i++) {
> -               struct rte_ether_addr *ea;
> -               struct rte_mbuf *pkt = pkts[i];
> +               const struct rte_ether_addr *ea;
> +               const struct rte_mbuf *pkt = pkts[i];
>                uint32_t pkt_len = rte_pktmbuf_pkt_len(pkt);
> 
>                stats->packets++;
>                stats->bytes += pkt_len;
> 
> -               if (pkt_len == 64) {
> -                       stats->size_bins[1]++;
> -               } else if (pkt_len > 64 && pkt_len < 1024) {
> -                       uint32_t bin;
> -
> -                       /* count zeros, and offset into correct bin */
> -                       bin = (sizeof(pkt_len) * 8) - rte_clz32(pkt_len) - 5;
> -                       stats->size_bins[bin]++;
> -               } else {
> -                       if (pkt_len < 64)
> -                               stats->size_bins[0]++;
> -                       else if (pkt_len < 1519)
> -                               stats->size_bins[6]++;
> -                       else
> -                               stats->size_bins[7]++;
> -               }
> +               if (pkt_len >= 1024)
> +                       stats->size_bins[6 + (pkt_len > 1518)]++;
> +               else if (pkt_len <= 64)
> +                       stats->size_bins[pkt_len >> 6]++;
> +               else
> +                       stats->size_bins[32UL - rte_clz32(pkt_len) - 5]++;
> 
> -               ea = rte_pktmbuf_mtod(pkt, struct rte_ether_addr *);
> -               if (rte_is_multicast_ether_addr(ea)) {
> -                       if (rte_is_broadcast_ether_addr(ea))
> -                               stats->broadcast++;
> -                       else
> -                               stats->multicast++;
> -               }
> +               ea = rte_pktmbuf_mtod(pkt, const struct rte_ether_addr *);
> +               RTE_BUILD_BUG_ON(offsetof(struct virtqueue_stats, broadcast) !=
> +                               offsetof(struct virtqueue_stats, multicast) + sizeof(uint64_t));
> +               if (unlikely(rte_is_multicast_ether_addr(ea)))
> +                       (&stats->multicast)[rte_is_broadcast_ether_addr(ea)]++;
>        }
> }
> 
> --
> 2.43.0
> 

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


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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-02 14:32 Morten Brørup
2024-08-06  8:24 ` Chenbo Xia [this message]
2024-09-10 14:59 ` Maxime Coquelin
2024-09-19 12:05 ` 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=EFAA0B24-FB98-4215-937C-A9C26956BE21@nvidia.com \
    --to=chenbox@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@redhat.com \
    --cc=mb@smartsharesystems.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).