Re: [V2 RFC net-next PATCH 1/2] virtio_net: convert the statisticsinto array
From: Eric Dumazet
Date: Wed Jun 06 2012 - 04:22:22 EST
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@xxxxxxxxxx>
> ---
> 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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/