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> |
Tejun Heo | 829fdb5 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 18 | #include <linux/seq_file.h> |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 19 | |
Vivek Goyal | 062a644 | 2010-09-15 17:06:33 -0400 | [diff] [blame] | 20 | enum blkio_policy_id { |
| 21 | BLKIO_POLICY_PROP = 0, /* Proportional Bandwidth division */ |
Vivek Goyal | 4c9eefa | 2010-09-15 17:06:34 -0400 | [diff] [blame] | 22 | BLKIO_POLICY_THROTL, /* Throttling */ |
Tejun Heo | 035d10b | 2012-03-05 13:15:04 -0800 | [diff] [blame] | 23 | |
| 24 | BLKIO_NR_POLICIES, |
Vivek Goyal | 062a644 | 2010-09-15 17:06:33 -0400 | [diff] [blame] | 25 | }; |
| 26 | |
Vivek Goyal | 9355aed | 2010-10-01 21:16:41 +0200 | [diff] [blame] | 27 | /* Max limits for throttle policy */ |
| 28 | #define THROTL_IOPS_MAX UINT_MAX |
| 29 | |
Tejun Heo | 32e380a | 2012-03-05 13:14:54 -0800 | [diff] [blame] | 30 | #ifdef CONFIG_BLK_CGROUP |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 31 | |
Tejun Heo | d3d32e69 | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 32 | /* cft->private [un]packing for stat printing */ |
| 33 | #define BLKCG_STAT_PRIV(pol, off) (((unsigned)(pol) << 16) | (off)) |
| 34 | #define BLKCG_STAT_POL(prv) ((unsigned)(prv) >> 16) |
| 35 | #define BLKCG_STAT_OFF(prv) ((unsigned)(prv) & 0xffff) |
Tejun Heo | 2aa4a15 | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 36 | |
Tejun Heo | edcb072 | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 37 | enum blkg_rwstat_type { |
| 38 | BLKG_RWSTAT_READ, |
| 39 | BLKG_RWSTAT_WRITE, |
| 40 | BLKG_RWSTAT_SYNC, |
| 41 | BLKG_RWSTAT_ASYNC, |
| 42 | |
| 43 | BLKG_RWSTAT_NR, |
| 44 | BLKG_RWSTAT_TOTAL = BLKG_RWSTAT_NR, |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 47 | struct blkio_cgroup { |
| 48 | struct cgroup_subsys_state css; |
| 49 | unsigned int weight; |
| 50 | spinlock_t lock; |
| 51 | struct hlist_head blkg_list; |
Tejun Heo | 9a9e8a2 | 2012-03-19 15:10:56 -0700 | [diff] [blame] | 52 | |
| 53 | /* for policies to test whether associated blkcg has changed */ |
| 54 | uint64_t id; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 55 | }; |
| 56 | |
Tejun Heo | edcb072 | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 57 | struct blkg_stat { |
| 58 | struct u64_stats_sync syncp; |
| 59 | uint64_t cnt; |
| 60 | }; |
| 61 | |
| 62 | struct blkg_rwstat { |
| 63 | struct u64_stats_sync syncp; |
| 64 | uint64_t cnt[BLKG_RWSTAT_NR]; |
| 65 | }; |
| 66 | |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 67 | struct blkio_group_stats { |
Tejun Heo | 41b38b6 | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 68 | /* total bytes transferred */ |
| 69 | struct blkg_rwstat service_bytes; |
| 70 | /* total IOs serviced, post merge */ |
| 71 | struct blkg_rwstat serviced; |
Tejun Heo | edcb072 | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 72 | /* number of ios merged */ |
| 73 | struct blkg_rwstat merged; |
| 74 | /* total time spent on device in ns, may not be accurate w/ queueing */ |
| 75 | struct blkg_rwstat service_time; |
| 76 | /* total time spent waiting in scheduler queue in ns */ |
| 77 | struct blkg_rwstat wait_time; |
| 78 | /* number of IOs queued up */ |
| 79 | struct blkg_rwstat queued; |
Tejun Heo | 41b38b6 | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 80 | /* total sectors transferred */ |
| 81 | struct blkg_stat sectors; |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 82 | /* total disk time and nr sectors dispatched by this group */ |
Tejun Heo | edcb072 | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 83 | struct blkg_stat time; |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 84 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
Tejun Heo | edcb072 | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 85 | /* time not charged to this cgroup */ |
| 86 | struct blkg_stat unaccounted_time; |
| 87 | /* sum of number of ios queued across all samples */ |
| 88 | struct blkg_stat avg_queue_size_sum; |
| 89 | /* count of samples taken for average */ |
| 90 | struct blkg_stat avg_queue_size_samples; |
| 91 | /* how many times this group has been removed from service tree */ |
| 92 | struct blkg_stat dequeue; |
| 93 | /* total time spent waiting for it to be assigned a timeslice. */ |
| 94 | struct blkg_stat group_wait_time; |
| 95 | /* time spent idling for this blkio_group */ |
| 96 | struct blkg_stat idle_time; |
| 97 | /* total time with empty current active q with other requests queued */ |
| 98 | struct blkg_stat empty_time; |
Tejun Heo | 997a026 | 2012-03-08 10:53:58 -0800 | [diff] [blame] | 99 | /* fields after this shouldn't be cleared on stat reset */ |
Tejun Heo | edcb072 | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 100 | uint64_t start_group_wait_time; |
| 101 | uint64_t start_idle_time; |
| 102 | uint64_t start_empty_time; |
| 103 | uint16_t flags; |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 104 | #endif |
| 105 | }; |
| 106 | |
Vivek Goyal | 5624a4e | 2011-05-19 15:38:28 -0400 | [diff] [blame] | 107 | /* Per cpu blkio group stats */ |
| 108 | struct blkio_group_stats_cpu { |
Tejun Heo | edcb072 | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 109 | /* total bytes transferred */ |
| 110 | struct blkg_rwstat service_bytes; |
| 111 | /* total IOs serviced, post merge */ |
| 112 | struct blkg_rwstat serviced; |
Vivek Goyal | 5624a4e | 2011-05-19 15:38:28 -0400 | [diff] [blame] | 113 | }; |
| 114 | |
Tejun Heo | e56da7e | 2012-03-05 13:15:07 -0800 | [diff] [blame] | 115 | struct blkio_group_conf { |
| 116 | unsigned int weight; |
Tejun Heo | c4682ae | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 117 | u64 iops[2]; |
Tejun Heo | e56da7e | 2012-03-05 13:15:07 -0800 | [diff] [blame] | 118 | u64 bps[2]; |
| 119 | }; |
| 120 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 121 | /* per-blkg per-policy data */ |
| 122 | struct blkg_policy_data { |
| 123 | /* the blkg this per-policy data belongs to */ |
| 124 | struct blkio_group *blkg; |
| 125 | |
Tejun Heo | 549d3aa | 2012-03-05 13:15:16 -0800 | [diff] [blame] | 126 | /* Configuration */ |
| 127 | struct blkio_group_conf conf; |
| 128 | |
| 129 | struct blkio_group_stats stats; |
| 130 | /* Per cpu stats pointer */ |
| 131 | struct blkio_group_stats_cpu __percpu *stats_cpu; |
| 132 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 133 | /* pol->pdata_size bytes of private data used by policy impl */ |
| 134 | char pdata[] __aligned(__alignof__(unsigned long long)); |
| 135 | }; |
| 136 | |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 137 | struct blkio_group { |
Tejun Heo | c875f4d | 2012-03-05 13:15:22 -0800 | [diff] [blame] | 138 | /* Pointer to the associated request_queue */ |
| 139 | struct request_queue *q; |
Tejun Heo | e8989fa | 2012-03-05 13:15:20 -0800 | [diff] [blame] | 140 | struct list_head q_node; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 141 | struct hlist_node blkcg_node; |
Tejun Heo | 7ee9c56 | 2012-03-05 13:15:11 -0800 | [diff] [blame] | 142 | struct blkio_cgroup *blkcg; |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 143 | /* Store cgroup path */ |
| 144 | char path[128]; |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 145 | /* reference count */ |
| 146 | int refcnt; |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 147 | |
Tejun Heo | 549d3aa | 2012-03-05 13:15:16 -0800 | [diff] [blame] | 148 | struct blkg_policy_data *pd[BLKIO_NR_POLICIES]; |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 149 | |
Vivek Goyal | 1cd9e03 | 2012-03-08 10:53:56 -0800 | [diff] [blame] | 150 | /* List of blkg waiting for per cpu stats memory to be allocated */ |
| 151 | struct list_head alloc_node; |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 152 | struct rcu_head rcu_head; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 153 | }; |
| 154 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 155 | typedef void (blkio_init_group_fn)(struct blkio_group *blkg); |
Tejun Heo | 9ade5ea | 2012-04-01 14:38:44 -0700 | [diff] [blame^] | 156 | typedef void (blkio_exit_group_fn)(struct blkio_group *blkg); |
| 157 | typedef void (blkio_reset_group_stats_fn)(struct blkio_group *blkg); |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 158 | |
| 159 | struct blkio_policy_ops { |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 160 | blkio_init_group_fn *blkio_init_group_fn; |
Tejun Heo | 9ade5ea | 2012-04-01 14:38:44 -0700 | [diff] [blame^] | 161 | blkio_exit_group_fn *blkio_exit_group_fn; |
| 162 | blkio_reset_group_stats_fn *blkio_reset_group_stats_fn; |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | struct blkio_policy_type { |
| 166 | struct list_head list; |
| 167 | struct blkio_policy_ops ops; |
Vivek Goyal | 062a644 | 2010-09-15 17:06:33 -0400 | [diff] [blame] | 168 | enum blkio_policy_id plid; |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 169 | size_t pdata_size; /* policy specific private data size */ |
Tejun Heo | 44ea53d | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 170 | struct cftype *cftypes; /* cgroup files for the policy */ |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 171 | }; |
| 172 | |
Tejun Heo | 5efd611 | 2012-03-05 13:15:12 -0800 | [diff] [blame] | 173 | extern int blkcg_init_queue(struct request_queue *q); |
| 174 | extern void blkcg_drain_queue(struct request_queue *q); |
| 175 | extern void blkcg_exit_queue(struct request_queue *q); |
| 176 | |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 177 | /* Blkio controller policy registration */ |
| 178 | extern void blkio_policy_register(struct blkio_policy_type *); |
| 179 | extern void blkio_policy_unregister(struct blkio_policy_type *); |
Tejun Heo | e8989fa | 2012-03-05 13:15:20 -0800 | [diff] [blame] | 180 | extern void blkg_destroy_all(struct request_queue *q, bool destroy_root); |
| 181 | extern void update_root_blkg_pd(struct request_queue *q, |
| 182 | enum blkio_policy_id plid); |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 183 | |
Tejun Heo | 829fdb5 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 184 | void blkcg_print_blkgs(struct seq_file *sf, struct blkio_cgroup *blkcg, |
| 185 | u64 (*prfill)(struct seq_file *, struct blkg_policy_data *, int), |
| 186 | int pol, int data, bool show_total); |
| 187 | u64 __blkg_prfill_u64(struct seq_file *sf, struct blkg_policy_data *pd, u64 v); |
| 188 | u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd, |
| 189 | const struct blkg_rwstat *rwstat); |
| 190 | int blkcg_print_stat(struct cgroup *cgrp, struct cftype *cft, |
| 191 | struct seq_file *sf); |
| 192 | int blkcg_print_rwstat(struct cgroup *cgrp, struct cftype *cft, |
| 193 | struct seq_file *sf); |
Tejun Heo | 829fdb5 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 194 | |
| 195 | struct blkg_conf_ctx { |
| 196 | struct gendisk *disk; |
| 197 | struct blkio_group *blkg; |
| 198 | u64 v; |
| 199 | }; |
| 200 | |
| 201 | int blkg_conf_prep(struct blkio_cgroup *blkcg, const char *input, |
| 202 | struct blkg_conf_ctx *ctx); |
| 203 | void blkg_conf_finish(struct blkg_conf_ctx *ctx); |
| 204 | |
| 205 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 206 | /** |
| 207 | * blkg_to_pdata - get policy private data |
| 208 | * @blkg: blkg of interest |
| 209 | * @pol: policy of interest |
| 210 | * |
| 211 | * Return pointer to private data associated with the @blkg-@pol pair. |
| 212 | */ |
| 213 | static inline void *blkg_to_pdata(struct blkio_group *blkg, |
| 214 | struct blkio_policy_type *pol) |
| 215 | { |
Tejun Heo | 549d3aa | 2012-03-05 13:15:16 -0800 | [diff] [blame] | 216 | return blkg ? blkg->pd[pol->plid]->pdata : NULL; |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | /** |
| 220 | * pdata_to_blkg - get blkg associated with policy private data |
| 221 | * @pdata: policy private data of interest |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 222 | * |
Tejun Heo | aaec55a | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 223 | * @pdata is policy private data. Determine the blkg it's associated with. |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 224 | */ |
Tejun Heo | aaec55a | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 225 | static inline struct blkio_group *pdata_to_blkg(void *pdata) |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 226 | { |
| 227 | if (pdata) { |
| 228 | struct blkg_policy_data *pd = |
| 229 | container_of(pdata, struct blkg_policy_data, pdata); |
| 230 | return pd->blkg; |
| 231 | } |
| 232 | return NULL; |
| 233 | } |
| 234 | |
Vivek Goyal | afc24d4 | 2010-04-26 19:27:56 +0200 | [diff] [blame] | 235 | static inline char *blkg_path(struct blkio_group *blkg) |
| 236 | { |
| 237 | return blkg->path; |
| 238 | } |
| 239 | |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 240 | /** |
| 241 | * blkg_get - get a blkg reference |
| 242 | * @blkg: blkg to get |
| 243 | * |
| 244 | * The caller should be holding queue_lock and an existing reference. |
| 245 | */ |
| 246 | static inline void blkg_get(struct blkio_group *blkg) |
| 247 | { |
| 248 | lockdep_assert_held(blkg->q->queue_lock); |
| 249 | WARN_ON_ONCE(!blkg->refcnt); |
| 250 | blkg->refcnt++; |
| 251 | } |
| 252 | |
| 253 | void __blkg_release(struct blkio_group *blkg); |
| 254 | |
| 255 | /** |
| 256 | * blkg_put - put a blkg reference |
| 257 | * @blkg: blkg to put |
| 258 | * |
| 259 | * The caller should be holding queue_lock. |
| 260 | */ |
| 261 | static inline void blkg_put(struct blkio_group *blkg) |
| 262 | { |
| 263 | lockdep_assert_held(blkg->q->queue_lock); |
| 264 | WARN_ON_ONCE(blkg->refcnt <= 0); |
| 265 | if (!--blkg->refcnt) |
| 266 | __blkg_release(blkg); |
| 267 | } |
| 268 | |
Tejun Heo | edcb072 | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 269 | /** |
| 270 | * blkg_stat_add - add a value to a blkg_stat |
| 271 | * @stat: target blkg_stat |
| 272 | * @val: value to add |
| 273 | * |
| 274 | * Add @val to @stat. The caller is responsible for synchronizing calls to |
| 275 | * this function. |
| 276 | */ |
| 277 | static inline void blkg_stat_add(struct blkg_stat *stat, uint64_t val) |
| 278 | { |
| 279 | u64_stats_update_begin(&stat->syncp); |
| 280 | stat->cnt += val; |
| 281 | u64_stats_update_end(&stat->syncp); |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * blkg_stat_read - read the current value of a blkg_stat |
| 286 | * @stat: blkg_stat to read |
| 287 | * |
| 288 | * Read the current value of @stat. This function can be called without |
| 289 | * synchroniztion and takes care of u64 atomicity. |
| 290 | */ |
| 291 | static inline uint64_t blkg_stat_read(struct blkg_stat *stat) |
| 292 | { |
| 293 | unsigned int start; |
| 294 | uint64_t v; |
| 295 | |
| 296 | do { |
| 297 | start = u64_stats_fetch_begin(&stat->syncp); |
| 298 | v = stat->cnt; |
| 299 | } while (u64_stats_fetch_retry(&stat->syncp, start)); |
| 300 | |
| 301 | return v; |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * blkg_stat_reset - reset a blkg_stat |
| 306 | * @stat: blkg_stat to reset |
| 307 | */ |
| 308 | static inline void blkg_stat_reset(struct blkg_stat *stat) |
| 309 | { |
| 310 | stat->cnt = 0; |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * blkg_rwstat_add - add a value to a blkg_rwstat |
| 315 | * @rwstat: target blkg_rwstat |
| 316 | * @rw: mask of REQ_{WRITE|SYNC} |
| 317 | * @val: value to add |
| 318 | * |
| 319 | * Add @val to @rwstat. The counters are chosen according to @rw. The |
| 320 | * caller is responsible for synchronizing calls to this function. |
| 321 | */ |
| 322 | static inline void blkg_rwstat_add(struct blkg_rwstat *rwstat, |
| 323 | int rw, uint64_t val) |
| 324 | { |
| 325 | u64_stats_update_begin(&rwstat->syncp); |
| 326 | |
| 327 | if (rw & REQ_WRITE) |
| 328 | rwstat->cnt[BLKG_RWSTAT_WRITE] += val; |
| 329 | else |
| 330 | rwstat->cnt[BLKG_RWSTAT_READ] += val; |
| 331 | if (rw & REQ_SYNC) |
| 332 | rwstat->cnt[BLKG_RWSTAT_SYNC] += val; |
| 333 | else |
| 334 | rwstat->cnt[BLKG_RWSTAT_ASYNC] += val; |
| 335 | |
| 336 | u64_stats_update_end(&rwstat->syncp); |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * blkg_rwstat_read - read the current values of a blkg_rwstat |
| 341 | * @rwstat: blkg_rwstat to read |
| 342 | * |
| 343 | * Read the current snapshot of @rwstat and return it as the return value. |
| 344 | * This function can be called without synchronization and takes care of |
| 345 | * u64 atomicity. |
| 346 | */ |
| 347 | static struct blkg_rwstat blkg_rwstat_read(struct blkg_rwstat *rwstat) |
| 348 | { |
| 349 | unsigned int start; |
| 350 | struct blkg_rwstat tmp; |
| 351 | |
| 352 | do { |
| 353 | start = u64_stats_fetch_begin(&rwstat->syncp); |
| 354 | tmp = *rwstat; |
| 355 | } while (u64_stats_fetch_retry(&rwstat->syncp, start)); |
| 356 | |
| 357 | return tmp; |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * blkg_rwstat_sum - read the total count of a blkg_rwstat |
| 362 | * @rwstat: blkg_rwstat to read |
| 363 | * |
| 364 | * Return the total count of @rwstat regardless of the IO direction. This |
| 365 | * function can be called without synchronization and takes care of u64 |
| 366 | * atomicity. |
| 367 | */ |
| 368 | static inline uint64_t blkg_rwstat_sum(struct blkg_rwstat *rwstat) |
| 369 | { |
| 370 | struct blkg_rwstat tmp = blkg_rwstat_read(rwstat); |
| 371 | |
| 372 | return tmp.cnt[BLKG_RWSTAT_READ] + tmp.cnt[BLKG_RWSTAT_WRITE]; |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * blkg_rwstat_reset - reset a blkg_rwstat |
| 377 | * @rwstat: blkg_rwstat to reset |
| 378 | */ |
| 379 | static inline void blkg_rwstat_reset(struct blkg_rwstat *rwstat) |
| 380 | { |
| 381 | memset(rwstat->cnt, 0, sizeof(rwstat->cnt)); |
| 382 | } |
| 383 | |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 384 | #else |
| 385 | |
| 386 | struct blkio_group { |
| 387 | }; |
| 388 | |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 389 | struct blkio_policy_type { |
| 390 | }; |
| 391 | |
Tejun Heo | 5efd611 | 2012-03-05 13:15:12 -0800 | [diff] [blame] | 392 | static inline int blkcg_init_queue(struct request_queue *q) { return 0; } |
| 393 | static inline void blkcg_drain_queue(struct request_queue *q) { } |
| 394 | static inline void blkcg_exit_queue(struct request_queue *q) { } |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 395 | static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { } |
| 396 | static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { } |
Tejun Heo | 03aa264a | 2012-03-05 13:15:19 -0800 | [diff] [blame] | 397 | static inline void blkg_destroy_all(struct request_queue *q, |
Tejun Heo | 03aa264a | 2012-03-05 13:15:19 -0800 | [diff] [blame] | 398 | bool destory_root) { } |
Tejun Heo | e8989fa | 2012-03-05 13:15:20 -0800 | [diff] [blame] | 399 | static inline void update_root_blkg_pd(struct request_queue *q, |
| 400 | enum blkio_policy_id plid) { } |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 401 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 402 | static inline void *blkg_to_pdata(struct blkio_group *blkg, |
| 403 | struct blkio_policy_type *pol) { return NULL; } |
| 404 | static inline struct blkio_group *pdata_to_blkg(void *pdata, |
| 405 | struct blkio_policy_type *pol) { return NULL; } |
Vivek Goyal | afc24d4 | 2010-04-26 19:27:56 +0200 | [diff] [blame] | 406 | static inline char *blkg_path(struct blkio_group *blkg) { return NULL; } |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 407 | static inline void blkg_get(struct blkio_group *blkg) { } |
| 408 | static inline void blkg_put(struct blkio_group *blkg) { } |
Vivek Goyal | afc24d4 | 2010-04-26 19:27:56 +0200 | [diff] [blame] | 409 | |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 410 | #endif |
| 411 | |
Justin TerAvest | df457f8 | 2011-03-08 19:45:00 +0100 | [diff] [blame] | 412 | #define BLKIO_WEIGHT_MIN 10 |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 413 | #define BLKIO_WEIGHT_MAX 1000 |
| 414 | #define BLKIO_WEIGHT_DEFAULT 500 |
| 415 | |
Tejun Heo | 32e380a | 2012-03-05 13:14:54 -0800 | [diff] [blame] | 416 | #ifdef CONFIG_BLK_CGROUP |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 417 | extern struct blkio_cgroup blkio_root_cgroup; |
| 418 | extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup); |
Tejun Heo | 4f85cb9 | 2012-03-05 13:15:28 -0800 | [diff] [blame] | 419 | extern struct blkio_cgroup *bio_blkio_cgroup(struct bio *bio); |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 420 | extern struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg, |
Tejun Heo | e8989fa | 2012-03-05 13:15:20 -0800 | [diff] [blame] | 421 | struct request_queue *q); |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 422 | struct blkio_group *blkg_lookup_create(struct blkio_cgroup *blkcg, |
| 423 | struct request_queue *q, |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 424 | bool for_root); |
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; } |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 434 | #endif |
| 435 | #endif /* _BLK_CGROUP_H */ |