blk-mq: avoid to write intermediate result to hctx->next_cpu

This patch figures out the final selected CPU, then writes
it to hctx->next_cpu once, then we can avoid to intermediate
next cpu observed from other dispatch paths.

Cc: Stefan Haberland <sth@linux.vnet.ibm.com>
Tested-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Ming Lei 2018-04-08 17:48:09 +08:00 коммит произвёл Jens Axboe
Родитель bffa9909a6
Коммит 476f8c98a9
1 изменённых файлов: 9 добавлений и 8 удалений

Просмотреть файл

@ -1344,26 +1344,24 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx)
static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx) static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx *hctx)
{ {
bool tried = false; bool tried = false;
int next_cpu = hctx->next_cpu;
if (hctx->queue->nr_hw_queues == 1) if (hctx->queue->nr_hw_queues == 1)
return WORK_CPU_UNBOUND; return WORK_CPU_UNBOUND;
if (--hctx->next_cpu_batch <= 0) { if (--hctx->next_cpu_batch <= 0) {
int next_cpu;
select_cpu: select_cpu:
next_cpu = cpumask_next_and(hctx->next_cpu, hctx->cpumask, next_cpu = cpumask_next_and(next_cpu, hctx->cpumask,
cpu_online_mask); cpu_online_mask);
if (next_cpu >= nr_cpu_ids) if (next_cpu >= nr_cpu_ids)
next_cpu = cpumask_first_and(hctx->cpumask,cpu_online_mask); next_cpu = cpumask_first_and(hctx->cpumask, cpu_online_mask);
/* /*
* No online CPU is found, so have to make sure hctx->next_cpu * No online CPU is found, so have to make sure hctx->next_cpu
* is set correctly for not breaking workqueue. * is set correctly for not breaking workqueue.
*/ */
if (next_cpu >= nr_cpu_ids) if (next_cpu >= nr_cpu_ids)
hctx->next_cpu = cpumask_first(hctx->cpumask); next_cpu = cpumask_first(hctx->cpumask);
else
hctx->next_cpu = next_cpu;
hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH; hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH;
} }
@ -1371,7 +1369,7 @@ select_cpu:
* Do unbound schedule if we can't find a online CPU for this hctx, * Do unbound schedule if we can't find a online CPU for this hctx,
* and it should only happen in the path of handling CPU DEAD. * and it should only happen in the path of handling CPU DEAD.
*/ */
if (!cpu_online(hctx->next_cpu)) { if (!cpu_online(next_cpu)) {
if (!tried) { if (!tried) {
tried = true; tried = true;
goto select_cpu; goto select_cpu;
@ -1381,10 +1379,13 @@ select_cpu:
* Make sure to re-select CPU next time once after CPUs * Make sure to re-select CPU next time once after CPUs
* in hctx->cpumask become online again. * in hctx->cpumask become online again.
*/ */
hctx->next_cpu = next_cpu;
hctx->next_cpu_batch = 1; hctx->next_cpu_batch = 1;
return WORK_CPU_UNBOUND; return WORK_CPU_UNBOUND;
} }
return hctx->next_cpu;
hctx->next_cpu = next_cpu;
return next_cpu;
} }
static void __blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async, static void __blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async,