Blame view

block/blk-wbt.h 2.87 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
e34cbd307   Jens Axboe   blk-wbt: add gene...
2
3
4
5
6
7
8
9
10
11
  #ifndef WB_THROTTLE_H
  #define WB_THROTTLE_H
  
  #include <linux/kernel.h>
  #include <linux/atomic.h>
  #include <linux/wait.h>
  #include <linux/timer.h>
  #include <linux/ktime.h>
  
  #include "blk-stat.h"
a79050434   Josef Bacik   blk-rq-qos: refac...
12
  #include "blk-rq-qos.h"
e34cbd307   Jens Axboe   blk-wbt: add gene...
13
14
15
16
17
  
  enum wbt_flags {
  	WBT_TRACKED		= 1,	/* write, tracked for throttling */
  	WBT_READ		= 2,	/* read */
  	WBT_KSWAPD		= 4,	/* write, from kswapd */
782f56977   Jens Axboe   blk-wbt: throttle...
18
  	WBT_DISCARD		= 8,	/* discard */
e34cbd307   Jens Axboe   blk-wbt: add gene...
19

782f56977   Jens Axboe   blk-wbt: throttle...
20
  	WBT_NR_BITS		= 4,	/* number of bits */
e34cbd307   Jens Axboe   blk-wbt: add gene...
21
22
23
  };
  
  enum {
8bea60901   Jens Axboe   blk-wbt: pass in ...
24
25
  	WBT_RWQ_BG		= 0,
  	WBT_RWQ_KSWAPD,
782f56977   Jens Axboe   blk-wbt: throttle...
26
  	WBT_RWQ_DISCARD,
8bea60901   Jens Axboe   blk-wbt: pass in ...
27
  	WBT_NUM_RWQ,
e34cbd307   Jens Axboe   blk-wbt: add gene...
28
  };
d62118b6d   Jens Axboe   blk-wbt: allow wb...
29
30
31
32
33
34
35
36
  /*
   * Enable states. Either off, or on by default (done at init time),
   * or on through manual setup in sysfs.
   */
  enum {
  	WBT_STATE_ON_DEFAULT	= 1,
  	WBT_STATE_ON_MANUAL	= 2,
  };
e34cbd307   Jens Axboe   blk-wbt: add gene...
37
38
39
40
41
42
  struct rq_wb {
  	/*
  	 * Settings that govern how we throttle
  	 */
  	unsigned int wb_background;		/* background writeback */
  	unsigned int wb_normal;			/* normal writeback */
e34cbd307   Jens Axboe   blk-wbt: add gene...
43

d62118b6d   Jens Axboe   blk-wbt: allow wb...
44
  	short enable_state;			/* WBT_STATE_* */
e34cbd307   Jens Axboe   blk-wbt: add gene...
45
46
47
48
49
50
51
52
  	/*
  	 * Number of consecutive periods where we don't have enough
  	 * information to make a firm scale up/down decision.
  	 */
  	unsigned int unknown_cnt;
  
  	u64 win_nsec;				/* default window size */
  	u64 cur_win_nsec;			/* current window size */
34dbad5d2   Omar Sandoval   blk-stat: convert...
53
  	struct blk_stat_callback *cb;
e34cbd307   Jens Axboe   blk-wbt: add gene...
54

544ccc8dc   Omar Sandoval   block: get rid of...
55
  	u64 sync_issue;
e34cbd307   Jens Axboe   blk-wbt: add gene...
56
57
58
  	void *sync_cookie;
  
  	unsigned int wc;
e34cbd307   Jens Axboe   blk-wbt: add gene...
59
60
61
62
  
  	unsigned long last_issue;		/* last non-throttled issue */
  	unsigned long last_comp;		/* last non-throttled comp */
  	unsigned long min_lat_nsec;
a79050434   Josef Bacik   blk-rq-qos: refac...
63
  	struct rq_qos rqos;
e34cbd307   Jens Axboe   blk-wbt: add gene...
64
  	struct rq_wait rq_wait[WBT_NUM_RWQ];
a79050434   Josef Bacik   blk-rq-qos: refac...
65
  	struct rq_depth rq_depth;
e34cbd307   Jens Axboe   blk-wbt: add gene...
66
  };
a79050434   Josef Bacik   blk-rq-qos: refac...
67
68
69
70
  static inline struct rq_wb *RQWB(struct rq_qos *rqos)
  {
  	return container_of(rqos, struct rq_wb, rqos);
  }
e34cbd307   Jens Axboe   blk-wbt: add gene...
71
72
73
74
75
76
77
78
79
  static inline unsigned int wbt_inflight(struct rq_wb *rwb)
  {
  	unsigned int i, ret = 0;
  
  	for (i = 0; i < WBT_NUM_RWQ; i++)
  		ret += atomic_read(&rwb->rq_wait[i].inflight);
  
  	return ret;
  }
a79050434   Josef Bacik   blk-rq-qos: refac...
80

e34cbd307   Jens Axboe   blk-wbt: add gene...
81
  #ifdef CONFIG_BLK_WBT
8054b89f8   Jens Axboe   blk-wbt: remove s...
82
  int wbt_init(struct request_queue *);
a79050434   Josef Bacik   blk-rq-qos: refac...
83
  void wbt_update_limits(struct request_queue *);
fa224eed2   Jens Axboe   blk-wbt: cleanup ...
84
  void wbt_disable_default(struct request_queue *);
8330cdb0f   Jan Kara   block: Make write...
85
  void wbt_enable_default(struct request_queue *);
e34cbd307   Jens Axboe   blk-wbt: add gene...
86

a79050434   Josef Bacik   blk-rq-qos: refac...
87
88
  u64 wbt_get_min_lat(struct request_queue *q);
  void wbt_set_min_lat(struct request_queue *q, u64 val);
a79050434   Josef Bacik   blk-rq-qos: refac...
89
  void wbt_set_write_cache(struct request_queue *, bool);
e34cbd307   Jens Axboe   blk-wbt: add gene...
90

80e091d10   Jens Axboe   blk-wbt: allow re...
91
  u64 wbt_default_latency_nsec(struct request_queue *);
e34cbd307   Jens Axboe   blk-wbt: add gene...
92
  #else
a8a459417   Omar Sandoval   block: pass struc...
93
  static inline void wbt_track(struct request *rq, enum wbt_flags flags)
934031a12   Omar Sandoval   block: move some ...
94
95
  {
  }
8054b89f8   Jens Axboe   blk-wbt: remove s...
96
  static inline int wbt_init(struct request_queue *q)
e34cbd307   Jens Axboe   blk-wbt: add gene...
97
98
99
  {
  	return -EINVAL;
  }
a79050434   Josef Bacik   blk-rq-qos: refac...
100
  static inline void wbt_update_limits(struct request_queue *q)
e34cbd307   Jens Axboe   blk-wbt: add gene...
101
102
  {
  }
a79050434   Josef Bacik   blk-rq-qos: refac...
103
  static inline void wbt_disable_default(struct request_queue *q)
e34cbd307   Jens Axboe   blk-wbt: add gene...
104
105
  {
  }
a79050434   Josef Bacik   blk-rq-qos: refac...
106
  static inline void wbt_enable_default(struct request_queue *q)
e34cbd307   Jens Axboe   blk-wbt: add gene...
107
108
  {
  }
a79050434   Josef Bacik   blk-rq-qos: refac...
109
  static inline void wbt_set_write_cache(struct request_queue *q, bool wc)
8330cdb0f   Jan Kara   block: Make write...
110
111
  {
  }
a79050434   Josef Bacik   blk-rq-qos: refac...
112
  static inline u64 wbt_get_min_lat(struct request_queue *q)
e34cbd307   Jens Axboe   blk-wbt: add gene...
113
  {
a79050434   Josef Bacik   blk-rq-qos: refac...
114
  	return 0;
e34cbd307   Jens Axboe   blk-wbt: add gene...
115
  }
a79050434   Josef Bacik   blk-rq-qos: refac...
116
  static inline void wbt_set_min_lat(struct request_queue *q, u64 val)
e34cbd307   Jens Axboe   blk-wbt: add gene...
117
118
  {
  }
80e091d10   Jens Axboe   blk-wbt: allow re...
119
120
121
122
  static inline u64 wbt_default_latency_nsec(struct request_queue *q)
  {
  	return 0;
  }
e34cbd307   Jens Axboe   blk-wbt: add gene...
123
124
125
126
  
  #endif /* CONFIG_BLK_WBT */
  
  #endif