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 /* Number of IOs merged */
39 /* All the single valued stats go below this */
42 #ifdef CONFIG_DEBUG_BLK_CGROUP
56 struct cgroup_subsys_state css;
59 struct hlist_head blkg_list;
62 struct blkio_group_stats {
63 /* total disk time and nr sectors dispatched by this group */
66 uint64_t stat_arr[BLKIO_STAT_MERGED + 1][BLKIO_STAT_TOTAL];
67 #ifdef CONFIG_DEBUG_BLK_CGROUP
68 /* How many times this group has been removed from service tree */
69 unsigned long dequeue;
74 /* An rcu protected unique identifier for the group */
76 struct hlist_node blkcg_node;
77 unsigned short blkcg_id;
78 #ifdef CONFIG_DEBUG_BLK_CGROUP
79 /* Store cgroup path */
82 /* The device MKDEV(major, minor), this group has been created for */
85 /* Need to serialize the stats in the case of reset/update */
86 spinlock_t stats_lock;
87 struct blkio_group_stats stats;
90 typedef void (blkio_unlink_group_fn) (void *key, struct blkio_group *blkg);
91 typedef void (blkio_update_group_weight_fn) (struct blkio_group *blkg,
94 struct blkio_policy_ops {
95 blkio_unlink_group_fn *blkio_unlink_group_fn;
96 blkio_update_group_weight_fn *blkio_update_group_weight_fn;
99 struct blkio_policy_type {
100 struct list_head list;
101 struct blkio_policy_ops ops;
104 /* Blkio controller policy registration */
105 extern void blkio_policy_register(struct blkio_policy_type *);
106 extern void blkio_policy_unregister(struct blkio_policy_type *);
113 struct blkio_policy_type {
116 static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { }
117 static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { }
121 #define BLKIO_WEIGHT_MIN 100
122 #define BLKIO_WEIGHT_MAX 1000
123 #define BLKIO_WEIGHT_DEFAULT 500
125 #ifdef CONFIG_DEBUG_BLK_CGROUP
126 static inline char *blkg_path(struct blkio_group *blkg)
130 void blkiocg_update_dequeue_stats(struct blkio_group *blkg,
131 unsigned long dequeue);
133 static inline char *blkg_path(struct blkio_group *blkg) { return NULL; }
134 static inline void blkiocg_update_dequeue_stats(struct blkio_group *blkg,
135 unsigned long dequeue) {}
138 #if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
139 extern struct blkio_cgroup blkio_root_cgroup;
140 extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
141 extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
142 struct blkio_group *blkg, void *key, dev_t dev);
143 extern int blkiocg_del_blkio_group(struct blkio_group *blkg);
144 extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg,
146 void blkio_group_init(struct blkio_group *blkg);
147 void blkiocg_update_timeslice_used(struct blkio_group *blkg,
149 void blkiocg_update_dispatch_stats(struct blkio_group *blkg, uint64_t bytes,
150 bool direction, bool sync);
151 void blkiocg_update_completion_stats(struct blkio_group *blkg,
152 uint64_t start_time, uint64_t io_start_time, bool direction, bool sync);
153 void blkiocg_update_io_merged_stats(struct blkio_group *blkg, bool direction,
157 static inline struct blkio_cgroup *
158 cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; }
160 static inline void blkio_group_init(struct blkio_group *blkg) {}
161 static inline void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
162 struct blkio_group *blkg, void *key, dev_t dev) {}
165 blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; }
167 static inline struct blkio_group *
168 blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; }
169 static inline void blkiocg_update_timeslice_used(struct blkio_group *blkg,
170 unsigned long time) {}
171 static inline void blkiocg_update_dispatch_stats(struct blkio_group *blkg,
172 uint64_t bytes, bool direction, bool sync) {}
173 static inline void blkiocg_update_completion_stats(struct blkio_group *blkg,
174 uint64_t start_time, uint64_t io_start_time, bool direction,
176 static inline void blkiocg_update_io_merged_stats(struct blkio_group *blkg,
177 bool direction, bool sync) {}
179 #endif /* _BLK_CGROUP_H */