public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Robert Love <robert.w.love@intel.com>
To: James.Bottomley@HansenPartnership.com, linux-scsi@vger.kernel.org
Cc: Vasu Dev <vasu.dev@intel.com>, Robert Love <robert.w.love@intel.com>
Subject: [PATCH 29/54] libfc: adds can_queue ramp up
Date: Tue, 03 Nov 2009 11:48:06 -0800	[thread overview]
Message-ID: <20091103194806.4085.45070.stgit@localhost.localdomain> (raw)
In-Reply-To: <20091103194530.4085.37963.stgit@localhost.localdomain>

From: Vasu Dev <vasu.dev@intel.com>

Adds last_can_queue_ramp_down_time and updates this on every
ramp down. If last_can_queue_ramp_down_time is not zero then
do ramp up on any IO completion in added fc_fcp_can_queue_ramp_up.

Reset last_can_queue_ramp_down_time to zero once can_queue
is ramped up to added max_can_queue limit, this is to avoid any
more ramp up attempts on subsequent IO completion.

The ramp down and up are skipped for FC_CAN_QUEUE_PERIOD
to avoid infrequent changes to can_queue, this required
keeping track of ramp up time also in last_can_queue_ramp_up_time.

Adds code to ramp down can_queue if lp->qfull is set, with added
new ramp up code the can_queue will be increased after
FC_CAN_QUEUE_PERIOD, therefore it is safe to do ramp down
without fsp in this case and will avoid thrash. This required
fc_fcp_can_queue_ramp_down locking change so that it can be
called with Scsi_Host lock held.

Removes si->throttled and fsp state FC_SRB_NOMEM, not needed with
added ramp up code.

Signed-off-by: Vasu Dev <vasu.dev@intel.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
---

 drivers/scsi/libfc/fc_fcp.c |   78 +++++++++++++++++++++++++++++++++----------
 1 files changed, 59 insertions(+), 19 deletions(-)

diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index ac5c148..4bfab4f 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -52,7 +52,6 @@ struct kmem_cache *scsi_pkt_cachep;
 #define FC_SRB_DISCONTIG	(1 << 4)	/* non-sequential data recvd */
 #define FC_SRB_COMPL		(1 << 5)	/* fc_io_compl has been run */
 #define FC_SRB_FCP_PROCESSING_TMO (1 << 6)	/* timer function processing */
-#define FC_SRB_NOMEM		(1 << 7)	/* dropped to out of mem */
 
 #define FC_SRB_READ		(1 << 1)
 #define FC_SRB_WRITE		(1 << 0)
@@ -71,12 +70,16 @@ struct kmem_cache *scsi_pkt_cachep;
  * struct fc_fcp_internal - FCP layer internal data
  * @scsi_pkt_pool:  Memory pool to draw FCP packets from
  * @scsi_pkt_queue: Current FCP packets
- * @throttled:	    The FCP packet queue is throttled
+ * @last_can_queue_ramp_down_time: ramp down time
+ * @last_can_queue_ramp_up_time: ramp up time
+ * @max_can_queue: max can_queue size
  */
 struct fc_fcp_internal {
 	mempool_t	 *scsi_pkt_pool;
 	struct list_head scsi_pkt_queue;
-	u8		 throttled;
+	unsigned long last_can_queue_ramp_down_time;
+	unsigned long last_can_queue_ramp_up_time;
+	int max_can_queue;
 };
 
 #define fc_get_scsi_internal(x)	((struct fc_fcp_internal *)(x)->scsi_priv)
@@ -124,6 +127,7 @@ static void fc_fcp_srr_error(struct fc_fcp_pkt *, struct fc_frame *);
 #define FC_SCSI_TM_TOV		(10 * HZ)
 #define FC_SCSI_REC_TOV		(2 * HZ)
 #define FC_HOST_RESET_TIMEOUT	(30 * HZ)
+#define FC_CAN_QUEUE_PERIOD	(60 * HZ)
 
 #define FC_MAX_ERROR_CNT	5
 #define FC_MAX_RECOV_RETRY	3
@@ -327,6 +331,38 @@ static void fc_fcp_ddp_done(struct fc_fcp_pkt *fsp)
 }
 
 /**
+ * fc_fcp_can_queue_ramp_up() - increases can_queue
+ * @lport: lport to ramp up can_queue
+ *
+ * Locking notes: Called with Scsi_Host lock held
+ */
+static void fc_fcp_can_queue_ramp_up(struct fc_lport *lport)
+{
+	struct fc_fcp_internal *si = fc_get_scsi_internal(lport);
+	int can_queue;
+
+	if (si->last_can_queue_ramp_up_time &&
+	    (time_before(jiffies, si->last_can_queue_ramp_up_time +
+			 FC_CAN_QUEUE_PERIOD)))
+		return;
+
+	if (time_before(jiffies, si->last_can_queue_ramp_down_time +
+			FC_CAN_QUEUE_PERIOD))
+		return;
+
+	si->last_can_queue_ramp_up_time = jiffies;
+
+	can_queue = lport->host->can_queue << 1;
+	if (can_queue >= si->max_can_queue) {
+		can_queue = si->max_can_queue;
+		si->last_can_queue_ramp_down_time = 0;
+	}
+	lport->host->can_queue = can_queue;
+	shost_printk(KERN_ERR, lport->host, "libfc: increased "
+		     "can_queue to %d.\n", can_queue);
+}
+
+/**
  * fc_fcp_can_queue_ramp_down() - reduces can_queue
  * @lport: lport to reduce can_queue
  *
@@ -335,17 +371,20 @@ static void fc_fcp_ddp_done(struct fc_fcp_pkt *fsp)
  * commands complete or timeout, then try again with a reduced
  * can_queue. Eventually we will hit the point where we run
  * on all reserved structs.
+ *
+ * Locking notes: Called with Scsi_Host lock held
  */
 static void fc_fcp_can_queue_ramp_down(struct fc_lport *lport)
 {
 	struct fc_fcp_internal *si = fc_get_scsi_internal(lport);
-	unsigned long flags;
 	int can_queue;
 
-	spin_lock_irqsave(lport->host->host_lock, flags);
-	if (si->throttled)
-		goto done;
-	si->throttled = 1;
+	if (si->last_can_queue_ramp_down_time &&
+	    (time_before(jiffies, si->last_can_queue_ramp_down_time +
+			 FC_CAN_QUEUE_PERIOD)))
+		return;
+
+	si->last_can_queue_ramp_down_time = jiffies;
 
 	can_queue = lport->host->can_queue;
 	can_queue >>= 1;
@@ -354,8 +393,6 @@ static void fc_fcp_can_queue_ramp_down(struct fc_lport *lport)
 	lport->host->can_queue = can_queue;
 	shost_printk(KERN_ERR, lport->host, "libfc: Could not allocate frame.\n"
 		     "Reducing can_queue to %d.\n", can_queue);
-done:
-	spin_unlock_irqrestore(lport->host->host_lock, flags);
 }
 
 /*
@@ -370,10 +407,14 @@ static inline struct fc_frame *fc_fcp_frame_alloc(struct fc_lport *lport,
 						  size_t len)
 {
 	struct fc_frame *fp;
+	unsigned long flags;
 
 	fp = fc_frame_alloc(lport, len);
-	if (!fp)
+	if (!fp) {
+		spin_lock_irqsave(lport->host->host_lock, flags);
 		fc_fcp_can_queue_ramp_down(lport);
+		spin_unlock_irqrestore(lport->host->host_lock, flags);
+	}
 	return fp;
 }
 
@@ -720,8 +761,6 @@ static void fc_fcp_recv(struct fc_seq *seq, struct fc_frame *fp, void *arg)
 				      (size_t) ntohl(dd->ft_burst_len));
 		if (!rc)
 			seq->rec_data = fsp->xfer_len;
-		else if (rc == -ENOMEM)
-			fsp->state |= FC_SRB_NOMEM;
 	} else if (r_ctl == FC_RCTL_DD_SOL_DATA) {
 		/*
 		 * received a DATA frame
@@ -1734,6 +1773,8 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *))
 	rpriv = rport->dd_data;
 
 	if (!fc_fcp_lport_queue_ready(lport)) {
+		if (lport->qfull)
+			fc_fcp_can_queue_ramp_down(lport);
 		rc = SCSI_MLQUEUE_HOST_BUSY;
 		goto out;
 	}
@@ -1830,13 +1871,11 @@ static void fc_io_compl(struct fc_fcp_pkt *fsp)
 	}
 
 	/*
-	 * if a command timed out while we had to try and throttle IO
-	 * and it is now getting cleaned up, then we are about to
-	 * try again so clear the throttled flag incase we get more
-	 * time outs.
+	 * if can_queue ramp down is done then try can_queue ramp up
+	 * since commands are completing now.
 	 */
-	if (si->throttled && fsp->state & FC_SRB_NOMEM)
-		si->throttled = 0;
+	if (si->last_can_queue_ramp_down_time)
+		fc_fcp_can_queue_ramp_up(lport);
 
 	sc_cmd = fsp->cmd;
 	fsp->cmd = NULL;
@@ -2176,6 +2215,7 @@ int fc_fcp_init(struct fc_lport *lport)
 	if (!si)
 		return -ENOMEM;
 	lport->scsi_priv = si;
+	si->max_can_queue = lport->host->can_queue;
 	INIT_LIST_HEAD(&si->scsi_pkt_queue);
 
 	si->scsi_pkt_pool = mempool_create_slab_pool(2, scsi_pkt_cachep);


  parent reply	other threads:[~2009-11-03 19:48 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-03 19:45 [PATCH 00/54] libfc, libfcoe, fcoe and fnic updates for 2.6.33 Robert Love
2009-11-03 19:45 ` [PATCH 01/54] fnic: Allocate OS interrupt resources just before enabling interrupts Robert Love
2009-11-03 19:45 ` [PATCH 02/54] fcoe: Increase FCOE_MAX_LUN to 0xFFFF (65535) Robert Love
2009-11-03 19:45 ` [PATCH 03/54] libfc: Move non-common routines and prototypes out of libfc.h Robert Love
2009-11-03 19:45 ` [PATCH 04/54] libfc: Remove fc_fcp_complete Robert Love
2009-11-03 19:45 ` [PATCH 05/54] libfc: Add libfc/fc_libfc.[ch] for libfc internal routines Robert Love
2009-11-03 19:46 ` [PATCH 06/54] libfc: Move libfc_init and libfc_exit to fc_libfc.c Robert Love
2009-11-03 19:46 ` [PATCH 07/54] libfc: changes to libfc_host_alloc to consolidate initialization with allocation Robert Love
2009-11-03 19:46 ` [PATCH 08/54] libfc: add some generic NPIV support routines to libfc Robert Love
2009-11-03 19:46 ` [PATCH 09/54] libfc: vport link handling and fc_vport state managment Robert Love
2009-11-03 19:46 ` [PATCH 10/54] libfc, libfcoe: FDISC ELS for NPIV Robert Love
2009-11-03 19:46 ` [PATCH 11/54] libfcoe, fcoe: libfcoe NPIV support Robert Love
2009-11-03 19:46 ` [PATCH 12/54] fcoe: add a separate scsi transport template for NPIV vports Robert Love
2009-11-03 19:46 ` [PATCH 13/54] fcoe: NPIV vport create/destroy Robert Love
2009-11-03 19:46 ` [PATCH 14/54] libfc: RPN_ID is obsolete and unnecessary Robert Love
2009-11-03 19:46 ` [PATCH 15/54] libfc: RNN_ID may be required before RSNN_NN with some switches Robert Love
2009-11-03 19:46 ` [PATCH 16/54] libfc: Register Symbolic Node Name (RSNN_NN) Robert Love
2009-11-03 19:47 ` [PATCH 17/54] libfc: Register Symbolic Port Name (RSPN_ID) Robert Love
2009-11-03 19:47 ` [PATCH 18/54] libfc: combine name server registration response handlers Robert Love
2009-11-03 19:47 ` [PATCH 19/54] libfc: combine name server registration request functions Robert Love
2009-11-03 19:47 ` [PATCH 20/54] fcoe: vport symbolic name support Robert Love
2009-11-03 19:47 ` [PATCH 21/54] libfc: Export FC headers Robert Love
2009-11-03 19:47 ` [PATCH 22/54] libfc: Add routine to copy data from a buffer to a SG list Robert Love
2009-11-03 19:47 ` [PATCH 23/54] libfc, fcoe: Add FC passthrough support Robert Love
2009-11-03 19:47 ` [PATCH 24/54] libfc: Formatting cleanups across libfc Robert Love
2009-11-03 19:47 ` [PATCH 25/54] libfcoe: formatting and comment cleanups Robert Love
2009-11-03 19:47 ` [PATCH 26/54] fcoe: Formatting cleanups and commenting Robert Love
2009-11-03 19:47 ` [PATCH 27/54] fcoe, libfc: use single frame allocation API Robert Love
2009-11-03 19:48 ` [PATCH 28/54] libfc: reduce can_queue for all FCP frame allocation failures Robert Love
2009-11-03 19:48 ` Robert Love [this message]
2009-11-03 19:48 ` [PATCH 30/54] libfcoe: Allow FIP to be disabled by the driver Robert Love
2009-11-03 19:48 ` [PATCH 31/54] libfcoe: fip: use SCSI host number to identify debug messages Robert Love
2009-11-03 19:48 ` [PATCH 32/54] libfcoe: fip: allow FIP receive to be called from IRQ Robert Love
2009-11-03 19:48 ` [PATCH 33/54] libfcoe: FIP should report link to libfc whether selected or not Robert Love
2009-11-03 19:48 ` [PATCH 34/54] libfcoe: don't send ELS in FIP mode if no FCF selected Robert Love
2009-11-03 19:48 ` [PATCH 35/54] fcoe: remove extra function decalrations Robert Love
2009-11-03 19:48 ` [PATCH 36/54] fcoe: add check to fail gracefully in bonding mode Robert Love
2009-11-03 19:48 ` [PATCH 37/54] libfc: fix RNN_ID smashing skb payload Robert Love
2009-11-03 19:48 ` [PATCH 38/54] libfc: fix symbolic name registrations smashing skb data Robert Love
2009-11-03 19:49 ` [PATCH 39/54] libfc: fix fc_els_resp_type to correct display of CT responses Robert Love
2009-11-03 19:49 ` [PATCH 40/54] libfc: add set_fid function to libfc template Robert Love
2009-11-03 19:49 ` [PATCH 41/54] libfc: add host number to lport link up/down messages Robert Love
2009-11-03 19:49 ` [PATCH 42/54] libfcoe: fcoe: simplify receive FLOGI response Robert Love
2009-11-03 19:49 ` [PATCH 43/54] fnic: Add FIP support to the fnic driver Robert Love
2009-11-03 19:49 ` [PATCH 44/54] libfc: register FC4 features with the FC switch Robert Love
2009-11-03 19:49 ` [PATCH 45/54] fnic: enable bsg pass-thru for fcping Robert Love
2009-11-03 19:49 ` [PATCH 46/54] fcoe: Fix checking san mac address Robert Love
2009-11-03 19:49 ` [PATCH 47/54] fcoe: Fix getting san mac for VLAN interface Robert Love
2009-11-03 19:49 ` [PATCH 48/54] fcoe: Fix setting lport's WWNN/WWPN to use san mac address Robert Love
2009-11-03 19:49 ` [PATCH 49/54] libfc: do not use DID_NO_CONNECT for pkt alloc failures Robert Love
2009-11-03 19:49 ` [PATCH 50/54] fcoe: Fix using VLAN ID in creating lport's WWWN/WWPN Robert Love
2009-11-03 19:50 ` [PATCH 51/54] libfc, fcoe: fixes for highmem skb linearize panics Robert Love
2009-11-03 19:50 ` [PATCH 52/54] libfc: fix an issue of pending exch/es after i/f destroyed or rmmod fcoe Robert Love
2009-11-03 19:50 ` [PATCH 53/54] libfcoe: Do not pad FIP keep-alive to full frame size Robert Love
2009-11-03 19:50 ` [PATCH 54/54] libfc fcoe: increase ELS and CT timeouts Robert Love

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=20091103194806.4085.45070.stgit@localhost.localdomain \
    --to=robert.w.love@intel.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=vasu.dev@intel.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