1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/kernel.h>
6 #include <linux/atomic.h>
7 #include <linux/wait.h>
8 #include <linux/timer.h>
9 #include <linux/ktime.h>
12 #include "blk-rq-qos.h"
15 WBT_TRACKED = 1, /* write, tracked for throttling */
16 WBT_READ = 2, /* read */
17 WBT_KSWAPD = 4, /* write, from kswapd */
18 WBT_DISCARD = 8, /* discard */
20 WBT_NR_BITS = 4, /* number of bits */
31 * Enable states. Either off, or on by default (done at init time),
32 * or on through manual setup in sysfs.
35 WBT_STATE_ON_DEFAULT = 1,
36 WBT_STATE_ON_MANUAL = 2,
42 * Settings that govern how we throttle
44 unsigned int wb_background; /* background writeback */
45 unsigned int wb_normal; /* normal writeback */
47 short enable_state; /* WBT_STATE_* */
50 * Number of consecutive periods where we don't have enough
51 * information to make a firm scale up/down decision.
53 unsigned int unknown_cnt;
55 u64 win_nsec; /* default window size */
56 u64 cur_win_nsec; /* current window size */
58 struct blk_stat_callback *cb;
65 unsigned long last_issue; /* last non-throttled issue */
66 unsigned long last_comp; /* last non-throttled comp */
67 unsigned long min_lat_nsec;
69 struct rq_wait rq_wait[WBT_NUM_RWQ];
70 struct rq_depth rq_depth;
73 static inline struct rq_wb *RQWB(struct rq_qos *rqos)
75 return container_of(rqos, struct rq_wb, rqos);
78 static inline unsigned int wbt_inflight(struct rq_wb *rwb)
80 unsigned int i, ret = 0;
82 for (i = 0; i < WBT_NUM_RWQ; i++)
83 ret += atomic_read(&rwb->rq_wait[i].inflight);
91 int wbt_init(struct request_queue *);
92 void wbt_disable_default(struct request_queue *);
93 void wbt_enable_default(struct request_queue *);
95 u64 wbt_get_min_lat(struct request_queue *q);
96 void wbt_set_min_lat(struct request_queue *q, u64 val);
98 void wbt_set_write_cache(struct request_queue *, bool);
100 u64 wbt_default_latency_nsec(struct request_queue *);
104 static inline void wbt_track(struct request *rq, enum wbt_flags flags)
107 static inline int wbt_init(struct request_queue *q)
111 static inline void wbt_disable_default(struct request_queue *q)
114 static inline void wbt_enable_default(struct request_queue *q)
117 static inline void wbt_set_write_cache(struct request_queue *q, bool wc)
120 static inline u64 wbt_get_min_lat(struct request_queue *q)
124 static inline void wbt_set_min_lat(struct request_queue *q, u64 val)
127 static inline u64 wbt_default_latency_nsec(struct request_queue *q)
132 #endif /* CONFIG_BLK_WBT */