4 #include <linux/kernel.h>
5 #include <linux/atomic.h>
6 #include <linux/wait.h>
7 #include <linux/timer.h>
8 #include <linux/ktime.h>
13 WBT_TRACKED
= 1, /* write, tracked for throttling */
14 WBT_READ
= 2, /* read */
15 WBT_KSWAPD
= 4, /* write, from kswapd */
17 WBT_NR_BITS
= 3, /* number of bits */
25 * Enable states. Either off, or on by default (done at init time),
26 * or on through manual setup in sysfs.
29 WBT_STATE_ON_DEFAULT
= 1,
30 WBT_STATE_ON_MANUAL
= 2,
33 static inline void wbt_clear_state(struct blk_issue_stat
*stat
)
35 stat
->time
&= BLK_STAT_TIME_MASK
;
38 static inline enum wbt_flags
wbt_stat_to_mask(struct blk_issue_stat
*stat
)
40 return (stat
->time
& BLK_STAT_MASK
) >> BLK_STAT_SHIFT
;
43 static inline void wbt_track(struct blk_issue_stat
*stat
, enum wbt_flags wb_acct
)
45 stat
->time
|= ((u64
) wb_acct
) << BLK_STAT_SHIFT
;
48 static inline bool wbt_is_tracked(struct blk_issue_stat
*stat
)
50 return (stat
->time
>> BLK_STAT_SHIFT
) & WBT_TRACKED
;
53 static inline bool wbt_is_read(struct blk_issue_stat
*stat
)
55 return (stat
->time
>> BLK_STAT_SHIFT
) & WBT_READ
;
59 wait_queue_head_t wait
;
65 * Settings that govern how we throttle
67 unsigned int wb_background
; /* background writeback */
68 unsigned int wb_normal
; /* normal writeback */
69 unsigned int wb_max
; /* max throughput writeback */
73 short enable_state
; /* WBT_STATE_* */
76 * Number of consecutive periods where we don't have enough
77 * information to make a firm scale up/down decision.
79 unsigned int unknown_cnt
;
81 u64 win_nsec
; /* default window size */
82 u64 cur_win_nsec
; /* current window size */
84 struct timer_list window_timer
;
90 unsigned int queue_depth
;
92 unsigned long last_issue
; /* last non-throttled issue */
93 unsigned long last_comp
; /* last non-throttled comp */
94 unsigned long min_lat_nsec
;
95 struct request_queue
*queue
;
96 struct rq_wait rq_wait
[WBT_NUM_RWQ
];
99 static inline unsigned int wbt_inflight(struct rq_wb
*rwb
)
101 unsigned int i
, ret
= 0;
103 for (i
= 0; i
< WBT_NUM_RWQ
; i
++)
104 ret
+= atomic_read(&rwb
->rq_wait
[i
].inflight
);
109 #ifdef CONFIG_BLK_WBT
111 void __wbt_done(struct rq_wb
*, enum wbt_flags
);
112 void wbt_done(struct rq_wb
*, struct blk_issue_stat
*);
113 enum wbt_flags
wbt_wait(struct rq_wb
*, struct bio
*, spinlock_t
*);
114 int wbt_init(struct request_queue
*);
115 void wbt_exit(struct request_queue
*);
116 void wbt_update_limits(struct rq_wb
*);
117 void wbt_requeue(struct rq_wb
*, struct blk_issue_stat
*);
118 void wbt_issue(struct rq_wb
*, struct blk_issue_stat
*);
119 void wbt_disable_default(struct request_queue
*);
121 void wbt_set_queue_depth(struct rq_wb
*, unsigned int);
122 void wbt_set_write_cache(struct rq_wb
*, bool);
124 u64
wbt_default_latency_nsec(struct request_queue
*);
128 static inline void __wbt_done(struct rq_wb
*rwb
, enum wbt_flags flags
)
131 static inline void wbt_done(struct rq_wb
*rwb
, struct blk_issue_stat
*stat
)
134 static inline enum wbt_flags
wbt_wait(struct rq_wb
*rwb
, struct bio
*bio
,
139 static inline int wbt_init(struct request_queue
*q
)
143 static inline void wbt_exit(struct request_queue
*q
)
146 static inline void wbt_update_limits(struct rq_wb
*rwb
)
149 static inline void wbt_requeue(struct rq_wb
*rwb
, struct blk_issue_stat
*stat
)
152 static inline void wbt_issue(struct rq_wb
*rwb
, struct blk_issue_stat
*stat
)
155 static inline void wbt_disable_default(struct request_queue
*q
)
158 static inline void wbt_set_queue_depth(struct rq_wb
*rwb
, unsigned int depth
)
161 static inline void wbt_set_write_cache(struct rq_wb
*rwb
, bool wc
)
164 static inline u64
wbt_default_latency_nsec(struct request_queue
*q
)
169 #endif /* CONFIG_BLK_WBT */