public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Sabrina Dubroca <sd@queasysnail.net>
To: Ben Hutchings <bhutchings@solarflare.com>
Cc: David Miller <davem@davemloft.net>,
	johannes@sipsolutions.net, netdev@vger.kernel.org
Subject: Re: [PATCH 4/5] alx: add alx_get_stats operation
Date: Thu, 2 Jan 2014 17:05:31 +0100	[thread overview]
Message-ID: <20140102160531.GA25216@kria> (raw)
In-Reply-To: <1388663813.22017.12.camel@deadeye.wl.decadent.org.uk>

[2014-01-02, 11:56:53] Ben Hutchings wrote:
> On Wed, 2014-01-01 at 22:27 -0500, David Miller wrote:
> > From: Sabrina Dubroca <sd@queasysnail.net>
> > Date: Thu,  2 Jan 2014 00:40:27 +0100
> > 
> > > +	spin_lock(&alx->stats_lock);
> > > +
> > > +	__alx_update_hw_stats(&alx->hw);
> > 
> > Please use something like the linux/u64_stats_sync.h stuff rather
> > than spin locking.
> 
> I don't think that'sa useful, as we can have multiple writers
> (concurrent calls to get_stats).  And there is really no harm in using a
> spinlock to serialise get_stats calls.  The u64_stats API is good for
> statistics updated from the data path.

I've read the comments in linux/u64_stats_sync.h, which mentions the
need for exclusive access to the data. I've looked at other drivers
(broadcom/b44.c, nvidia/forcedeth.c) that use the u64_stats functions
to get stats from hardware, and they use a spin_lock around the update
code. The other drivers that I've looked at and that use u64_stats
have software stats that they update on rx/tx, so I think the
situation is a bit different.


For now I've added u64_stats and modified the functions this way:

static struct net_device_stats *alx_get_stats(struct net_device *netdev)
{
	struct alx_priv *alx = netdev_priv(netdev);
	struct net_device_stats *net_stats = &netdev->stats;
	struct alx_hw_stats *hw_stats = &alx->hw.stats;

	unsigned int start;

	spin_lock(&alx->stats_lock);

	__alx_update_hw_stats(&alx->hw);

	spin_unlock(&alx->stats_lock);

	do {
		start = u64_stats_fetch_begin(&hw_stats->syncp);
		/* fill net_stat... */
	} while (u64_stats_fetch_retry(&hw_stats->syncp, start));

	return net_stats;
}


void __alx_update_hw_stats(struct alx_hw *hw)
{
	u64_stats_update_begin(&hw->stats.syncp);

	/* fill hw->stats */

	u64_stats_update_end(&hw->stats.syncp);
}


static void alx_get_ethtool_stats(struct net_device *netdev,
				  struct ethtool_stats *estats, u64 *data)
{
	struct alx_priv *alx = netdev_priv(netdev);
	struct alx_hw *hw = &alx->hw;

	unsigned int start;

	spin_lock(&alx->stats_lock);
	__alx_update_hw_stats(hw);
	spin_unlock(&alx->stats_lock);

	do {
		start = u64_stats_fetch_begin(&hw->stats.syncp);
		memcpy(data, &hw->stats, sizeof(hw->stats));
	} while (u64_stats_fetch_retry(&hw->stats.syncp, start));
}

Thanks,

-- 
Sabrina Dubroca

  reply	other threads:[~2014-01-02 16:05 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-01 23:40 [PATCH 0/5] alx: add statistics Sabrina Dubroca
2014-01-01 23:40 ` [PATCH 1/5] alx: add a hardware stats structure Sabrina Dubroca
2014-01-02 11:52   ` Ben Hutchings
2014-01-01 23:40 ` [PATCH 2/5] alx: add constants for the stats fields Sabrina Dubroca
2014-01-01 23:40 ` [PATCH 3/5] alx: add stats update function Sabrina Dubroca
2014-01-02  5:55   ` Stephen Hemminger
2014-01-02 11:52     ` Ben Hutchings
2014-01-01 23:40 ` [PATCH 4/5] alx: add alx_get_stats operation Sabrina Dubroca
2014-01-02  3:27   ` David Miller
2014-01-02 11:56     ` Ben Hutchings
2014-01-02 16:05       ` Sabrina Dubroca [this message]
2014-01-02 16:25         ` Ben Hutchings
2014-01-02 17:39       ` David Miller
2014-01-02 11:57   ` Ben Hutchings
2014-01-01 23:40 ` [PATCH 5/5] alx: add stats to ethtool Sabrina Dubroca
2014-01-02 12:01   ` Ben Hutchings
2014-01-02 18:23     ` Ben Hutchings
2014-01-02 13:09   ` Johannes Berg
2014-01-02 18:19     ` Sabrina Dubroca

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=20140102160531.GA25216@kria \
    --to=sd@queasysnail.net \
    --cc=bhutchings@solarflare.com \
    --cc=davem@davemloft.net \
    --cc=johannes@sipsolutions.net \
    --cc=netdev@vger.kernel.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