History

block: move poll code to blk-mq

The poll code is blk-mq specific, let's move it to blk-mq.c. This is a prep patch for improving the polling code.

Jens Axboe committed 10 years ago

Commit bbd7bb71 parent b425b025 files · +57 −49Browse files

Unified · Split

5 files
  1. block/blk-core.c +0 −46
  2. block/blk-mq.c +54 −0
  3. drivers/nvme/target/io-cmd.c +1 −1
  4. fs/direct-io.c +1 −1
  5. include/linux/blkdev.h +1 −1
block/blk-core.c+0−46
@@ -3312,52 +3312,6 @@ void blk_finish_plug(struct blk_plug *plug) · 3311 unmodified lines
33123312 }
33133313 EXPORT_SYMBOL(blk_finish_plug);
33143314
3315−bool blk_poll(struct request_queue *q, blk_qc_t cookie)
3316−{
3317− struct blk_plug *plug;
3318− long state;
3319− unsigned int queue_num;
3320− struct blk_mq_hw_ctx *hctx;
3321−
3322− if (!q->mq_ops || !q->mq_ops->poll || !blk_qc_t_valid(cookie) ||
3323− !test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
3324− return false;
3325−
3326− queue_num = blk_qc_t_to_queue_num(cookie);
3327− hctx = q->queue_hw_ctx[queue_num];
3328− hctx->poll_considered++;
3329−
3330− plug = current->plug;
3331− if (plug)
3332− blk_flush_plug_list(plug, false);
3333−
3334− state = current->state;
3335− while (!need_resched()) {
3336− int ret;
3337−
3338− hctx->poll_invoked++;
3339−
3340− ret = q->mq_ops->poll(hctx, blk_qc_t_to_tag(cookie));
3341− if (ret > 0) {
3342− hctx->poll_success++;
3343− set_current_state(TASK_RUNNING);
3344− return true;
3345− }
3346−
3347− if (signal_pending_state(state, current))
3348− set_current_state(TASK_RUNNING);
3349−
3350− if (current->state == TASK_RUNNING)
3351− return true;
3352− if (ret < 0)
3353− break;
3354− cpu_relax();
3355− }
3356−
3357− return false;
3358−}
3359−EXPORT_SYMBOL_GPL(blk_poll);
3360−
33613315 #ifdef CONFIG_PM
33623316 /**
33633317 * blk_pm_runtime_init - Block layer runtime PM initialization routine
block/blk-mq.c+54−0
@@ -2461,6 +2461,60 @@ void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queues) · 2460 unmodified lines
24612461 }
24622462 EXPORT_SYMBOL_GPL(blk_mq_update_nr_hw_queues);
24632463
2464+static bool __blk_mq_poll(struct blk_mq_hw_ctx *hctx, struct request *rq)
2465+{
2466+ struct request_queue *q = hctx->queue;
2467+ long state;
2468+
2469+ hctx->poll_considered++;
2470+
2471+ state = current->state;
2472+ while (!need_resched()) {
2473+ int ret;
2474+
2475+ hctx->poll_invoked++;
2476+
2477+ ret = q->mq_ops->poll(hctx, rq->tag);
2478+ if (ret > 0) {
2479+ hctx->poll_success++;
2480+ set_current_state(TASK_RUNNING);
2481+ return true;
2482+ }
2483+
2484+ if (signal_pending_state(state, current))
2485+ set_current_state(TASK_RUNNING);
2486+
2487+ if (current->state == TASK_RUNNING)
2488+ return true;
2489+ if (ret < 0)
2490+ break;
2491+ cpu_relax();
2492+ }
2493+
2494+ return false;
2495+}
2496+
2497+bool blk_mq_poll(struct request_queue *q, blk_qc_t cookie)
2498+{
2499+ struct blk_mq_hw_ctx *hctx;
2500+ struct blk_plug *plug;
2501+ struct request *rq;
2502+
2503+ if (!q->mq_ops || !q->mq_ops->poll || !blk_qc_t_valid(cookie) ||
2504+ !test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
2505+ return false;
2506+
2507+ plug = current->plug;
2508+ if (plug)
2509+ blk_flush_plug_list(plug, false);
2510+
2511+ hctx = q->queue_hw_ctx[blk_qc_t_to_queue_num(cookie)];
2512+ rq = blk_mq_tag_to_rq(hctx->tags, blk_qc_t_to_tag(cookie));
2513+
2514+ return __blk_mq_poll(hctx, rq);
2515+}
2516+EXPORT_SYMBOL_GPL(blk_mq_poll);
2517+
24642518 void blk_mq_disable_hotplug(void)
24652519 {
24662520 mutex_lock(&all_q_mutex);
drivers/nvme/target/io-cmd.c+1−1
@@ -96,7 +96,7 @@ static void nvmet_execute_rw(struct nvmet_req *req) · 95 unmodified lines
9696
9797 cookie = submit_bio(bio);
9898
99− blk_poll(bdev_get_queue(req->ns->bdev), cookie);
99+ blk_mq_poll(bdev_get_queue(req->ns->bdev), cookie);
100100 }
101101
102102 static void nvmet_execute_flush(struct nvmet_req *req)
fs/direct-io.c+1−1
@@ -457,7 +457,7 @@ static struct bio *dio_await_one(struct dio *dio) · 456 unmodified lines
457457 dio->waiter = current;
458458 spin_unlock_irqrestore(&dio->bio_lock, flags);
459459 if (!(dio->iocb->ki_flags & IOCB_HIPRI) ||
460− !blk_poll(bdev_get_queue(dio->bio_bdev), dio->bio_cookie))
460+ !blk_mq_poll(bdev_get_queue(dio->bio_bdev), dio->bio_cookie))
461461 io_schedule();
462462 /* wake up sets us TASK_RUNNING */
463463 spin_lock_irqsave(&dio->bio_lock, flags);
include/linux/blkdev.h+1−1
@@ -952,7 +952,7 @@ extern int blk_execute_rq(struct request_queue *, struct gendisk *, · 951 unmodified lines
952952 extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *,
953953 struct request *, int, rq_end_io_fn *);
954954
955−bool blk_poll(struct request_queue *q, blk_qc_t cookie);
955+bool blk_mq_poll(struct request_queue *q, blk_qc_t cookie);
956956
957957 static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
958958 {