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 | |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 18 | #ifdef CONFIG_BLK_CGROUP |
| 19 | |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 20 | struct blkio_cgroup { |
| 21 | struct cgroup_subsys_state css; |
| 22 | unsigned int weight; |
| 23 | spinlock_t lock; |
| 24 | struct hlist_head blkg_list; |
| 25 | }; |
| 26 | |
| 27 | struct blkio_group { |
| 28 | /* An rcu protected unique identifier for the group */ |
| 29 | void *key; |
| 30 | struct hlist_node blkcg_node; |
Vivek Goyal | b1c3576 | 2009-12-03 12:59:47 -0500 | [diff] [blame] | 31 | unsigned short blkcg_id; |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 32 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
| 33 | /* Store cgroup path */ |
| 34 | char path[128]; |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 35 | /* How many times this group has been removed from service tree */ |
| 36 | unsigned long dequeue; |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 37 | #endif |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 38 | /* 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 Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 44 | }; |
| 45 | |
Vivek Goyal | 9d6a986 | 2009-12-04 10:36:41 -0500 | [diff] [blame] | 46 | extern bool blkiocg_css_tryget(struct blkio_cgroup *blkcg); |
| 47 | extern void blkiocg_css_put(struct blkio_cgroup *blkcg); |
| 48 | |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 49 | typedef void (blkio_unlink_group_fn) (void *key, struct blkio_group *blkg); |
| 50 | typedef void (blkio_update_group_weight_fn) (struct blkio_group *blkg, |
| 51 | unsigned int weight); |
| 52 | |
| 53 | struct blkio_policy_ops { |
| 54 | blkio_unlink_group_fn *blkio_unlink_group_fn; |
| 55 | blkio_update_group_weight_fn *blkio_update_group_weight_fn; |
| 56 | }; |
| 57 | |
| 58 | struct blkio_policy_type { |
| 59 | struct list_head list; |
| 60 | struct blkio_policy_ops ops; |
| 61 | }; |
| 62 | |
| 63 | /* Blkio controller policy registration */ |
| 64 | extern void blkio_policy_register(struct blkio_policy_type *); |
| 65 | extern void blkio_policy_unregister(struct blkio_policy_type *); |
| 66 | |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 67 | #else |
| 68 | |
| 69 | struct blkio_group { |
| 70 | }; |
| 71 | |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 72 | struct blkio_policy_type { |
| 73 | }; |
| 74 | |
| 75 | static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { } |
| 76 | static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { } |
| 77 | |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 78 | #endif |
| 79 | |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 80 | #define BLKIO_WEIGHT_MIN 100 |
| 81 | #define BLKIO_WEIGHT_MAX 1000 |
| 82 | #define BLKIO_WEIGHT_DEFAULT 500 |
| 83 | |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 84 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
| 85 | static inline char *blkg_path(struct blkio_group *blkg) |
| 86 | { |
| 87 | return blkg->path; |
| 88 | } |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 89 | void blkiocg_update_blkio_group_dequeue_stats(struct blkio_group *blkg, |
| 90 | unsigned long dequeue); |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 91 | #else |
| 92 | static inline char *blkg_path(struct blkio_group *blkg) { return NULL; } |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 93 | static inline void blkiocg_update_blkio_group_dequeue_stats( |
| 94 | struct blkio_group *blkg, unsigned long dequeue) {} |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 95 | #endif |
| 96 | |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 97 | #ifdef CONFIG_BLK_CGROUP |
| 98 | extern struct blkio_cgroup blkio_root_cgroup; |
| 99 | extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup); |
| 100 | extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg, |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 101 | struct blkio_group *blkg, void *key, dev_t dev); |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 102 | extern int blkiocg_del_blkio_group(struct blkio_group *blkg); |
| 103 | extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg, |
| 104 | void *key); |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 105 | void blkiocg_update_blkio_group_stats(struct blkio_group *blkg, |
| 106 | unsigned long time, unsigned long sectors); |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 107 | #else |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 108 | struct cgroup; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 109 | static inline struct blkio_cgroup * |
| 110 | cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; } |
| 111 | |
| 112 | static inline void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg, |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 113 | struct blkio_group *blkg, void *key, dev_t dev) |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 114 | { |
| 115 | } |
| 116 | |
| 117 | static inline int |
| 118 | blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; } |
| 119 | |
| 120 | static inline struct blkio_group * |
| 121 | blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; } |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 122 | static inline void blkiocg_update_blkio_group_stats(struct blkio_group *blkg, |
| 123 | unsigned long time, unsigned long sectors) |
| 124 | { |
| 125 | } |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 126 | #endif |
| 127 | #endif /* _BLK_CGROUP_H */ |