blob: 6e09e98b93eae8630326a73ee78242f8438c918f [file] [log] [blame]
Josef Bacika7905042018-07-03 09:32:35 -06001#ifndef RQ_QOS_H
2#define RQ_QOS_H
3
4#include <linux/kernel.h>
5#include <linux/blkdev.h>
6#include <linux/blk_types.h>
7#include <linux/atomic.h>
8#include <linux/wait.h>
9
10enum rq_qos_id {
11 RQ_QOS_WBT,
12 RQ_QOS_CGROUP,
13};
14
15struct rq_wait {
16 wait_queue_head_t wait;
17 atomic_t inflight;
18};
19
20struct rq_qos {
21 struct rq_qos_ops *ops;
22 struct request_queue *q;
23 enum rq_qos_id id;
24 struct rq_qos *next;
25};
26
27struct rq_qos_ops {
Christoph Hellwigd5337562018-11-14 17:02:09 +010028 void (*throttle)(struct rq_qos *, struct bio *);
Josef Bacikc1c80382018-07-03 11:14:59 -040029 void (*track)(struct rq_qos *, struct request *, struct bio *);
Josef Bacika7905042018-07-03 09:32:35 -060030 void (*issue)(struct rq_qos *, struct request *);
31 void (*requeue)(struct rq_qos *, struct request *);
32 void (*done)(struct rq_qos *, struct request *);
Josef Bacik67b42d02018-07-03 11:15:00 -040033 void (*done_bio)(struct rq_qos *, struct bio *);
Josef Bacikc1c80382018-07-03 11:14:59 -040034 void (*cleanup)(struct rq_qos *, struct bio *);
Josef Bacika7905042018-07-03 09:32:35 -060035 void (*exit)(struct rq_qos *);
36};
37
38struct rq_depth {
39 unsigned int max_depth;
40
41 int scale_step;
42 bool scaled_max;
43
44 unsigned int queue_depth;
45 unsigned int default_depth;
46};
47
48static inline struct rq_qos *rq_qos_id(struct request_queue *q,
49 enum rq_qos_id id)
50{
51 struct rq_qos *rqos;
52 for (rqos = q->rq_qos; rqos; rqos = rqos->next) {
53 if (rqos->id == id)
54 break;
55 }
56 return rqos;
57}
58
59static inline struct rq_qos *wbt_rq_qos(struct request_queue *q)
60{
61 return rq_qos_id(q, RQ_QOS_WBT);
62}
63
64static inline struct rq_qos *blkcg_rq_qos(struct request_queue *q)
65{
66 return rq_qos_id(q, RQ_QOS_CGROUP);
67}
68
69static inline void rq_wait_init(struct rq_wait *rq_wait)
70{
71 atomic_set(&rq_wait->inflight, 0);
72 init_waitqueue_head(&rq_wait->wait);
73}
74
75static inline void rq_qos_add(struct request_queue *q, struct rq_qos *rqos)
76{
77 rqos->next = q->rq_qos;
78 q->rq_qos = rqos;
79}
80
81static inline void rq_qos_del(struct request_queue *q, struct rq_qos *rqos)
82{
83 struct rq_qos *cur, *prev = NULL;
84 for (cur = q->rq_qos; cur; cur = cur->next) {
85 if (cur == rqos) {
86 if (prev)
87 prev->next = rqos->next;
88 else
89 q->rq_qos = cur;
90 break;
91 }
92 prev = cur;
93 }
94}
95
Josef Bacik22f17952018-07-19 21:42:13 -040096bool rq_wait_inc_below(struct rq_wait *rq_wait, unsigned int limit);
Josef Bacika7905042018-07-03 09:32:35 -060097void rq_depth_scale_up(struct rq_depth *rqd);
98void rq_depth_scale_down(struct rq_depth *rqd, bool hard_throttle);
99bool rq_depth_calc_max_depth(struct rq_depth *rqd);
100
Jens Axboee5045452018-11-15 12:25:10 -0700101void __rq_qos_cleanup(struct rq_qos *rqos, struct bio *bio);
102void __rq_qos_done(struct rq_qos *rqos, struct request *rq);
103void __rq_qos_issue(struct rq_qos *rqos, struct request *rq);
104void __rq_qos_requeue(struct rq_qos *rqos, struct request *rq);
105void __rq_qos_throttle(struct rq_qos *rqos, struct bio *bio);
106void __rq_qos_track(struct rq_qos *rqos, struct request *rq, struct bio *bio);
107void __rq_qos_done_bio(struct rq_qos *rqos, struct bio *bio);
108
109static inline void rq_qos_cleanup(struct request_queue *q, struct bio *bio)
110{
111 if (q->rq_qos)
112 __rq_qos_cleanup(q->rq_qos, bio);
113}
114
115static inline void rq_qos_done(struct request_queue *q, struct request *rq)
116{
117 if (q->rq_qos)
118 __rq_qos_done(q->rq_qos, rq);
119}
120
121static inline void rq_qos_issue(struct request_queue *q, struct request *rq)
122{
123 if (q->rq_qos)
124 __rq_qos_issue(q->rq_qos, rq);
125}
126
127static inline void rq_qos_requeue(struct request_queue *q, struct request *rq)
128{
129 if (q->rq_qos)
130 __rq_qos_requeue(q->rq_qos, rq);
131}
132
133static inline void rq_qos_done_bio(struct request_queue *q, struct bio *bio)
134{
135 if (q->rq_qos)
136 __rq_qos_done_bio(q->rq_qos, bio);
137}
138
139static inline void rq_qos_throttle(struct request_queue *q, struct bio *bio)
140{
141 if (q->rq_qos)
142 __rq_qos_throttle(q->rq_qos, bio);
143}
144
145static inline void rq_qos_track(struct request_queue *q, struct request *rq,
146 struct bio *bio)
147{
148 if (q->rq_qos)
149 __rq_qos_track(q->rq_qos, rq, bio);
150}
151
Josef Bacika7905042018-07-03 09:32:35 -0600152void rq_qos_exit(struct request_queue *);
Jens Axboee5045452018-11-15 12:25:10 -0700153
Josef Bacika7905042018-07-03 09:32:35 -0600154#endif