blob: 120c6abc37cc9d8c5b30aca520be5f99ad3f1aee [file] [log] [blame]
Jens Axboebd166ef2017-01-17 06:03:22 -07001#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 Axboebd166ef2017-01-17 06:03:22 -07007void blk_mq_sched_free_hctx_data(struct request_queue *q,
8 void (*exit)(struct blk_mq_hw_ctx *));
9
10struct request *blk_mq_sched_get_request(struct request_queue *q, struct bio *bio, unsigned int op, struct blk_mq_alloc_data *data);
11void blk_mq_sched_put_request(struct request *rq);
12
13void blk_mq_sched_request_inserted(struct request *rq);
Jens Axboee4d750c2017-02-03 09:48:28 -070014bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio,
15 struct request **merged_request);
Jens Axboebd166ef2017-01-17 06:03:22 -070016bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio);
17bool blk_mq_sched_try_insert_merge(struct request_queue *q, struct request *rq);
Bart Van Assche6d8c6c02017-04-07 12:40:09 -060018void blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx);
Jens Axboebd166ef2017-01-17 06:03:22 -070019
Jens Axboebd6737f2017-01-27 01:00:47 -070020void blk_mq_sched_insert_request(struct request *rq, bool at_head,
21 bool run_queue, bool async, bool can_block);
22void 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 Axboebd166ef2017-01-17 06:03:22 -070026void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx);
27void 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 Sandoval6917ff02017-04-05 12:01:30 -070031int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e);
Omar Sandoval54d53292017-04-07 08:52:27 -060032void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e);
Jens Axboebd166ef2017-01-17 06:03:22 -070033
Omar Sandoval93252632017-04-05 12:01:31 -070034int blk_mq_sched_init_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx,
35 unsigned int hctx_idx);
36void blk_mq_sched_exit_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx,
37 unsigned int hctx_idx);
38
Jens Axboed3484992017-01-13 14:43:58 -070039int blk_mq_sched_init(struct request_queue *q);
40
Jens Axboebd166ef2017-01-17 06:03:22 -070041static inline bool
42blk_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
52static inline int blk_mq_sched_get_rq_priv(struct request_queue *q,
Paolo Valentef1ba8262017-02-07 18:24:43 +010053 struct request *rq,
54 struct bio *bio)
Jens Axboebd166ef2017-01-17 06:03:22 -070055{
56 struct elevator_queue *e = q->elevator;
57
58 if (e && e->type->ops.mq.get_rq_priv)
Paolo Valentef1ba8262017-02-07 18:24:43 +010059 return e->type->ops.mq.get_rq_priv(q, rq, bio);
Jens Axboebd166ef2017-01-17 06:03:22 -070060
61 return 0;
62}
63
64static 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 Axboebd166ef2017-01-17 06:03:22 -070073static inline bool
74blk_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 Sandovalc05f8522017-04-14 01:00:01 -070085static inline void blk_mq_sched_completed_request(struct request *rq)
Jens Axboebd166ef2017-01-17 06:03:22 -070086{
Omar Sandovalc05f8522017-04-14 01:00:01 -070087 struct elevator_queue *e = rq->q->elevator;
Jens Axboebd166ef2017-01-17 06:03:22 -070088
89 if (e && e->type->ops.mq.completed_request)
Omar Sandovalc05f8522017-04-14 01:00:01 -070090 e->type->ops.mq.completed_request(rq);
Jens Axboebd166ef2017-01-17 06:03:22 -070091}
92
93static 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
102static 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
111static 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 Sandovald38d3512017-02-22 10:58:30 -0800121/*
122 * Mark a hardware queue as needing a restart.
123 */
124static inline void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx)
Jens Axboebd166ef2017-01-17 06:03:22 -0700125{
Omar Sandovald38d3512017-02-22 10:58:30 -0800126 if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
Jens Axboebd166ef2017-01-17 06:03:22 -0700127 set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
Omar Sandovald38d3512017-02-22 10:58:30 -0800128}
Jens Axboe50e1dab2017-01-26 14:42:34 -0700129
Jens Axboebd166ef2017-01-17 06:03:22 -0700130static 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