Skip to content

Commit 2ccbb00

Browse files
author
Christoph Hellwig
committed
scsi: only maintain target_blocked if the driver has a target queue limit
This saves us an atomic operation for each I/O submission and completion for the usual case where the driver doesn't set a per-target can_queue value. Only a few iscsi hardware offload drivers set the per-target can_queue value at the moment. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Reviewed-by: Webb Scales <[email protected]> Acked-by: Jens Axboe <[email protected]> Tested-by: Bart Van Assche <[email protected]> Tested-by: Robert Elliott <[email protected]>
1 parent cd9070c commit 2ccbb00

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

drivers/scsi/scsi_lib.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ void scsi_device_unbusy(struct scsi_device *sdev)
295295
unsigned long flags;
296296

297297
atomic_dec(&shost->host_busy);
298-
atomic_dec(&starget->target_busy);
298+
if (starget->can_queue > 0)
299+
atomic_dec(&starget->target_busy);
299300

300301
if (unlikely(scsi_host_in_recovery(shost) &&
301302
(shost->host_failed || shost->host_eh_scheduled))) {
@@ -364,11 +365,12 @@ static inline bool scsi_device_is_busy(struct scsi_device *sdev)
364365

365366
static inline bool scsi_target_is_busy(struct scsi_target *starget)
366367
{
367-
if (starget->can_queue > 0 &&
368-
atomic_read(&starget->target_busy) >= starget->can_queue)
369-
return true;
370-
if (atomic_read(&starget->target_blocked) > 0)
371-
return true;
368+
if (starget->can_queue > 0) {
369+
if (atomic_read(&starget->target_busy) >= starget->can_queue)
370+
return true;
371+
if (atomic_read(&starget->target_blocked) > 0)
372+
return true;
373+
}
372374
return false;
373375
}
374376

@@ -1309,6 +1311,9 @@ static inline int scsi_target_queue_ready(struct Scsi_Host *shost,
13091311
spin_unlock_irq(shost->host_lock);
13101312
}
13111313

1314+
if (starget->can_queue <= 0)
1315+
return 1;
1316+
13121317
busy = atomic_inc_return(&starget->target_busy) - 1;
13131318
if (atomic_read(&starget->target_blocked) > 0) {
13141319
if (busy)
@@ -1324,7 +1329,7 @@ static inline int scsi_target_queue_ready(struct Scsi_Host *shost,
13241329
"unblocking target at zero depth\n"));
13251330
}
13261331

1327-
if (starget->can_queue > 0 && busy >= starget->can_queue)
1332+
if (busy >= starget->can_queue)
13281333
goto starved;
13291334

13301335
return 1;
@@ -1334,7 +1339,8 @@ static inline int scsi_target_queue_ready(struct Scsi_Host *shost,
13341339
list_move_tail(&sdev->starved_entry, &shost->starved_list);
13351340
spin_unlock_irq(shost->host_lock);
13361341
out_dec:
1337-
atomic_dec(&starget->target_busy);
1342+
if (starget->can_queue > 0)
1343+
atomic_dec(&starget->target_busy);
13381344
return 0;
13391345
}
13401346

@@ -1455,7 +1461,8 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
14551461
*/
14561462
atomic_inc(&sdev->device_busy);
14571463
atomic_inc(&shost->host_busy);
1458-
atomic_inc(&starget->target_busy);
1464+
if (starget->can_queue > 0)
1465+
atomic_inc(&starget->target_busy);
14591466

14601467
blk_complete_request(req);
14611468
}
@@ -1624,7 +1631,8 @@ static void scsi_request_fn(struct request_queue *q)
16241631
return;
16251632

16261633
host_not_ready:
1627-
atomic_dec(&scsi_target(sdev)->target_busy);
1634+
if (scsi_target(sdev)->can_queue > 0)
1635+
atomic_dec(&scsi_target(sdev)->target_busy);
16281636
not_ready:
16291637
/*
16301638
* lock q, handle tag, requeue req, and decrement device_busy. We

0 commit comments

Comments
 (0)