1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/kernel.h>
6 #include <linux/blkdev.h>
7 #include <linux/blk_types.h>
8 #include <linux/atomic.h>
9 #include <linux/wait.h>
11 #include "blk-mq-debugfs.h"
13 struct blk_mq_debugfs_attr;
22 wait_queue_head_t wait;
27 struct rq_qos_ops *ops;
28 struct request_queue *q;
31 #ifdef CONFIG_BLK_DEBUG_FS
32 struct dentry *debugfs_dir;
37 void (*throttle)(struct rq_qos *, struct bio *);
38 void (*track)(struct rq_qos *, struct request *, struct bio *);
39 void (*merge)(struct rq_qos *, struct request *, struct bio *);
40 void (*issue)(struct rq_qos *, struct request *);
41 void (*requeue)(struct rq_qos *, struct request *);
42 void (*done)(struct rq_qos *, struct request *);
43 void (*done_bio)(struct rq_qos *, struct bio *);
44 void (*cleanup)(struct rq_qos *, struct bio *);
45 void (*queue_depth_changed)(struct rq_qos *);
46 void (*exit)(struct rq_qos *);
47 const struct blk_mq_debugfs_attr *debugfs_attrs;
51 unsigned int max_depth;
56 unsigned int queue_depth;
57 unsigned int default_depth;
60 static inline struct rq_qos *rq_qos_id(struct request_queue *q,
64 for (rqos = q->rq_qos; rqos; rqos = rqos->next) {
71 static inline struct rq_qos *wbt_rq_qos(struct request_queue *q)
73 return rq_qos_id(q, RQ_QOS_WBT);
76 static inline struct rq_qos *blkcg_rq_qos(struct request_queue *q)
78 return rq_qos_id(q, RQ_QOS_LATENCY);
81 static inline const char *rq_qos_id_to_name(enum rq_qos_id id)
94 static inline void rq_wait_init(struct rq_wait *rq_wait)
96 atomic_set(&rq_wait->inflight, 0);
97 init_waitqueue_head(&rq_wait->wait);
100 static inline void rq_qos_add(struct request_queue *q, struct rq_qos *rqos)
102 rqos->next = q->rq_qos;
105 if (rqos->ops->debugfs_attrs)
106 blk_mq_debugfs_register_rqos(rqos);
109 static inline void rq_qos_del(struct request_queue *q, struct rq_qos *rqos)
111 struct rq_qos *cur, *prev = NULL;
112 for (cur = q->rq_qos; cur; cur = cur->next) {
115 prev->next = rqos->next;
123 blk_mq_debugfs_unregister_rqos(rqos);
126 typedef bool (acquire_inflight_cb_t)(struct rq_wait *rqw, void *private_data);
127 typedef void (cleanup_cb_t)(struct rq_wait *rqw, void *private_data);
129 void rq_qos_wait(struct rq_wait *rqw, void *private_data,
130 acquire_inflight_cb_t *acquire_inflight_cb,
131 cleanup_cb_t *cleanup_cb);
132 bool rq_wait_inc_below(struct rq_wait *rq_wait, unsigned int limit);
133 bool rq_depth_scale_up(struct rq_depth *rqd);
134 bool rq_depth_scale_down(struct rq_depth *rqd, bool hard_throttle);
135 bool rq_depth_calc_max_depth(struct rq_depth *rqd);
137 void __rq_qos_cleanup(struct rq_qos *rqos, struct bio *bio);
138 void __rq_qos_done(struct rq_qos *rqos, struct request *rq);
139 void __rq_qos_issue(struct rq_qos *rqos, struct request *rq);
140 void __rq_qos_requeue(struct rq_qos *rqos, struct request *rq);
141 void __rq_qos_throttle(struct rq_qos *rqos, struct bio *bio);
142 void __rq_qos_track(struct rq_qos *rqos, struct request *rq, struct bio *bio);
143 void __rq_qos_merge(struct rq_qos *rqos, struct request *rq, struct bio *bio);
144 void __rq_qos_done_bio(struct rq_qos *rqos, struct bio *bio);
145 void __rq_qos_queue_depth_changed(struct rq_qos *rqos);
147 static inline void rq_qos_cleanup(struct request_queue *q, struct bio *bio)
150 __rq_qos_cleanup(q->rq_qos, bio);
153 static inline void rq_qos_done(struct request_queue *q, struct request *rq)
156 __rq_qos_done(q->rq_qos, rq);
159 static inline void rq_qos_issue(struct request_queue *q, struct request *rq)
162 __rq_qos_issue(q->rq_qos, rq);
165 static inline void rq_qos_requeue(struct request_queue *q, struct request *rq)
168 __rq_qos_requeue(q->rq_qos, rq);
171 static inline void rq_qos_done_bio(struct request_queue *q, struct bio *bio)
174 __rq_qos_done_bio(q->rq_qos, bio);
177 static inline void rq_qos_throttle(struct request_queue *q, struct bio *bio)
180 * BIO_TRACKED lets controllers know that a bio went through the
181 * normal rq_qos path.
183 bio_set_flag(bio, BIO_TRACKED);
185 __rq_qos_throttle(q->rq_qos, bio);
188 static inline void rq_qos_track(struct request_queue *q, struct request *rq,
192 __rq_qos_track(q->rq_qos, rq, bio);
195 static inline void rq_qos_merge(struct request_queue *q, struct request *rq,
199 __rq_qos_merge(q->rq_qos, rq, bio);
202 static inline void rq_qos_queue_depth_changed(struct request_queue *q)
205 __rq_qos_queue_depth_changed(q->rq_qos);
208 void rq_qos_exit(struct request_queue *);