Skip to content

Commit 398205b

Browse files
bonziniaxboe
authored andcommitted
blk_mq: call preempt_disable/enable in blk_mq_run_hw_queue, and only if needed
preempt_disable/enable surrounds every call to blk_mq_run_hw_queue, except the one in blk-flush.c. In fact that one is always asynchronous, and it does not need smp_processor_id(). We can do the same for all other calls, avoiding preempt_disable when async is true. This avoids peppering blk-mq.c with preemption-disabled regions. Cc: Jens Axboe <[email protected]> Cc: Thomas Gleixner <[email protected]> Reported-by: Clark Williams <[email protected]> Tested-by: Clark Williams <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 9c6ac78 commit 398205b

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

block/blk-mq.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -801,9 +801,18 @@ void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async)
801801
if (unlikely(test_bit(BLK_MQ_S_STOPPED, &hctx->state)))
802802
return;
803803

804-
if (!async && cpumask_test_cpu(smp_processor_id(), hctx->cpumask))
805-
__blk_mq_run_hw_queue(hctx);
806-
else if (hctx->queue->nr_hw_queues == 1)
804+
if (!async) {
805+
preempt_disable();
806+
if (cpumask_test_cpu(smp_processor_id(), hctx->cpumask)) {
807+
__blk_mq_run_hw_queue(hctx);
808+
preempt_enable();
809+
return;
810+
}
811+
812+
preempt_enable();
813+
}
814+
815+
if (hctx->queue->nr_hw_queues == 1)
807816
kblockd_schedule_delayed_work(&hctx->run_work, 0);
808817
else {
809818
unsigned int cpu;
@@ -824,9 +833,7 @@ void blk_mq_run_queues(struct request_queue *q, bool async)
824833
test_bit(BLK_MQ_S_STOPPED, &hctx->state))
825834
continue;
826835

827-
preempt_disable();
828836
blk_mq_run_hw_queue(hctx, async);
829-
preempt_enable();
830837
}
831838
}
832839
EXPORT_SYMBOL(blk_mq_run_queues);
@@ -853,9 +860,7 @@ void blk_mq_start_hw_queue(struct blk_mq_hw_ctx *hctx)
853860
{
854861
clear_bit(BLK_MQ_S_STOPPED, &hctx->state);
855862

856-
preempt_disable();
857863
blk_mq_run_hw_queue(hctx, false);
858-
preempt_enable();
859864
}
860865
EXPORT_SYMBOL(blk_mq_start_hw_queue);
861866

@@ -880,9 +885,7 @@ void blk_mq_start_stopped_hw_queues(struct request_queue *q, bool async)
880885
continue;
881886

882887
clear_bit(BLK_MQ_S_STOPPED, &hctx->state);
883-
preempt_disable();
884888
blk_mq_run_hw_queue(hctx, async);
885-
preempt_enable();
886889
}
887890
}
888891
EXPORT_SYMBOL(blk_mq_start_stopped_hw_queues);

0 commit comments

Comments
 (0)