diff options
| author | Ming Lei <ming.lei@redhat.com> | 2018-04-08 05:48:10 -0400 |
|---|---|---|
| committer | Jens Axboe <axboe@kernel.dk> | 2018-04-10 10:38:46 -0400 |
| commit | f82ddf1923b90f89665d08cf219287c8f9deb739 (patch) | |
| tree | 24becd9e5556a348cf23859eea2dbe5acb020e59 | |
| parent | 476f8c98a9bccccbb97866974ffc80879adf2bbb (diff) | |
blk-mq: introduce blk_mq_hw_queue_first_cpu() to figure out first cpu
This patch introduces helper of blk_mq_hw_queue_first_cpu() for
figuring out the hctx's first cpu, and code duplication can be
avoided.
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>
| -rw-r--r-- | block/blk-mq.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/block/blk-mq.c b/block/blk-mq.c index db178c577068..e05bd10d5c84 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c | |||
| @@ -1335,6 +1335,15 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx) | |||
| 1335 | hctx_unlock(hctx, srcu_idx); | 1335 | hctx_unlock(hctx, srcu_idx); |
| 1336 | } | 1336 | } |
| 1337 | 1337 | ||
| 1338 | static inline int blk_mq_first_mapped_cpu(struct blk_mq_hw_ctx *hctx) | ||
| 1339 | { | ||
| 1340 | int cpu = cpumask_first_and(hctx->cpumask, cpu_online_mask); | ||
| 1341 | |||
| 1342 | if (cpu >= nr_cpu_ids) | ||
| 1343 | cpu = cpumask_first(hctx->cpumask); | ||
| 1344 | return cpu; | ||
| 1345 | } | ||
| 1346 | |||
| 1338 | /* | 1347 | /* |
| 1339 | * It'd be great if the workqueue API had a way to pass | 1348 | * It'd be great if the workqueue API had a way to pass |
| 1340 | * in a mask and had some smarts for more clever placement. | 1349 | * in a mask and had some smarts for more clever placement. |
| @@ -1354,14 +1363,7 @@ select_cpu: | |||
| 1354 | next_cpu = cpumask_next_and(next_cpu, hctx->cpumask, | 1363 | next_cpu = cpumask_next_and(next_cpu, hctx->cpumask, |
| 1355 | cpu_online_mask); | 1364 | cpu_online_mask); |
| 1356 | if (next_cpu >= nr_cpu_ids) | 1365 | if (next_cpu >= nr_cpu_ids) |
| 1357 | next_cpu = cpumask_first_and(hctx->cpumask, cpu_online_mask); | 1366 | next_cpu = blk_mq_first_mapped_cpu(hctx); |
| 1358 | |||
| 1359 | /* | ||
| 1360 | * No online CPU is found, so have to make sure hctx->next_cpu | ||
| 1361 | * is set correctly for not breaking workqueue. | ||
| 1362 | */ | ||
| 1363 | if (next_cpu >= nr_cpu_ids) | ||
| 1364 | next_cpu = cpumask_first(hctx->cpumask); | ||
| 1365 | hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH; | 1367 | hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH; |
| 1366 | } | 1368 | } |
| 1367 | 1369 | ||
| @@ -2430,10 +2432,7 @@ static void blk_mq_map_swqueue(struct request_queue *q) | |||
| 2430 | /* | 2432 | /* |
| 2431 | * Initialize batch roundrobin counts | 2433 | * Initialize batch roundrobin counts |
| 2432 | */ | 2434 | */ |
| 2433 | hctx->next_cpu = cpumask_first_and(hctx->cpumask, | 2435 | hctx->next_cpu = blk_mq_first_mapped_cpu(hctx); |
| 2434 | cpu_online_mask); | ||
| 2435 | if (hctx->next_cpu >= nr_cpu_ids) | ||
| 2436 | hctx->next_cpu = cpumask_first(hctx->cpumask); | ||
| 2437 | hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH; | 2436 | hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH; |
| 2438 | } | 2437 | } |
| 2439 | } | 2438 | } |
