Skip to content

Commit b05d4e4

Browse files
doug-gilbertmartinkpetersen
authored andcommitted
scsi: scsi_debug: Refine sdebug_blk_mq_poll()
Refine the sdebug_blk_mq_poll() function so it only takes the spinlock on the queue when it can see one or more requests with the in_use bitmap flag set. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Douglas Gilbert <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 7d5a129 commit b05d4e4

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

drivers/scsi/scsi_debug.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7396,6 +7396,7 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num)
73967396
{
73977397
bool first;
73987398
bool retiring = false;
7399+
bool locked = false;
73997400
int num_entries = 0;
74007401
unsigned int qc_idx = 0;
74017402
unsigned long iflags;
@@ -7407,16 +7408,23 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num)
74077408
struct sdebug_defer *sd_dp;
74087409

74097410
sqp = sdebug_q_arr + queue_num;
7410-
spin_lock_irqsave(&sqp->qc_lock, iflags);
7411+
qc_idx = find_first_bit(sqp->in_use_bm, sdebug_max_queue);
7412+
if (qc_idx >= sdebug_max_queue)
7413+
return 0;
74117414

74127415
for (first = true; first || qc_idx + 1 < sdebug_max_queue; ) {
7416+
if (!locked) {
7417+
spin_lock_irqsave(&sqp->qc_lock, iflags);
7418+
locked = true;
7419+
}
74137420
if (first) {
7414-
qc_idx = find_first_bit(sqp->in_use_bm, sdebug_max_queue);
74157421
first = false;
7422+
if (!test_bit(qc_idx, sqp->in_use_bm))
7423+
continue;
74167424
} else {
74177425
qc_idx = find_next_bit(sqp->in_use_bm, sdebug_max_queue, qc_idx + 1);
74187426
}
7419-
if (unlikely(qc_idx >= sdebug_max_queue))
7427+
if (qc_idx >= sdebug_max_queue)
74207428
break;
74217429

74227430
sqcp = &sqp->qc_arr[qc_idx];
@@ -7465,11 +7473,14 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num)
74657473
}
74667474
WRITE_ONCE(sd_dp->defer_t, SDEB_DEFER_NONE);
74677475
spin_unlock_irqrestore(&sqp->qc_lock, iflags);
7476+
locked = false;
74687477
scsi_done(scp); /* callback to mid level */
7469-
spin_lock_irqsave(&sqp->qc_lock, iflags);
74707478
num_entries++;
7479+
if (find_first_bit(sqp->in_use_bm, sdebug_max_queue) >= sdebug_max_queue)
7480+
break; /* if no more then exit without retaking spinlock */
74717481
}
7472-
spin_unlock_irqrestore(&sqp->qc_lock, iflags);
7482+
if (locked)
7483+
spin_unlock_irqrestore(&sqp->qc_lock, iflags);
74737484
if (num_entries > 0)
74747485
atomic_add(num_entries, &sdeb_mq_poll_count);
74757486
return num_entries;

0 commit comments

Comments
 (0)