All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lino Sanfilippo <LinoSanfilippo@gmx.de>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: David Laight <David.Laight@ACULAB.COM>,
	David Miller <davem@davemloft.net>,
	netdev <netdev@vger.kernel.org>,
	Tariq Toukan <tariqt@mellanox.com>
Subject: Re: Aw: Re: [PATCH] mlx4: give precise rx/tx bytes/packets counters
Date: Mon, 28 Nov 2016 23:02:36 +0100	[thread overview]
Message-ID: <b58286a4-d97f-18dd-e5bd-0f69d3746b81@gmx.de> (raw)
In-Reply-To: <1480101551.8455.557.camel@edumazet-glaptop3.roam.corp.google.com>

Hi Eric,

On 25.11.2016 20:19, Eric Dumazet wrote:
> On Fri, 2016-11-25 at 17:30 +0100, Lino Sanfilippo wrote:
>> Hi,
>> 
>> 
>> > 
>> > The READ_ONCE() are documenting the fact that no lock is taken to fetch
>> > the stats, while another cpus might being changing them.
>> > 
>> > I had no answer yet from https://patchwork.ozlabs.org/patch/698449/
>> > 
>> > So I thought it was not needed to explain this in the changelog, given
>> > that it apparently is one of the few things that can block someone to
>> > understand one of my changes :/
>> > 
>> > Apparently nobody really understands READ_ONCE() purpose, it is really a
>> > pity we have to explain this over and over.
>> > 
>> 
>> Even at the risk of showing once more a lack of understanding for
>> READ_ONCE():
>> Does not a READ_ONCE() have to e paired with some kind of
>> WRITE_ONCE()? 
> 
> You are right.
> 
> Although in this case, the producers are using a lock, and do
> 
> ring->packets++;
> 
> We hopefully have compilers/cpus that do not put intermediate garbage in
> ring->packets while doing the increment.
> 
> One problem with :
> 
> WRITE_ONCE(ring->packets, ring->packets + 1);
> 
> is that gcc no longer uses an INC instruction.

I see. So we would have to do something like

tmp = ring->packets;
tmp++;
WRITE_ONCE(ring->packets, tmp);

to use WRITE_ONCE in this case? If so, could it be worth doing something like this to 
have a balanced READ_ONCE, WRITE_ONCE usage?

> 
> Maybe we need some ADD_ONCE(ptr, val) macro doing the proper thing.
> 
>> Furthermore: there a quite some network drivers that ensure visibility
>> of 
>> the descriptor queue indices between xmit and xmit completion function
>> by means of
>> smp barriers. Could all these drivers theoretically be adjusted to use
>> READ_ONCE(),
>> WRITE_ONCE() for the indices instead?
>> 
> 
> Well, for this precise case we do need appropriate smp barriers.
> 
> READ_ONCE() can be better than poor barrier(), look at 
> https://git.kernel.org/cgit/linux/kernel/git/davem/net-next.git/commit/?id=b668534c1d9b80f4cda4d761eb11d3a6c9f4ced8
> 
> 

Regards,
Lino

  reply	other threads:[~2016-11-28 22:02 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-25 15:46 [PATCH] mlx4: give precise rx/tx bytes/packets counters Eric Dumazet
2016-11-25 16:03 ` David Laight
2016-11-25 16:16   ` Eric Dumazet
2016-11-25 16:30     ` Aw: " Lino Sanfilippo
2016-11-25 19:19       ` Eric Dumazet
2016-11-28 22:02         ` Lino Sanfilippo [this message]
2016-11-29  0:19           ` Eric Dumazet
2016-11-30 15:28             ` David Laight
2016-11-30 15:47               ` Eric Dumazet
2016-11-26 22:47 ` Saeed Mahameed
2016-11-27  2:16   ` Eric Dumazet
2016-11-28 20:40     ` David Miller
2016-11-28 21:55       ` Saeed Mahameed
2016-11-28 22:57         ` Eric Dumazet
2016-11-29 18:37 ` David Miller
2016-11-30 14:08 ` Regression: " Jesper Dangaard Brouer
2016-11-30 15:58   ` Eric Dumazet
2016-11-30 16:46     ` Saeed Mahameed
2016-11-30 17:35       ` Eric Dumazet
2016-11-30 20:42         ` Saeed Mahameed
2016-11-30 21:00           ` Eric Dumazet
2016-12-01 12:37             ` Jesper Dangaard Brouer
2016-12-01 13:02               ` [PATCH net-next] mlx4: fix use-after-free in mlx4_en_fold_software_stats() Eric Dumazet
2016-12-01 15:23                 ` Saeed Mahameed
2016-12-02 18:36                 ` David Miller
2016-12-01 15:38             ` Regression: [PATCH] mlx4: give precise rx/tx bytes/packets counters Saeed Mahameed
2016-12-01 15:55               ` Eric Dumazet
2016-12-01 16:08                 ` Eric Dumazet
2016-12-01 17:36                   ` Eric Dumazet
2016-12-04 13:23                     ` Saeed Mahameed
2016-12-01 16:33                 ` Saeed Mahameed
2016-12-01 17:08                   ` Eric Dumazet
2016-12-04 13:21                     ` Saeed Mahameed

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=b58286a4-d97f-18dd-e5bd-0f69d3746b81@gmx.de \
    --to=linosanfilippo@gmx.de \
    --cc=David.Laight@ACULAB.COM \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=tariqt@mellanox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.