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 | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 26 | enum io_type { |
| 27 | IO_READ = 0, |
| 28 | IO_WRITE, |
| 29 | IO_SYNC, |
| 30 | IO_ASYNC, |
| 31 | IO_TYPE_MAX |
| 32 | }; |
| 33 | |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 34 | struct blkio_cgroup { |
| 35 | struct cgroup_subsys_state css; |
| 36 | unsigned int weight; |
| 37 | spinlock_t lock; |
| 38 | struct hlist_head blkg_list; |
| 39 | }; |
| 40 | |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 41 | struct blkio_group_stats { |
| 42 | /* total disk time and nr sectors dispatched by this group */ |
| 43 | uint64_t time; |
| 44 | uint64_t sectors; |
| 45 | /* Total disk time used by IOs in ns */ |
| 46 | uint64_t io_service_time[IO_TYPE_MAX]; |
| 47 | uint64_t io_service_bytes[IO_TYPE_MAX]; /* Total bytes transferred */ |
| 48 | /* Total IOs serviced, post merge */ |
| 49 | uint64_t io_serviced[IO_TYPE_MAX]; |
| 50 | /* Total time spent waiting in scheduler queue in ns */ |
| 51 | uint64_t io_wait_time[IO_TYPE_MAX]; |
| 52 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
| 53 | /* How many times this group has been removed from service tree */ |
| 54 | unsigned long dequeue; |
| 55 | #endif |
| 56 | }; |
| 57 | |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 58 | struct blkio_group { |
| 59 | /* An rcu protected unique identifier for the group */ |
| 60 | void *key; |
| 61 | struct hlist_node blkcg_node; |
Vivek Goyal | b1c3576 | 2009-12-03 12:59:47 -0500 | [diff] [blame] | 62 | unsigned short blkcg_id; |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 63 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
| 64 | /* Store cgroup path */ |
| 65 | char path[128]; |
| 66 | #endif |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 67 | /* The device MKDEV(major, minor), this group has been created for */ |
| 68 | dev_t dev; |
| 69 | |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 70 | /* Need to serialize the stats in the case of reset/update */ |
| 71 | spinlock_t stats_lock; |
| 72 | struct blkio_group_stats stats; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 73 | }; |
| 74 | |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 75 | typedef void (blkio_unlink_group_fn) (void *key, struct blkio_group *blkg); |
| 76 | typedef void (blkio_update_group_weight_fn) (struct blkio_group *blkg, |
| 77 | unsigned int weight); |
| 78 | |
| 79 | struct blkio_policy_ops { |
| 80 | blkio_unlink_group_fn *blkio_unlink_group_fn; |
| 81 | blkio_update_group_weight_fn *blkio_update_group_weight_fn; |
| 82 | }; |
| 83 | |
| 84 | struct blkio_policy_type { |
| 85 | struct list_head list; |
| 86 | struct blkio_policy_ops ops; |
| 87 | }; |
| 88 | |
| 89 | /* Blkio controller policy registration */ |
| 90 | extern void blkio_policy_register(struct blkio_policy_type *); |
| 91 | extern void blkio_policy_unregister(struct blkio_policy_type *); |
| 92 | |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 93 | #else |
| 94 | |
| 95 | struct blkio_group { |
| 96 | }; |
| 97 | |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 98 | struct blkio_policy_type { |
| 99 | }; |
| 100 | |
| 101 | static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { } |
| 102 | static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { } |
| 103 | |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 104 | #endif |
| 105 | |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 106 | #define BLKIO_WEIGHT_MIN 100 |
| 107 | #define BLKIO_WEIGHT_MAX 1000 |
| 108 | #define BLKIO_WEIGHT_DEFAULT 500 |
| 109 | |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 110 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
| 111 | static inline char *blkg_path(struct blkio_group *blkg) |
| 112 | { |
| 113 | return blkg->path; |
| 114 | } |
Divyesh Shah | 9195291 | 2010-04-01 15:01:41 -0700 | [diff] [blame^] | 115 | void blkiocg_update_dequeue_stats(struct blkio_group *blkg, |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 116 | unsigned long dequeue); |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 117 | #else |
| 118 | static inline char *blkg_path(struct blkio_group *blkg) { return NULL; } |
Divyesh Shah | 9195291 | 2010-04-01 15:01:41 -0700 | [diff] [blame^] | 119 | static inline void blkiocg_update_dequeue_stats(struct blkio_group *blkg, |
| 120 | unsigned long dequeue) {} |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 121 | #endif |
| 122 | |
Ben Blum | 67523c4 | 2010-03-10 15:22:11 -0800 | [diff] [blame] | 123 | #if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE) |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 124 | extern struct blkio_cgroup blkio_root_cgroup; |
| 125 | extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup); |
| 126 | extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg, |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 127 | struct blkio_group *blkg, void *key, dev_t dev); |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 128 | extern int blkiocg_del_blkio_group(struct blkio_group *blkg); |
| 129 | extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg, |
| 130 | void *key); |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 131 | void blkiocg_update_timeslice_used(struct blkio_group *blkg, |
| 132 | unsigned long time); |
Divyesh Shah | 9195291 | 2010-04-01 15:01:41 -0700 | [diff] [blame^] | 133 | void blkiocg_update_request_dispatch_stats(struct blkio_group *blkg, |
| 134 | struct request *rq); |
| 135 | void blkiocg_update_request_completion_stats(struct blkio_group *blkg, |
| 136 | struct request *rq); |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 137 | #else |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 138 | struct cgroup; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 139 | static inline struct blkio_cgroup * |
| 140 | cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; } |
| 141 | |
| 142 | static inline void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg, |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 143 | struct blkio_group *blkg, void *key, dev_t dev) |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 144 | { |
| 145 | } |
| 146 | |
| 147 | static inline int |
| 148 | blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; } |
| 149 | |
| 150 | static inline struct blkio_group * |
| 151 | blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; } |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 152 | static inline void blkiocg_update_timeslice_used(struct blkio_group *blkg, |
Divyesh Shah | 9a0785b | 2010-04-01 15:01:04 -0700 | [diff] [blame] | 153 | unsigned long time) {} |
Divyesh Shah | 9195291 | 2010-04-01 15:01:41 -0700 | [diff] [blame^] | 154 | static inline void blkiocg_update_request_dispatch_stats( |
| 155 | struct blkio_group *blkg, struct request *rq) {} |
| 156 | static inline void blkiocg_update_request_completion_stats( |
| 157 | struct blkio_group *blkg, struct request *rq) {} |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 158 | #endif |
| 159 | #endif /* _BLK_CGROUP_H */ |