netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Saeed Mahameed <saeedm@dev.mellanox.co.il>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Jesper Dangaard Brouer <brouer@redhat.com>,
	David Miller <davem@davemloft.net>,
	netdev <netdev@vger.kernel.org>,
	Tariq Toukan <tariqt@mellanox.com>
Subject: Re: Regression: [PATCH] mlx4: give precise rx/tx bytes/packets counters
Date: Thu, 1 Dec 2016 18:33:50 +0200	[thread overview]
Message-ID: <CALzJLG_=Z_anekLaiT0giK+RaOGRWmvK6MUP4UWXqsQQysR55w@mail.gmail.com> (raw)
In-Reply-To: <1480607729.18162.311.camel@edumazet-glaptop3.roam.corp.google.com>

On Thu, Dec 1, 2016 at 5:55 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> On Thu, 2016-12-01 at 17:38 +0200, Saeed Mahameed wrote:
>
>>
>> Hi Eric, Thanks for the patch, I already acked it.
>
> Thanks !
>
>>
>> I have one educational question (not related to this patch, but
>> related to stats reading in general).
>> I was wondering why do we need to disable bh every time we read stats
>> "spin_lock_bh" ? is it essential ?
>>
>> I checked and in mlx4 we don't hold stats_lock in softirq
>> (en_rx.c/en_tx.c), so I don't see any deadlock risk in here..
>
> Excellent question, and I chose to keep the spinlock.
>
> That would be doable, only if we do not overwrite dev->stats.
>
> Current code is :
>
> static struct rtnl_link_stats64 *
> mlx4_en_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
> {
>         struct mlx4_en_priv *priv = netdev_priv(dev);
>
>         spin_lock_bh(&priv->stats_lock);
>         mlx4_en_fold_software_stats(dev);
>         netdev_stats_to_stats64(stats, &dev->stats);
>         spin_unlock_bh(&priv->stats_lock);
>
>         return stats;
> }
>
> If you remove the spin_lock_bh() :
>
>
> static struct rtnl_link_stats64 *
> mlx4_en_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
> {
>         struct mlx4_en_priv *priv = netdev_priv(dev);
>
>         mlx4_en_fold_software_stats(dev); // possible races
>
>         netdev_stats_to_stats64(stats, &dev->stats);
>
>         return stats;
> }
>
> 1) one mlx4_en_fold_software_stats(dev) could be preempted
> on a CONFIG_PREEMPT kernel, or interrupted by long irqs.
>
> 2) Another cpu would also call mlx4_en_fold_software_stats(dev) while
>    first cpu is busy.
>
> 3) Then when resuming first cpu/thread, part of the dev->stats fieds
> would be updated with 'old counters',
> while another thread might have updated them with newer values.
>
> 4) A SNMP reader could then get counters that are not monotonically
> increasing,
> which would be confusing/buggy.
>
> So removing the spinlock is doable, but needs to add a new parameter
> to mlx4_en_fold_software_stats() and call netdev_stats_to_stats64()
> before mlx4_en_fold_software_stats(dev)
>
> static struct rtnl_link_stats64 *
> mlx4_en_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
> {
>         struct mlx4_en_priv *priv = netdev_priv(dev);
>
>         netdev_stats_to_stats64(stats, &dev->stats);
>
>         // Passing a non NULL stats asks mlx4_en_fold_software_stats()
>         // to not update dev->stats, but stats directly.
>
>         mlx4_en_fold_software_stats(dev, stats)
>
>
>         return stats;
> }
>
>

Thanks for the detailed answer !!

BTW you went 5 steps ahead of my original question :)), so far you
already have a patch without locking at all (really impressive).

What i wanted to ask originally, was regarding the "_bh", i didn't
mean to completely remove the "spin_lock_bh",
I meant, what happens if we replace "spin_lock_bh"  with "spin_lock",
without disabling bh ?
I gues raw "sping_lock" handles points (2 to 4) from above, but it
won't handle long irqs.

  parent reply	other threads:[~2016-12-01 16:34 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
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 [this message]
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='CALzJLG_=Z_anekLaiT0giK+RaOGRWmvK6MUP4UWXqsQQysR55w@mail.gmail.com' \
    --to=saeedm@dev.mellanox.co.il \
    --cc=brouer@redhat.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 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).