[PATCH] scsi: megaraid_sas - intercepts cmd timeout and throttle io

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



eh_timed_out call back (megasas_reset_timer) is used to throttle io to the adapter
when it is called the first time for a scmd.
The MEGASAS_FW_BUSY flag is set and can_queue reduced to 16. The can_queue is restored
from completion routine in following two conditions : 5 seconds has elapsed and the # of
outstanding cmds in FW is < 17.
Also removed reserved fields from struct megasas_instance.

Signed-off-by: Sumant Patro <sumant.patro@xxxxxxx>
---
 drivers/scsi/megaraid/megaraid_sas.c |   65 +++++++++++++++++++++++--
 drivers/scsi/megaraid/megaraid_sas.h |   13 +++--
 2 files changed, 69 insertions(+), 9 deletions(-)

Re-submitting after removing the reserved fields from megasas_instance.

On Thu, 2007-04-26 at 11:52 -0600, Patro, Sumant wrote:
>         The rsvd[3] is reserved for future use. If you have objection to
> the definition I will take it out in a future patch submission.

But this is a structure that's internal to the driver isn't it?  It's
not shared with the card, so there's no need to pad it or reserve
elements ... you can add anything you need at the point you need it.

James

diff -uprN orig/drivers/scsi/megaraid/megaraid_sas.c new/drivers/scsi/megaraid/megaraid_sas.c
--- orig/drivers/scsi/megaraid/megaraid_sas.c	2007-05-09 05:32:21.000000000 -0700
+++ new/drivers/scsi/megaraid/megaraid_sas.c	2007-05-10 06:11:44.000000000 -0700
@@ -10,7 +10,7 @@
  *	   2 of the License, or (at your option) any later version.
  *
  * FILE		: megaraid_sas.c
- * Version	: v00.00.03.10-rc1
+ * Version	: v00.00.03.10-rc4
  *
  * Authors:
  *	(email-id : megaraidlinux@xxxxxxx)
@@ -886,6 +886,7 @@ megasas_queue_command(struct scsi_cmnd *
 		goto out_return_cmd;
 
 	cmd->scmd = scmd;
+	scmd->SCp.ptr = (char *)cmd;
 
 	/*
 	 * Issue the command to the FW
@@ -981,8 +982,8 @@ static int megasas_generic_reset(struct 
 
 	instance = (struct megasas_instance *)scmd->device->host->hostdata;
 
-	scmd_printk(KERN_NOTICE, scmd, "megasas: RESET -%ld cmd=%x\n",
-	       scmd->serial_number, scmd->cmnd[0]);
+	scmd_printk(KERN_NOTICE, scmd, "megasas: RESET -%ld cmd=%x retries=%x\n",
+		 scmd->serial_number, scmd->cmnd[0], scmd->retries);
 
 	if (instance->hw_crit_error) {
 		printk(KERN_ERR "megasas: cannot recover from previous reset "
@@ -1000,6 +1001,40 @@ static int megasas_generic_reset(struct 
 }
 
 /**
+ * megasas_reset_timer - quiesce the adapter if required
+ * @scmd:		scsi cmnd
+ *
+ * Sets the FW busy flag and reduces the host->can_queue if the
+ * cmd has not been completed within the timeout period.
+ */
+static enum
+scsi_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd)
+{
+	struct megasas_cmd *cmd = (struct megasas_cmd *)scmd->SCp.ptr;
+	struct megasas_instance *instance;
+	unsigned long flags;
+
+	if (cmd) {
+		if (time_after(jiffies, scmd->jiffies_at_alloc + 170 * HZ))
+			return EH_NOT_HANDLED;
+
+		instance = cmd->instance;
+		if (!(instance->flag & MEGASAS_FW_BUSY)) {
+			/* FW is busy, throttle IO */
+			spin_lock_irqsave(&instance->throttle_io_lock, flags);
+
+			instance->host->can_queue = 16;
+			instance->last_time = jiffies;
+			instance->flag |= MEGASAS_FW_BUSY;
+
+			spin_unlock_irqrestore(&instance->throttle_io_lock, flags);
+		}
+		return EH_RESET_TIMER;
+	}
+	return EH_HANDLED;
+}
+
+/**
  * megasas_reset_device -	Device reset handler entry point
  */
 static int megasas_reset_device(struct scsi_cmnd *scmd)
@@ -1112,6 +1147,7 @@ static struct scsi_host_template megasas
 	.eh_device_reset_handler = megasas_reset_device,
 	.eh_bus_reset_handler = megasas_reset_bus_host,
 	.eh_host_reset_handler = megasas_reset_bus_host,
+	.eh_timed_out = megasas_reset_timer,
 	.bios_param = megasas_bios_param,
 	.use_clustering = ENABLE_CLUSTERING,
 };
@@ -1215,9 +1251,8 @@ megasas_complete_cmd(struct megasas_inst
 	int exception = 0;
 	struct megasas_header *hdr = &cmd->frame->hdr;
 
-	if (cmd->scmd) {
+	if (cmd->scmd)
 		cmd->scmd->SCp.ptr = (char *)0;
-	}
 
 	switch (hdr->cmd) {
 
@@ -1806,6 +1841,7 @@ static void megasas_complete_cmd_dpc(uns
 	u32 context;
 	struct megasas_cmd *cmd;
 	struct megasas_instance *instance = (struct megasas_instance *)instance_addr;
+	unsigned long flags;
 
 	/* If we have already declared adapter dead, donot complete cmds */
 	if (instance->hw_crit_error)
@@ -1828,6 +1864,22 @@ static void megasas_complete_cmd_dpc(uns
 	}
 
 	*instance->consumer = producer;
+
+	/*
+	 * Check if we can restore can_queue
+	 */
+	if (instance->flag & MEGASAS_FW_BUSY
+		&& time_after(jiffies, instance->last_time + 5 * HZ)
+		&& atomic_read(&instance->fw_outstanding) < 17) {
+
+		spin_lock_irqsave(&instance->throttle_io_lock, flags);
+
+		instance->flag &= ~MEGASAS_FW_BUSY;
+		instance->host->can_queue =
+				instance->max_fw_cmds - MEGASAS_INT_CMDS;
+
+		spin_unlock_irqrestore(&instance->throttle_io_lock, flags);
+	}
 }
 
 /**
@@ -2384,6 +2436,7 @@ megasas_probe_one(struct pci_dev *pdev, 
 	init_waitqueue_head(&instance->int_cmd_wait_q);
 	init_waitqueue_head(&instance->abort_cmd_wait_q);
 
+	spin_lock_init(&instance->throttle_io_lock);
 	spin_lock_init(&instance->cmd_pool_lock);
 
 	sema_init(&instance->aen_mutex, 1);
@@ -2398,6 +2451,8 @@ megasas_probe_one(struct pci_dev *pdev, 
 	instance->init_id = MEGASAS_DEFAULT_INIT_ID;
 
 	megasas_dbg_lvl = 0;
+	instance->flag = 0;
+	instance->last_time = 0;
 
 	/*
 	 * Initialize MFI Firmware
diff -uprN orig/drivers/scsi/megaraid/megaraid_sas.h new/drivers/scsi/megaraid/megaraid_sas.h
--- orig/drivers/scsi/megaraid/megaraid_sas.h	2007-05-09 05:32:21.000000000 -0700
+++ new/drivers/scsi/megaraid/megaraid_sas.h	2007-05-10 06:13:07.000000000 -0700
@@ -18,9 +18,9 @@
 /*
  * MegaRAID SAS Driver meta data
  */
-#define MEGASAS_VERSION				"00.00.03.10-rc1"
-#define MEGASAS_RELDATE				"Feb 14, 2007"
-#define MEGASAS_EXT_VERSION			"Wed Feb 14 10:14:25 PST 2007"
+#define MEGASAS_VERSION				"00.00.03.10-rc4"
+#define MEGASAS_RELDATE				"May 10, 2007"
+#define MEGASAS_EXT_VERSION			"Thu May 10 11:20:22 PST 2007"
 
 /*
  * Device IDs
@@ -539,6 +539,8 @@ struct megasas_ctrl_info {
 
 #define MEGASAS_DBG_LVL				1
 
+#define MEGASAS_FW_BUSY				1
+
 /*
  * When SCSI mid-layer calls driver's reset routine, driver waits for
  * MEGASAS_RESET_WAIT_TIME seconds for all outstanding IO to complete. Note
@@ -1073,7 +1075,6 @@ struct megasas_instance {
 	struct megasas_register_set __iomem *reg_set;
 
 	s8 init_id;
-	u8 reserved[3];
 
 	u16 max_num_sge;
 	u16 max_fw_cmds;
@@ -1104,6 +1105,10 @@ struct megasas_instance {
 
 	struct megasas_instance_template *instancet;
 	struct tasklet_struct isr_tasklet;
+
+	u8 flag;
+	unsigned long last_time;
+	spinlock_t throttle_io_lock;
 };
 
 #define MEGASAS_IS_LOGICAL(scp)						\


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux