blob: 3a9e6e40558b599dee22115be54f5f7ce9f11080 [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
7int blk_mq_sched_init_hctx_data(struct request_queue *q, size_t size,
8 int (*init)(struct blk_mq_hw_ctx *),
9 void (*exit)(struct blk_mq_hw_ctx *));
10
11void blk_mq_sched_free_hctx_data(struct request_queue *q,
12 void (*exit)(struct blk_mq_hw_ctx *));
13
14struct request *blk_mq_sched_get_request(struct request_queue *q, struct bio *bio, unsigned int op, struct blk_mq_alloc_data *data);
15void blk_mq_sched_put_request(struct request *rq);
16
17void blk_mq_sched_request_inserted(struct request *rq);
Jens Axboee4d750c2017-02-03 09:48:28 -070018bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio,
19 struct request **merged_request);
Jens Axboebd166ef2017-01-17 06:03:22 -070020bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio);
21bool blk_mq_sched_try_insert_merge(struct request_queue *q, struct request *rq);
Bart Van Assche6d8c6c02017-04-07 12:40:09 -060022void blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx);
Jens Axboebd166ef2017-01-17 06:03:22 -070023
Jens Axboebd6737f2017-01-27 01:00:47 -070024void blk_mq_sched_insert_request(struct request *rq, bool at_head,
25 bool run_queue, bool async, bool can_block);
26void blk_mq_sched_insert_requests(struct request_queue *q,
27 struct blk_mq_ctx *ctx,
28 struct list_head *list, bool run_queue_async);
29
Jens Axboebd166ef2017-01-17 06:03:22 -070030void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx);
31void blk_mq_sched_move_to_dispatch(struct blk_mq_hw_ctx *hctx,
32 struct list_head *rq_list,
33 struct request *(*get_rq)(struct blk_mq_hw_ctx *));
34
Omar Sandoval6917ff02017-04-05 12:01:30 -070035int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e);
Omar Sandoval54d53292017-04-07 08:52:27 -060036void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e);
Jens Axboebd166ef2017-01-17 06:03:22 -070037
Omar Sandoval93252632017-04-05 12:01:31 -070038int blk_mq_sched_init_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx,
39 unsigned int hctx_idx);
40void blk_mq_sched_exit_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx,
41 unsigned int hctx_idx);
42
Jens Axboed3484992017-01-13 14:43:58 -070043int blk_mq_sched_init(struct request_queue *q);
44
Jens Axboebd166ef2017-01-17 06:03:22 -070045static inline bool
46blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio)
47{
48 struct elevator_queue *e = q->elevator;
49
50 if (!e || blk_queue_nomerges(q) || !bio_mergeable(bio))
51 return false;
52
53 return __blk_mq_sched_bio_merge(q, bio);
54}
55
56static inline int blk_mq_sched_get_rq_priv(struct request_queue *q,
Paolo Valentef1ba8262017-02-07 18:24:43 +010057 struct request *rq,
58 struct bio *bio)
Jens Axboebd166ef2017-01-17 06:03:22 -070059{
60 struct elevator_queue *e = q->elevator;
61
62 if (e && e->type->ops.mq.get_rq_priv)
Paolo Valentef1ba8262017-02-07 18:24:43 +010063 return e->type->ops.mq.get_rq_priv(q, rq, bio);
Jens Axboebd166ef2017-01-17 06:03:22 -070064
65 return 0;
66}
67
68static inline void blk_mq_sched_put_rq_priv(struct request_queue *q,
69 struct request *rq)
70{
71 struct elevator_queue *e = q->elevator;
72
73 if (e && e->type->ops.mq.put_rq_priv)
74 e->type->ops.mq.put_rq_priv(q, rq);
75}
76
Jens Axboebd166ef2017-01-17 06:03:22 -070077static inline bool
78blk_mq_sched_allow_merge(struct request_queue *q, struct request *rq,
79 struct bio *bio)
80{
81 struct elevator_queue *e = q->elevator;
82
83 if (e && e->type->ops.mq.allow_merge)
84 return e->type->ops.mq.allow_merge(q, rq, bio);
85
86 return true;
87}
88
89static inline void
90blk_mq_sched_completed_request(struct blk_mq_hw_ctx *hctx, struct request *rq)
91{
92 struct elevator_queue *e = hctx->queue->elevator;
93
94 if (e && e->type->ops.mq.completed_request)
95 e->type->ops.mq.completed_request(hctx, rq);
96
97 BUG_ON(rq->internal_tag == -1);
98
99 blk_mq_put_tag(hctx, hctx->sched_tags, rq->mq_ctx, rq->internal_tag);
Jens Axboebd166ef2017-01-17 06:03:22 -0700100}
101
102static inline void blk_mq_sched_started_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.started_request)
108 e->type->ops.mq.started_request(rq);
109}
110
111static inline void blk_mq_sched_requeue_request(struct request *rq)
112{
113 struct request_queue *q = rq->q;
114 struct elevator_queue *e = q->elevator;
115
116 if (e && e->type->ops.mq.requeue_request)
117 e->type->ops.mq.requeue_request(rq);
118}
119
120static inline bool blk_mq_sched_has_work(struct blk_mq_hw_ctx *hctx)
121{
122 struct elevator_queue *e = hctx->queue->elevator;
123
124 if (e && e->type->ops.mq.has_work)
125 return e->type->ops.mq.has_work(hctx);
126
127 return false;
128}
129
Omar Sandovald38d3512017-02-22 10:58:30 -0800130/*
131 * Mark a hardware queue as needing a restart.
132 */
133static inline void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx)
Jens Axboebd166ef2017-01-17 06:03:22 -0700134{
Omar Sandovald38d3512017-02-22 10:58:30 -0800135 if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
Jens Axboebd166ef2017-01-17 06:03:22 -0700136 set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
Omar Sandovald38d3512017-02-22 10:58:30 -0800137}
Jens Axboe50e1dab2017-01-26 14:42:34 -0700138
Jens Axboebd166ef2017-01-17 06:03:22 -0700139static inline bool blk_mq_sched_needs_restart(struct blk_mq_hw_ctx *hctx)
140{
141 return test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
142}
143
144#endif