Josef Bacik | a790504 | 2018-07-03 09:32:35 -0600 | [diff] [blame^] | 1 | #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 | |
| 10 | enum rq_qos_id { |
| 11 | RQ_QOS_WBT, |
| 12 | RQ_QOS_CGROUP, |
| 13 | }; |
| 14 | |
| 15 | struct rq_wait { |
| 16 | wait_queue_head_t wait; |
| 17 | atomic_t inflight; |
| 18 | }; |
| 19 | |
| 20 | struct 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 | |
| 27 | struct rq_qos_ops { |
| 28 | enum wbt_flags (*throttle)(struct rq_qos *, struct bio *, |
| 29 | spinlock_t *); |
| 30 | void (*issue)(struct rq_qos *, struct request *); |
| 31 | void (*requeue)(struct rq_qos *, struct request *); |
| 32 | void (*done)(struct rq_qos *, struct request *); |
| 33 | void (*cleanup)(struct rq_qos *, enum wbt_flags); |
| 34 | void (*exit)(struct rq_qos *); |
| 35 | }; |
| 36 | |
| 37 | struct rq_depth { |
| 38 | unsigned int max_depth; |
| 39 | |
| 40 | int scale_step; |
| 41 | bool scaled_max; |
| 42 | |
| 43 | unsigned int queue_depth; |
| 44 | unsigned int default_depth; |
| 45 | }; |
| 46 | |
| 47 | static inline struct rq_qos *rq_qos_id(struct request_queue *q, |
| 48 | enum rq_qos_id id) |
| 49 | { |
| 50 | struct rq_qos *rqos; |
| 51 | for (rqos = q->rq_qos; rqos; rqos = rqos->next) { |
| 52 | if (rqos->id == id) |
| 53 | break; |
| 54 | } |
| 55 | return rqos; |
| 56 | } |
| 57 | |
| 58 | static inline struct rq_qos *wbt_rq_qos(struct request_queue *q) |
| 59 | { |
| 60 | return rq_qos_id(q, RQ_QOS_WBT); |
| 61 | } |
| 62 | |
| 63 | static inline struct rq_qos *blkcg_rq_qos(struct request_queue *q) |
| 64 | { |
| 65 | return rq_qos_id(q, RQ_QOS_CGROUP); |
| 66 | } |
| 67 | |
| 68 | static inline void rq_wait_init(struct rq_wait *rq_wait) |
| 69 | { |
| 70 | atomic_set(&rq_wait->inflight, 0); |
| 71 | init_waitqueue_head(&rq_wait->wait); |
| 72 | } |
| 73 | |
| 74 | static inline void rq_qos_add(struct request_queue *q, struct rq_qos *rqos) |
| 75 | { |
| 76 | rqos->next = q->rq_qos; |
| 77 | q->rq_qos = rqos; |
| 78 | } |
| 79 | |
| 80 | static inline void rq_qos_del(struct request_queue *q, struct rq_qos *rqos) |
| 81 | { |
| 82 | struct rq_qos *cur, *prev = NULL; |
| 83 | for (cur = q->rq_qos; cur; cur = cur->next) { |
| 84 | if (cur == rqos) { |
| 85 | if (prev) |
| 86 | prev->next = rqos->next; |
| 87 | else |
| 88 | q->rq_qos = cur; |
| 89 | break; |
| 90 | } |
| 91 | prev = cur; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | bool rq_wait_inc_below(struct rq_wait *rq_wait, int limit); |
| 96 | void rq_depth_scale_up(struct rq_depth *rqd); |
| 97 | void rq_depth_scale_down(struct rq_depth *rqd, bool hard_throttle); |
| 98 | bool rq_depth_calc_max_depth(struct rq_depth *rqd); |
| 99 | |
| 100 | void rq_qos_cleanup(struct request_queue *, enum wbt_flags); |
| 101 | void rq_qos_done(struct request_queue *, struct request *); |
| 102 | void rq_qos_issue(struct request_queue *, struct request *); |
| 103 | void rq_qos_requeue(struct request_queue *, struct request *); |
| 104 | enum wbt_flags rq_qos_throttle(struct request_queue *, struct bio *, spinlock_t *); |
| 105 | void rq_qos_exit(struct request_queue *); |
| 106 | #endif |