blob: 2060d812ae8e130d9372e97acef8805759e7db36 [file] [log] [blame]
Vivek Goyal31e4c282009-12-03 12:59:42 -05001#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>
Vivek Goyal575969a2011-05-19 15:38:29 -040017#include <linux/u64_stats_sync.h>
Vivek Goyal31e4c282009-12-03 12:59:42 -050018
Vivek Goyal062a6442010-09-15 17:06:33 -040019enum blkio_policy_id {
20 BLKIO_POLICY_PROP = 0, /* Proportional Bandwidth division */
Vivek Goyal4c9eefa2010-09-15 17:06:34 -040021 BLKIO_POLICY_THROTL, /* Throttling */
Tejun Heo035d10b2012-03-05 13:15:04 -080022
23 BLKIO_NR_POLICIES,
Vivek Goyal062a6442010-09-15 17:06:33 -040024};
25
Vivek Goyal9355aed2010-10-01 21:16:41 +020026/* Max limits for throttle policy */
27#define THROTL_IOPS_MAX UINT_MAX
28
Tejun Heo32e380a2012-03-05 13:14:54 -080029#ifdef CONFIG_BLK_CGROUP
Jens Axboe2f5ea472009-12-03 21:06:43 +010030
Divyesh Shah84c124d2010-04-09 08:31:19 +020031enum stat_type {
Tejun Heo5fe224d2012-03-08 10:53:57 -080032 /* Number of IOs merged */
33 BLKIO_STAT_MERGED,
Divyesh Shah84c124d2010-04-09 08:31:19 +020034 /* Total time spent (in ns) between request dispatch to the driver and
35 * request completion for IOs doen by this cgroup. This may not be
36 * accurate when NCQ is turned on. */
Tejun Heo5fe224d2012-03-08 10:53:57 -080037 BLKIO_STAT_SERVICE_TIME,
Divyesh Shah84c124d2010-04-09 08:31:19 +020038 /* Total time spent waiting in scheduler queue in ns */
39 BLKIO_STAT_WAIT_TIME,
Divyesh Shahcdc11842010-04-08 21:15:10 -070040 /* Number of IOs queued up */
41 BLKIO_STAT_QUEUED,
Tejun Heoc4c76a02012-03-08 10:53:59 -080042
Divyesh Shah84c124d2010-04-09 08:31:19 +020043 /* All the single valued stats go below this */
44 BLKIO_STAT_TIME,
Vivek Goyala23e6862011-05-19 15:38:20 -040045#ifdef CONFIG_DEBUG_BLK_CGROUP
Justin TerAvest167400d2011-03-12 16:54:00 +010046 /* Time not charged to this cgroup */
47 BLKIO_STAT_UNACCOUNTED_TIME,
Divyesh Shahcdc11842010-04-08 21:15:10 -070048 BLKIO_STAT_AVG_QUEUE_SIZE,
Divyesh Shah812df482010-04-08 21:15:35 -070049 BLKIO_STAT_IDLE_TIME,
50 BLKIO_STAT_EMPTY_TIME,
51 BLKIO_STAT_GROUP_WAIT_TIME,
Divyesh Shah84c124d2010-04-09 08:31:19 +020052 BLKIO_STAT_DEQUEUE
53#endif
54};
55
Tejun Heoc4c76a02012-03-08 10:53:59 -080056/* Types lower than this live in stat_arr and have subtypes */
57#define BLKIO_STAT_ARR_NR (BLKIO_STAT_QUEUED + 1)
58
Vivek Goyal5624a4e2011-05-19 15:38:28 -040059/* Per cpu stats */
60enum stat_type_cpu {
Vivek Goyal5624a4e2011-05-19 15:38:28 -040061 /* Total bytes transferred */
62 BLKIO_STAT_CPU_SERVICE_BYTES,
63 /* Total IOs serviced, post merge */
64 BLKIO_STAT_CPU_SERVICED,
Tejun Heo2aa4a152012-04-01 14:38:42 -070065
66 /* All the single valued stats go below this */
67 BLKIO_STAT_CPU_SECTORS,
Vivek Goyal5624a4e2011-05-19 15:38:28 -040068};
69
Tejun Heo2aa4a152012-04-01 14:38:42 -070070#define BLKIO_STAT_CPU_ARR_NR (BLKIO_STAT_CPU_SERVICED + 1)
71
Divyesh Shah84c124d2010-04-09 08:31:19 +020072enum stat_sub_type {
73 BLKIO_STAT_READ = 0,
74 BLKIO_STAT_WRITE,
75 BLKIO_STAT_SYNC,
76 BLKIO_STAT_ASYNC,
77 BLKIO_STAT_TOTAL
Divyesh Shah303a3ac2010-04-01 15:01:24 -070078};
79
Divyesh Shah812df482010-04-08 21:15:35 -070080/* blkg state flags */
81enum blkg_state_flags {
82 BLKG_waiting = 0,
83 BLKG_idling,
84 BLKG_empty,
85};
86
Vivek Goyal062a6442010-09-15 17:06:33 -040087/* cgroup files owned by proportional weight policy */
88enum blkcg_file_name_prop {
89 BLKIO_PROP_weight = 1,
90 BLKIO_PROP_weight_device,
91 BLKIO_PROP_io_service_bytes,
92 BLKIO_PROP_io_serviced,
93 BLKIO_PROP_time,
94 BLKIO_PROP_sectors,
Justin TerAvest167400d2011-03-12 16:54:00 +010095 BLKIO_PROP_unaccounted_time,
Vivek Goyal062a6442010-09-15 17:06:33 -040096 BLKIO_PROP_io_service_time,
97 BLKIO_PROP_io_wait_time,
98 BLKIO_PROP_io_merged,
99 BLKIO_PROP_io_queued,
100 BLKIO_PROP_avg_queue_size,
101 BLKIO_PROP_group_wait_time,
102 BLKIO_PROP_idle_time,
103 BLKIO_PROP_empty_time,
104 BLKIO_PROP_dequeue,
105};
106
Vivek Goyal4c9eefa2010-09-15 17:06:34 -0400107/* cgroup files owned by throttle policy */
108enum blkcg_file_name_throtl {
109 BLKIO_THROTL_read_bps_device,
110 BLKIO_THROTL_write_bps_device,
Vivek Goyal7702e8f2010-09-15 17:06:36 -0400111 BLKIO_THROTL_read_iops_device,
112 BLKIO_THROTL_write_iops_device,
Vivek Goyal4c9eefa2010-09-15 17:06:34 -0400113 BLKIO_THROTL_io_service_bytes,
114 BLKIO_THROTL_io_serviced,
115};
116
Vivek Goyal31e4c282009-12-03 12:59:42 -0500117struct blkio_cgroup {
118 struct cgroup_subsys_state css;
119 unsigned int weight;
120 spinlock_t lock;
121 struct hlist_head blkg_list;
Tejun Heo9a9e8a22012-03-19 15:10:56 -0700122
123 /* for policies to test whether associated blkcg has changed */
124 uint64_t id;
Vivek Goyal31e4c282009-12-03 12:59:42 -0500125};
126
Divyesh Shah303a3ac2010-04-01 15:01:24 -0700127struct blkio_group_stats {
Tejun Heoedf1b872012-03-08 10:54:00 -0800128 struct u64_stats_sync syncp;
Divyesh Shah303a3ac2010-04-01 15:01:24 -0700129 /* total disk time and nr sectors dispatched by this group */
130 uint64_t time;
Tejun Heoc4c76a02012-03-08 10:53:59 -0800131 uint64_t stat_arr[BLKIO_STAT_ARR_NR][BLKIO_STAT_TOTAL];
Divyesh Shah303a3ac2010-04-01 15:01:24 -0700132#ifdef CONFIG_DEBUG_BLK_CGROUP
Vivek Goyala23e6862011-05-19 15:38:20 -0400133 /* Time not charged to this cgroup */
134 uint64_t unaccounted_time;
135
Divyesh Shahcdc11842010-04-08 21:15:10 -0700136 /* Sum of number of IOs queued across all samples */
137 uint64_t avg_queue_size_sum;
138 /* Count of samples taken for average */
139 uint64_t avg_queue_size_samples;
Divyesh Shah303a3ac2010-04-01 15:01:24 -0700140 /* How many times this group has been removed from service tree */
141 unsigned long dequeue;
Divyesh Shah812df482010-04-08 21:15:35 -0700142
143 /* Total time spent waiting for it to be assigned a timeslice. */
144 uint64_t group_wait_time;
Divyesh Shah812df482010-04-08 21:15:35 -0700145
146 /* Time spent idling for this blkio_group */
147 uint64_t idle_time;
Divyesh Shah812df482010-04-08 21:15:35 -0700148 /*
149 * Total time when we have requests queued and do not contain the
150 * current active queue.
151 */
152 uint64_t empty_time;
Tejun Heo997a0262012-03-08 10:53:58 -0800153
154 /* fields after this shouldn't be cleared on stat reset */
155 uint64_t start_group_wait_time;
156 uint64_t start_idle_time;
Divyesh Shah812df482010-04-08 21:15:35 -0700157 uint64_t start_empty_time;
158 uint16_t flags;
Divyesh Shah303a3ac2010-04-01 15:01:24 -0700159#endif
160};
161
Tejun Heo997a0262012-03-08 10:53:58 -0800162#ifdef CONFIG_DEBUG_BLK_CGROUP
163#define BLKG_STATS_DEBUG_CLEAR_START \
164 offsetof(struct blkio_group_stats, unaccounted_time)
165#define BLKG_STATS_DEBUG_CLEAR_SIZE \
166 (offsetof(struct blkio_group_stats, start_group_wait_time) - \
167 BLKG_STATS_DEBUG_CLEAR_START)
168#endif
169
Vivek Goyal5624a4e2011-05-19 15:38:28 -0400170/* Per cpu blkio group stats */
171struct blkio_group_stats_cpu {
172 uint64_t sectors;
Tejun Heo2aa4a152012-04-01 14:38:42 -0700173 uint64_t stat_arr_cpu[BLKIO_STAT_CPU_ARR_NR][BLKIO_STAT_TOTAL];
Vivek Goyal575969a2011-05-19 15:38:29 -0400174 struct u64_stats_sync syncp;
Vivek Goyal5624a4e2011-05-19 15:38:28 -0400175};
176
Tejun Heoe56da7e2012-03-05 13:15:07 -0800177struct blkio_group_conf {
178 unsigned int weight;
179 unsigned int iops[2];
180 u64 bps[2];
181};
182
Tejun Heo03814112012-03-05 13:15:14 -0800183/* per-blkg per-policy data */
184struct blkg_policy_data {
185 /* the blkg this per-policy data belongs to */
186 struct blkio_group *blkg;
187
Tejun Heo549d3aa2012-03-05 13:15:16 -0800188 /* Configuration */
189 struct blkio_group_conf conf;
190
191 struct blkio_group_stats stats;
192 /* Per cpu stats pointer */
193 struct blkio_group_stats_cpu __percpu *stats_cpu;
194
Tejun Heo03814112012-03-05 13:15:14 -0800195 /* pol->pdata_size bytes of private data used by policy impl */
196 char pdata[] __aligned(__alignof__(unsigned long long));
197};
198
Vivek Goyal31e4c282009-12-03 12:59:42 -0500199struct blkio_group {
Tejun Heoc875f4d2012-03-05 13:15:22 -0800200 /* Pointer to the associated request_queue */
201 struct request_queue *q;
Tejun Heoe8989fa2012-03-05 13:15:20 -0800202 struct list_head q_node;
Vivek Goyal31e4c282009-12-03 12:59:42 -0500203 struct hlist_node blkcg_node;
Tejun Heo7ee9c562012-03-05 13:15:11 -0800204 struct blkio_cgroup *blkcg;
Vivek Goyal2868ef72009-12-03 12:59:48 -0500205 /* Store cgroup path */
206 char path[128];
Tejun Heo1adaf3d2012-03-05 13:15:15 -0800207 /* reference count */
208 int refcnt;
Vivek Goyal22084192009-12-03 12:59:49 -0500209
Tejun Heo549d3aa2012-03-05 13:15:16 -0800210 struct blkg_policy_data *pd[BLKIO_NR_POLICIES];
Tejun Heo1adaf3d2012-03-05 13:15:15 -0800211
Vivek Goyal1cd9e032012-03-08 10:53:56 -0800212 /* List of blkg waiting for per cpu stats memory to be allocated */
213 struct list_head alloc_node;
Tejun Heo1adaf3d2012-03-05 13:15:15 -0800214 struct rcu_head rcu_head;
Vivek Goyal31e4c282009-12-03 12:59:42 -0500215};
216
Tejun Heo03814112012-03-05 13:15:14 -0800217typedef void (blkio_init_group_fn)(struct blkio_group *blkg);
Tejun Heoca32aef2012-03-05 13:15:03 -0800218typedef void (blkio_update_group_weight_fn)(struct request_queue *q,
Vivek Goyalfe071432010-10-01 14:49:49 +0200219 struct blkio_group *blkg, unsigned int weight);
Tejun Heoca32aef2012-03-05 13:15:03 -0800220typedef void (blkio_update_group_read_bps_fn)(struct request_queue *q,
Vivek Goyalfe071432010-10-01 14:49:49 +0200221 struct blkio_group *blkg, u64 read_bps);
Tejun Heoca32aef2012-03-05 13:15:03 -0800222typedef void (blkio_update_group_write_bps_fn)(struct request_queue *q,
Vivek Goyalfe071432010-10-01 14:49:49 +0200223 struct blkio_group *blkg, u64 write_bps);
Tejun Heoca32aef2012-03-05 13:15:03 -0800224typedef void (blkio_update_group_read_iops_fn)(struct request_queue *q,
Vivek Goyalfe071432010-10-01 14:49:49 +0200225 struct blkio_group *blkg, unsigned int read_iops);
Tejun Heoca32aef2012-03-05 13:15:03 -0800226typedef void (blkio_update_group_write_iops_fn)(struct request_queue *q,
Vivek Goyalfe071432010-10-01 14:49:49 +0200227 struct blkio_group *blkg, unsigned int write_iops);
Vivek Goyal3e252062009-12-04 10:36:42 -0500228
229struct blkio_policy_ops {
Tejun Heo03814112012-03-05 13:15:14 -0800230 blkio_init_group_fn *blkio_init_group_fn;
Vivek Goyal3e252062009-12-04 10:36:42 -0500231 blkio_update_group_weight_fn *blkio_update_group_weight_fn;
Vivek Goyal4c9eefa2010-09-15 17:06:34 -0400232 blkio_update_group_read_bps_fn *blkio_update_group_read_bps_fn;
233 blkio_update_group_write_bps_fn *blkio_update_group_write_bps_fn;
Vivek Goyal7702e8f2010-09-15 17:06:36 -0400234 blkio_update_group_read_iops_fn *blkio_update_group_read_iops_fn;
235 blkio_update_group_write_iops_fn *blkio_update_group_write_iops_fn;
Vivek Goyal3e252062009-12-04 10:36:42 -0500236};
237
238struct blkio_policy_type {
239 struct list_head list;
240 struct blkio_policy_ops ops;
Vivek Goyal062a6442010-09-15 17:06:33 -0400241 enum blkio_policy_id plid;
Tejun Heo03814112012-03-05 13:15:14 -0800242 size_t pdata_size; /* policy specific private data size */
Vivek Goyal3e252062009-12-04 10:36:42 -0500243};
244
Tejun Heo5efd6112012-03-05 13:15:12 -0800245extern int blkcg_init_queue(struct request_queue *q);
246extern void blkcg_drain_queue(struct request_queue *q);
247extern void blkcg_exit_queue(struct request_queue *q);
248
Vivek Goyal3e252062009-12-04 10:36:42 -0500249/* Blkio controller policy registration */
250extern void blkio_policy_register(struct blkio_policy_type *);
251extern void blkio_policy_unregister(struct blkio_policy_type *);
Tejun Heoe8989fa2012-03-05 13:15:20 -0800252extern void blkg_destroy_all(struct request_queue *q, bool destroy_root);
253extern void update_root_blkg_pd(struct request_queue *q,
254 enum blkio_policy_id plid);
Vivek Goyal3e252062009-12-04 10:36:42 -0500255
Tejun Heo03814112012-03-05 13:15:14 -0800256/**
257 * blkg_to_pdata - get policy private data
258 * @blkg: blkg of interest
259 * @pol: policy of interest
260 *
261 * Return pointer to private data associated with the @blkg-@pol pair.
262 */
263static inline void *blkg_to_pdata(struct blkio_group *blkg,
264 struct blkio_policy_type *pol)
265{
Tejun Heo549d3aa2012-03-05 13:15:16 -0800266 return blkg ? blkg->pd[pol->plid]->pdata : NULL;
Tejun Heo03814112012-03-05 13:15:14 -0800267}
268
269/**
270 * pdata_to_blkg - get blkg associated with policy private data
271 * @pdata: policy private data of interest
Tejun Heo03814112012-03-05 13:15:14 -0800272 *
Tejun Heoaaec55a2012-04-01 14:38:42 -0700273 * @pdata is policy private data. Determine the blkg it's associated with.
Tejun Heo03814112012-03-05 13:15:14 -0800274 */
Tejun Heoaaec55a2012-04-01 14:38:42 -0700275static inline struct blkio_group *pdata_to_blkg(void *pdata)
Tejun Heo03814112012-03-05 13:15:14 -0800276{
277 if (pdata) {
278 struct blkg_policy_data *pd =
279 container_of(pdata, struct blkg_policy_data, pdata);
280 return pd->blkg;
281 }
282 return NULL;
283}
284
Vivek Goyalafc24d42010-04-26 19:27:56 +0200285static inline char *blkg_path(struct blkio_group *blkg)
286{
287 return blkg->path;
288}
289
Tejun Heo1adaf3d2012-03-05 13:15:15 -0800290/**
291 * blkg_get - get a blkg reference
292 * @blkg: blkg to get
293 *
294 * The caller should be holding queue_lock and an existing reference.
295 */
296static inline void blkg_get(struct blkio_group *blkg)
297{
298 lockdep_assert_held(blkg->q->queue_lock);
299 WARN_ON_ONCE(!blkg->refcnt);
300 blkg->refcnt++;
301}
302
303void __blkg_release(struct blkio_group *blkg);
304
305/**
306 * blkg_put - put a blkg reference
307 * @blkg: blkg to put
308 *
309 * The caller should be holding queue_lock.
310 */
311static inline void blkg_put(struct blkio_group *blkg)
312{
313 lockdep_assert_held(blkg->q->queue_lock);
314 WARN_ON_ONCE(blkg->refcnt <= 0);
315 if (!--blkg->refcnt)
316 __blkg_release(blkg);
317}
318
Jens Axboe2f5ea472009-12-03 21:06:43 +0100319#else
320
321struct blkio_group {
322};
323
Vivek Goyal3e252062009-12-04 10:36:42 -0500324struct blkio_policy_type {
325};
326
Tejun Heo5efd6112012-03-05 13:15:12 -0800327static inline int blkcg_init_queue(struct request_queue *q) { return 0; }
328static inline void blkcg_drain_queue(struct request_queue *q) { }
329static inline void blkcg_exit_queue(struct request_queue *q) { }
Vivek Goyal3e252062009-12-04 10:36:42 -0500330static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { }
331static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { }
Tejun Heo03aa2642012-03-05 13:15:19 -0800332static inline void blkg_destroy_all(struct request_queue *q,
Tejun Heo03aa2642012-03-05 13:15:19 -0800333 bool destory_root) { }
Tejun Heoe8989fa2012-03-05 13:15:20 -0800334static inline void update_root_blkg_pd(struct request_queue *q,
335 enum blkio_policy_id plid) { }
Vivek Goyal3e252062009-12-04 10:36:42 -0500336
Tejun Heo03814112012-03-05 13:15:14 -0800337static inline void *blkg_to_pdata(struct blkio_group *blkg,
338 struct blkio_policy_type *pol) { return NULL; }
339static inline struct blkio_group *pdata_to_blkg(void *pdata,
340 struct blkio_policy_type *pol) { return NULL; }
Vivek Goyalafc24d42010-04-26 19:27:56 +0200341static inline char *blkg_path(struct blkio_group *blkg) { return NULL; }
Tejun Heo1adaf3d2012-03-05 13:15:15 -0800342static inline void blkg_get(struct blkio_group *blkg) { }
343static inline void blkg_put(struct blkio_group *blkg) { }
Vivek Goyalafc24d42010-04-26 19:27:56 +0200344
Jens Axboe2f5ea472009-12-03 21:06:43 +0100345#endif
346
Justin TerAvestdf457f82011-03-08 19:45:00 +0100347#define BLKIO_WEIGHT_MIN 10
Vivek Goyal31e4c282009-12-03 12:59:42 -0500348#define BLKIO_WEIGHT_MAX 1000
349#define BLKIO_WEIGHT_DEFAULT 500
350
Vivek Goyal2868ef72009-12-03 12:59:48 -0500351#ifdef CONFIG_DEBUG_BLK_CGROUP
Tejun Heoc1768262012-03-05 13:15:17 -0800352void blkiocg_update_avg_queue_size_stats(struct blkio_group *blkg,
353 struct blkio_policy_type *pol);
Divyesh Shah91952912010-04-01 15:01:41 -0700354void blkiocg_update_dequeue_stats(struct blkio_group *blkg,
Tejun Heoc1768262012-03-05 13:15:17 -0800355 struct blkio_policy_type *pol,
356 unsigned long dequeue);
357void blkiocg_update_set_idle_time_stats(struct blkio_group *blkg,
358 struct blkio_policy_type *pol);
359void blkiocg_update_idle_time_stats(struct blkio_group *blkg,
360 struct blkio_policy_type *pol);
361void blkiocg_set_start_empty_time(struct blkio_group *blkg,
362 struct blkio_policy_type *pol);
Divyesh Shah812df482010-04-08 21:15:35 -0700363
364#define BLKG_FLAG_FNS(name) \
365static inline void blkio_mark_blkg_##name( \
366 struct blkio_group_stats *stats) \
367{ \
368 stats->flags |= (1 << BLKG_##name); \
369} \
370static inline void blkio_clear_blkg_##name( \
371 struct blkio_group_stats *stats) \
372{ \
373 stats->flags &= ~(1 << BLKG_##name); \
374} \
375static inline int blkio_blkg_##name(struct blkio_group_stats *stats) \
376{ \
377 return (stats->flags & (1 << BLKG_##name)) != 0; \
378} \
379
380BLKG_FLAG_FNS(waiting)
381BLKG_FLAG_FNS(idling)
382BLKG_FLAG_FNS(empty)
383#undef BLKG_FLAG_FNS
Vivek Goyal2868ef72009-12-03 12:59:48 -0500384#else
Tejun Heoc1768262012-03-05 13:15:17 -0800385static inline void blkiocg_update_avg_queue_size_stats(struct blkio_group *blkg,
386 struct blkio_policy_type *pol) { }
Divyesh Shah91952912010-04-01 15:01:41 -0700387static inline void blkiocg_update_dequeue_stats(struct blkio_group *blkg,
Tejun Heoc1768262012-03-05 13:15:17 -0800388 struct blkio_policy_type *pol, unsigned long dequeue) { }
389static inline void blkiocg_update_set_idle_time_stats(struct blkio_group *blkg,
390 struct blkio_policy_type *pol) { }
391static inline void blkiocg_update_idle_time_stats(struct blkio_group *blkg,
392 struct blkio_policy_type *pol) { }
393static inline void blkiocg_set_start_empty_time(struct blkio_group *blkg,
394 struct blkio_policy_type *pol) { }
Vivek Goyal2868ef72009-12-03 12:59:48 -0500395#endif
396
Tejun Heo32e380a2012-03-05 13:14:54 -0800397#ifdef CONFIG_BLK_CGROUP
Vivek Goyal31e4c282009-12-03 12:59:42 -0500398extern struct blkio_cgroup blkio_root_cgroup;
399extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
Tejun Heo4f85cb92012-03-05 13:15:28 -0800400extern struct blkio_cgroup *bio_blkio_cgroup(struct bio *bio);
Tejun Heocd1604f2012-03-05 13:15:06 -0800401extern struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg,
Tejun Heoe8989fa2012-03-05 13:15:20 -0800402 struct request_queue *q);
Tejun Heocd1604f2012-03-05 13:15:06 -0800403struct blkio_group *blkg_lookup_create(struct blkio_cgroup *blkcg,
404 struct request_queue *q,
Tejun Heocd1604f2012-03-05 13:15:06 -0800405 bool for_root);
Divyesh Shah303a3ac2010-04-01 15:01:24 -0700406void blkiocg_update_timeslice_used(struct blkio_group *blkg,
Tejun Heoc1768262012-03-05 13:15:17 -0800407 struct blkio_policy_type *pol,
408 unsigned long time,
409 unsigned long unaccounted_time);
410void blkiocg_update_dispatch_stats(struct blkio_group *blkg,
411 struct blkio_policy_type *pol,
412 uint64_t bytes, bool direction, bool sync);
Divyesh Shah84c124d2010-04-09 08:31:19 +0200413void blkiocg_update_completion_stats(struct blkio_group *blkg,
Tejun Heoc1768262012-03-05 13:15:17 -0800414 struct blkio_policy_type *pol,
415 uint64_t start_time,
416 uint64_t io_start_time, bool direction,
417 bool sync);
418void blkiocg_update_io_merged_stats(struct blkio_group *blkg,
419 struct blkio_policy_type *pol,
420 bool direction, bool sync);
Divyesh Shaha11cdaa2010-04-13 19:59:17 +0200421void blkiocg_update_io_add_stats(struct blkio_group *blkg,
Tejun Heoc1768262012-03-05 13:15:17 -0800422 struct blkio_policy_type *pol,
423 struct blkio_group *curr_blkg, bool direction,
424 bool sync);
Divyesh Shaha11cdaa2010-04-13 19:59:17 +0200425void blkiocg_update_io_remove_stats(struct blkio_group *blkg,
Tejun Heoc1768262012-03-05 13:15:17 -0800426 struct blkio_policy_type *pol,
427 bool direction, bool sync);
Vivek Goyal31e4c282009-12-03 12:59:42 -0500428#else
Jens Axboe2f5ea472009-12-03 21:06:43 +0100429struct cgroup;
Vivek Goyal31e4c282009-12-03 12:59:42 -0500430static inline struct blkio_cgroup *
431cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; }
Vivek Goyal70087dc2011-05-16 15:24:08 +0200432static inline struct blkio_cgroup *
Tejun Heo4f85cb92012-03-05 13:15:28 -0800433bio_blkio_cgroup(struct bio *bio) { return NULL; }
Vivek Goyal31e4c282009-12-03 12:59:42 -0500434
Tejun Heocd1604f2012-03-05 13:15:06 -0800435static inline struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg,
436 void *key) { return NULL; }
Divyesh Shah303a3ac2010-04-01 15:01:24 -0700437static inline void blkiocg_update_timeslice_used(struct blkio_group *blkg,
Tejun Heoc1768262012-03-05 13:15:17 -0800438 struct blkio_policy_type *pol, unsigned long time,
439 unsigned long unaccounted_time) { }
Divyesh Shah84c124d2010-04-09 08:31:19 +0200440static inline void blkiocg_update_dispatch_stats(struct blkio_group *blkg,
Tejun Heoc1768262012-03-05 13:15:17 -0800441 struct blkio_policy_type *pol, uint64_t bytes,
442 bool direction, bool sync) { }
Divyesh Shah84c124d2010-04-09 08:31:19 +0200443static inline void blkiocg_update_completion_stats(struct blkio_group *blkg,
Tejun Heoc1768262012-03-05 13:15:17 -0800444 struct blkio_policy_type *pol, uint64_t start_time,
445 uint64_t io_start_time, bool direction, bool sync) { }
Divyesh Shah812d4022010-04-08 21:14:23 -0700446static inline void blkiocg_update_io_merged_stats(struct blkio_group *blkg,
Tejun Heoc1768262012-03-05 13:15:17 -0800447 struct blkio_policy_type *pol, bool direction,
448 bool sync) { }
Divyesh Shaha11cdaa2010-04-13 19:59:17 +0200449static inline void blkiocg_update_io_add_stats(struct blkio_group *blkg,
Tejun Heoc1768262012-03-05 13:15:17 -0800450 struct blkio_policy_type *pol,
451 struct blkio_group *curr_blkg, bool direction,
452 bool sync) { }
Divyesh Shaha11cdaa2010-04-13 19:59:17 +0200453static inline void blkiocg_update_io_remove_stats(struct blkio_group *blkg,
Tejun Heoc1768262012-03-05 13:15:17 -0800454 struct blkio_policy_type *pol, bool direction,
455 bool sync) { }
Vivek Goyal31e4c282009-12-03 12:59:42 -0500456#endif
457#endif /* _BLK_CGROUP_H */