1
2#ifndef WB_THROTTLE_H
3#define WB_THROTTLE_H
4
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>
10
11#include "blk-stat.h"
12#include "blk-rq-qos.h"
13
14enum wbt_flags {
15 WBT_TRACKED = 1,
16 WBT_READ = 2,
17 WBT_KSWAPD = 4,
18 WBT_DISCARD = 8,
19
20 WBT_NR_BITS = 4,
21};
22
23enum {
24 WBT_RWQ_BG = 0,
25 WBT_RWQ_KSWAPD,
26 WBT_RWQ_DISCARD,
27 WBT_NUM_RWQ,
28};
29
30
31
32
33
34enum {
35 WBT_STATE_ON_DEFAULT = 1,
36 WBT_STATE_ON_MANUAL = 2,
37};
38
39struct rq_wb {
40
41
42
43 unsigned int wb_background;
44 unsigned int wb_normal;
45
46 short enable_state;
47
48
49
50
51
52 unsigned int unknown_cnt;
53
54 u64 win_nsec;
55 u64 cur_win_nsec;
56
57 struct blk_stat_callback *cb;
58
59 u64 sync_issue;
60 void *sync_cookie;
61
62 unsigned int wc;
63
64 unsigned long last_issue;
65 unsigned long last_comp;
66 unsigned long min_lat_nsec;
67 struct rq_qos rqos;
68 struct rq_wait rq_wait[WBT_NUM_RWQ];
69 struct rq_depth rq_depth;
70};
71
72static inline struct rq_wb *RQWB(struct rq_qos *rqos)
73{
74 return container_of(rqos, struct rq_wb, rqos);
75}
76
77static inline unsigned int wbt_inflight(struct rq_wb *rwb)
78{
79 unsigned int i, ret = 0;
80
81 for (i = 0; i < WBT_NUM_RWQ; i++)
82 ret += atomic_read(&rwb->rq_wait[i].inflight);
83
84 return ret;
85}
86
87
88#ifdef CONFIG_BLK_WBT
89
90int wbt_init(struct request_queue *);
91void wbt_update_limits(struct request_queue *);
92void wbt_disable_default(struct request_queue *);
93void wbt_enable_default(struct request_queue *);
94
95u64 wbt_get_min_lat(struct request_queue *q);
96void wbt_set_min_lat(struct request_queue *q, u64 val);
97
98void wbt_set_write_cache(struct request_queue *, bool);
99
100u64 wbt_default_latency_nsec(struct request_queue *);
101
102#else
103
104static inline void wbt_track(struct request *rq, enum wbt_flags flags)
105{
106}
107static inline int wbt_init(struct request_queue *q)
108{
109 return -EINVAL;
110}
111static inline void wbt_update_limits(struct request_queue *q)
112{
113}
114static inline void wbt_disable_default(struct request_queue *q)
115{
116}
117static inline void wbt_enable_default(struct request_queue *q)
118{
119}
120static inline void wbt_set_write_cache(struct request_queue *q, bool wc)
121{
122}
123static inline u64 wbt_get_min_lat(struct request_queue *q)
124{
125 return 0;
126}
127static inline void wbt_set_min_lat(struct request_queue *q, u64 val)
128{
129}
130static inline u64 wbt_default_latency_nsec(struct request_queue *q)
131{
132 return 0;
133}
134
135#endif
136
137#endif
138