Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 1 | #ifndef BLK_MQ_SCHED_H |
| 2 | #define BLK_MQ_SCHED_H |
| 3 | |
| 4 | #include "blk-mq.h" |
| 5 | #include "blk-mq-tag.h" |
| 6 | |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 7 | void blk_mq_sched_free_hctx_data(struct request_queue *q, |
| 8 | void (*exit)(struct blk_mq_hw_ctx *)); |
| 9 | |
| 10 | struct request *blk_mq_sched_get_request(struct request_queue *q, struct bio *bio, unsigned int op, struct blk_mq_alloc_data *data); |
| 11 | void blk_mq_sched_put_request(struct request *rq); |
| 12 | |
| 13 | void blk_mq_sched_request_inserted(struct request *rq); |
Jens Axboe | e4d750c | 2017-02-03 09:48:28 -0700 | [diff] [blame] | 14 | bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio, |
| 15 | struct request **merged_request); |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 16 | bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio); |
| 17 | bool blk_mq_sched_try_insert_merge(struct request_queue *q, struct request *rq); |
Bart Van Assche | 6d8c6c0 | 2017-04-07 12:40:09 -0600 | [diff] [blame] | 18 | void blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx); |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 19 | |
Jens Axboe | bd6737f | 2017-01-27 01:00:47 -0700 | [diff] [blame] | 20 | void blk_mq_sched_insert_request(struct request *rq, bool at_head, |
| 21 | bool run_queue, bool async, bool can_block); |
| 22 | void blk_mq_sched_insert_requests(struct request_queue *q, |
| 23 | struct blk_mq_ctx *ctx, |
| 24 | struct list_head *list, bool run_queue_async); |
| 25 | |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 26 | void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx); |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 27 | |
Omar Sandoval | 6917ff0 | 2017-04-05 12:01:30 -0700 | [diff] [blame] | 28 | int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e); |
Omar Sandoval | 54d5329 | 2017-04-07 08:52:27 -0600 | [diff] [blame] | 29 | void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e); |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 30 | |
Omar Sandoval | 9325263 | 2017-04-05 12:01:31 -0700 | [diff] [blame] | 31 | int blk_mq_sched_init_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx, |
| 32 | unsigned int hctx_idx); |
| 33 | void blk_mq_sched_exit_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx, |
| 34 | unsigned int hctx_idx); |
| 35 | |
Jens Axboe | d348499 | 2017-01-13 14:43:58 -0700 | [diff] [blame] | 36 | int blk_mq_sched_init(struct request_queue *q); |
| 37 | |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 38 | static inline bool |
| 39 | blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio) |
| 40 | { |
| 41 | struct elevator_queue *e = q->elevator; |
| 42 | |
| 43 | if (!e || blk_queue_nomerges(q) || !bio_mergeable(bio)) |
| 44 | return false; |
| 45 | |
| 46 | return __blk_mq_sched_bio_merge(q, bio); |
| 47 | } |
| 48 | |
| 49 | static inline int blk_mq_sched_get_rq_priv(struct request_queue *q, |
Paolo Valente | f1ba826 | 2017-02-07 18:24:43 +0100 | [diff] [blame] | 50 | struct request *rq, |
| 51 | struct bio *bio) |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 52 | { |
| 53 | struct elevator_queue *e = q->elevator; |
| 54 | |
| 55 | if (e && e->type->ops.mq.get_rq_priv) |
Paolo Valente | f1ba826 | 2017-02-07 18:24:43 +0100 | [diff] [blame] | 56 | return e->type->ops.mq.get_rq_priv(q, rq, bio); |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static inline void blk_mq_sched_put_rq_priv(struct request_queue *q, |
| 62 | struct request *rq) |
| 63 | { |
| 64 | struct elevator_queue *e = q->elevator; |
| 65 | |
| 66 | if (e && e->type->ops.mq.put_rq_priv) |
| 67 | e->type->ops.mq.put_rq_priv(q, rq); |
| 68 | } |
| 69 | |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 70 | static inline bool |
| 71 | blk_mq_sched_allow_merge(struct request_queue *q, struct request *rq, |
| 72 | struct bio *bio) |
| 73 | { |
| 74 | struct elevator_queue *e = q->elevator; |
| 75 | |
| 76 | if (e && e->type->ops.mq.allow_merge) |
| 77 | return e->type->ops.mq.allow_merge(q, rq, bio); |
| 78 | |
| 79 | return true; |
| 80 | } |
| 81 | |
Omar Sandoval | c05f852 | 2017-04-14 01:00:01 -0700 | [diff] [blame] | 82 | static inline void blk_mq_sched_completed_request(struct request *rq) |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 83 | { |
Omar Sandoval | c05f852 | 2017-04-14 01:00:01 -0700 | [diff] [blame] | 84 | struct elevator_queue *e = rq->q->elevator; |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 85 | |
| 86 | if (e && e->type->ops.mq.completed_request) |
Omar Sandoval | c05f852 | 2017-04-14 01:00:01 -0700 | [diff] [blame] | 87 | e->type->ops.mq.completed_request(rq); |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static inline void blk_mq_sched_started_request(struct request *rq) |
| 91 | { |
| 92 | struct request_queue *q = rq->q; |
| 93 | struct elevator_queue *e = q->elevator; |
| 94 | |
| 95 | if (e && e->type->ops.mq.started_request) |
| 96 | e->type->ops.mq.started_request(rq); |
| 97 | } |
| 98 | |
| 99 | static inline void blk_mq_sched_requeue_request(struct request *rq) |
| 100 | { |
| 101 | struct request_queue *q = rq->q; |
| 102 | struct elevator_queue *e = q->elevator; |
| 103 | |
| 104 | if (e && e->type->ops.mq.requeue_request) |
| 105 | e->type->ops.mq.requeue_request(rq); |
| 106 | } |
| 107 | |
| 108 | static inline bool blk_mq_sched_has_work(struct blk_mq_hw_ctx *hctx) |
| 109 | { |
| 110 | struct elevator_queue *e = hctx->queue->elevator; |
| 111 | |
| 112 | if (e && e->type->ops.mq.has_work) |
| 113 | return e->type->ops.mq.has_work(hctx); |
| 114 | |
| 115 | return false; |
| 116 | } |
| 117 | |
Omar Sandoval | d38d351 | 2017-02-22 10:58:30 -0800 | [diff] [blame] | 118 | /* |
| 119 | * Mark a hardware queue as needing a restart. |
| 120 | */ |
| 121 | static inline void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx) |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 122 | { |
Omar Sandoval | d38d351 | 2017-02-22 10:58:30 -0800 | [diff] [blame] | 123 | if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state)) |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 124 | set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state); |
Omar Sandoval | d38d351 | 2017-02-22 10:58:30 -0800 | [diff] [blame] | 125 | } |
Jens Axboe | 50e1dab | 2017-01-26 14:42:34 -0700 | [diff] [blame] | 126 | |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 127 | static inline bool blk_mq_sched_needs_restart(struct blk_mq_hw_ctx *hctx) |
| 128 | { |
| 129 | return test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state); |
| 130 | } |
| 131 | |
| 132 | #endif |