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> |
Vivek Goyal | 575969a | 2011-05-19 15:38:29 -0400 | [diff] [blame] | 17 | #include <linux/u64_stats_sync.h> |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 18 | |
Vivek Goyal | 062a644 | 2010-09-15 17:06:33 -0400 | [diff] [blame] | 19 | enum blkio_policy_id { |
| 20 | BLKIO_POLICY_PROP = 0, /* Proportional Bandwidth division */ |
Vivek Goyal | 4c9eefa | 2010-09-15 17:06:34 -0400 | [diff] [blame] | 21 | BLKIO_POLICY_THROTL, /* Throttling */ |
Tejun Heo | 035d10b | 2012-03-05 13:15:04 -0800 | [diff] [blame] | 22 | |
| 23 | BLKIO_NR_POLICIES, |
Vivek Goyal | 062a644 | 2010-09-15 17:06:33 -0400 | [diff] [blame] | 24 | }; |
| 25 | |
Vivek Goyal | 9355aed | 2010-10-01 21:16:41 +0200 | [diff] [blame] | 26 | /* Max limits for throttle policy */ |
| 27 | #define THROTL_IOPS_MAX UINT_MAX |
| 28 | |
Tejun Heo | 32e380a | 2012-03-05 13:14:54 -0800 | [diff] [blame] | 29 | #ifdef CONFIG_BLK_CGROUP |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 30 | |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 31 | enum stat_type { |
Tejun Heo | 5fe224d | 2012-03-08 10:53:57 -0800 | [diff] [blame] | 32 | /* Number of IOs merged */ |
| 33 | BLKIO_STAT_MERGED, |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 34 | /* Total time spent (in ns) between request dispatch to the driver and |
| 35 | * request completion for IOs doen by this cgroup. This may not be |
| 36 | * accurate when NCQ is turned on. */ |
Tejun Heo | 5fe224d | 2012-03-08 10:53:57 -0800 | [diff] [blame] | 37 | BLKIO_STAT_SERVICE_TIME, |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 38 | /* Total time spent waiting in scheduler queue in ns */ |
| 39 | BLKIO_STAT_WAIT_TIME, |
Divyesh Shah | cdc1184 | 2010-04-08 21:15:10 -0700 | [diff] [blame] | 40 | /* Number of IOs queued up */ |
| 41 | BLKIO_STAT_QUEUED, |
Tejun Heo | c4c76a0 | 2012-03-08 10:53:59 -0800 | [diff] [blame] | 42 | |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 43 | /* All the single valued stats go below this */ |
| 44 | BLKIO_STAT_TIME, |
Vivek Goyal | a23e686 | 2011-05-19 15:38:20 -0400 | [diff] [blame] | 45 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
Justin TerAvest | 167400d | 2011-03-12 16:54:00 +0100 | [diff] [blame] | 46 | /* Time not charged to this cgroup */ |
| 47 | BLKIO_STAT_UNACCOUNTED_TIME, |
Divyesh Shah | cdc1184 | 2010-04-08 21:15:10 -0700 | [diff] [blame] | 48 | BLKIO_STAT_AVG_QUEUE_SIZE, |
Divyesh Shah | 812df48 | 2010-04-08 21:15:35 -0700 | [diff] [blame] | 49 | BLKIO_STAT_IDLE_TIME, |
| 50 | BLKIO_STAT_EMPTY_TIME, |
| 51 | BLKIO_STAT_GROUP_WAIT_TIME, |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 52 | BLKIO_STAT_DEQUEUE |
| 53 | #endif |
| 54 | }; |
| 55 | |
Tejun Heo | c4c76a0 | 2012-03-08 10:53:59 -0800 | [diff] [blame] | 56 | /* Types lower than this live in stat_arr and have subtypes */ |
| 57 | #define BLKIO_STAT_ARR_NR (BLKIO_STAT_QUEUED + 1) |
| 58 | |
Vivek Goyal | 5624a4e | 2011-05-19 15:38:28 -0400 | [diff] [blame] | 59 | /* Per cpu stats */ |
| 60 | enum stat_type_cpu { |
| 61 | BLKIO_STAT_CPU_SECTORS, |
| 62 | /* Total bytes transferred */ |
| 63 | BLKIO_STAT_CPU_SERVICE_BYTES, |
| 64 | /* Total IOs serviced, post merge */ |
| 65 | BLKIO_STAT_CPU_SERVICED, |
| 66 | BLKIO_STAT_CPU_NR |
| 67 | }; |
| 68 | |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 69 | enum stat_sub_type { |
| 70 | BLKIO_STAT_READ = 0, |
| 71 | BLKIO_STAT_WRITE, |
| 72 | BLKIO_STAT_SYNC, |
| 73 | BLKIO_STAT_ASYNC, |
| 74 | BLKIO_STAT_TOTAL |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
Divyesh Shah | 812df48 | 2010-04-08 21:15:35 -0700 | [diff] [blame] | 77 | /* blkg state flags */ |
| 78 | enum blkg_state_flags { |
| 79 | BLKG_waiting = 0, |
| 80 | BLKG_idling, |
| 81 | BLKG_empty, |
| 82 | }; |
| 83 | |
Vivek Goyal | 062a644 | 2010-09-15 17:06:33 -0400 | [diff] [blame] | 84 | /* cgroup files owned by proportional weight policy */ |
| 85 | enum blkcg_file_name_prop { |
| 86 | BLKIO_PROP_weight = 1, |
| 87 | BLKIO_PROP_weight_device, |
| 88 | BLKIO_PROP_io_service_bytes, |
| 89 | BLKIO_PROP_io_serviced, |
| 90 | BLKIO_PROP_time, |
| 91 | BLKIO_PROP_sectors, |
Justin TerAvest | 167400d | 2011-03-12 16:54:00 +0100 | [diff] [blame] | 92 | BLKIO_PROP_unaccounted_time, |
Vivek Goyal | 062a644 | 2010-09-15 17:06:33 -0400 | [diff] [blame] | 93 | BLKIO_PROP_io_service_time, |
| 94 | BLKIO_PROP_io_wait_time, |
| 95 | BLKIO_PROP_io_merged, |
| 96 | BLKIO_PROP_io_queued, |
| 97 | BLKIO_PROP_avg_queue_size, |
| 98 | BLKIO_PROP_group_wait_time, |
| 99 | BLKIO_PROP_idle_time, |
| 100 | BLKIO_PROP_empty_time, |
| 101 | BLKIO_PROP_dequeue, |
| 102 | }; |
| 103 | |
Vivek Goyal | 4c9eefa | 2010-09-15 17:06:34 -0400 | [diff] [blame] | 104 | /* cgroup files owned by throttle policy */ |
| 105 | enum blkcg_file_name_throtl { |
| 106 | BLKIO_THROTL_read_bps_device, |
| 107 | BLKIO_THROTL_write_bps_device, |
Vivek Goyal | 7702e8f | 2010-09-15 17:06:36 -0400 | [diff] [blame] | 108 | BLKIO_THROTL_read_iops_device, |
| 109 | BLKIO_THROTL_write_iops_device, |
Vivek Goyal | 4c9eefa | 2010-09-15 17:06:34 -0400 | [diff] [blame] | 110 | BLKIO_THROTL_io_service_bytes, |
| 111 | BLKIO_THROTL_io_serviced, |
| 112 | }; |
| 113 | |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 114 | struct blkio_cgroup { |
| 115 | struct cgroup_subsys_state css; |
| 116 | unsigned int weight; |
| 117 | spinlock_t lock; |
| 118 | struct hlist_head blkg_list; |
Tejun Heo | 9a9e8a2 | 2012-03-19 15:10:56 -0700 | [diff] [blame] | 119 | |
| 120 | /* for policies to test whether associated blkcg has changed */ |
| 121 | uint64_t id; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 122 | }; |
| 123 | |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 124 | struct blkio_group_stats { |
Tejun Heo | edf1b87 | 2012-03-08 10:54:00 -0800 | [diff] [blame] | 125 | struct u64_stats_sync syncp; |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 126 | /* total disk time and nr sectors dispatched by this group */ |
| 127 | uint64_t time; |
Tejun Heo | c4c76a0 | 2012-03-08 10:53:59 -0800 | [diff] [blame] | 128 | uint64_t stat_arr[BLKIO_STAT_ARR_NR][BLKIO_STAT_TOTAL]; |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 129 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
Vivek Goyal | a23e686 | 2011-05-19 15:38:20 -0400 | [diff] [blame] | 130 | /* Time not charged to this cgroup */ |
| 131 | uint64_t unaccounted_time; |
| 132 | |
Divyesh Shah | cdc1184 | 2010-04-08 21:15:10 -0700 | [diff] [blame] | 133 | /* Sum of number of IOs queued across all samples */ |
| 134 | uint64_t avg_queue_size_sum; |
| 135 | /* Count of samples taken for average */ |
| 136 | uint64_t avg_queue_size_samples; |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 137 | /* How many times this group has been removed from service tree */ |
| 138 | unsigned long dequeue; |
Divyesh Shah | 812df48 | 2010-04-08 21:15:35 -0700 | [diff] [blame] | 139 | |
| 140 | /* Total time spent waiting for it to be assigned a timeslice. */ |
| 141 | uint64_t group_wait_time; |
Divyesh Shah | 812df48 | 2010-04-08 21:15:35 -0700 | [diff] [blame] | 142 | |
| 143 | /* Time spent idling for this blkio_group */ |
| 144 | uint64_t idle_time; |
Divyesh Shah | 812df48 | 2010-04-08 21:15:35 -0700 | [diff] [blame] | 145 | /* |
| 146 | * Total time when we have requests queued and do not contain the |
| 147 | * current active queue. |
| 148 | */ |
| 149 | uint64_t empty_time; |
Tejun Heo | 997a026 | 2012-03-08 10:53:58 -0800 | [diff] [blame] | 150 | |
| 151 | /* fields after this shouldn't be cleared on stat reset */ |
| 152 | uint64_t start_group_wait_time; |
| 153 | uint64_t start_idle_time; |
Divyesh Shah | 812df48 | 2010-04-08 21:15:35 -0700 | [diff] [blame] | 154 | uint64_t start_empty_time; |
| 155 | uint16_t flags; |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 156 | #endif |
| 157 | }; |
| 158 | |
Tejun Heo | 997a026 | 2012-03-08 10:53:58 -0800 | [diff] [blame] | 159 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
| 160 | #define BLKG_STATS_DEBUG_CLEAR_START \ |
| 161 | offsetof(struct blkio_group_stats, unaccounted_time) |
| 162 | #define BLKG_STATS_DEBUG_CLEAR_SIZE \ |
| 163 | (offsetof(struct blkio_group_stats, start_group_wait_time) - \ |
| 164 | BLKG_STATS_DEBUG_CLEAR_START) |
| 165 | #endif |
| 166 | |
Vivek Goyal | 5624a4e | 2011-05-19 15:38:28 -0400 | [diff] [blame] | 167 | /* Per cpu blkio group stats */ |
| 168 | struct blkio_group_stats_cpu { |
| 169 | uint64_t sectors; |
| 170 | uint64_t stat_arr_cpu[BLKIO_STAT_CPU_NR][BLKIO_STAT_TOTAL]; |
Vivek Goyal | 575969a | 2011-05-19 15:38:29 -0400 | [diff] [blame] | 171 | struct u64_stats_sync syncp; |
Vivek Goyal | 5624a4e | 2011-05-19 15:38:28 -0400 | [diff] [blame] | 172 | }; |
| 173 | |
Tejun Heo | e56da7e | 2012-03-05 13:15:07 -0800 | [diff] [blame] | 174 | struct blkio_group_conf { |
| 175 | unsigned int weight; |
| 176 | unsigned int iops[2]; |
| 177 | u64 bps[2]; |
| 178 | }; |
| 179 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 180 | /* per-blkg per-policy data */ |
| 181 | struct blkg_policy_data { |
| 182 | /* the blkg this per-policy data belongs to */ |
| 183 | struct blkio_group *blkg; |
| 184 | |
Tejun Heo | 549d3aa | 2012-03-05 13:15:16 -0800 | [diff] [blame] | 185 | /* Configuration */ |
| 186 | struct blkio_group_conf conf; |
| 187 | |
| 188 | struct blkio_group_stats stats; |
| 189 | /* Per cpu stats pointer */ |
| 190 | struct blkio_group_stats_cpu __percpu *stats_cpu; |
| 191 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 192 | /* pol->pdata_size bytes of private data used by policy impl */ |
| 193 | char pdata[] __aligned(__alignof__(unsigned long long)); |
| 194 | }; |
| 195 | |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 196 | struct blkio_group { |
Tejun Heo | c875f4d | 2012-03-05 13:15:22 -0800 | [diff] [blame] | 197 | /* Pointer to the associated request_queue */ |
| 198 | struct request_queue *q; |
Tejun Heo | e8989fa | 2012-03-05 13:15:20 -0800 | [diff] [blame] | 199 | struct list_head q_node; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 200 | struct hlist_node blkcg_node; |
Tejun Heo | 7ee9c56 | 2012-03-05 13:15:11 -0800 | [diff] [blame] | 201 | struct blkio_cgroup *blkcg; |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 202 | /* Store cgroup path */ |
| 203 | char path[128]; |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 204 | /* reference count */ |
| 205 | int refcnt; |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 206 | |
Tejun Heo | 549d3aa | 2012-03-05 13:15:16 -0800 | [diff] [blame] | 207 | struct blkg_policy_data *pd[BLKIO_NR_POLICIES]; |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 208 | |
Vivek Goyal | 1cd9e03 | 2012-03-08 10:53:56 -0800 | [diff] [blame] | 209 | /* List of blkg waiting for per cpu stats memory to be allocated */ |
| 210 | struct list_head alloc_node; |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 211 | struct rcu_head rcu_head; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 212 | }; |
| 213 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 214 | typedef void (blkio_init_group_fn)(struct blkio_group *blkg); |
Tejun Heo | ca32aef | 2012-03-05 13:15:03 -0800 | [diff] [blame] | 215 | typedef void (blkio_update_group_weight_fn)(struct request_queue *q, |
Vivek Goyal | fe07143 | 2010-10-01 14:49:49 +0200 | [diff] [blame] | 216 | struct blkio_group *blkg, unsigned int weight); |
Tejun Heo | ca32aef | 2012-03-05 13:15:03 -0800 | [diff] [blame] | 217 | typedef void (blkio_update_group_read_bps_fn)(struct request_queue *q, |
Vivek Goyal | fe07143 | 2010-10-01 14:49:49 +0200 | [diff] [blame] | 218 | struct blkio_group *blkg, u64 read_bps); |
Tejun Heo | ca32aef | 2012-03-05 13:15:03 -0800 | [diff] [blame] | 219 | typedef void (blkio_update_group_write_bps_fn)(struct request_queue *q, |
Vivek Goyal | fe07143 | 2010-10-01 14:49:49 +0200 | [diff] [blame] | 220 | struct blkio_group *blkg, u64 write_bps); |
Tejun Heo | ca32aef | 2012-03-05 13:15:03 -0800 | [diff] [blame] | 221 | typedef void (blkio_update_group_read_iops_fn)(struct request_queue *q, |
Vivek Goyal | fe07143 | 2010-10-01 14:49:49 +0200 | [diff] [blame] | 222 | struct blkio_group *blkg, unsigned int read_iops); |
Tejun Heo | ca32aef | 2012-03-05 13:15:03 -0800 | [diff] [blame] | 223 | typedef void (blkio_update_group_write_iops_fn)(struct request_queue *q, |
Vivek Goyal | fe07143 | 2010-10-01 14:49:49 +0200 | [diff] [blame] | 224 | struct blkio_group *blkg, unsigned int write_iops); |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 225 | |
| 226 | struct blkio_policy_ops { |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 227 | blkio_init_group_fn *blkio_init_group_fn; |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 228 | blkio_update_group_weight_fn *blkio_update_group_weight_fn; |
Vivek Goyal | 4c9eefa | 2010-09-15 17:06:34 -0400 | [diff] [blame] | 229 | blkio_update_group_read_bps_fn *blkio_update_group_read_bps_fn; |
| 230 | blkio_update_group_write_bps_fn *blkio_update_group_write_bps_fn; |
Vivek Goyal | 7702e8f | 2010-09-15 17:06:36 -0400 | [diff] [blame] | 231 | blkio_update_group_read_iops_fn *blkio_update_group_read_iops_fn; |
| 232 | blkio_update_group_write_iops_fn *blkio_update_group_write_iops_fn; |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | struct blkio_policy_type { |
| 236 | struct list_head list; |
| 237 | struct blkio_policy_ops ops; |
Vivek Goyal | 062a644 | 2010-09-15 17:06:33 -0400 | [diff] [blame] | 238 | enum blkio_policy_id plid; |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 239 | size_t pdata_size; /* policy specific private data size */ |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 240 | }; |
| 241 | |
Tejun Heo | 5efd611 | 2012-03-05 13:15:12 -0800 | [diff] [blame] | 242 | extern int blkcg_init_queue(struct request_queue *q); |
| 243 | extern void blkcg_drain_queue(struct request_queue *q); |
| 244 | extern void blkcg_exit_queue(struct request_queue *q); |
| 245 | |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 246 | /* Blkio controller policy registration */ |
| 247 | extern void blkio_policy_register(struct blkio_policy_type *); |
| 248 | extern void blkio_policy_unregister(struct blkio_policy_type *); |
Tejun Heo | e8989fa | 2012-03-05 13:15:20 -0800 | [diff] [blame] | 249 | extern void blkg_destroy_all(struct request_queue *q, bool destroy_root); |
| 250 | extern void update_root_blkg_pd(struct request_queue *q, |
| 251 | enum blkio_policy_id plid); |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 252 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 253 | /** |
| 254 | * blkg_to_pdata - get policy private data |
| 255 | * @blkg: blkg of interest |
| 256 | * @pol: policy of interest |
| 257 | * |
| 258 | * Return pointer to private data associated with the @blkg-@pol pair. |
| 259 | */ |
| 260 | static inline void *blkg_to_pdata(struct blkio_group *blkg, |
| 261 | struct blkio_policy_type *pol) |
| 262 | { |
Tejun Heo | 549d3aa | 2012-03-05 13:15:16 -0800 | [diff] [blame] | 263 | return blkg ? blkg->pd[pol->plid]->pdata : NULL; |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | /** |
| 267 | * pdata_to_blkg - get blkg associated with policy private data |
| 268 | * @pdata: policy private data of interest |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 269 | * |
Tejun Heo | aaec55a | 2012-04-01 14:38:42 -0700 | [diff] [blame^] | 270 | * @pdata is policy private data. Determine the blkg it's associated with. |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 271 | */ |
Tejun Heo | aaec55a | 2012-04-01 14:38:42 -0700 | [diff] [blame^] | 272 | static inline struct blkio_group *pdata_to_blkg(void *pdata) |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 273 | { |
| 274 | if (pdata) { |
| 275 | struct blkg_policy_data *pd = |
| 276 | container_of(pdata, struct blkg_policy_data, pdata); |
| 277 | return pd->blkg; |
| 278 | } |
| 279 | return NULL; |
| 280 | } |
| 281 | |
Vivek Goyal | afc24d4 | 2010-04-26 19:27:56 +0200 | [diff] [blame] | 282 | static inline char *blkg_path(struct blkio_group *blkg) |
| 283 | { |
| 284 | return blkg->path; |
| 285 | } |
| 286 | |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 287 | /** |
| 288 | * blkg_get - get a blkg reference |
| 289 | * @blkg: blkg to get |
| 290 | * |
| 291 | * The caller should be holding queue_lock and an existing reference. |
| 292 | */ |
| 293 | static inline void blkg_get(struct blkio_group *blkg) |
| 294 | { |
| 295 | lockdep_assert_held(blkg->q->queue_lock); |
| 296 | WARN_ON_ONCE(!blkg->refcnt); |
| 297 | blkg->refcnt++; |
| 298 | } |
| 299 | |
| 300 | void __blkg_release(struct blkio_group *blkg); |
| 301 | |
| 302 | /** |
| 303 | * blkg_put - put a blkg reference |
| 304 | * @blkg: blkg to put |
| 305 | * |
| 306 | * The caller should be holding queue_lock. |
| 307 | */ |
| 308 | static inline void blkg_put(struct blkio_group *blkg) |
| 309 | { |
| 310 | lockdep_assert_held(blkg->q->queue_lock); |
| 311 | WARN_ON_ONCE(blkg->refcnt <= 0); |
| 312 | if (!--blkg->refcnt) |
| 313 | __blkg_release(blkg); |
| 314 | } |
| 315 | |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 316 | #else |
| 317 | |
| 318 | struct blkio_group { |
| 319 | }; |
| 320 | |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 321 | struct blkio_policy_type { |
| 322 | }; |
| 323 | |
Tejun Heo | 5efd611 | 2012-03-05 13:15:12 -0800 | [diff] [blame] | 324 | static inline int blkcg_init_queue(struct request_queue *q) { return 0; } |
| 325 | static inline void blkcg_drain_queue(struct request_queue *q) { } |
| 326 | static inline void blkcg_exit_queue(struct request_queue *q) { } |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 327 | static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { } |
| 328 | static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { } |
Tejun Heo | 03aa264 | 2012-03-05 13:15:19 -0800 | [diff] [blame] | 329 | static inline void blkg_destroy_all(struct request_queue *q, |
Tejun Heo | 03aa264 | 2012-03-05 13:15:19 -0800 | [diff] [blame] | 330 | bool destory_root) { } |
Tejun Heo | e8989fa | 2012-03-05 13:15:20 -0800 | [diff] [blame] | 331 | static inline void update_root_blkg_pd(struct request_queue *q, |
| 332 | enum blkio_policy_id plid) { } |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 333 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 334 | static inline void *blkg_to_pdata(struct blkio_group *blkg, |
| 335 | struct blkio_policy_type *pol) { return NULL; } |
| 336 | static inline struct blkio_group *pdata_to_blkg(void *pdata, |
| 337 | struct blkio_policy_type *pol) { return NULL; } |
Vivek Goyal | afc24d4 | 2010-04-26 19:27:56 +0200 | [diff] [blame] | 338 | static inline char *blkg_path(struct blkio_group *blkg) { return NULL; } |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 339 | static inline void blkg_get(struct blkio_group *blkg) { } |
| 340 | static inline void blkg_put(struct blkio_group *blkg) { } |
Vivek Goyal | afc24d4 | 2010-04-26 19:27:56 +0200 | [diff] [blame] | 341 | |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 342 | #endif |
| 343 | |
Justin TerAvest | df457f8 | 2011-03-08 19:45:00 +0100 | [diff] [blame] | 344 | #define BLKIO_WEIGHT_MIN 10 |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 345 | #define BLKIO_WEIGHT_MAX 1000 |
| 346 | #define BLKIO_WEIGHT_DEFAULT 500 |
| 347 | |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 348 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 349 | void blkiocg_update_avg_queue_size_stats(struct blkio_group *blkg, |
| 350 | struct blkio_policy_type *pol); |
Divyesh Shah | 9195291 | 2010-04-01 15:01:41 -0700 | [diff] [blame] | 351 | void blkiocg_update_dequeue_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 352 | struct blkio_policy_type *pol, |
| 353 | unsigned long dequeue); |
| 354 | void blkiocg_update_set_idle_time_stats(struct blkio_group *blkg, |
| 355 | struct blkio_policy_type *pol); |
| 356 | void blkiocg_update_idle_time_stats(struct blkio_group *blkg, |
| 357 | struct blkio_policy_type *pol); |
| 358 | void blkiocg_set_start_empty_time(struct blkio_group *blkg, |
| 359 | struct blkio_policy_type *pol); |
Divyesh Shah | 812df48 | 2010-04-08 21:15:35 -0700 | [diff] [blame] | 360 | |
| 361 | #define BLKG_FLAG_FNS(name) \ |
| 362 | static inline void blkio_mark_blkg_##name( \ |
| 363 | struct blkio_group_stats *stats) \ |
| 364 | { \ |
| 365 | stats->flags |= (1 << BLKG_##name); \ |
| 366 | } \ |
| 367 | static inline void blkio_clear_blkg_##name( \ |
| 368 | struct blkio_group_stats *stats) \ |
| 369 | { \ |
| 370 | stats->flags &= ~(1 << BLKG_##name); \ |
| 371 | } \ |
| 372 | static inline int blkio_blkg_##name(struct blkio_group_stats *stats) \ |
| 373 | { \ |
| 374 | return (stats->flags & (1 << BLKG_##name)) != 0; \ |
| 375 | } \ |
| 376 | |
| 377 | BLKG_FLAG_FNS(waiting) |
| 378 | BLKG_FLAG_FNS(idling) |
| 379 | BLKG_FLAG_FNS(empty) |
| 380 | #undef BLKG_FLAG_FNS |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 381 | #else |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 382 | static inline void blkiocg_update_avg_queue_size_stats(struct blkio_group *blkg, |
| 383 | struct blkio_policy_type *pol) { } |
Divyesh Shah | 9195291 | 2010-04-01 15:01:41 -0700 | [diff] [blame] | 384 | static inline void blkiocg_update_dequeue_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 385 | struct blkio_policy_type *pol, unsigned long dequeue) { } |
| 386 | static inline void blkiocg_update_set_idle_time_stats(struct blkio_group *blkg, |
| 387 | struct blkio_policy_type *pol) { } |
| 388 | static inline void blkiocg_update_idle_time_stats(struct blkio_group *blkg, |
| 389 | struct blkio_policy_type *pol) { } |
| 390 | static inline void blkiocg_set_start_empty_time(struct blkio_group *blkg, |
| 391 | struct blkio_policy_type *pol) { } |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 392 | #endif |
| 393 | |
Tejun Heo | 32e380a | 2012-03-05 13:14:54 -0800 | [diff] [blame] | 394 | #ifdef CONFIG_BLK_CGROUP |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 395 | extern struct blkio_cgroup blkio_root_cgroup; |
| 396 | extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup); |
Tejun Heo | 4f85cb9 | 2012-03-05 13:15:28 -0800 | [diff] [blame] | 397 | extern struct blkio_cgroup *bio_blkio_cgroup(struct bio *bio); |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 398 | extern struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg, |
Tejun Heo | e8989fa | 2012-03-05 13:15:20 -0800 | [diff] [blame] | 399 | struct request_queue *q); |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 400 | struct blkio_group *blkg_lookup_create(struct blkio_cgroup *blkcg, |
| 401 | struct request_queue *q, |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 402 | bool for_root); |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 403 | void blkiocg_update_timeslice_used(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 404 | struct blkio_policy_type *pol, |
| 405 | unsigned long time, |
| 406 | unsigned long unaccounted_time); |
| 407 | void blkiocg_update_dispatch_stats(struct blkio_group *blkg, |
| 408 | struct blkio_policy_type *pol, |
| 409 | uint64_t bytes, bool direction, bool sync); |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 410 | void blkiocg_update_completion_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 411 | struct blkio_policy_type *pol, |
| 412 | uint64_t start_time, |
| 413 | uint64_t io_start_time, bool direction, |
| 414 | bool sync); |
| 415 | void blkiocg_update_io_merged_stats(struct blkio_group *blkg, |
| 416 | struct blkio_policy_type *pol, |
| 417 | bool direction, bool sync); |
Divyesh Shah | a11cdaa | 2010-04-13 19:59:17 +0200 | [diff] [blame] | 418 | void blkiocg_update_io_add_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 419 | struct blkio_policy_type *pol, |
| 420 | struct blkio_group *curr_blkg, bool direction, |
| 421 | bool sync); |
Divyesh Shah | a11cdaa | 2010-04-13 19:59:17 +0200 | [diff] [blame] | 422 | void blkiocg_update_io_remove_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 423 | struct blkio_policy_type *pol, |
| 424 | bool direction, bool sync); |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 425 | #else |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 426 | struct cgroup; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 427 | static inline struct blkio_cgroup * |
| 428 | cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; } |
Vivek Goyal | 70087dc | 2011-05-16 15:24:08 +0200 | [diff] [blame] | 429 | static inline struct blkio_cgroup * |
Tejun Heo | 4f85cb9 | 2012-03-05 13:15:28 -0800 | [diff] [blame] | 430 | bio_blkio_cgroup(struct bio *bio) { return NULL; } |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 431 | |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 432 | static inline struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg, |
| 433 | void *key) { return NULL; } |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 434 | static inline void blkiocg_update_timeslice_used(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 435 | struct blkio_policy_type *pol, unsigned long time, |
| 436 | unsigned long unaccounted_time) { } |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 437 | static inline void blkiocg_update_dispatch_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 438 | struct blkio_policy_type *pol, uint64_t bytes, |
| 439 | bool direction, bool sync) { } |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 440 | static inline void blkiocg_update_completion_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 441 | struct blkio_policy_type *pol, uint64_t start_time, |
| 442 | uint64_t io_start_time, bool direction, bool sync) { } |
Divyesh Shah | 812d402 | 2010-04-08 21:14:23 -0700 | [diff] [blame] | 443 | static inline void blkiocg_update_io_merged_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 444 | struct blkio_policy_type *pol, bool direction, |
| 445 | bool sync) { } |
Divyesh Shah | a11cdaa | 2010-04-13 19:59:17 +0200 | [diff] [blame] | 446 | static inline void blkiocg_update_io_add_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 447 | struct blkio_policy_type *pol, |
| 448 | struct blkio_group *curr_blkg, bool direction, |
| 449 | bool sync) { } |
Divyesh Shah | a11cdaa | 2010-04-13 19:59:17 +0200 | [diff] [blame] | 450 | static inline void blkiocg_update_io_remove_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 451 | struct blkio_policy_type *pol, bool direction, |
| 452 | bool sync) { } |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 453 | #endif |
| 454 | #endif /* _BLK_CGROUP_H */ |