Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Jason Wang <jasowang@redhat.com>
Cc: netdev@vger.kernel.org, mst@redhat.com,
	linux-kernel@vger.kernel.org,
	virtualization@lists.linux-foundation.org
Subject: Re: [V2 RFC net-next PATCH 1/2] virtio_net: convert the statistics into array
Date: Wed, 06 Jun 2012 10:22:19 +0200	[thread overview]
Message-ID: <1338970939.2760.3887.camel@edumazet-glaptop> (raw)
In-Reply-To: <20120606075208.29081.75284.stgit@amd-6168-8-1.englab.nay.redhat.com>

On Wed, 2012-06-06 at 15:52 +0800, Jason Wang wrote:
> Currently, we store the statistics in the independent fields of virtnet_stats,
> this is not scalable when we want to add more counters. As suggested by Michael,
> this patch convert it to an array and use the enum as the index to access them.
> 
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
>  drivers/net/virtio_net.c |   30 +++++++++++++++++-------------
>  1 files changed, 17 insertions(+), 13 deletions(-)
> 

>  struct virtnet_stats {
>  	struct u64_stats_sync syncp;
> -	u64 tx_bytes;
> -	u64 tx_packets;
> -
> -	u64 rx_bytes;
> -	u64 rx_packets;
> +	u64 data[VIRTNET_NUM_STATS];
>  };
>  

Interesting, but I fear you'll have a lot of problems.

Current code is buggy, and you are adding more possible races.

We could have one cpu doing the :

       u64_stats_update_begin(&stats->syncp);
       stats->rx_bytes += skb->len;
       stats->rx_packets++;
       u64_stats_update_end(&stats->syncp);

And another one doing :

       u64_stats_update_begin(&stats->syncp);
       stats->tx_bytes += skb->len;
       stats->tx_packets++;
       u64_stats_update_end(&stats->syncp);
 
And one syncp sequence increment can be lost, since both cpus are
basically doing this at the same time :

    write_seqcount_begin(&syncp->seq);

I'll send a fix in a separate thread.

      parent reply	other threads:[~2012-06-06  8:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-06  7:52 [V2 RFC net-next PATCH 1/2] virtio_net: convert the statistics into array Jason Wang
2012-06-06  7:52 ` [V2 RFC net-next PATCH 2/2] virtio_net: export more statistics through ethtool Jason Wang
2012-06-06  8:27   ` Michael S. Tsirkin
2012-06-06  9:37     ` Jason Wang
2012-06-06  9:32   ` Michael S. Tsirkin
2012-06-07 17:15   ` Ben Hutchings
2012-06-07 20:05     ` David Miller
2012-06-07 20:24       ` Ben Hutchings
2012-06-07 20:39         ` Rick Jones
2012-06-07 20:56           ` Ben Hutchings
2012-06-07 20:58             ` Ben Hutchings
2012-06-08  3:33             ` Jason Wang
2012-06-07 22:19   ` Michael S. Tsirkin
2012-06-08  3:35     ` Jason Wang
2012-06-08  7:02       ` Michael S. Tsirkin
2012-06-08  7:04       ` Michael S. Tsirkin
2012-06-06  8:22 ` Eric Dumazet [this message]

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=1338970939.2760.3887.camel@edumazet-glaptop \
    --to=eric.dumazet@gmail.com \
    --cc=jasowang@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=virtualization@lists.linux-foundation.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