Skip to content

Commit b657d7e

Browse files
Christoph Hellwigaxboe
authored andcommitted
blk-mq: handle the single queue case in blk_mq_hctx_next_cpu
Don't duplicate the code to handle the not cpu bounce case in the caller, do it inside blk_mq_hctx_next_cpu instead. Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 5fabcb4 commit b657d7e

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

block/blk-mq.c

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -788,20 +788,23 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx)
788788
*/
789789
static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx)
790790
{
791-
int cpu = hctx->next_cpu;
791+
if (hctx->queue->nr_hw_queues == 1)
792+
return WORK_CPU_UNBOUND;
792793

793794
if (--hctx->next_cpu_batch <= 0) {
794-
int next_cpu;
795+
int cpu = hctx->next_cpu, next_cpu;
795796

796797
next_cpu = cpumask_next(hctx->next_cpu, hctx->cpumask);
797798
if (next_cpu >= nr_cpu_ids)
798799
next_cpu = cpumask_first(hctx->cpumask);
799800

800801
hctx->next_cpu = next_cpu;
801802
hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH;
803+
804+
return cpu;
802805
}
803806

804-
return cpu;
807+
return hctx->next_cpu;
805808
}
806809

807810
void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async)
@@ -820,14 +823,8 @@ void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async)
820823
put_cpu();
821824
}
822825

823-
if (hctx->queue->nr_hw_queues == 1)
824-
kblockd_schedule_delayed_work(&hctx->run_work, 0);
825-
else {
826-
unsigned int cpu;
827-
828-
cpu = blk_mq_hctx_next_cpu(hctx);
829-
kblockd_schedule_delayed_work_on(cpu, &hctx->run_work, 0);
830-
}
826+
kblockd_schedule_delayed_work_on(blk_mq_hctx_next_cpu(hctx),
827+
&hctx->run_work, 0);
831828
}
832829

833830
void blk_mq_run_queues(struct request_queue *q, bool async)
@@ -919,16 +916,8 @@ static void blk_mq_delay_work_fn(struct work_struct *work)
919916

920917
void blk_mq_delay_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs)
921918
{
922-
unsigned long tmo = msecs_to_jiffies(msecs);
923-
924-
if (hctx->queue->nr_hw_queues == 1)
925-
kblockd_schedule_delayed_work(&hctx->delay_work, tmo);
926-
else {
927-
unsigned int cpu;
928-
929-
cpu = blk_mq_hctx_next_cpu(hctx);
930-
kblockd_schedule_delayed_work_on(cpu, &hctx->delay_work, tmo);
931-
}
919+
kblockd_schedule_delayed_work_on(blk_mq_hctx_next_cpu(hctx),
920+
&hctx->delay_work, msecs_to_jiffies(msecs));
932921
}
933922
EXPORT_SYMBOL(blk_mq_delay_queue);
934923

0 commit comments

Comments
 (0)