]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - block/blk-cgroup.h
io-controller: Document for blkio.weight_device
[mirror_ubuntu-artful-kernel.git] / block / blk-cgroup.h
CommitLineData
31e4c28d
VG
1#ifndef _BLK_CGROUP_H
2#define _BLK_CGROUP_H
3/*
4 * Common Block IO controller cgroup interface
5 *
6 * Based on ideas and code from CFQ, CFS and BFQ:
7 * Copyright (C) 2003 Jens Axboe <axboe@kernel.dk>
8 *
9 * Copyright (C) 2008 Fabio Checconi <fabio@gandalf.sssup.it>
10 * Paolo Valente <paolo.valente@unimore.it>
11 *
12 * Copyright (C) 2009 Vivek Goyal <vgoyal@redhat.com>
13 * Nauman Rafique <nauman@google.com>
14 */
15
16#include <linux/cgroup.h>
17
67523c48
BB
18#if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
19
20#ifndef CONFIG_BLK_CGROUP
21/* When blk-cgroup is a module, its subsys_id isn't a compile-time constant */
22extern struct cgroup_subsys blkio_subsys;
23#define blkio_subsys_id blkio_subsys.subsys_id
24#endif
2f5ea477 25
84c124da
DS
26enum stat_type {
27 /* Total time spent (in ns) between request dispatch to the driver and
28 * request completion for IOs doen by this cgroup. This may not be
29 * accurate when NCQ is turned on. */
30 BLKIO_STAT_SERVICE_TIME = 0,
31 /* Total bytes transferred */
32 BLKIO_STAT_SERVICE_BYTES,
33 /* Total IOs serviced, post merge */
34 BLKIO_STAT_SERVICED,
35 /* Total time spent waiting in scheduler queue in ns */
36 BLKIO_STAT_WAIT_TIME,
812d4026
DS
37 /* Number of IOs merged */
38 BLKIO_STAT_MERGED,
cdc1184c
DS
39 /* Number of IOs queued up */
40 BLKIO_STAT_QUEUED,
84c124da
DS
41 /* All the single valued stats go below this */
42 BLKIO_STAT_TIME,
43 BLKIO_STAT_SECTORS,
44#ifdef CONFIG_DEBUG_BLK_CGROUP
cdc1184c 45 BLKIO_STAT_AVG_QUEUE_SIZE,
812df48d
DS
46 BLKIO_STAT_IDLE_TIME,
47 BLKIO_STAT_EMPTY_TIME,
48 BLKIO_STAT_GROUP_WAIT_TIME,
84c124da
DS
49 BLKIO_STAT_DEQUEUE
50#endif
51};
52
53enum stat_sub_type {
54 BLKIO_STAT_READ = 0,
55 BLKIO_STAT_WRITE,
56 BLKIO_STAT_SYNC,
57 BLKIO_STAT_ASYNC,
58 BLKIO_STAT_TOTAL
303a3acb
DS
59};
60
812df48d
DS
61/* blkg state flags */
62enum blkg_state_flags {
63 BLKG_waiting = 0,
64 BLKG_idling,
65 BLKG_empty,
66};
67
31e4c28d
VG
68struct blkio_cgroup {
69 struct cgroup_subsys_state css;
70 unsigned int weight;
71 spinlock_t lock;
72 struct hlist_head blkg_list;
34d0f179 73 struct list_head policy_list; /* list of blkio_policy_node */
31e4c28d
VG
74};
75
303a3acb
DS
76struct blkio_group_stats {
77 /* total disk time and nr sectors dispatched by this group */
78 uint64_t time;
79 uint64_t sectors;
cdc1184c 80 uint64_t stat_arr[BLKIO_STAT_QUEUED + 1][BLKIO_STAT_TOTAL];
303a3acb 81#ifdef CONFIG_DEBUG_BLK_CGROUP
cdc1184c
DS
82 /* Sum of number of IOs queued across all samples */
83 uint64_t avg_queue_size_sum;
84 /* Count of samples taken for average */
85 uint64_t avg_queue_size_samples;
303a3acb
DS
86 /* How many times this group has been removed from service tree */
87 unsigned long dequeue;
812df48d
DS
88
89 /* Total time spent waiting for it to be assigned a timeslice. */
90 uint64_t group_wait_time;
91 uint64_t start_group_wait_time;
92
93 /* Time spent idling for this blkio_group */
94 uint64_t idle_time;
95 uint64_t start_idle_time;
96 /*
97 * Total time when we have requests queued and do not contain the
98 * current active queue.
99 */
100 uint64_t empty_time;
101 uint64_t start_empty_time;
102 uint16_t flags;
303a3acb
DS
103#endif
104};
105
31e4c28d
VG
106struct blkio_group {
107 /* An rcu protected unique identifier for the group */
108 void *key;
109 struct hlist_node blkcg_node;
b1c35769 110 unsigned short blkcg_id;
2868ef7b
VG
111#ifdef CONFIG_DEBUG_BLK_CGROUP
112 /* Store cgroup path */
113 char path[128];
114#endif
22084190 115 /* The device MKDEV(major, minor), this group has been created for */
84c124da 116 dev_t dev;
22084190 117
303a3acb
DS
118 /* Need to serialize the stats in the case of reset/update */
119 spinlock_t stats_lock;
120 struct blkio_group_stats stats;
31e4c28d
VG
121};
122
34d0f179
GJ
123struct blkio_policy_node {
124 struct list_head node;
125 dev_t dev;
126 unsigned int weight;
127};
128
129extern unsigned int blkcg_get_weight(struct blkio_cgroup *blkcg,
130 dev_t dev);
131
3e252066
VG
132typedef void (blkio_unlink_group_fn) (void *key, struct blkio_group *blkg);
133typedef void (blkio_update_group_weight_fn) (struct blkio_group *blkg,
134 unsigned int weight);
135
136struct blkio_policy_ops {
137 blkio_unlink_group_fn *blkio_unlink_group_fn;
138 blkio_update_group_weight_fn *blkio_update_group_weight_fn;
139};
140
141struct blkio_policy_type {
142 struct list_head list;
143 struct blkio_policy_ops ops;
144};
145
146/* Blkio controller policy registration */
147extern void blkio_policy_register(struct blkio_policy_type *);
148extern void blkio_policy_unregister(struct blkio_policy_type *);
149
2f5ea477
JA
150#else
151
152struct blkio_group {
153};
154
3e252066
VG
155struct blkio_policy_type {
156};
157
158static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { }
159static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { }
160
2f5ea477
JA
161#endif
162
31e4c28d
VG
163#define BLKIO_WEIGHT_MIN 100
164#define BLKIO_WEIGHT_MAX 1000
165#define BLKIO_WEIGHT_DEFAULT 500
166
2868ef7b
VG
167#ifdef CONFIG_DEBUG_BLK_CGROUP
168static inline char *blkg_path(struct blkio_group *blkg)
169{
170 return blkg->path;
171}
cdc1184c 172void blkiocg_update_set_active_queue_stats(struct blkio_group *blkg);
9195291e 173void blkiocg_update_dequeue_stats(struct blkio_group *blkg,
22084190 174 unsigned long dequeue);
812df48d
DS
175void blkiocg_update_set_idle_time_stats(struct blkio_group *blkg);
176void blkiocg_update_idle_time_stats(struct blkio_group *blkg);
177void blkiocg_set_start_empty_time(struct blkio_group *blkg, bool ignore);
178
179#define BLKG_FLAG_FNS(name) \
180static inline void blkio_mark_blkg_##name( \
181 struct blkio_group_stats *stats) \
182{ \
183 stats->flags |= (1 << BLKG_##name); \
184} \
185static inline void blkio_clear_blkg_##name( \
186 struct blkio_group_stats *stats) \
187{ \
188 stats->flags &= ~(1 << BLKG_##name); \
189} \
190static inline int blkio_blkg_##name(struct blkio_group_stats *stats) \
191{ \
192 return (stats->flags & (1 << BLKG_##name)) != 0; \
193} \
194
195BLKG_FLAG_FNS(waiting)
196BLKG_FLAG_FNS(idling)
197BLKG_FLAG_FNS(empty)
198#undef BLKG_FLAG_FNS
2868ef7b
VG
199#else
200static inline char *blkg_path(struct blkio_group *blkg) { return NULL; }
cdc1184c
DS
201static inline void blkiocg_update_set_active_queue_stats(
202 struct blkio_group *blkg) {}
9195291e
DS
203static inline void blkiocg_update_dequeue_stats(struct blkio_group *blkg,
204 unsigned long dequeue) {}
812df48d
DS
205static inline void blkiocg_update_set_idle_time_stats(struct blkio_group *blkg)
206{}
207static inline void blkiocg_update_idle_time_stats(struct blkio_group *blkg) {}
208static inline void blkiocg_set_start_empty_time(struct blkio_group *blkg,
209 bool ignore) {}
2868ef7b
VG
210#endif
211
67523c48 212#if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
31e4c28d
VG
213extern struct blkio_cgroup blkio_root_cgroup;
214extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
215extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
22084190 216 struct blkio_group *blkg, void *key, dev_t dev);
31e4c28d
VG
217extern int blkiocg_del_blkio_group(struct blkio_group *blkg);
218extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg,
219 void *key);
84c124da 220void blkio_group_init(struct blkio_group *blkg);
303a3acb
DS
221void blkiocg_update_timeslice_used(struct blkio_group *blkg,
222 unsigned long time);
84c124da
DS
223void blkiocg_update_dispatch_stats(struct blkio_group *blkg, uint64_t bytes,
224 bool direction, bool sync);
225void blkiocg_update_completion_stats(struct blkio_group *blkg,
226 uint64_t start_time, uint64_t io_start_time, bool direction, bool sync);
812d4026
DS
227void blkiocg_update_io_merged_stats(struct blkio_group *blkg, bool direction,
228 bool sync);
cdc1184c
DS
229void blkiocg_update_request_add_stats(struct blkio_group *blkg,
230 struct blkio_group *curr_blkg, bool direction, bool sync);
231void blkiocg_update_request_remove_stats(struct blkio_group *blkg,
232 bool direction, bool sync);
31e4c28d 233#else
2f5ea477 234struct cgroup;
31e4c28d
VG
235static inline struct blkio_cgroup *
236cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; }
237
84c124da 238static inline void blkio_group_init(struct blkio_group *blkg) {}
31e4c28d 239static inline void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
84c124da 240 struct blkio_group *blkg, void *key, dev_t dev) {}
31e4c28d
VG
241
242static inline int
243blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; }
244
245static inline struct blkio_group *
246blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; }
303a3acb 247static inline void blkiocg_update_timeslice_used(struct blkio_group *blkg,
9a0785b0 248 unsigned long time) {}
84c124da
DS
249static inline void blkiocg_update_dispatch_stats(struct blkio_group *blkg,
250 uint64_t bytes, bool direction, bool sync) {}
251static inline void blkiocg_update_completion_stats(struct blkio_group *blkg,
252 uint64_t start_time, uint64_t io_start_time, bool direction,
253 bool sync) {}
812d4026
DS
254static inline void blkiocg_update_io_merged_stats(struct blkio_group *blkg,
255 bool direction, bool sync) {}
cdc1184c
DS
256static inline void blkiocg_update_request_add_stats(struct blkio_group *blkg,
257 struct blkio_group *curr_blkg, bool direction, bool sync) {}
258static inline void blkiocg_update_request_remove_stats(struct blkio_group *blkg,
259 bool direction, bool sync) {}
31e4c28d
VG
260#endif
261#endif /* _BLK_CGROUP_H */