blob: 257dc6a956b626936d1e0ecd6fdeb708916c964e [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>
17
Jens Axboe2f5ea472009-12-03 21:06:43 +010018#ifdef CONFIG_BLK_CGROUP
19
Vivek Goyal31e4c282009-12-03 12:59:42 -050020struct blkio_cgroup {
21 struct cgroup_subsys_state css;
22 unsigned int weight;
23 spinlock_t lock;
24 struct hlist_head blkg_list;
25};
26
27struct blkio_group {
28 /* An rcu protected unique identifier for the group */
29 void *key;
30 struct hlist_node blkcg_node;
Vivek Goyalb1c35762009-12-03 12:59:47 -050031 unsigned short blkcg_id;
Vivek Goyal2868ef72009-12-03 12:59:48 -050032#ifdef CONFIG_DEBUG_BLK_CGROUP
33 /* Store cgroup path */
34 char path[128];
Vivek Goyal22084192009-12-03 12:59:49 -050035 /* How many times this group has been removed from service tree */
36 unsigned long dequeue;
Vivek Goyal2868ef72009-12-03 12:59:48 -050037#endif
Vivek Goyal22084192009-12-03 12:59:49 -050038 /* The device MKDEV(major, minor), this group has been created for */
39 dev_t dev;
40
41 /* total disk time and nr sectors dispatched by this group */
42 unsigned long time;
43 unsigned long sectors;
Vivek Goyal31e4c282009-12-03 12:59:42 -050044};
45
Jens Axboe2f5ea472009-12-03 21:06:43 +010046#else
47
48struct blkio_group {
49};
50
51#endif
52
Vivek Goyal31e4c282009-12-03 12:59:42 -050053#define BLKIO_WEIGHT_MIN 100
54#define BLKIO_WEIGHT_MAX 1000
55#define BLKIO_WEIGHT_DEFAULT 500
56
Vivek Goyal2868ef72009-12-03 12:59:48 -050057#ifdef CONFIG_DEBUG_BLK_CGROUP
58static inline char *blkg_path(struct blkio_group *blkg)
59{
60 return blkg->path;
61}
Vivek Goyal22084192009-12-03 12:59:49 -050062void blkiocg_update_blkio_group_dequeue_stats(struct blkio_group *blkg,
63 unsigned long dequeue);
Vivek Goyal2868ef72009-12-03 12:59:48 -050064#else
65static inline char *blkg_path(struct blkio_group *blkg) { return NULL; }
Vivek Goyal22084192009-12-03 12:59:49 -050066static inline void blkiocg_update_blkio_group_dequeue_stats(
67 struct blkio_group *blkg, unsigned long dequeue) {}
Vivek Goyal2868ef72009-12-03 12:59:48 -050068#endif
69
Vivek Goyal31e4c282009-12-03 12:59:42 -050070#ifdef CONFIG_BLK_CGROUP
71extern struct blkio_cgroup blkio_root_cgroup;
72extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
73extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
Vivek Goyal22084192009-12-03 12:59:49 -050074 struct blkio_group *blkg, void *key, dev_t dev);
Vivek Goyal31e4c282009-12-03 12:59:42 -050075extern int blkiocg_del_blkio_group(struct blkio_group *blkg);
76extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg,
77 void *key);
Vivek Goyal22084192009-12-03 12:59:49 -050078void blkiocg_update_blkio_group_stats(struct blkio_group *blkg,
79 unsigned long time, unsigned long sectors);
Vivek Goyal31e4c282009-12-03 12:59:42 -050080#else
Jens Axboe2f5ea472009-12-03 21:06:43 +010081struct cgroup;
Vivek Goyal31e4c282009-12-03 12:59:42 -050082static inline struct blkio_cgroup *
83cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; }
84
85static inline void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
Vivek Goyal22084192009-12-03 12:59:49 -050086 struct blkio_group *blkg, void *key, dev_t dev)
Vivek Goyal31e4c282009-12-03 12:59:42 -050087{
88}
89
90static inline int
91blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; }
92
93static inline struct blkio_group *
94blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; }
Vivek Goyal22084192009-12-03 12:59:49 -050095static inline void blkiocg_update_blkio_group_stats(struct blkio_group *blkg,
96 unsigned long time, unsigned long sectors)
97{
98}
Vivek Goyal31e4c282009-12-03 12:59:42 -050099#endif
100#endif /* _BLK_CGROUP_H */