From: "Stephen M. Cameron" <scameron@beardog.cce.hp.com>
To: james.bottomley@parallels.com
Cc: webb.scales@hp.com, martin.petersen@oracle.com,
linux-scsi@vger.kernel.org, justin.lindley@hp.com,
stephenmcameron@gmail.com, joseph.t.handzik@hp.com,
thenzl@redhat.com, michael.miller@canonical.com,
scott.teel@hp.com, hch@lst.de, dan.carpenter@oracle.com
Subject: [PATCH 2 11/24] hpsa: use per-cpu variable for lockup_detected
Date: Thu, 29 May 2014 10:53:18 -0500 [thread overview]
Message-ID: <20140529155318.8180.49035.stgit@beardog.cce.hp.com> (raw)
In-Reply-To: <20140529154739.8180.50710.stgit@beardog.cce.hp.com>
From: Stephen M. Cameron <scameron@beardog.cce.hp.com>
Avoid excessive locking by using per-cpu variable for lockup_detected
Signed-off-by: Stephen M. Cameron <scameron@beardog.cce.hp.com>
Reviewed-by: Scott Teel <scott.teel@hp.com>
---
drivers/scsi/hpsa.c | 80 ++++++++++++++++++++++++++++++++++-----------------
drivers/scsi/hpsa.h | 2 +
2 files changed, 54 insertions(+), 28 deletions(-)
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index e8090e2..acb88e5 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -48,6 +48,7 @@
#include <linux/bitmap.h>
#include <linux/atomic.h>
#include <linux/jiffies.h>
+#include <linux/percpu.h>
#include <asm/div64.h>
#include "hpsa_cmd.h"
#include "hpsa.h"
@@ -1991,20 +1992,26 @@ static inline void hpsa_scsi_do_simple_cmd_core(struct ctlr_info *h,
wait_for_completion(&wait);
}
+static u32 lockup_detected(struct ctlr_info *h)
+{
+ int cpu;
+ u32 rc, *lockup_detected;
+
+ cpu = get_cpu();
+ lockup_detected = per_cpu_ptr(h->lockup_detected, cpu);
+ rc = *lockup_detected;
+ put_cpu();
+ return rc;
+}
+
static void hpsa_scsi_do_simple_cmd_core_if_no_lockup(struct ctlr_info *h,
struct CommandList *c)
{
- unsigned long flags;
-
/* If controller lockup detected, fake a hardware error. */
- spin_lock_irqsave(&h->lock, flags);
- if (unlikely(h->lockup_detected)) {
- spin_unlock_irqrestore(&h->lock, flags);
+ if (unlikely(lockup_detected(h)))
c->err_info->CommandStatus = CMD_HARDWARE_ERR;
- } else {
- spin_unlock_irqrestore(&h->lock, flags);
+ else
hpsa_scsi_do_simple_cmd_core(h, c);
- }
}
#define MAX_DRIVER_CMD_RETRIES 25
@@ -3964,7 +3971,6 @@ static int hpsa_scsi_queue_command_lck(struct scsi_cmnd *cmd,
struct hpsa_scsi_dev_t *dev;
unsigned char scsi3addr[8];
struct CommandList *c;
- unsigned long flags;
int rc = 0;
/* Get the ptr to our adapter structure out of cmd->host. */
@@ -3977,14 +3983,11 @@ static int hpsa_scsi_queue_command_lck(struct scsi_cmnd *cmd,
}
memcpy(scsi3addr, dev->scsi3addr, sizeof(scsi3addr));
- spin_lock_irqsave(&h->lock, flags);
- if (unlikely(h->lockup_detected)) {
- spin_unlock_irqrestore(&h->lock, flags);
+ if (unlikely(lockup_detected(h))) {
cmd->result = DID_ERROR << 16;
done(cmd);
return 0;
}
- spin_unlock_irqrestore(&h->lock, flags);
c = cmd_alloc(h);
if (c == NULL) { /* trouble... */
dev_err(&h->pdev->dev, "cmd_alloc returned NULL!\n");
@@ -4096,16 +4099,13 @@ static int do_not_scan_if_controller_locked_up(struct ctlr_info *h)
* we can prevent new rescan threads from piling up on a
* locked up controller.
*/
- spin_lock_irqsave(&h->lock, flags);
- if (unlikely(h->lockup_detected)) {
- spin_unlock_irqrestore(&h->lock, flags);
+ if (unlikely(lockup_detected(h))) {
spin_lock_irqsave(&h->scan_lock, flags);
h->scan_finished = 1;
wake_up_all(&h->scan_wait_queue);
spin_unlock_irqrestore(&h->scan_lock, flags);
return 1;
}
- spin_unlock_irqrestore(&h->lock, flags);
return 0;
}
@@ -6761,16 +6761,38 @@ static void fail_all_cmds_on_list(struct ctlr_info *h, struct list_head *list)
}
}
+static void set_lockup_detected_for_all_cpus(struct ctlr_info *h, u32 value)
+{
+ int i, cpu;
+
+ cpu = cpumask_first(cpu_online_mask);
+ for (i = 0; i < num_online_cpus(); i++) {
+ u32 *lockup_detected;
+ lockup_detected = per_cpu_ptr(h->lockup_detected, cpu);
+ *lockup_detected = value;
+ cpu = cpumask_next(cpu, cpu_online_mask);
+ }
+ wmb(); /* be sure the per-cpu variables are out to memory */
+}
+
static void controller_lockup_detected(struct ctlr_info *h)
{
unsigned long flags;
+ u32 lockup_detected;
h->access.set_intr_mask(h, HPSA_INTR_OFF);
spin_lock_irqsave(&h->lock, flags);
- h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
+ lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
+ if (!lockup_detected) {
+ /* no heartbeat, but controller gave us a zero. */
+ dev_warn(&h->pdev->dev,
+ "lockup detected but scratchpad register is zero\n");
+ lockup_detected = 0xffffffff;
+ }
+ set_lockup_detected_for_all_cpus(h, lockup_detected);
spin_unlock_irqrestore(&h->lock, flags);
dev_warn(&h->pdev->dev, "Controller lockup detected: 0x%08x\n",
- h->lockup_detected);
+ lockup_detected);
pci_disable_device(h->pdev);
spin_lock_irqsave(&h->lock, flags);
fail_all_cmds_on_list(h, &h->cmpQ);
@@ -6905,7 +6927,7 @@ static void hpsa_monitor_ctlr_worker(struct work_struct *work)
struct ctlr_info *h = container_of(to_delayed_work(work),
struct ctlr_info, monitor_ctlr_work);
detect_controller_lockup(h);
- if (h->lockup_detected)
+ if (lockup_detected(h))
return;
if (hpsa_ctlr_needs_rescan(h) || hpsa_offline_devices_ready(h)) {
@@ -6969,6 +6991,13 @@ reinit_after_soft_reset:
spin_lock_init(&h->offline_device_lock);
spin_lock_init(&h->scan_lock);
spin_lock_init(&h->passthru_count_lock);
+
+ /* Allocate and clear per-cpu variable lockup_detected */
+ h->lockup_detected = alloc_percpu(u32);
+ if (!h->lockup_detected)
+ goto clean1;
+ set_lockup_detected_for_all_cpus(h, 0);
+
rc = hpsa_pci_init(h);
if (rc != 0)
goto clean1;
@@ -7092,6 +7121,8 @@ clean4:
free_irqs(h);
clean2:
clean1:
+ if (h->lockup_detected)
+ free_percpu(h->lockup_detected);
kfree(h);
return rc;
}
@@ -7100,16 +7131,10 @@ static void hpsa_flush_cache(struct ctlr_info *h)
{
char *flush_buf;
struct CommandList *c;
- unsigned long flags;
/* Don't bother trying to flush the cache if locked up */
- spin_lock_irqsave(&h->lock, flags);
- if (unlikely(h->lockup_detected)) {
- spin_unlock_irqrestore(&h->lock, flags);
+ if (unlikely(lockup_detected(h)))
return;
- }
- spin_unlock_irqrestore(&h->lock, flags);
-
flush_buf = kzalloc(4, GFP_KERNEL);
if (!flush_buf)
return;
@@ -7193,6 +7218,7 @@ static void hpsa_remove_one(struct pci_dev *pdev)
kfree(h->hba_inquiry_data);
pci_disable_device(pdev);
pci_release_regions(pdev);
+ free_percpu(h->lockup_detected);
kfree(h);
}
diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
index fa63576..8e8310e 100644
--- a/drivers/scsi/hpsa.h
+++ b/drivers/scsi/hpsa.h
@@ -191,7 +191,7 @@ struct ctlr_info {
u64 last_heartbeat_timestamp;
u32 heartbeat_sample_interval;
atomic_t firmware_flash_in_progress;
- u32 lockup_detected;
+ u32 *lockup_detected;
struct delayed_work monitor_ctlr_work;
int remove_in_progress;
u32 fifo_recently_full;
next prev parent reply other threads:[~2014-05-29 15:54 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-29 15:52 [PATCH 2 00/24] Resend of May 2014 patches for hpsa driver Stephen M. Cameron
2014-05-29 15:52 ` [PATCH 2 01/24] hpsa: add new Smart Array PCI IDs (May 2014) Stephen M. Cameron
2014-05-29 15:52 ` [PATCH 2 02/24] hpsa: fix missing check of kzalloc return value Stephen M. Cameron
2014-05-29 15:52 ` [PATCH 2 03/24] hpsa: remove unused fields from struct ctlr_info Stephen M. Cameron
2014-05-29 15:52 ` [PATCH 2 04/24] hpsa: allow passthru ioctls to work with bidirectional commands Stephen M. Cameron
2014-05-29 15:52 ` [PATCH 2 05/24] hpsa: change doorbell reset delay to ten seconds Stephen M. Cameron
2014-05-29 15:52 ` [PATCH 2 06/24] hpsa: use gcc aligned attribute instead of manually padding structs Stephen M. Cameron
2014-05-29 15:52 ` [PATCH 2 07/24] hpsa: remove dev_dbg() calls from hot paths Stephen M. Cameron
2014-05-29 15:53 ` [PATCH 2 08/24] hpsa: choose number of reply queues more intelligently Stephen M. Cameron
2014-06-02 9:27 ` Christoph Hellwig
2014-06-02 14:52 ` scameron
2014-06-02 15:00 ` scameron
2014-05-29 15:53 ` [PATCH 2 09/24] hpsa: allocate reply queues individually Stephen M. Cameron
2014-05-29 15:53 ` [PATCH 2 10/24] hpsa: set irq affinity hints to route MSI-X vectors across CPUs Stephen M. Cameron
2014-05-29 15:53 ` Stephen M. Cameron [this message]
2014-05-29 15:53 ` [PATCH 2 12/24] hpsa: avoid unnecessary readl on every command submission Stephen M. Cameron
2014-05-29 15:53 ` [PATCH 2 13/24] hpsa: Rearrange start_io to avoid one unlock/lock sequence in main io path Stephen M. Cameron
2014-05-29 15:53 ` [PATCH 2 14/24] hpsa: define extended_report_lun_entry data structure Stephen M. Cameron
2014-05-29 15:53 ` [PATCH 2 15/24] hpsa: kill annoying messages about SSD Smart Path retries Stephen M. Cameron
2014-05-29 15:53 ` [PATCH 2 16/24] hpsa: fix event filtering to prevent excessive rescans with old firmware Stephen M. Cameron
2014-05-29 15:53 ` [PATCH 2 17/24] hpsa: remove bad unlikely annotation from device list updating code Stephen M. Cameron
2014-05-29 15:53 ` [PATCH 2 18/24] hpsa: report check condition even if no sense data present for ioaccel2 mode Stephen M. Cameron
2014-05-29 15:54 ` [PATCH 2 19/24] hpsa: fix memory leak in hpsa_hba_mode_enabled Stephen M. Cameron
2014-05-29 15:54 ` [PATCH 2 20/24] hpsa: do not ignore failure of sense controller parameters command Stephen M. Cameron
2014-05-29 15:54 ` [PATCH 2 21/24] hpsa: remove messages about volume status VPD inquiry page not supported Stephen M. Cameron
2014-05-29 15:54 ` [PATCH 2 22/24] hpsa: fix bad comparison of signed with unsigned in hpsa_update_scsi_devices Stephen M. Cameron
2014-05-29 15:54 ` [PATCH 2 23/24] hpsa: return -ENOMEM not -1 on kzalloc failure in hpsa_get_device_id Stephen M. Cameron
2014-05-29 15:54 ` [PATCH 2 24/24] hpsa: fix handling of hpsa_volume_offline return value Stephen M. Cameron
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=20140529155318.8180.49035.stgit@beardog.cce.hp.com \
--to=scameron@beardog.cce.hp.com \
--cc=dan.carpenter@oracle.com \
--cc=hch@lst.de \
--cc=james.bottomley@parallels.com \
--cc=joseph.t.handzik@hp.com \
--cc=justin.lindley@hp.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=michael.miller@canonical.com \
--cc=scott.teel@hp.com \
--cc=stephenmcameron@gmail.com \
--cc=thenzl@redhat.com \
--cc=webb.scales@hp.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).