4 * Common Block IO controller cgroup interface
6 * Based on ideas and code from CFQ, CFS and BFQ:
7 * Copyright (C) 2003 Jens Axboe <axboe@kernel.dk>
9 * Copyright (C) 2008 Fabio Checconi <fabio@gandalf.sssup.it>
10 * Paolo Valente <paolo.valente@unimore.it>
12 * Copyright (C) 2009 Vivek Goyal <vgoyal@redhat.com>
13 * Nauman Rafique <nauman@google.com>
16 #include <linux/cgroup.h>
18 #if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
20 #ifndef CONFIG_BLK_CGROUP
21 /* When blk-cgroup is a module, its subsys_id isn't a compile-time constant */
22 extern struct cgroup_subsys blkio_subsys;
23 #define blkio_subsys_id blkio_subsys.subsys_id
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 */
35 /* Total time spent waiting in scheduler queue in ns */
37 /* All the single valued stats go below this */
40 #ifdef CONFIG_DEBUG_BLK_CGROUP
54 struct cgroup_subsys_state css;
57 struct hlist_head blkg_list;
60 struct blkio_group_stats {
61 /* total disk time and nr sectors dispatched by this group */
64 uint64_t stat_arr[BLKIO_STAT_WAIT_TIME + 1][BLKIO_STAT_TOTAL];
65 #ifdef CONFIG_DEBUG_BLK_CGROUP
66 /* How many times this group has been removed from service tree */
67 unsigned long dequeue;
72 /* An rcu protected unique identifier for the group */
74 struct hlist_node blkcg_node;
75 unsigned short blkcg_id;
76 #ifdef CONFIG_DEBUG_BLK_CGROUP
77 /* Store cgroup path */
80 /* The device MKDEV(major, minor), this group has been created for */
83 /* Need to serialize the stats in the case of reset/update */
84 spinlock_t stats_lock;
85 struct blkio_group_stats stats;
88 typedef void (blkio_unlink_group_fn) (void *key, struct blkio_group *blkg);
89 typedef void (blkio_update_group_weight_fn) (struct blkio_group *blkg,
92 struct blkio_policy_ops {
93 blkio_unlink_group_fn *blkio_unlink_group_fn;
94 blkio_update_group_weight_fn *blkio_update_group_weight_fn;
97 struct blkio_policy_type {
98 struct list_head list;
99 struct blkio_policy_ops ops;
102 /* Blkio controller policy registration */
103 extern void blkio_policy_register(struct blkio_policy_type *);
104 extern void blkio_policy_unregister(struct blkio_policy_type *);
111 struct blkio_policy_type {
114 static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { }
115 static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { }
119 #define BLKIO_WEIGHT_MIN 100
120 #define BLKIO_WEIGHT_MAX 1000
121 #define BLKIO_WEIGHT_DEFAULT 500
123 #ifdef CONFIG_DEBUG_BLK_CGROUP
124 static inline char *blkg_path(struct blkio_group *blkg)
128 void blkiocg_update_dequeue_stats(struct blkio_group *blkg,
129 unsigned long dequeue);
131 static inline char *blkg_path(struct blkio_group *blkg) { return NULL; }
132 static inline void blkiocg_update_dequeue_stats(struct blkio_group *blkg,
133 unsigned long dequeue) {}
136 #if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
137 extern struct blkio_cgroup blkio_root_cgroup;
138 extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
139 extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
140 struct blkio_group *blkg, void *key, dev_t dev);
141 extern int blkiocg_del_blkio_group(struct blkio_group *blkg);
142 extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg,
144 void blkio_group_init(struct blkio_group *blkg);
145 void blkiocg_update_timeslice_used(struct blkio_group *blkg,
147 void blkiocg_update_dispatch_stats(struct blkio_group *blkg, uint64_t bytes,
148 bool direction, bool sync);
149 void blkiocg_update_completion_stats(struct blkio_group *blkg,
150 uint64_t start_time, uint64_t io_start_time, bool direction, bool sync);
153 static inline struct blkio_cgroup *
154 cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; }
156 static inline void blkio_group_init(struct blkio_group *blkg) {}
157 static inline void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
158 struct blkio_group *blkg, void *key, dev_t dev) {}
161 blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; }
163 static inline struct blkio_group *
164 blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; }
165 static inline void blkiocg_update_timeslice_used(struct blkio_group *blkg,
166 unsigned long time) {}
167 static inline void blkiocg_update_dispatch_stats(struct blkio_group *blkg,
168 uint64_t bytes, bool direction, bool sync) {}
169 static inline void blkiocg_update_completion_stats(struct blkio_group *blkg,
170 uint64_t start_time, uint64_t io_start_time, bool direction,
173 #endif /* _BLK_CGROUP_H */