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> |
Tejun Heo | a637120 | 2012-04-19 16:29:24 -0700 | [diff] [blame^] | 19 | #include <linux/radix-tree.h> |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 20 | |
Vivek Goyal | 9355aed | 2010-10-01 21:16:41 +0200 | [diff] [blame] | 21 | /* Max limits for throttle policy */ |
| 22 | #define THROTL_IOPS_MAX UINT_MAX |
| 23 | |
Tejun Heo | 3381cb8 | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 24 | /* CFQ specific, out here for blkcg->cfq_weight */ |
| 25 | #define CFQ_WEIGHT_MIN 10 |
| 26 | #define CFQ_WEIGHT_MAX 1000 |
| 27 | #define CFQ_WEIGHT_DEFAULT 500 |
| 28 | |
Tejun Heo | f48ec1d | 2012-04-13 13:11:25 -0700 | [diff] [blame] | 29 | #ifdef CONFIG_BLK_CGROUP |
| 30 | |
Tejun Heo | edcb072 | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 31 | enum blkg_rwstat_type { |
| 32 | BLKG_RWSTAT_READ, |
| 33 | BLKG_RWSTAT_WRITE, |
| 34 | BLKG_RWSTAT_SYNC, |
| 35 | BLKG_RWSTAT_ASYNC, |
| 36 | |
| 37 | BLKG_RWSTAT_NR, |
| 38 | BLKG_RWSTAT_TOTAL = BLKG_RWSTAT_NR, |
Divyesh Shah | 303a3ac | 2010-04-01 15:01:24 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
Tejun Heo | a637120 | 2012-04-19 16:29:24 -0700 | [diff] [blame^] | 41 | struct blkcg_gq; |
| 42 | |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 43 | struct blkcg { |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 44 | struct cgroup_subsys_state css; |
| 45 | spinlock_t lock; |
Tejun Heo | a637120 | 2012-04-19 16:29:24 -0700 | [diff] [blame^] | 46 | |
| 47 | struct radix_tree_root blkg_tree; |
| 48 | struct blkcg_gq *blkg_hint; |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 49 | struct hlist_head blkg_list; |
Tejun Heo | 9a9e8a2 | 2012-03-19 15:10:56 -0700 | [diff] [blame] | 50 | |
| 51 | /* for policies to test whether associated blkcg has changed */ |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 52 | uint64_t id; |
Tejun Heo | 3381cb8 | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 53 | |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 54 | /* TODO: per-policy storage in blkcg */ |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 55 | unsigned int cfq_weight; /* belongs to cfq */ |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 56 | }; |
| 57 | |
Tejun Heo | edcb072 | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 58 | struct blkg_stat { |
| 59 | struct u64_stats_sync syncp; |
| 60 | uint64_t cnt; |
| 61 | }; |
| 62 | |
| 63 | struct blkg_rwstat { |
| 64 | struct u64_stats_sync syncp; |
| 65 | uint64_t cnt[BLKG_RWSTAT_NR]; |
| 66 | }; |
| 67 | |
Tejun Heo | f95a04a | 2012-04-16 13:57:26 -0700 | [diff] [blame] | 68 | /* |
| 69 | * A blkcg_gq (blkg) is association between a block cgroup (blkcg) and a |
| 70 | * request_queue (q). This is used by blkcg policies which need to track |
| 71 | * information per blkcg - q pair. |
| 72 | * |
| 73 | * There can be multiple active blkcg policies and each has its private |
| 74 | * data on each blkg, the size of which is determined by |
| 75 | * blkcg_policy->pd_size. blkcg core allocates and frees such areas |
| 76 | * together with blkg and invokes pd_init/exit_fn() methods. |
| 77 | * |
| 78 | * Such private data must embed struct blkg_policy_data (pd) at the |
| 79 | * beginning and pd_size can't be smaller than pd. |
| 80 | */ |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 81 | struct blkg_policy_data { |
| 82 | /* the blkg this per-policy data belongs to */ |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 83 | struct blkcg_gq *blkg; |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 84 | |
Tejun Heo | a2b1693 | 2012-04-13 13:11:33 -0700 | [diff] [blame] | 85 | /* used during policy activation */ |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 86 | struct list_head alloc_node; |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 89 | /* association between a blk cgroup and a request queue */ |
| 90 | struct blkcg_gq { |
Tejun Heo | c875f4d | 2012-03-05 13:15:22 -0800 | [diff] [blame] | 91 | /* Pointer to the associated request_queue */ |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 92 | struct request_queue *q; |
| 93 | struct list_head q_node; |
| 94 | struct hlist_node blkcg_node; |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 95 | struct blkcg *blkcg; |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 96 | /* reference count */ |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 97 | int refcnt; |
Vivek Goyal | 2208419 | 2009-12-03 12:59:49 -0500 | [diff] [blame] | 98 | |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 99 | struct blkg_policy_data *pd[BLKCG_MAX_POLS]; |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 100 | |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 101 | struct rcu_head rcu_head; |
Vivek Goyal | 31e4c28 | 2009-12-03 12:59:42 -0500 | [diff] [blame] | 102 | }; |
| 103 | |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 104 | typedef void (blkcg_pol_init_pd_fn)(struct blkcg_gq *blkg); |
| 105 | typedef void (blkcg_pol_exit_pd_fn)(struct blkcg_gq *blkg); |
| 106 | typedef void (blkcg_pol_reset_pd_stats_fn)(struct blkcg_gq *blkg); |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 107 | |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 108 | struct blkcg_policy { |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 109 | int plid; |
| 110 | /* policy specific private data size */ |
Tejun Heo | f95a04a | 2012-04-16 13:57:26 -0700 | [diff] [blame] | 111 | size_t pd_size; |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 112 | /* cgroup files for the policy */ |
| 113 | struct cftype *cftypes; |
Tejun Heo | f9fcc2d | 2012-04-16 13:57:27 -0700 | [diff] [blame] | 114 | |
| 115 | /* operations */ |
| 116 | blkcg_pol_init_pd_fn *pd_init_fn; |
| 117 | blkcg_pol_exit_pd_fn *pd_exit_fn; |
| 118 | blkcg_pol_reset_pd_stats_fn *pd_reset_stats_fn; |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 119 | }; |
| 120 | |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 121 | extern struct blkcg blkcg_root; |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 122 | |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 123 | struct blkcg *cgroup_to_blkcg(struct cgroup *cgroup); |
| 124 | struct blkcg *bio_blkcg(struct bio *bio); |
| 125 | struct blkcg_gq *blkg_lookup(struct blkcg *blkcg, struct request_queue *q); |
| 126 | struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg, |
| 127 | struct request_queue *q); |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 128 | int blkcg_init_queue(struct request_queue *q); |
| 129 | void blkcg_drain_queue(struct request_queue *q); |
| 130 | void blkcg_exit_queue(struct request_queue *q); |
Tejun Heo | 5efd611 | 2012-03-05 13:15:12 -0800 | [diff] [blame] | 131 | |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 132 | /* Blkio controller policy registration */ |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 133 | int blkcg_policy_register(struct blkcg_policy *pol); |
| 134 | void blkcg_policy_unregister(struct blkcg_policy *pol); |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 135 | int blkcg_activate_policy(struct request_queue *q, |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 136 | const struct blkcg_policy *pol); |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 137 | void blkcg_deactivate_policy(struct request_queue *q, |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 138 | const struct blkcg_policy *pol); |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 139 | |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 140 | void blkcg_print_blkgs(struct seq_file *sf, struct blkcg *blkcg, |
Tejun Heo | f95a04a | 2012-04-16 13:57:26 -0700 | [diff] [blame] | 141 | u64 (*prfill)(struct seq_file *, |
| 142 | struct blkg_policy_data *, int), |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 143 | const struct blkcg_policy *pol, int data, |
Tejun Heo | ec39934 | 2012-04-13 13:11:27 -0700 | [diff] [blame] | 144 | bool show_total); |
Tejun Heo | f95a04a | 2012-04-16 13:57:26 -0700 | [diff] [blame] | 145 | u64 __blkg_prfill_u64(struct seq_file *sf, struct blkg_policy_data *pd, u64 v); |
| 146 | u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd, |
Tejun Heo | 829fdb5 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 147 | const struct blkg_rwstat *rwstat); |
Tejun Heo | f95a04a | 2012-04-16 13:57:26 -0700 | [diff] [blame] | 148 | u64 blkg_prfill_stat(struct seq_file *sf, struct blkg_policy_data *pd, int off); |
| 149 | u64 blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd, |
| 150 | int off); |
Tejun Heo | 829fdb5 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 151 | |
| 152 | struct blkg_conf_ctx { |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 153 | struct gendisk *disk; |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 154 | struct blkcg_gq *blkg; |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 155 | u64 v; |
Tejun Heo | 829fdb5 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 156 | }; |
| 157 | |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 158 | int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, |
| 159 | const char *input, struct blkg_conf_ctx *ctx); |
Tejun Heo | 829fdb5 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 160 | void blkg_conf_finish(struct blkg_conf_ctx *ctx); |
| 161 | |
| 162 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 163 | /** |
| 164 | * blkg_to_pdata - get policy private data |
| 165 | * @blkg: blkg of interest |
| 166 | * @pol: policy of interest |
| 167 | * |
| 168 | * Return pointer to private data associated with the @blkg-@pol pair. |
| 169 | */ |
Tejun Heo | f95a04a | 2012-04-16 13:57:26 -0700 | [diff] [blame] | 170 | static inline struct blkg_policy_data *blkg_to_pd(struct blkcg_gq *blkg, |
| 171 | struct blkcg_policy *pol) |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 172 | { |
Tejun Heo | f95a04a | 2012-04-16 13:57:26 -0700 | [diff] [blame] | 173 | return blkg ? blkg->pd[pol->plid] : NULL; |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | /** |
| 177 | * pdata_to_blkg - get blkg associated with policy private data |
Tejun Heo | f95a04a | 2012-04-16 13:57:26 -0700 | [diff] [blame] | 178 | * @pd: policy private data of interest |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 179 | * |
Tejun Heo | f95a04a | 2012-04-16 13:57:26 -0700 | [diff] [blame] | 180 | * @pd is policy private data. Determine the blkg it's associated with. |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 181 | */ |
Tejun Heo | f95a04a | 2012-04-16 13:57:26 -0700 | [diff] [blame] | 182 | static inline struct blkcg_gq *pd_to_blkg(struct blkg_policy_data *pd) |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 183 | { |
Tejun Heo | f95a04a | 2012-04-16 13:57:26 -0700 | [diff] [blame] | 184 | return pd ? pd->blkg : NULL; |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Tejun Heo | 54e7ed1 | 2012-04-16 13:57:23 -0700 | [diff] [blame] | 187 | /** |
| 188 | * blkg_path - format cgroup path of blkg |
| 189 | * @blkg: blkg of interest |
| 190 | * @buf: target buffer |
| 191 | * @buflen: target buffer length |
| 192 | * |
| 193 | * Format the path of the cgroup of @blkg into @buf. |
| 194 | */ |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 195 | static inline int blkg_path(struct blkcg_gq *blkg, char *buf, int buflen) |
Vivek Goyal | afc24d4 | 2010-04-26 19:27:56 +0200 | [diff] [blame] | 196 | { |
Tejun Heo | 54e7ed1 | 2012-04-16 13:57:23 -0700 | [diff] [blame] | 197 | int ret; |
| 198 | |
| 199 | rcu_read_lock(); |
| 200 | ret = cgroup_path(blkg->blkcg->css.cgroup, buf, buflen); |
| 201 | rcu_read_unlock(); |
| 202 | if (ret) |
| 203 | strncpy(buf, "<unavailable>", buflen); |
| 204 | return ret; |
Vivek Goyal | afc24d4 | 2010-04-26 19:27:56 +0200 | [diff] [blame] | 205 | } |
| 206 | |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 207 | /** |
| 208 | * blkg_get - get a blkg reference |
| 209 | * @blkg: blkg to get |
| 210 | * |
| 211 | * The caller should be holding queue_lock and an existing reference. |
| 212 | */ |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 213 | static inline void blkg_get(struct blkcg_gq *blkg) |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 214 | { |
| 215 | lockdep_assert_held(blkg->q->queue_lock); |
| 216 | WARN_ON_ONCE(!blkg->refcnt); |
| 217 | blkg->refcnt++; |
| 218 | } |
| 219 | |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 220 | void __blkg_release(struct blkcg_gq *blkg); |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 221 | |
| 222 | /** |
| 223 | * blkg_put - put a blkg reference |
| 224 | * @blkg: blkg to put |
| 225 | * |
| 226 | * The caller should be holding queue_lock. |
| 227 | */ |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 228 | static inline void blkg_put(struct blkcg_gq *blkg) |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 229 | { |
| 230 | lockdep_assert_held(blkg->q->queue_lock); |
| 231 | WARN_ON_ONCE(blkg->refcnt <= 0); |
| 232 | if (!--blkg->refcnt) |
| 233 | __blkg_release(blkg); |
| 234 | } |
| 235 | |
Tejun Heo | edcb072 | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 236 | /** |
| 237 | * blkg_stat_add - add a value to a blkg_stat |
| 238 | * @stat: target blkg_stat |
| 239 | * @val: value to add |
| 240 | * |
| 241 | * Add @val to @stat. The caller is responsible for synchronizing calls to |
| 242 | * this function. |
| 243 | */ |
| 244 | static inline void blkg_stat_add(struct blkg_stat *stat, uint64_t val) |
| 245 | { |
| 246 | u64_stats_update_begin(&stat->syncp); |
| 247 | stat->cnt += val; |
| 248 | u64_stats_update_end(&stat->syncp); |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * blkg_stat_read - read the current value of a blkg_stat |
| 253 | * @stat: blkg_stat to read |
| 254 | * |
| 255 | * Read the current value of @stat. This function can be called without |
| 256 | * synchroniztion and takes care of u64 atomicity. |
| 257 | */ |
| 258 | static inline uint64_t blkg_stat_read(struct blkg_stat *stat) |
| 259 | { |
| 260 | unsigned int start; |
| 261 | uint64_t v; |
| 262 | |
| 263 | do { |
| 264 | start = u64_stats_fetch_begin(&stat->syncp); |
| 265 | v = stat->cnt; |
| 266 | } while (u64_stats_fetch_retry(&stat->syncp, start)); |
| 267 | |
| 268 | return v; |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * blkg_stat_reset - reset a blkg_stat |
| 273 | * @stat: blkg_stat to reset |
| 274 | */ |
| 275 | static inline void blkg_stat_reset(struct blkg_stat *stat) |
| 276 | { |
| 277 | stat->cnt = 0; |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * blkg_rwstat_add - add a value to a blkg_rwstat |
| 282 | * @rwstat: target blkg_rwstat |
| 283 | * @rw: mask of REQ_{WRITE|SYNC} |
| 284 | * @val: value to add |
| 285 | * |
| 286 | * Add @val to @rwstat. The counters are chosen according to @rw. The |
| 287 | * caller is responsible for synchronizing calls to this function. |
| 288 | */ |
| 289 | static inline void blkg_rwstat_add(struct blkg_rwstat *rwstat, |
| 290 | int rw, uint64_t val) |
| 291 | { |
| 292 | u64_stats_update_begin(&rwstat->syncp); |
| 293 | |
| 294 | if (rw & REQ_WRITE) |
| 295 | rwstat->cnt[BLKG_RWSTAT_WRITE] += val; |
| 296 | else |
| 297 | rwstat->cnt[BLKG_RWSTAT_READ] += val; |
| 298 | if (rw & REQ_SYNC) |
| 299 | rwstat->cnt[BLKG_RWSTAT_SYNC] += val; |
| 300 | else |
| 301 | rwstat->cnt[BLKG_RWSTAT_ASYNC] += val; |
| 302 | |
| 303 | u64_stats_update_end(&rwstat->syncp); |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * blkg_rwstat_read - read the current values of a blkg_rwstat |
| 308 | * @rwstat: blkg_rwstat to read |
| 309 | * |
| 310 | * Read the current snapshot of @rwstat and return it as the return value. |
| 311 | * This function can be called without synchronization and takes care of |
| 312 | * u64 atomicity. |
| 313 | */ |
Tejun Heo | c94bed89 | 2012-04-16 13:57:22 -0700 | [diff] [blame] | 314 | static inline struct blkg_rwstat blkg_rwstat_read(struct blkg_rwstat *rwstat) |
Tejun Heo | edcb072 | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 315 | { |
| 316 | unsigned int start; |
| 317 | struct blkg_rwstat tmp; |
| 318 | |
| 319 | do { |
| 320 | start = u64_stats_fetch_begin(&rwstat->syncp); |
| 321 | tmp = *rwstat; |
| 322 | } while (u64_stats_fetch_retry(&rwstat->syncp, start)); |
| 323 | |
| 324 | return tmp; |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * blkg_rwstat_sum - read the total count of a blkg_rwstat |
| 329 | * @rwstat: blkg_rwstat to read |
| 330 | * |
| 331 | * Return the total count of @rwstat regardless of the IO direction. This |
| 332 | * function can be called without synchronization and takes care of u64 |
| 333 | * atomicity. |
| 334 | */ |
| 335 | static inline uint64_t blkg_rwstat_sum(struct blkg_rwstat *rwstat) |
| 336 | { |
| 337 | struct blkg_rwstat tmp = blkg_rwstat_read(rwstat); |
| 338 | |
| 339 | return tmp.cnt[BLKG_RWSTAT_READ] + tmp.cnt[BLKG_RWSTAT_WRITE]; |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * blkg_rwstat_reset - reset a blkg_rwstat |
| 344 | * @rwstat: blkg_rwstat to reset |
| 345 | */ |
| 346 | static inline void blkg_rwstat_reset(struct blkg_rwstat *rwstat) |
| 347 | { |
| 348 | memset(rwstat->cnt, 0, sizeof(rwstat->cnt)); |
| 349 | } |
| 350 | |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 351 | #else /* CONFIG_BLK_CGROUP */ |
| 352 | |
| 353 | struct cgroup; |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 354 | |
Tejun Heo | f95a04a | 2012-04-16 13:57:26 -0700 | [diff] [blame] | 355 | struct blkg_policy_data { |
| 356 | }; |
| 357 | |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 358 | struct blkcg_gq { |
Jens Axboe | 2f5ea47 | 2009-12-03 21:06:43 +0100 | [diff] [blame] | 359 | }; |
| 360 | |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 361 | struct blkcg_policy { |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 362 | }; |
| 363 | |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 364 | static inline struct blkcg *cgroup_to_blkcg(struct cgroup *cgroup) { return NULL; } |
| 365 | static inline struct blkcg *bio_blkcg(struct bio *bio) { return NULL; } |
| 366 | static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg, void *key) { return NULL; } |
Tejun Heo | 5efd611 | 2012-03-05 13:15:12 -0800 | [diff] [blame] | 367 | static inline int blkcg_init_queue(struct request_queue *q) { return 0; } |
| 368 | static inline void blkcg_drain_queue(struct request_queue *q) { } |
| 369 | static inline void blkcg_exit_queue(struct request_queue *q) { } |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 370 | static inline int blkcg_policy_register(struct blkcg_policy *pol) { return 0; } |
| 371 | static inline void blkcg_policy_unregister(struct blkcg_policy *pol) { } |
Tejun Heo | a2b1693 | 2012-04-13 13:11:33 -0700 | [diff] [blame] | 372 | static inline int blkcg_activate_policy(struct request_queue *q, |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 373 | const struct blkcg_policy *pol) { return 0; } |
Tejun Heo | a2b1693 | 2012-04-13 13:11:33 -0700 | [diff] [blame] | 374 | static inline void blkcg_deactivate_policy(struct request_queue *q, |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 375 | const struct blkcg_policy *pol) { } |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 376 | |
Tejun Heo | f95a04a | 2012-04-16 13:57:26 -0700 | [diff] [blame] | 377 | static inline struct blkg_policy_data *blkg_to_pd(struct blkcg_gq *blkg, |
| 378 | struct blkcg_policy *pol) { return NULL; } |
| 379 | static inline struct blkcg_gq *pd_to_blkg(struct blkg_policy_data *pd) { return NULL; } |
Tejun Heo | 3c79839 | 2012-04-16 13:57:25 -0700 | [diff] [blame] | 380 | static inline char *blkg_path(struct blkcg_gq *blkg) { return NULL; } |
| 381 | static inline void blkg_get(struct blkcg_gq *blkg) { } |
| 382 | static inline void blkg_put(struct blkcg_gq *blkg) { } |
Vivek Goyal | afc24d4 | 2010-04-26 19:27:56 +0200 | [diff] [blame] | 383 | |
Tejun Heo | 36558c8 | 2012-04-16 13:57:24 -0700 | [diff] [blame] | 384 | #endif /* CONFIG_BLK_CGROUP */ |
| 385 | #endif /* _BLK_CGROUP_H */ |