All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
To: davem@davemloft.net
Cc: Jacob Keller <jacob.e.keller@intel.com>,
	netdev@vger.kernel.org, nhorman@redhat.com, sassmann@redhat.com,
	jogreene@redhat.com, guru.anbalagane@oracle.com,
	Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Subject: [net-next 03/20] fm10k: prevent multiple threads updating statistics
Date: Wed, 20 Jul 2016 15:23:41 -0700	[thread overview]
Message-ID: <1469053438-85381-4-git-send-email-jeffrey.t.kirsher@intel.com> (raw)
In-Reply-To: <1469053438-85381-1-git-send-email-jeffrey.t.kirsher@intel.com>

From: Jacob Keller <jacob.e.keller@intel.com>

Also prevent updating stats while the interface is down. If we're
already updating stats, just return doing nothing. When we take the
device down, block stat updates until we come back up. This ensures that
we avoid tearing down rings when we're updating statistics, and prevents
updating statistics until we're up.

We can't re-use the __FM10K_DOWN for this because it wouldn't prevent
multiple threads from accessing statistics. Neither does it prevent the
case where we start updating stats and then start going down in another
thread.

The fm10k_get_stats64 is except from this, because it has a completely
different flow which does not suffer from the same issues as
fm10k_update_stats might.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Krishneil Singh <Krishneil.k.singh@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
---
 drivers/net/ethernet/intel/fm10k/fm10k.h     |  1 +
 drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/drivers/net/ethernet/intel/fm10k/fm10k.h b/drivers/net/ethernet/intel/fm10k/fm10k.h
index e98b86b..c8d0817 100644
--- a/drivers/net/ethernet/intel/fm10k/fm10k.h
+++ b/drivers/net/ethernet/intel/fm10k/fm10k.h
@@ -362,6 +362,7 @@ enum fm10k_state_t {
 	__FM10K_SERVICE_DISABLE,
 	__FM10K_MBX_LOCK,
 	__FM10K_LINK_DOWN,
+	__FM10K_UPDATING_STATS,
 };
 
 static inline void fm10k_mbx_lock(struct fm10k_intfc *interface)
diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_pci.c b/drivers/net/ethernet/intel/fm10k/fm10k_pci.c
index be0b7de..4439376 100644
--- a/drivers/net/ethernet/intel/fm10k/fm10k_pci.c
+++ b/drivers/net/ethernet/intel/fm10k/fm10k_pci.c
@@ -372,6 +372,10 @@ void fm10k_update_stats(struct fm10k_intfc *interface)
 	u64 bytes, pkts;
 	int i;
 
+	/* ensure only one thread updates stats at a time */
+	if (test_and_set_bit(__FM10K_UPDATING_STATS, &interface->state))
+		return;
+
 	/* do not allow stats update via service task for next second */
 	interface->next_stats_update = jiffies + HZ;
 
@@ -449,6 +453,8 @@ void fm10k_update_stats(struct fm10k_intfc *interface)
 	/* Fill out the OS statistics structure */
 	net_stats->rx_errors = rx_errors;
 	net_stats->rx_dropped = interface->stats.nodesc_drop.count;
+
+	clear_bit(__FM10K_UPDATING_STATS, &interface->state);
 }
 
 /**
@@ -1572,6 +1578,9 @@ void fm10k_up(struct fm10k_intfc *interface)
 	/* configure interrupts */
 	hw->mac.ops.update_int_moderator(hw);
 
+	/* enable statistics capture again */
+	clear_bit(__FM10K_UPDATING_STATS, &interface->state);
+
 	/* clear down bit to indicate we are ready to go */
 	clear_bit(__FM10K_DOWN, &interface->state);
 
@@ -1629,6 +1638,10 @@ void fm10k_down(struct fm10k_intfc *interface)
 	/* capture stats one last time before stopping interface */
 	fm10k_update_stats(interface);
 
+	/* prevent updating statistics while we're down */
+	while (test_and_set_bit(__FM10K_UPDATING_STATS, &interface->state))
+		usleep_range(1000, 2000);
+
 	/* Disable DMA engine for Tx/Rx */
 	err = hw->mac.ops.stop_hw(hw);
 	if (err)
@@ -1757,6 +1770,7 @@ static int fm10k_sw_init(struct fm10k_intfc *interface,
 
 	/* Start off interface as being down */
 	set_bit(__FM10K_DOWN, &interface->state);
+	set_bit(__FM10K_UPDATING_STATS, &interface->state);
 
 	return 0;
 }
-- 
2.5.5

  parent reply	other threads:[~2016-07-20 22:24 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-20 22:23 [net-next 00/20][pull request] 100GbE Intel Wired LAN Driver Updates 2016-07-20 Jeff Kirsher
2016-07-20 22:23 ` [net-next 01/20] fm10k: no need to continue in fm10k_down if __FM10K_DOWN already set Jeff Kirsher
2016-07-20 22:23 ` [net-next 02/20] fm10k: avoid possible null pointer dereference in fm10k_update_stats Jeff Kirsher
2016-07-20 22:23 ` Jeff Kirsher [this message]
2016-07-20 22:23 ` [net-next 04/20] fm10k: Reset mailbox global interrupts Jeff Kirsher
2016-07-20 22:23 ` [net-next 05/20] fm10k: don't stop reset due to FM10K_ERR_REQUESTS_PENDING Jeff Kirsher
2016-07-20 22:23 ` [net-next 06/20] fm10k: perform data path reset even when switch is not ready Jeff Kirsher
2016-07-20 22:23 ` [net-next 07/20] fm10k: use actual hardware registers when checking for pending Tx Jeff Kirsher
2016-07-20 22:23 ` [net-next 08/20] fm10k: only warn when stop_hw fails with FM10K_ERR_REQUESTS_PENDING Jeff Kirsher
2016-07-20 22:23 ` [net-next 09/20] fm10k: wait for queues to drain if stop_hw() fails once Jeff Kirsher
2016-07-20 22:23 ` [net-next 10/20] fm10k: split fm10k_reinit into two functions Jeff Kirsher
2016-07-20 22:23 ` [net-next 11/20] fm10k: implement prepare_suspend and handle_resume Jeff Kirsher
2016-07-20 22:23 ` [net-next 12/20] fm10k: use common reset flow when handling io errors from PCI stack Jeff Kirsher
2016-07-20 22:23 ` [net-next 13/20] fm10k: implement reset_notify handler for PCIe FLR events Jeff Kirsher
2016-07-20 22:23 ` [net-next 14/20] fm10k: use common flow for suspend and resume Jeff Kirsher
2016-07-20 22:23 ` [net-next 15/20] fm10k: enable bus master after every reset Jeff Kirsher
2016-07-20 22:23 ` [net-next 16/20] fm10k: check if PCIe link is restored Jeff Kirsher
2016-07-21 10:51   ` Sergei Shtylyov
2016-07-21 20:13     ` ~~ Keller, Jacob E
2016-07-20 22:23 ` [net-next 17/20] fm10k: implement request_lport_map pointer Jeff Kirsher
2016-07-20 22:23 ` [net-next 18/20] fm10k: force link to remain down for at least a second on resume events Jeff Kirsher
2016-07-20 22:23 ` [net-next 19/20] fm10k: return proper error code when pci_enable_msix_range fails Jeff Kirsher
2016-07-20 22:23 ` [net-next 20/20] fm10k: bump version number Jeff Kirsher
2016-07-21  5:05 ` [net-next 00/20][pull request] 100GbE Intel Wired LAN Driver Updates 2016-07-20 David Miller

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=1469053438-85381-4-git-send-email-jeffrey.t.kirsher@intel.com \
    --to=jeffrey.t.kirsher@intel.com \
    --cc=davem@davemloft.net \
    --cc=guru.anbalagane@oracle.com \
    --cc=jacob.e.keller@intel.com \
    --cc=jogreene@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@redhat.com \
    --cc=sassmann@redhat.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.