summaryrefslogtreecommitdiff
path: root/include/linux/wbt.h
blob: 872da2d73faa10066606070d13d58ae81a114974 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef WB_THROTTLE_H
#define WB_THROTTLE_H

#include <linux/atomic.h>
#include <linux/wait.h>
#include <linux/timer.h>
#include <linux/ktime.h>

#define ISSUE_STAT_MASK		(1ULL << 63)
#define ISSUE_STAT_TIME_MASK	~ISSUE_STAT_MASK

struct wb_issue_stat {
	u64 time;
};

static inline void wbt_issue_stat_set_time(struct wb_issue_stat *stat)
{
	stat->time = (stat->time & ISSUE_STAT_MASK) |
			(ktime_to_ns(ktime_get()) & ISSUE_STAT_TIME_MASK);
}

static inline u64 wbt_issue_stat_get_time(struct wb_issue_stat *stat)
{
	return stat->time & ISSUE_STAT_TIME_MASK;
}

static inline void wbt_mark_tracked(struct wb_issue_stat *stat)
{
	stat->time |= ISSUE_STAT_MASK;
}

static inline void wbt_clear_tracked(struct wb_issue_stat *stat)
{
	stat->time &= ~ISSUE_STAT_MASK;
}

static inline bool wbt_tracked(struct wb_issue_stat *stat)
{
	return (stat->time & ISSUE_STAT_MASK) != 0;
}

struct wb_stat_ops {
	void (*get)(void *, struct blk_rq_stat *);
	void (*clear)(void *);
};

struct rq_wb {
	/*
	 * Settings that govern how we throttle
	 */
	unsigned int wb_background;		/* background writeback */
	unsigned int wb_normal;			/* normal writeback */
	unsigned int wb_max;			/* max throughput writeback */
	unsigned int scale_step;

	u64 win_nsec;				/* default window size */
	u64 cur_win_nsec;			/* current window size */

	/*
	 * Number of consecutive periods where we don't have enough
	 * information to make a firm scale up/down decision.
	 */
	unsigned int unknown_cnt;

	struct timer_list window_timer;

	s64 sync_issue;
	void *sync_cookie;

	unsigned int wc;
	unsigned int queue_depth;

	unsigned long last_issue;		/* last non-throttled issue */
	unsigned long last_comp;		/* last non-throttled comp */
	unsigned long min_lat_nsec;
	struct backing_dev_info *bdi;
	struct request_queue *q;
	wait_queue_head_t wait;
	atomic_t inflight;

	struct wb_stat_ops *stat_ops;
	void *ops_data;
};

struct backing_dev_info;

void __wbt_done(struct rq_wb *);
void wbt_done(struct rq_wb *, struct wb_issue_stat *);
bool wbt_wait(struct rq_wb *, unsigned int, spinlock_t *);
struct rq_wb *wbt_init(struct backing_dev_info *, struct wb_stat_ops *, void *);
void wbt_exit(struct rq_wb *);
void wbt_update_limits(struct rq_wb *);
void wbt_requeue(struct rq_wb *, struct wb_issue_stat *);
void wbt_issue(struct rq_wb *, struct wb_issue_stat *);
void wbt_disable(struct rq_wb *);

void wbt_set_queue_depth(struct rq_wb *, unsigned int);
void wbt_set_write_cache(struct rq_wb *, bool);

#endif