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); |
| 27 | void blk_mq_sched_move_to_dispatch(struct blk_mq_hw_ctx *hctx, |
| 28 | struct list_head *rq_list, |
| 29 | struct request *(*get_rq)(struct blk_mq_hw_ctx *)); |
| 30 | |
Omar Sandoval | 6917ff0 | 2017-04-05 12:01:30 -0700 | [diff] [blame] | 31 | 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] | 32 | 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] | 33 | |
Omar Sandoval | 9325263 | 2017-04-05 12:01:31 -0700 | [diff] [blame] | 34 | int blk_mq_sched_init_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx, |
| 35 | unsigned int hctx_idx); |
| 36 | void blk_mq_sched_exit_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx, |
| 37 | unsigned int hctx_idx); |
| 38 | |
Jens Axboe | d348499 | 2017-01-13 14:43:58 -0700 | [diff] [blame] | 39 | int blk_mq_sched_init(struct request_queue *q); |
| 40 | |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 41 | static inline bool |
| 42 | blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio) |
| 43 | { |
| 44 | struct elevator_queue *e = q->elevator; |
| 45 | |
| 46 | if (!e || blk_queue_nomerges(q) || !bio_mergeable(bio)) |
| 47 | return false; |
| 48 | |
| 49 | return __blk_mq_sched_bio_merge(q, bio); |
| 50 | } |
| 51 | |
| 52 | 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] | 53 | struct request *rq, |
| 54 | struct bio *bio) |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 55 | { |
| 56 | struct elevator_queue *e = q->elevator; |
| 57 | |
| 58 | if (e && e->type->ops.mq.get_rq_priv) |
Paolo Valente | f1ba826 | 2017-02-07 18:24:43 +0100 | [diff] [blame] | 59 | return e->type->ops.mq.get_rq_priv(q, rq, bio); |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static inline void blk_mq_sched_put_rq_priv(struct request_queue *q, |
| 65 | struct request *rq) |
| 66 | { |
| 67 | struct elevator_queue *e = q->elevator; |
| 68 | |
| 69 | if (e && e->type->ops.mq.put_rq_priv) |
| 70 | e->type->ops.mq.put_rq_priv(q, rq); |
| 71 | } |
| 72 | |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 73 | static inline bool |
| 74 | blk_mq_sched_allow_merge(struct request_queue *q, struct request *rq, |
| 75 | struct bio *bio) |
| 76 | { |
| 77 | struct elevator_queue *e = q->elevator; |
| 78 | |
| 79 | if (e && e->type->ops.mq.allow_merge) |
| 80 | return e->type->ops.mq.allow_merge(q, rq, bio); |
| 81 | |
| 82 | return true; |
| 83 | } |
| 84 | |
Omar Sandoval | c05f852 | 2017-04-14 01:00:01 -0700 | [diff] [blame^] | 85 | static inline void blk_mq_sched_completed_request(struct request *rq) |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 86 | { |
Omar Sandoval | c05f852 | 2017-04-14 01:00:01 -0700 | [diff] [blame^] | 87 | struct elevator_queue *e = rq->q->elevator; |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 88 | |
| 89 | if (e && e->type->ops.mq.completed_request) |
Omar Sandoval | c05f852 | 2017-04-14 01:00:01 -0700 | [diff] [blame^] | 90 | e->type->ops.mq.completed_request(rq); |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static inline void blk_mq_sched_started_request(struct request *rq) |
| 94 | { |
| 95 | struct request_queue *q = rq->q; |
| 96 | struct elevator_queue *e = q->elevator; |
| 97 | |
| 98 | if (e && e->type->ops.mq.started_request) |
| 99 | e->type->ops.mq.started_request(rq); |
| 100 | } |
| 101 | |
| 102 | static inline void blk_mq_sched_requeue_request(struct request *rq) |
| 103 | { |
| 104 | struct request_queue *q = rq->q; |
| 105 | struct elevator_queue *e = q->elevator; |
| 106 | |
| 107 | if (e && e->type->ops.mq.requeue_request) |
| 108 | e->type->ops.mq.requeue_request(rq); |
| 109 | } |
| 110 | |
| 111 | static inline bool blk_mq_sched_has_work(struct blk_mq_hw_ctx *hctx) |
| 112 | { |
| 113 | struct elevator_queue *e = hctx->queue->elevator; |
| 114 | |
| 115 | if (e && e->type->ops.mq.has_work) |
| 116 | return e->type->ops.mq.has_work(hctx); |
| 117 | |
| 118 | return false; |
| 119 | } |
| 120 | |
Omar Sandoval | d38d351 | 2017-02-22 10:58:30 -0800 | [diff] [blame] | 121 | /* |
| 122 | * Mark a hardware queue as needing a restart. |
| 123 | */ |
| 124 | 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] | 125 | { |
Omar Sandoval | d38d351 | 2017-02-22 10:58:30 -0800 | [diff] [blame] | 126 | if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state)) |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 127 | set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state); |
Omar Sandoval | d38d351 | 2017-02-22 10:58:30 -0800 | [diff] [blame] | 128 | } |
Jens Axboe | 50e1dab | 2017-01-26 14:42:34 -0700 | [diff] [blame] | 129 | |
Jens Axboe | bd166ef | 2017-01-17 06:03:22 -0700 | [diff] [blame] | 130 | static inline bool blk_mq_sched_needs_restart(struct blk_mq_hw_ctx *hctx) |
| 131 | { |
| 132 | return test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state); |
| 133 | } |
| 134 | |
| 135 | #endif |