Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 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 | |
Ben Blum | 67523c4 | 2010-03-10 15:22:11 -0800 | [diff] [blame] | 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 */ |
| 22 | extern struct cgroup_subsys blkio_subsys; |
| 23 | #define blkio_subsys_id blkio_subsys.subsys_id |
| 24 | #endif |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 25 | |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 26 | enum 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, |
Divyesh Shah | 812d402 | 2010-04-08 21:14:23 -0700 | [diff] [blame^] | 37 | /* Number of IOs merged */ |
| 38 | BLKIO_STAT_MERGED, |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 39 | /* All the single valued stats go below this */ |
| 40 | BLKIO_STAT_TIME, |
| 41 | BLKIO_STAT_SECTORS, |
| 42 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
| 43 | BLKIO_STAT_DEQUEUE |
| 44 | #endif |
| 45 | }; |
| 46 | |
| 47 | enum stat_sub_type { |
| 48 | BLKIO_STAT_READ = 0, |
| 49 | BLKIO_STAT_WRITE, |
| 50 | BLKIO_STAT_SYNC, |
| 51 | BLKIO_STAT_ASYNC, |
| 52 | BLKIO_STAT_TOTAL |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 55 | struct blkio_cgroup { |
| 56 | struct cgroup_subsys_state css; |
| 57 | unsigned int weight; |
| 58 | spinlock_t lock; |
| 59 | struct hlist_head blkg_list; |
| 60 | }; |
| 61 | |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 62 | struct blkio_group_stats { |
| 63 | /* total disk time and nr sectors dispatched by this group */ |
| 64 | uint64_t time; |
| 65 | uint64_t sectors; |
Divyesh Shah | 812d402 | 2010-04-08 21:14:23 -0700 | [diff] [blame^] | 66 | uint64_t stat_arr[BLKIO_STAT_MERGED + 1][BLKIO_STAT_TOTAL]; |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 67 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
| 68 | /* How many times this group has been removed from service tree */ |
| 69 | unsigned long dequeue; |
| 70 | #endif |
| 71 | }; |
| 72 | |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 73 | struct blkio_group { |
| 74 | /* An rcu protected unique identifier for the group */ |
| 75 | void *key; |
| 76 | struct hlist_node blkcg_node; |
Vivek Goyal | b1c3576 | 2009-12-03 12:59:47 -0500 | [diff] [blame] | 77 | unsigned short blkcg_id; |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 78 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
| 79 | /* Store cgroup path */ |
| 80 | char path[128]; |
| 81 | #endif |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 82 | /* The device MKDEV(major, minor), this group has been created for */ |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 83 | dev_t dev; |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 84 | |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 85 | /* Need to serialize the stats in the case of reset/update */ |
| 86 | spinlock_t stats_lock; |
| 87 | struct blkio_group_stats stats; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 88 | }; |
| 89 | |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 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, |
| 92 | unsigned int weight); |
| 93 | |
| 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; |
| 97 | }; |
| 98 | |
| 99 | struct blkio_policy_type { |
| 100 | struct list_head list; |
| 101 | struct blkio_policy_ops ops; |
| 102 | }; |
| 103 | |
| 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 *); |
| 107 | |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 108 | #else |
| 109 | |
| 110 | struct blkio_group { |
| 111 | }; |
| 112 | |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 113 | struct blkio_policy_type { |
| 114 | }; |
| 115 | |
| 116 | static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { } |
| 117 | static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { } |
| 118 | |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 119 | #endif |
| 120 | |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 121 | #define BLKIO_WEIGHT_MIN 100 |
| 122 | #define BLKIO_WEIGHT_MAX 1000 |
| 123 | #define BLKIO_WEIGHT_DEFAULT 500 |
| 124 | |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 125 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
| 126 | static inline char *blkg_path(struct blkio_group *blkg) |
| 127 | { |
| 128 | return blkg->path; |
| 129 | } |
Divyesh Shah | 9195291 | 2010-04-01 15:01:41 -0700 | [diff] [blame] | 130 | void blkiocg_update_dequeue_stats(struct blkio_group *blkg, |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 131 | unsigned long dequeue); |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 132 | #else |
| 133 | static inline char *blkg_path(struct blkio_group *blkg) { return NULL; } |
Divyesh Shah | 9195291 | 2010-04-01 15:01:41 -0700 | [diff] [blame] | 134 | static inline void blkiocg_update_dequeue_stats(struct blkio_group *blkg, |
| 135 | unsigned long dequeue) {} |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 136 | #endif |
| 137 | |
Ben Blum | 67523c4 | 2010-03-10 15:22:11 -0800 | [diff] [blame] | 138 | #if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE) |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 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, |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 142 | struct blkio_group *blkg, void *key, dev_t dev); |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 143 | extern int blkiocg_del_blkio_group(struct blkio_group *blkg); |
| 144 | extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg, |
| 145 | void *key); |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 146 | void blkio_group_init(struct blkio_group *blkg); |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 147 | void blkiocg_update_timeslice_used(struct blkio_group *blkg, |
| 148 | unsigned long time); |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 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); |
Divyesh Shah | 812d402 | 2010-04-08 21:14:23 -0700 | [diff] [blame^] | 153 | void blkiocg_update_io_merged_stats(struct blkio_group *blkg, bool direction, |
| 154 | bool sync); |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 155 | #else |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 156 | struct cgroup; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 157 | static inline struct blkio_cgroup * |
| 158 | cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; } |
| 159 | |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 160 | static inline void blkio_group_init(struct blkio_group *blkg) {} |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 161 | static inline void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg, |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 162 | struct blkio_group *blkg, void *key, dev_t dev) {} |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 163 | |
| 164 | static inline int |
| 165 | blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; } |
| 166 | |
| 167 | static inline struct blkio_group * |
| 168 | blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; } |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 169 | static inline void blkiocg_update_timeslice_used(struct blkio_group *blkg, |
Divyesh Shah | 9a0785b | 2010-04-01 15:01:04 -0700 | [diff] [blame] | 170 | unsigned long time) {} |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 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, |
| 175 | bool sync) {} |
Divyesh Shah | 812d402 | 2010-04-08 21:14:23 -0700 | [diff] [blame^] | 176 | static inline void blkiocg_update_io_merged_stats(struct blkio_group *blkg, |
| 177 | bool direction, bool sync) {} |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 178 | #endif |
| 179 | #endif /* _BLK_CGROUP_H */ |