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>
10 #include <linux/blk-mq.h>
12 #include "blk-mq-debugfs.h"
14 struct blk_mq_debugfs_attr;
23 wait_queue_head_t wait;
28 const struct rq_qos_ops *ops;
32 #ifdef CONFIG_BLK_DEBUG_FS
33 struct dentry *debugfs_dir;
38 void (*throttle)(struct rq_qos *, struct bio *);
39 void (*track)(struct rq_qos *, struct request *, struct bio *);
40 void (*merge)(struct rq_qos *, struct request *, struct bio *);
41 void (*issue)(struct rq_qos *, struct request *);
42 void (*requeue)(struct rq_qos *, struct request *);
43 void (*done)(struct rq_qos *, struct request *);
44 void (*done_bio)(struct rq_qos *, struct bio *);
45 void (*cleanup)(struct rq_qos *, struct bio *);
46 void (*queue_depth_changed)(struct rq_qos *);
47 void (*exit)(struct rq_qos *);
48 const struct blk_mq_debugfs_attr *debugfs_attrs;
52 unsigned int max_depth;
57 unsigned int queue_depth;
58 unsigned int default_depth;
61 static inline struct rq_qos *rq_qos_id(struct request_queue *q,
65 for (rqos = q->rq_qos; rqos; rqos = rqos->next) {
72 static inline struct rq_qos *wbt_rq_qos(struct request_queue *q)
74 return rq_qos_id(q, RQ_QOS_WBT);
77 static inline struct rq_qos *iolat_rq_qos(struct request_queue *q)
79 return rq_qos_id(q, RQ_QOS_LATENCY);
82 static inline void rq_wait_init(struct rq_wait *rq_wait)
84 atomic_set(&rq_wait->inflight, 0);
85 init_waitqueue_head(&rq_wait->wait);
88 int rq_qos_add(struct rq_qos *rqos, struct gendisk *disk, enum rq_qos_id id,
89 const struct rq_qos_ops *ops);
90 void rq_qos_del(struct rq_qos *rqos);
92 typedef bool (acquire_inflight_cb_t)(struct rq_wait *rqw, void *private_data);
93 typedef void (cleanup_cb_t)(struct rq_wait *rqw, void *private_data);
95 void rq_qos_wait(struct rq_wait *rqw, void *private_data,
96 acquire_inflight_cb_t *acquire_inflight_cb,
97 cleanup_cb_t *cleanup_cb);
98 bool rq_wait_inc_below(struct rq_wait *rq_wait, unsigned int limit);
99 bool rq_depth_scale_up(struct rq_depth *rqd);
100 bool rq_depth_scale_down(struct rq_depth *rqd, bool hard_throttle);
101 bool rq_depth_calc_max_depth(struct rq_depth *rqd);
103 void __rq_qos_cleanup(struct rq_qos *rqos, struct bio *bio);
104 void __rq_qos_done(struct rq_qos *rqos, struct request *rq);
105 void __rq_qos_issue(struct rq_qos *rqos, struct request *rq);
106 void __rq_qos_requeue(struct rq_qos *rqos, struct request *rq);
107 void __rq_qos_throttle(struct rq_qos *rqos, struct bio *bio);
108 void __rq_qos_track(struct rq_qos *rqos, struct request *rq, struct bio *bio);
109 void __rq_qos_merge(struct rq_qos *rqos, struct request *rq, struct bio *bio);
110 void __rq_qos_done_bio(struct rq_qos *rqos, struct bio *bio);
111 void __rq_qos_queue_depth_changed(struct rq_qos *rqos);
113 static inline void rq_qos_cleanup(struct request_queue *q, struct bio *bio)
116 __rq_qos_cleanup(q->rq_qos, bio);
119 static inline void rq_qos_done(struct request_queue *q, struct request *rq)
122 __rq_qos_done(q->rq_qos, rq);
125 static inline void rq_qos_issue(struct request_queue *q, struct request *rq)
128 __rq_qos_issue(q->rq_qos, rq);
131 static inline void rq_qos_requeue(struct request_queue *q, struct request *rq)
134 __rq_qos_requeue(q->rq_qos, rq);
137 static inline void rq_qos_done_bio(struct bio *bio)
139 if (bio->bi_bdev && (bio_flagged(bio, BIO_QOS_THROTTLED) ||
140 bio_flagged(bio, BIO_QOS_MERGED))) {
141 struct request_queue *q = bdev_get_queue(bio->bi_bdev);
143 __rq_qos_done_bio(q->rq_qos, bio);
147 static inline void rq_qos_throttle(struct request_queue *q, struct bio *bio)
150 bio_set_flag(bio, BIO_QOS_THROTTLED);
151 __rq_qos_throttle(q->rq_qos, bio);
155 static inline void rq_qos_track(struct request_queue *q, struct request *rq,
159 __rq_qos_track(q->rq_qos, rq, bio);
162 static inline void rq_qos_merge(struct request_queue *q, struct request *rq,
166 bio_set_flag(bio, BIO_QOS_MERGED);
167 __rq_qos_merge(q->rq_qos, rq, bio);
171 static inline void rq_qos_queue_depth_changed(struct request_queue *q)
174 __rq_qos_queue_depth_changed(q->rq_qos);
177 void rq_qos_exit(struct request_queue *);