blob: 873f9af5a35bebd57f9a83555cda6461aa9b6990 [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);
Jens Axboe50e1dab2017-01-26 14:42:34 -070022void blk_mq_sched_restart_queues(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);
Jens Axboebd166ef2017-01-17 06:03:22 -070036void blk_mq_sched_teardown(struct request_queue *q);
37
Jens Axboed3484992017-01-13 14:43:58 -070038int blk_mq_sched_init(struct request_queue *q);
39
Jens Axboebd166ef2017-01-17 06:03:22 -070040static inline bool
41blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio)
42{
43 struct elevator_queue *e = q->elevator;
44
45 if (!e || blk_queue_nomerges(q) || !bio_mergeable(bio))
46 return false;
47
48 return __blk_mq_sched_bio_merge(q, bio);
49}
50
51static inline int blk_mq_sched_get_rq_priv(struct request_queue *q,
Paolo Valentef1ba8262017-02-07 18:24:43 +010052 struct request *rq,
53 struct bio *bio)
Jens Axboebd166ef2017-01-17 06:03:22 -070054{
55 struct elevator_queue *e = q->elevator;
56
57 if (e && e->type->ops.mq.get_rq_priv)
Paolo Valentef1ba8262017-02-07 18:24:43 +010058 return e->type->ops.mq.get_rq_priv(q, rq, bio);
Jens Axboebd166ef2017-01-17 06:03:22 -070059
60 return 0;
61}
62
63static inline void blk_mq_sched_put_rq_priv(struct request_queue *q,
64 struct request *rq)
65{
66 struct elevator_queue *e = q->elevator;
67
68 if (e && e->type->ops.mq.put_rq_priv)
69 e->type->ops.mq.put_rq_priv(q, rq);
70}
71
Jens Axboebd166ef2017-01-17 06:03:22 -070072static inline bool
73blk_mq_sched_allow_merge(struct request_queue *q, struct request *rq,
74 struct bio *bio)
75{
76 struct elevator_queue *e = q->elevator;
77
78 if (e && e->type->ops.mq.allow_merge)
79 return e->type->ops.mq.allow_merge(q, rq, bio);
80
81 return true;
82}
83
84static inline void
85blk_mq_sched_completed_request(struct blk_mq_hw_ctx *hctx, struct request *rq)
86{
87 struct elevator_queue *e = hctx->queue->elevator;
88
89 if (e && e->type->ops.mq.completed_request)
90 e->type->ops.mq.completed_request(hctx, rq);
91
92 BUG_ON(rq->internal_tag == -1);
93
94 blk_mq_put_tag(hctx, hctx->sched_tags, rq->mq_ctx, rq->internal_tag);
Jens Axboebd166ef2017-01-17 06:03:22 -070095}
96
97static inline void blk_mq_sched_started_request(struct request *rq)
98{
99 struct request_queue *q = rq->q;
100 struct elevator_queue *e = q->elevator;
101
102 if (e && e->type->ops.mq.started_request)
103 e->type->ops.mq.started_request(rq);
104}
105
106static inline void blk_mq_sched_requeue_request(struct request *rq)
107{
108 struct request_queue *q = rq->q;
109 struct elevator_queue *e = q->elevator;
110
111 if (e && e->type->ops.mq.requeue_request)
112 e->type->ops.mq.requeue_request(rq);
113}
114
115static inline bool blk_mq_sched_has_work(struct blk_mq_hw_ctx *hctx)
116{
117 struct elevator_queue *e = hctx->queue->elevator;
118
119 if (e && e->type->ops.mq.has_work)
120 return e->type->ops.mq.has_work(hctx);
121
122 return false;
123}
124
Omar Sandovald38d3512017-02-22 10:58:30 -0800125/*
126 * Mark a hardware queue as needing a restart.
127 */
128static inline void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx)
Jens Axboebd166ef2017-01-17 06:03:22 -0700129{
Omar Sandovald38d3512017-02-22 10:58:30 -0800130 if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
Jens Axboebd166ef2017-01-17 06:03:22 -0700131 set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
Omar Sandovald38d3512017-02-22 10:58:30 -0800132}
Jens Axboe50e1dab2017-01-26 14:42:34 -0700133
Omar Sandovald38d3512017-02-22 10:58:30 -0800134/*
135 * Mark a hardware queue and the request queue it belongs to as needing a
136 * restart.
137 */
138static inline void blk_mq_sched_mark_restart_queue(struct blk_mq_hw_ctx *hctx)
139{
140 struct request_queue *q = hctx->queue;
141
142 if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
143 set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
144 if (!test_bit(QUEUE_FLAG_RESTART, &q->queue_flags))
145 set_bit(QUEUE_FLAG_RESTART, &q->queue_flags);
Jens Axboebd166ef2017-01-17 06:03:22 -0700146}
147
148static inline bool blk_mq_sched_needs_restart(struct blk_mq_hw_ctx *hctx)
149{
150 return test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
151}
152
153#endif