summaryrefslogtreecommitdiffstats
path: root/block/blk-mq.c
diff options
context:
space:
mode:
authorJens Axboe <axboe@fb.com>2017-04-10 11:54:56 -0400
committerJens Axboe <axboe@fb.com>2017-04-28 10:11:43 -0400
commit21c6e939a9f6bb06fe616a87defec0f92a7c3df0 (patch)
tree4313793669d17a93b634236023d5ad3cf1c5ee22 /block/blk-mq.c
parent818cd1cbaa7b00bbc35452a76bebc681a65f1912 (diff)
blk-mq: unify hctx delay_work and run_work
The only difference between ->run_work and ->delay_work, is that the latter is used to defer running a queue. This is done by marking the queue stopped, and scheduling ->delay_work to run sometime in the future. While the queue is stopped, direct runs or runs through ->run_work will not run the queue. If we combine the handlers, then we need to handle two things: 1) If a delayed/stopped run is scheduled, then we should not run the queue before that has been completed. 2) If a queue is delayed/stopped, the handler needs to restart the queue. Normally a run of a queue with the stopped bit set would be a no-op. Case 1 is handled by modifying a currently pending queue run to the deadline set by the caller of blk_mq_delay_queue(). Subsequent attempts to queue a queue run will find the work item already pending, and direct runs will see a stopped queue as before. Case 2 is handled by adding a new bit, BLK_MQ_S_START_ON_RUN, that tells the work handler that it should clear a stopped queue and run the handler. Reviewed-by: Bart Van Assche <Bart.VanAssche@sandisk.com> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block/blk-mq.c')
-rw-r--r--block/blk-mq.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 5c68fce87ffc..a0bdf63aebfe 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1221,7 +1221,6 @@ EXPORT_SYMBOL(blk_mq_queue_stopped);
1221void blk_mq_stop_hw_queue(struct blk_mq_hw_ctx *hctx) 1221void blk_mq_stop_hw_queue(struct blk_mq_hw_ctx *hctx)
1222{ 1222{
1223 cancel_delayed_work_sync(&hctx->run_work); 1223 cancel_delayed_work_sync(&hctx->run_work);
1224 cancel_delayed_work(&hctx->delay_work);
1225 set_bit(BLK_MQ_S_STOPPED, &hctx->state); 1224 set_bit(BLK_MQ_S_STOPPED, &hctx->state);
1226} 1225}
1227EXPORT_SYMBOL(blk_mq_stop_hw_queue); 1226EXPORT_SYMBOL(blk_mq_stop_hw_queue);
@@ -1279,27 +1278,39 @@ static void blk_mq_run_work_fn(struct work_struct *work)
1279 struct blk_mq_hw_ctx *hctx; 1278 struct blk_mq_hw_ctx *hctx;
1280 1279
1281 hctx = container_of(work, struct blk_mq_hw_ctx, run_work.work); 1280 hctx = container_of(work, struct blk_mq_hw_ctx, run_work.work);
1282 __blk_mq_run_hw_queue(hctx);
1283}
1284 1281
1285static void blk_mq_delay_work_fn(struct work_struct *work) 1282 /*
1286{ 1283 * If we are stopped, don't run the queue. The exception is if
1287 struct blk_mq_hw_ctx *hctx; 1284 * BLK_MQ_S_START_ON_RUN is set. For that case, we auto-clear
1285 * the STOPPED bit and run it.
1286 */
1287 if (test_bit(BLK_MQ_S_STOPPED, &hctx->state)) {
1288 if (!test_bit(BLK_MQ_S_START_ON_RUN, &hctx->state))
1289 return;
1288 1290
1289 hctx = container_of(work, struct blk_mq_hw_ctx, delay_work.work); 1291 clear_bit(BLK_MQ_S_START_ON_RUN, &hctx->state);
1292 clear_bit(BLK_MQ_S_STOPPED, &hctx->state);
1293 }
1290 1294
1291 if (test_and_clear_bit(BLK_MQ_S_STOPPED, &hctx->state)) 1295 __blk_mq_run_hw_queue(hctx);
1292 __blk_mq_run_hw_queue(hctx);
1293} 1296}
1294 1297
1298
1295void blk_mq_delay_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs) 1299void blk_mq_delay_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs)
1296{ 1300{
1297 if (unlikely(!blk_mq_hw_queue_mapped(hctx))) 1301 if (unlikely(!blk_mq_hw_queue_mapped(hctx)))
1298 return; 1302 return;
1299 1303
1304 /*
1305 * Stop the hw queue, then modify currently delayed work.
1306 * This should prevent us from running the queue prematurely.
1307 * Mark the queue as auto-clearing STOPPED when it runs.
1308 */
1300 blk_mq_stop_hw_queue(hctx); 1309 blk_mq_stop_hw_queue(hctx);
1301 kblockd_schedule_delayed_work_on(blk_mq_hctx_next_cpu(hctx), 1310 set_bit(BLK_MQ_S_START_ON_RUN, &hctx->state);
1302 &hctx->delay_work, msecs_to_jiffies(msecs)); 1311 kblockd_mod_delayed_work_on(blk_mq_hctx_next_cpu(hctx),
1312 &hctx->run_work,
1313 msecs_to_jiffies(msecs));
1303} 1314}
1304EXPORT_SYMBOL(blk_mq_delay_queue); 1315EXPORT_SYMBOL(blk_mq_delay_queue);
1305 1316
@@ -1885,7 +1896,6 @@ static int blk_mq_init_hctx(struct request_queue *q,
1885 node = hctx->numa_node = set->numa_node; 1896 node = hctx->numa_node = set->numa_node;
1886 1897
1887 INIT_DELAYED_WORK(&hctx->run_work, blk_mq_run_work_fn); 1898 INIT_DELAYED_WORK(&hctx->run_work, blk_mq_run_work_fn);
1888 INIT_DELAYED_WORK(&hctx->delay_work, blk_mq_delay_work_fn);
1889 spin_lock_init(&hctx->lock); 1899 spin_lock_init(&hctx->lock);
1890 INIT_LIST_HEAD(&hctx->dispatch); 1900 INIT_LIST_HEAD(&hctx->dispatch);
1891 hctx->queue = q; 1901 hctx->queue = q;