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; |
| 119 | }; |
| 120 | |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 121 | struct blkio_group_stats { |
| 122 | /* total disk time and nr sectors dispatched by this group */ |
| 123 | uint64_t time; |
Tejun Heo | c4c76a0 | 2012-03-08 10:53:59 -0800 | [diff] [blame^] | 124 | uint64_t stat_arr[BLKIO_STAT_ARR_NR][BLKIO_STAT_TOTAL]; |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 125 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
Vivek Goyal | a23e686 | 2011-05-19 15:38:20 -0400 | [diff] [blame] | 126 | /* Time not charged to this cgroup */ |
| 127 | uint64_t unaccounted_time; |
| 128 | |
Divyesh Shah | cdc1184 | 2010-04-08 21:15:10 -0700 | [diff] [blame] | 129 | /* Sum of number of IOs queued across all samples */ |
| 130 | uint64_t avg_queue_size_sum; |
| 131 | /* Count of samples taken for average */ |
| 132 | uint64_t avg_queue_size_samples; |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 133 | /* How many times this group has been removed from service tree */ |
| 134 | unsigned long dequeue; |
Divyesh Shah | 812df48 | 2010-04-08 21:15:35 -0700 | [diff] [blame] | 135 | |
| 136 | /* Total time spent waiting for it to be assigned a timeslice. */ |
| 137 | uint64_t group_wait_time; |
Divyesh Shah | 812df48 | 2010-04-08 21:15:35 -0700 | [diff] [blame] | 138 | |
| 139 | /* Time spent idling for this blkio_group */ |
| 140 | uint64_t idle_time; |
Divyesh Shah | 812df48 | 2010-04-08 21:15:35 -0700 | [diff] [blame] | 141 | /* |
| 142 | * Total time when we have requests queued and do not contain the |
| 143 | * current active queue. |
| 144 | */ |
| 145 | uint64_t empty_time; |
Tejun Heo | 997a026 | 2012-03-08 10:53:58 -0800 | [diff] [blame] | 146 | |
| 147 | /* fields after this shouldn't be cleared on stat reset */ |
| 148 | uint64_t start_group_wait_time; |
| 149 | uint64_t start_idle_time; |
Divyesh Shah | 812df48 | 2010-04-08 21:15:35 -0700 | [diff] [blame] | 150 | uint64_t start_empty_time; |
| 151 | uint16_t flags; |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 152 | #endif |
| 153 | }; |
| 154 | |
Tejun Heo | 997a026 | 2012-03-08 10:53:58 -0800 | [diff] [blame] | 155 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
| 156 | #define BLKG_STATS_DEBUG_CLEAR_START \ |
| 157 | offsetof(struct blkio_group_stats, unaccounted_time) |
| 158 | #define BLKG_STATS_DEBUG_CLEAR_SIZE \ |
| 159 | (offsetof(struct blkio_group_stats, start_group_wait_time) - \ |
| 160 | BLKG_STATS_DEBUG_CLEAR_START) |
| 161 | #endif |
| 162 | |
Vivek Goyal | 5624a4e | 2011-05-19 15:38:28 -0400 | [diff] [blame] | 163 | /* Per cpu blkio group stats */ |
| 164 | struct blkio_group_stats_cpu { |
| 165 | uint64_t sectors; |
| 166 | uint64_t stat_arr_cpu[BLKIO_STAT_CPU_NR][BLKIO_STAT_TOTAL]; |
Vivek Goyal | 575969a | 2011-05-19 15:38:29 -0400 | [diff] [blame] | 167 | struct u64_stats_sync syncp; |
Vivek Goyal | 5624a4e | 2011-05-19 15:38:28 -0400 | [diff] [blame] | 168 | }; |
| 169 | |
Tejun Heo | e56da7e | 2012-03-05 13:15:07 -0800 | [diff] [blame] | 170 | struct blkio_group_conf { |
| 171 | unsigned int weight; |
| 172 | unsigned int iops[2]; |
| 173 | u64 bps[2]; |
| 174 | }; |
| 175 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 176 | /* per-blkg per-policy data */ |
| 177 | struct blkg_policy_data { |
| 178 | /* the blkg this per-policy data belongs to */ |
| 179 | struct blkio_group *blkg; |
| 180 | |
Tejun Heo | 549d3aa | 2012-03-05 13:15:16 -0800 | [diff] [blame] | 181 | /* Configuration */ |
| 182 | struct blkio_group_conf conf; |
| 183 | |
| 184 | struct blkio_group_stats stats; |
| 185 | /* Per cpu stats pointer */ |
| 186 | struct blkio_group_stats_cpu __percpu *stats_cpu; |
| 187 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 188 | /* pol->pdata_size bytes of private data used by policy impl */ |
| 189 | char pdata[] __aligned(__alignof__(unsigned long long)); |
| 190 | }; |
| 191 | |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 192 | struct blkio_group { |
Tejun Heo | c875f4d | 2012-03-05 13:15:22 -0800 | [diff] [blame] | 193 | /* Pointer to the associated request_queue */ |
| 194 | struct request_queue *q; |
Tejun Heo | e8989fa | 2012-03-05 13:15:20 -0800 | [diff] [blame] | 195 | struct list_head q_node; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 196 | struct hlist_node blkcg_node; |
Tejun Heo | 7ee9c56 | 2012-03-05 13:15:11 -0800 | [diff] [blame] | 197 | struct blkio_cgroup *blkcg; |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 198 | /* Store cgroup path */ |
| 199 | char path[128]; |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 200 | /* reference count */ |
| 201 | int refcnt; |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 202 | |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 203 | /* Need to serialize the stats in the case of reset/update */ |
| 204 | spinlock_t stats_lock; |
Tejun Heo | 549d3aa | 2012-03-05 13:15:16 -0800 | [diff] [blame] | 205 | struct blkg_policy_data *pd[BLKIO_NR_POLICIES]; |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 206 | |
Vivek Goyal | 1cd9e03 | 2012-03-08 10:53:56 -0800 | [diff] [blame] | 207 | /* List of blkg waiting for per cpu stats memory to be allocated */ |
| 208 | struct list_head alloc_node; |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 209 | struct rcu_head rcu_head; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 210 | }; |
| 211 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 212 | typedef void (blkio_init_group_fn)(struct blkio_group *blkg); |
Tejun Heo | ca32aef | 2012-03-05 13:15:03 -0800 | [diff] [blame] | 213 | typedef void (blkio_update_group_weight_fn)(struct request_queue *q, |
Vivek Goyal | fe07143 | 2010-10-01 14:49:49 +0200 | [diff] [blame] | 214 | struct blkio_group *blkg, unsigned int weight); |
Tejun Heo | ca32aef | 2012-03-05 13:15:03 -0800 | [diff] [blame] | 215 | typedef void (blkio_update_group_read_bps_fn)(struct request_queue *q, |
Vivek Goyal | fe07143 | 2010-10-01 14:49:49 +0200 | [diff] [blame] | 216 | struct blkio_group *blkg, u64 read_bps); |
Tejun Heo | ca32aef | 2012-03-05 13:15:03 -0800 | [diff] [blame] | 217 | typedef void (blkio_update_group_write_bps_fn)(struct request_queue *q, |
Vivek Goyal | fe07143 | 2010-10-01 14:49:49 +0200 | [diff] [blame] | 218 | struct blkio_group *blkg, u64 write_bps); |
Tejun Heo | ca32aef | 2012-03-05 13:15:03 -0800 | [diff] [blame] | 219 | typedef void (blkio_update_group_read_iops_fn)(struct request_queue *q, |
Vivek Goyal | fe07143 | 2010-10-01 14:49:49 +0200 | [diff] [blame] | 220 | struct blkio_group *blkg, unsigned int read_iops); |
Tejun Heo | ca32aef | 2012-03-05 13:15:03 -0800 | [diff] [blame] | 221 | typedef void (blkio_update_group_write_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 write_iops); |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 223 | |
| 224 | struct blkio_policy_ops { |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 225 | blkio_init_group_fn *blkio_init_group_fn; |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 226 | blkio_update_group_weight_fn *blkio_update_group_weight_fn; |
Vivek Goyal | 4c9eefa | 2010-09-15 17:06:34 -0400 | [diff] [blame] | 227 | blkio_update_group_read_bps_fn *blkio_update_group_read_bps_fn; |
| 228 | blkio_update_group_write_bps_fn *blkio_update_group_write_bps_fn; |
Vivek Goyal | 7702e8f | 2010-09-15 17:06:36 -0400 | [diff] [blame] | 229 | blkio_update_group_read_iops_fn *blkio_update_group_read_iops_fn; |
| 230 | blkio_update_group_write_iops_fn *blkio_update_group_write_iops_fn; |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | struct blkio_policy_type { |
| 234 | struct list_head list; |
| 235 | struct blkio_policy_ops ops; |
Vivek Goyal | 062a644 | 2010-09-15 17:06:33 -0400 | [diff] [blame] | 236 | enum blkio_policy_id plid; |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 237 | size_t pdata_size; /* policy specific private data size */ |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 238 | }; |
| 239 | |
Tejun Heo | 5efd611 | 2012-03-05 13:15:12 -0800 | [diff] [blame] | 240 | extern int blkcg_init_queue(struct request_queue *q); |
| 241 | extern void blkcg_drain_queue(struct request_queue *q); |
| 242 | extern void blkcg_exit_queue(struct request_queue *q); |
| 243 | |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 244 | /* Blkio controller policy registration */ |
| 245 | extern void blkio_policy_register(struct blkio_policy_type *); |
| 246 | extern void blkio_policy_unregister(struct blkio_policy_type *); |
Tejun Heo | e8989fa | 2012-03-05 13:15:20 -0800 | [diff] [blame] | 247 | extern void blkg_destroy_all(struct request_queue *q, bool destroy_root); |
| 248 | extern void update_root_blkg_pd(struct request_queue *q, |
| 249 | enum blkio_policy_id plid); |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 250 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 251 | /** |
| 252 | * blkg_to_pdata - get policy private data |
| 253 | * @blkg: blkg of interest |
| 254 | * @pol: policy of interest |
| 255 | * |
| 256 | * Return pointer to private data associated with the @blkg-@pol pair. |
| 257 | */ |
| 258 | static inline void *blkg_to_pdata(struct blkio_group *blkg, |
| 259 | struct blkio_policy_type *pol) |
| 260 | { |
Tejun Heo | 549d3aa | 2012-03-05 13:15:16 -0800 | [diff] [blame] | 261 | return blkg ? blkg->pd[pol->plid]->pdata : NULL; |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /** |
| 265 | * pdata_to_blkg - get blkg associated with policy private data |
| 266 | * @pdata: policy private data of interest |
| 267 | * @pol: policy @pdata is for |
| 268 | * |
| 269 | * @pdata is policy private data for @pol. Determine the blkg it's |
| 270 | * associated with. |
| 271 | */ |
| 272 | static inline struct blkio_group *pdata_to_blkg(void *pdata, |
| 273 | struct blkio_policy_type *pol) |
| 274 | { |
| 275 | if (pdata) { |
| 276 | struct blkg_policy_data *pd = |
| 277 | container_of(pdata, struct blkg_policy_data, pdata); |
| 278 | return pd->blkg; |
| 279 | } |
| 280 | return NULL; |
| 281 | } |
| 282 | |
Vivek Goyal | afc24d4 | 2010-04-26 19:27:56 +0200 | [diff] [blame] | 283 | static inline char *blkg_path(struct blkio_group *blkg) |
| 284 | { |
| 285 | return blkg->path; |
| 286 | } |
| 287 | |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 288 | /** |
| 289 | * blkg_get - get a blkg reference |
| 290 | * @blkg: blkg to get |
| 291 | * |
| 292 | * The caller should be holding queue_lock and an existing reference. |
| 293 | */ |
| 294 | static inline void blkg_get(struct blkio_group *blkg) |
| 295 | { |
| 296 | lockdep_assert_held(blkg->q->queue_lock); |
| 297 | WARN_ON_ONCE(!blkg->refcnt); |
| 298 | blkg->refcnt++; |
| 299 | } |
| 300 | |
| 301 | void __blkg_release(struct blkio_group *blkg); |
| 302 | |
| 303 | /** |
| 304 | * blkg_put - put a blkg reference |
| 305 | * @blkg: blkg to put |
| 306 | * |
| 307 | * The caller should be holding queue_lock. |
| 308 | */ |
| 309 | static inline void blkg_put(struct blkio_group *blkg) |
| 310 | { |
| 311 | lockdep_assert_held(blkg->q->queue_lock); |
| 312 | WARN_ON_ONCE(blkg->refcnt <= 0); |
| 313 | if (!--blkg->refcnt) |
| 314 | __blkg_release(blkg); |
| 315 | } |
| 316 | |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 317 | #else |
| 318 | |
| 319 | struct blkio_group { |
| 320 | }; |
| 321 | |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 322 | struct blkio_policy_type { |
| 323 | }; |
| 324 | |
Tejun Heo | 5efd611 | 2012-03-05 13:15:12 -0800 | [diff] [blame] | 325 | static inline int blkcg_init_queue(struct request_queue *q) { return 0; } |
| 326 | static inline void blkcg_drain_queue(struct request_queue *q) { } |
| 327 | static inline void blkcg_exit_queue(struct request_queue *q) { } |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 328 | static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { } |
| 329 | static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { } |
Tejun Heo | 03aa264 | 2012-03-05 13:15:19 -0800 | [diff] [blame] | 330 | static inline void blkg_destroy_all(struct request_queue *q, |
Tejun Heo | 03aa264 | 2012-03-05 13:15:19 -0800 | [diff] [blame] | 331 | bool destory_root) { } |
Tejun Heo | e8989fa | 2012-03-05 13:15:20 -0800 | [diff] [blame] | 332 | static inline void update_root_blkg_pd(struct request_queue *q, |
| 333 | enum blkio_policy_id plid) { } |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 334 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 335 | static inline void *blkg_to_pdata(struct blkio_group *blkg, |
| 336 | struct blkio_policy_type *pol) { return NULL; } |
| 337 | static inline struct blkio_group *pdata_to_blkg(void *pdata, |
| 338 | struct blkio_policy_type *pol) { return NULL; } |
Vivek Goyal | afc24d4 | 2010-04-26 19:27:56 +0200 | [diff] [blame] | 339 | static inline char *blkg_path(struct blkio_group *blkg) { return NULL; } |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 340 | static inline void blkg_get(struct blkio_group *blkg) { } |
| 341 | static inline void blkg_put(struct blkio_group *blkg) { } |
Vivek Goyal | afc24d4 | 2010-04-26 19:27:56 +0200 | [diff] [blame] | 342 | |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 343 | #endif |
| 344 | |
Justin TerAvest | df457f8 | 2011-03-08 19:45:00 +0100 | [diff] [blame] | 345 | #define BLKIO_WEIGHT_MIN 10 |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 346 | #define BLKIO_WEIGHT_MAX 1000 |
| 347 | #define BLKIO_WEIGHT_DEFAULT 500 |
| 348 | |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 349 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 350 | void blkiocg_update_avg_queue_size_stats(struct blkio_group *blkg, |
| 351 | struct blkio_policy_type *pol); |
Divyesh Shah | 9195291 | 2010-04-01 15:01:41 -0700 | [diff] [blame] | 352 | void blkiocg_update_dequeue_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 353 | struct blkio_policy_type *pol, |
| 354 | unsigned long dequeue); |
| 355 | void blkiocg_update_set_idle_time_stats(struct blkio_group *blkg, |
| 356 | struct blkio_policy_type *pol); |
| 357 | void blkiocg_update_idle_time_stats(struct blkio_group *blkg, |
| 358 | struct blkio_policy_type *pol); |
| 359 | void blkiocg_set_start_empty_time(struct blkio_group *blkg, |
| 360 | struct blkio_policy_type *pol); |
Divyesh Shah | 812df48 | 2010-04-08 21:15:35 -0700 | [diff] [blame] | 361 | |
| 362 | #define BLKG_FLAG_FNS(name) \ |
| 363 | static inline void blkio_mark_blkg_##name( \ |
| 364 | struct blkio_group_stats *stats) \ |
| 365 | { \ |
| 366 | stats->flags |= (1 << BLKG_##name); \ |
| 367 | } \ |
| 368 | static inline void blkio_clear_blkg_##name( \ |
| 369 | struct blkio_group_stats *stats) \ |
| 370 | { \ |
| 371 | stats->flags &= ~(1 << BLKG_##name); \ |
| 372 | } \ |
| 373 | static inline int blkio_blkg_##name(struct blkio_group_stats *stats) \ |
| 374 | { \ |
| 375 | return (stats->flags & (1 << BLKG_##name)) != 0; \ |
| 376 | } \ |
| 377 | |
| 378 | BLKG_FLAG_FNS(waiting) |
| 379 | BLKG_FLAG_FNS(idling) |
| 380 | BLKG_FLAG_FNS(empty) |
| 381 | #undef BLKG_FLAG_FNS |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 382 | #else |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 383 | static inline void blkiocg_update_avg_queue_size_stats(struct blkio_group *blkg, |
| 384 | struct blkio_policy_type *pol) { } |
Divyesh Shah | 9195291 | 2010-04-01 15:01:41 -0700 | [diff] [blame] | 385 | static inline void blkiocg_update_dequeue_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 386 | struct blkio_policy_type *pol, unsigned long dequeue) { } |
| 387 | static inline void blkiocg_update_set_idle_time_stats(struct blkio_group *blkg, |
| 388 | struct blkio_policy_type *pol) { } |
| 389 | static inline void blkiocg_update_idle_time_stats(struct blkio_group *blkg, |
| 390 | struct blkio_policy_type *pol) { } |
| 391 | static inline void blkiocg_set_start_empty_time(struct blkio_group *blkg, |
| 392 | struct blkio_policy_type *pol) { } |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 393 | #endif |
| 394 | |
Tejun Heo | 32e380a | 2012-03-05 13:14:54 -0800 | [diff] [blame] | 395 | #ifdef CONFIG_BLK_CGROUP |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 396 | extern struct blkio_cgroup blkio_root_cgroup; |
| 397 | extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup); |
Tejun Heo | 4f85cb9 | 2012-03-05 13:15:28 -0800 | [diff] [blame] | 398 | extern struct blkio_cgroup *bio_blkio_cgroup(struct bio *bio); |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 399 | extern struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg, |
Tejun Heo | e8989fa | 2012-03-05 13:15:20 -0800 | [diff] [blame] | 400 | struct request_queue *q); |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 401 | struct blkio_group *blkg_lookup_create(struct blkio_cgroup *blkcg, |
| 402 | struct request_queue *q, |
| 403 | enum blkio_policy_id plid, |
| 404 | bool for_root); |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 405 | void blkiocg_update_timeslice_used(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 406 | struct blkio_policy_type *pol, |
| 407 | unsigned long time, |
| 408 | unsigned long unaccounted_time); |
| 409 | void blkiocg_update_dispatch_stats(struct blkio_group *blkg, |
| 410 | struct blkio_policy_type *pol, |
| 411 | uint64_t bytes, bool direction, bool sync); |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 412 | void blkiocg_update_completion_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 413 | struct blkio_policy_type *pol, |
| 414 | uint64_t start_time, |
| 415 | uint64_t io_start_time, bool direction, |
| 416 | bool sync); |
| 417 | void blkiocg_update_io_merged_stats(struct blkio_group *blkg, |
| 418 | struct blkio_policy_type *pol, |
| 419 | bool direction, bool sync); |
Divyesh Shah | a11cdaa | 2010-04-13 19:59:17 +0200 | [diff] [blame] | 420 | void blkiocg_update_io_add_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 421 | struct blkio_policy_type *pol, |
| 422 | struct blkio_group *curr_blkg, bool direction, |
| 423 | bool sync); |
Divyesh Shah | a11cdaa | 2010-04-13 19:59:17 +0200 | [diff] [blame] | 424 | void blkiocg_update_io_remove_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 425 | struct blkio_policy_type *pol, |
| 426 | bool direction, bool sync); |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 427 | #else |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 428 | struct cgroup; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 429 | static inline struct blkio_cgroup * |
| 430 | cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; } |
Vivek Goyal | 70087dc | 2011-05-16 15:24:08 +0200 | [diff] [blame] | 431 | static inline struct blkio_cgroup * |
Tejun Heo | 4f85cb9 | 2012-03-05 13:15:28 -0800 | [diff] [blame] | 432 | bio_blkio_cgroup(struct bio *bio) { return NULL; } |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 433 | |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 434 | static inline struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg, |
| 435 | void *key) { return NULL; } |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 436 | static inline void blkiocg_update_timeslice_used(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 437 | struct blkio_policy_type *pol, unsigned long time, |
| 438 | unsigned long unaccounted_time) { } |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 439 | static inline void blkiocg_update_dispatch_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 440 | struct blkio_policy_type *pol, uint64_t bytes, |
| 441 | bool direction, bool sync) { } |
Divyesh Shah | 84c124d | 2010-04-09 08:31:19 +0200 | [diff] [blame] | 442 | static inline void blkiocg_update_completion_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 443 | struct blkio_policy_type *pol, uint64_t start_time, |
| 444 | uint64_t io_start_time, bool direction, bool sync) { } |
Divyesh Shah | 812d402 | 2010-04-08 21:14:23 -0700 | [diff] [blame] | 445 | static inline void blkiocg_update_io_merged_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 446 | struct blkio_policy_type *pol, bool direction, |
| 447 | bool sync) { } |
Divyesh Shah | a11cdaa | 2010-04-13 19:59:17 +0200 | [diff] [blame] | 448 | static inline void blkiocg_update_io_add_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 449 | struct blkio_policy_type *pol, |
| 450 | struct blkio_group *curr_blkg, bool direction, |
| 451 | bool sync) { } |
Divyesh Shah | a11cdaa | 2010-04-13 19:59:17 +0200 | [diff] [blame] | 452 | static inline void blkiocg_update_io_remove_stats(struct blkio_group *blkg, |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 453 | struct blkio_policy_type *pol, bool direction, |
| 454 | bool sync) { } |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 455 | #endif |
| 456 | #endif /* _BLK_CGROUP_H */ |