Skip to content

Commit 84c3e1a

Browse files
Vasu DevJames Bottomley
authored andcommitted
[SCSI] libfc: adds can_queue ramp up
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> Signed-off-by: James Bottomley <James.Bottomley@suse.de>
1 parent c46be11 commit 84c3e1a

1 file changed

Lines changed: 59 additions & 19 deletions

File tree

‎drivers/scsi/libfc/fc_fcp.c‎

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ struct kmem_cache *scsi_pkt_cachep;
5252
#define FC_SRB_DISCONTIG (1 << 4) /* non-sequential data recvd */
5353
#define FC_SRB_COMPL (1 << 5) /* fc_io_compl has been run */
5454
#define FC_SRB_FCP_PROCESSING_TMO (1 << 6) /* timer function processing */
55-
#define FC_SRB_NOMEM (1 << 7) /* dropped to out of mem */
5655

5756
#define FC_SRB_READ (1 << 1)
5857
#define FC_SRB_WRITE (1 << 0)
@@ -71,12 +70,16 @@ struct kmem_cache *scsi_pkt_cachep;
7170
* struct fc_fcp_internal - FCP layer internal data
7271
* @scsi_pkt_pool: Memory pool to draw FCP packets from
7372
* @scsi_pkt_queue: Current FCP packets
74-
* @throttled: The FCP packet queue is throttled
73+
* @last_can_queue_ramp_down_time: ramp down time
74+
* @last_can_queue_ramp_up_time: ramp up time
75+
* @max_can_queue: max can_queue size
7576
*/
7677
struct fc_fcp_internal {
7778
mempool_t *scsi_pkt_pool;
7879
struct list_head scsi_pkt_queue;
79-
u8 throttled;
80+
unsigned long last_can_queue_ramp_down_time;
81+
unsigned long last_can_queue_ramp_up_time;
82+
int max_can_queue;
8083
};
8184

8285
#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 *);
124127
#define FC_SCSI_TM_TOV (10 * HZ)
125128
#define FC_SCSI_REC_TOV (2 * HZ)
126129
#define FC_HOST_RESET_TIMEOUT (30 * HZ)
130+
#define FC_CAN_QUEUE_PERIOD (60 * HZ)
127131

128132
#define FC_MAX_ERROR_CNT 5
129133
#define FC_MAX_RECOV_RETRY 3
@@ -326,6 +330,38 @@ static void fc_fcp_ddp_done(struct fc_fcp_pkt *fsp)
326330
}
327331
}
328332

333+
/**
334+
* fc_fcp_can_queue_ramp_up() - increases can_queue
335+
* @lport: lport to ramp up can_queue
336+
*
337+
* Locking notes: Called with Scsi_Host lock held
338+
*/
339+
static void fc_fcp_can_queue_ramp_up(struct fc_lport *lport)
340+
{
341+
struct fc_fcp_internal *si = fc_get_scsi_internal(lport);
342+
int can_queue;
343+
344+
if (si->last_can_queue_ramp_up_time &&
345+
(time_before(jiffies, si->last_can_queue_ramp_up_time +
346+
FC_CAN_QUEUE_PERIOD)))
347+
return;
348+
349+
if (time_before(jiffies, si->last_can_queue_ramp_down_time +
350+
FC_CAN_QUEUE_PERIOD))
351+
return;
352+
353+
si->last_can_queue_ramp_up_time = jiffies;
354+
355+
can_queue = lport->host->can_queue << 1;
356+
if (can_queue >= si->max_can_queue) {
357+
can_queue = si->max_can_queue;
358+
si->last_can_queue_ramp_down_time = 0;
359+
}
360+
lport->host->can_queue = can_queue;
361+
shost_printk(KERN_ERR, lport->host, "libfc: increased "
362+
"can_queue to %d.\n", can_queue);
363+
}
364+
329365
/**
330366
* fc_fcp_can_queue_ramp_down() - reduces can_queue
331367
* @lport: lport to reduce can_queue
@@ -335,17 +371,20 @@ static void fc_fcp_ddp_done(struct fc_fcp_pkt *fsp)
335371
* commands complete or timeout, then try again with a reduced
336372
* can_queue. Eventually we will hit the point where we run
337373
* on all reserved structs.
374+
*
375+
* Locking notes: Called with Scsi_Host lock held
338376
*/
339377
static void fc_fcp_can_queue_ramp_down(struct fc_lport *lport)
340378
{
341379
struct fc_fcp_internal *si = fc_get_scsi_internal(lport);
342-
unsigned long flags;
343380
int can_queue;
344381

345-
spin_lock_irqsave(lport->host->host_lock, flags);
346-
if (si->throttled)
347-
goto done;
348-
si->throttled = 1;
382+
if (si->last_can_queue_ramp_down_time &&
383+
(time_before(jiffies, si->last_can_queue_ramp_down_time +
384+
FC_CAN_QUEUE_PERIOD)))
385+
return;
386+
387+
si->last_can_queue_ramp_down_time = jiffies;
349388

350389
can_queue = lport->host->can_queue;
351390
can_queue >>= 1;
@@ -354,8 +393,6 @@ static void fc_fcp_can_queue_ramp_down(struct fc_lport *lport)
354393
lport->host->can_queue = can_queue;
355394
shost_printk(KERN_ERR, lport->host, "libfc: Could not allocate frame.\n"
356395
"Reducing can_queue to %d.\n", can_queue);
357-
done:
358-
spin_unlock_irqrestore(lport->host->host_lock, flags);
359396
}
360397

361398
/*
@@ -370,10 +407,14 @@ static inline struct fc_frame *fc_fcp_frame_alloc(struct fc_lport *lport,
370407
size_t len)
371408
{
372409
struct fc_frame *fp;
410+
unsigned long flags;
373411

374412
fp = fc_frame_alloc(lport, len);
375-
if (!fp)
413+
if (!fp) {
414+
spin_lock_irqsave(lport->host->host_lock, flags);
376415
fc_fcp_can_queue_ramp_down(lport);
416+
spin_unlock_irqrestore(lport->host->host_lock, flags);
417+
}
377418
return fp;
378419
}
379420

@@ -720,8 +761,6 @@ static void fc_fcp_recv(struct fc_seq *seq, struct fc_frame *fp, void *arg)
720761
(size_t) ntohl(dd->ft_burst_len));
721762
if (!rc)
722763
seq->rec_data = fsp->xfer_len;
723-
else if (rc == -ENOMEM)
724-
fsp->state |= FC_SRB_NOMEM;
725764
} else if (r_ctl == FC_RCTL_DD_SOL_DATA) {
726765
/*
727766
* received a DATA frame
@@ -1734,6 +1773,8 @@ int fc_queuecommand(struct scsi_cmnd *sc_cmd, void (*done)(struct scsi_cmnd *))
17341773
rpriv = rport->dd_data;
17351774

17361775
if (!fc_fcp_lport_queue_ready(lport)) {
1776+
if (lport->qfull)
1777+
fc_fcp_can_queue_ramp_down(lport);
17371778
rc = SCSI_MLQUEUE_HOST_BUSY;
17381779
goto out;
17391780
}
@@ -1830,13 +1871,11 @@ static void fc_io_compl(struct fc_fcp_pkt *fsp)
18301871
}
18311872

18321873
/*
1833-
* if a command timed out while we had to try and throttle IO
1834-
* and it is now getting cleaned up, then we are about to
1835-
* try again so clear the throttled flag incase we get more
1836-
* time outs.
1874+
* if can_queue ramp down is done then try can_queue ramp up
1875+
* since commands are completing now.
18371876
*/
1838-
if (si->throttled && fsp->state & FC_SRB_NOMEM)
1839-
si->throttled = 0;
1877+
if (si->last_can_queue_ramp_down_time)
1878+
fc_fcp_can_queue_ramp_up(lport);
18401879

18411880
sc_cmd = fsp->cmd;
18421881
fsp->cmd = NULL;
@@ -2176,6 +2215,7 @@ int fc_fcp_init(struct fc_lport *lport)
21762215
if (!si)
21772216
return -ENOMEM;
21782217
lport->scsi_priv = si;
2218+
si->max_can_queue = lport->host->can_queue;
21792219
INIT_LIST_HEAD(&si->scsi_pkt_queue);
21802220

21812221
si->scsi_pkt_pool = mempool_create_slab_pool(2, scsi_pkt_cachep);

0 commit comments

Comments
 (0)