Blame view

block/bfq-cgroup.c 38.5 KB
a497ee34a   Christoph Hellwig   block: switch all...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
ea25da480   Paolo Valente   block, bfq: split...
2
3
  /*
   * cgroups support for the BFQ I/O scheduler.
ea25da480   Paolo Valente   block, bfq: split...
4
5
6
7
8
9
10
11
12
13
14
15
16
   */
  #include <linux/module.h>
  #include <linux/slab.h>
  #include <linux/blkdev.h>
  #include <linux/cgroup.h>
  #include <linux/elevator.h>
  #include <linux/ktime.h>
  #include <linux/rbtree.h>
  #include <linux/ioprio.h>
  #include <linux/sbitmap.h>
  #include <linux/delay.h>
  
  #include "bfq-iosched.h"
8060c47ba   Christoph Hellwig   block: rename CON...
17
  #ifdef CONFIG_BFQ_CGROUP_DEBUG
c0ce79dca   Christoph Hellwig   blk-cgroup: move ...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  static int bfq_stat_init(struct bfq_stat *stat, gfp_t gfp)
  {
  	int ret;
  
  	ret = percpu_counter_init(&stat->cpu_cnt, 0, gfp);
  	if (ret)
  		return ret;
  
  	atomic64_set(&stat->aux_cnt, 0);
  	return 0;
  }
  
  static void bfq_stat_exit(struct bfq_stat *stat)
  {
  	percpu_counter_destroy(&stat->cpu_cnt);
  }
  
  /**
   * bfq_stat_add - add a value to a bfq_stat
   * @stat: target bfq_stat
   * @val: value to add
   *
   * Add @val to @stat.  The caller must ensure that IRQ on the same CPU
   * don't re-enter this function for the same counter.
   */
  static inline void bfq_stat_add(struct bfq_stat *stat, uint64_t val)
  {
  	percpu_counter_add_batch(&stat->cpu_cnt, val, BLKG_STAT_CPU_BATCH);
  }
  
  /**
   * bfq_stat_read - read the current value of a bfq_stat
   * @stat: bfq_stat to read
   */
  static inline uint64_t bfq_stat_read(struct bfq_stat *stat)
  {
  	return percpu_counter_sum_positive(&stat->cpu_cnt);
  }
  
  /**
   * bfq_stat_reset - reset a bfq_stat
   * @stat: bfq_stat to reset
   */
  static inline void bfq_stat_reset(struct bfq_stat *stat)
  {
  	percpu_counter_set(&stat->cpu_cnt, 0);
  	atomic64_set(&stat->aux_cnt, 0);
  }
  
  /**
   * bfq_stat_add_aux - add a bfq_stat into another's aux count
   * @to: the destination bfq_stat
   * @from: the source
   *
   * Add @from's count including the aux one to @to's aux count.
   */
  static inline void bfq_stat_add_aux(struct bfq_stat *to,
  				     struct bfq_stat *from)
  {
  	atomic64_add(bfq_stat_read(from) + atomic64_read(&from->aux_cnt),
  		     &to->aux_cnt);
  }
  
  /**
c0ce79dca   Christoph Hellwig   blk-cgroup: move ...
82
83
84
85
86
87
88
89
90
91
92
93
   * blkg_prfill_stat - prfill callback for bfq_stat
   * @sf: seq_file to print to
   * @pd: policy private data of interest
   * @off: offset to the bfq_stat in @pd
   *
   * prfill callback for printing a bfq_stat.
   */
  static u64 blkg_prfill_stat(struct seq_file *sf, struct blkg_policy_data *pd,
  		int off)
  {
  	return __blkg_prfill_u64(sf, pd, bfq_stat_read((void *)pd + off));
  }
ea25da480   Paolo Valente   block, bfq: split...
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  /* bfqg stats flags */
  enum bfqg_stats_flags {
  	BFQG_stats_waiting = 0,
  	BFQG_stats_idling,
  	BFQG_stats_empty,
  };
  
  #define BFQG_FLAG_FNS(name)						\
  static void bfqg_stats_mark_##name(struct bfqg_stats *stats)	\
  {									\
  	stats->flags |= (1 << BFQG_stats_##name);			\
  }									\
  static void bfqg_stats_clear_##name(struct bfqg_stats *stats)	\
  {									\
  	stats->flags &= ~(1 << BFQG_stats_##name);			\
  }									\
  static int bfqg_stats_##name(struct bfqg_stats *stats)		\
  {									\
  	return (stats->flags & (1 << BFQG_stats_##name)) != 0;		\
  }									\
  
  BFQG_FLAG_FNS(waiting)
  BFQG_FLAG_FNS(idling)
  BFQG_FLAG_FNS(empty)
  #undef BFQG_FLAG_FNS
8f9bebc33   Paolo Valente   block, bfq: acces...
119
  /* This should be called with the scheduler lock held. */
ea25da480   Paolo Valente   block, bfq: split...
120
121
  static void bfqg_stats_update_group_wait_time(struct bfqg_stats *stats)
  {
84c7afceb   Omar Sandoval   block: use ktime_...
122
  	u64 now;
ea25da480   Paolo Valente   block, bfq: split...
123
124
125
  
  	if (!bfqg_stats_waiting(stats))
  		return;
84c7afceb   Omar Sandoval   block: use ktime_...
126
127
  	now = ktime_get_ns();
  	if (now > stats->start_group_wait_time)
c0ce79dca   Christoph Hellwig   blk-cgroup: move ...
128
  		bfq_stat_add(&stats->group_wait_time,
ea25da480   Paolo Valente   block, bfq: split...
129
130
131
  			      now - stats->start_group_wait_time);
  	bfqg_stats_clear_waiting(stats);
  }
8f9bebc33   Paolo Valente   block, bfq: acces...
132
  /* This should be called with the scheduler lock held. */
ea25da480   Paolo Valente   block, bfq: split...
133
134
135
136
137
138
139
140
141
  static void bfqg_stats_set_start_group_wait_time(struct bfq_group *bfqg,
  						 struct bfq_group *curr_bfqg)
  {
  	struct bfqg_stats *stats = &bfqg->stats;
  
  	if (bfqg_stats_waiting(stats))
  		return;
  	if (bfqg == curr_bfqg)
  		return;
84c7afceb   Omar Sandoval   block: use ktime_...
142
  	stats->start_group_wait_time = ktime_get_ns();
ea25da480   Paolo Valente   block, bfq: split...
143
144
  	bfqg_stats_mark_waiting(stats);
  }
8f9bebc33   Paolo Valente   block, bfq: acces...
145
  /* This should be called with the scheduler lock held. */
ea25da480   Paolo Valente   block, bfq: split...
146
147
  static void bfqg_stats_end_empty_time(struct bfqg_stats *stats)
  {
84c7afceb   Omar Sandoval   block: use ktime_...
148
  	u64 now;
ea25da480   Paolo Valente   block, bfq: split...
149
150
151
  
  	if (!bfqg_stats_empty(stats))
  		return;
84c7afceb   Omar Sandoval   block: use ktime_...
152
153
  	now = ktime_get_ns();
  	if (now > stats->start_empty_time)
c0ce79dca   Christoph Hellwig   blk-cgroup: move ...
154
  		bfq_stat_add(&stats->empty_time,
ea25da480   Paolo Valente   block, bfq: split...
155
156
157
158
159
160
  			      now - stats->start_empty_time);
  	bfqg_stats_clear_empty(stats);
  }
  
  void bfqg_stats_update_dequeue(struct bfq_group *bfqg)
  {
c0ce79dca   Christoph Hellwig   blk-cgroup: move ...
161
  	bfq_stat_add(&bfqg->stats.dequeue, 1);
ea25da480   Paolo Valente   block, bfq: split...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
  }
  
  void bfqg_stats_set_start_empty_time(struct bfq_group *bfqg)
  {
  	struct bfqg_stats *stats = &bfqg->stats;
  
  	if (blkg_rwstat_total(&stats->queued))
  		return;
  
  	/*
  	 * group is already marked empty. This can happen if bfqq got new
  	 * request in parent group and moved to this group while being added
  	 * to service tree. Just ignore the event and move on.
  	 */
  	if (bfqg_stats_empty(stats))
  		return;
84c7afceb   Omar Sandoval   block: use ktime_...
178
  	stats->start_empty_time = ktime_get_ns();
ea25da480   Paolo Valente   block, bfq: split...
179
180
181
182
183
184
185
186
  	bfqg_stats_mark_empty(stats);
  }
  
  void bfqg_stats_update_idle_time(struct bfq_group *bfqg)
  {
  	struct bfqg_stats *stats = &bfqg->stats;
  
  	if (bfqg_stats_idling(stats)) {
84c7afceb   Omar Sandoval   block: use ktime_...
187
  		u64 now = ktime_get_ns();
ea25da480   Paolo Valente   block, bfq: split...
188

84c7afceb   Omar Sandoval   block: use ktime_...
189
  		if (now > stats->start_idle_time)
c0ce79dca   Christoph Hellwig   blk-cgroup: move ...
190
  			bfq_stat_add(&stats->idle_time,
ea25da480   Paolo Valente   block, bfq: split...
191
192
193
194
195
196
197
198
  				      now - stats->start_idle_time);
  		bfqg_stats_clear_idling(stats);
  	}
  }
  
  void bfqg_stats_set_start_idle_time(struct bfq_group *bfqg)
  {
  	struct bfqg_stats *stats = &bfqg->stats;
84c7afceb   Omar Sandoval   block: use ktime_...
199
  	stats->start_idle_time = ktime_get_ns();
ea25da480   Paolo Valente   block, bfq: split...
200
201
202
203
204
205
  	bfqg_stats_mark_idling(stats);
  }
  
  void bfqg_stats_update_avg_queue_size(struct bfq_group *bfqg)
  {
  	struct bfqg_stats *stats = &bfqg->stats;
c0ce79dca   Christoph Hellwig   blk-cgroup: move ...
206
  	bfq_stat_add(&stats->avg_queue_size_sum,
ea25da480   Paolo Valente   block, bfq: split...
207
  		      blkg_rwstat_total(&stats->queued));
c0ce79dca   Christoph Hellwig   blk-cgroup: move ...
208
  	bfq_stat_add(&stats->avg_queue_size_samples, 1);
ea25da480   Paolo Valente   block, bfq: split...
209
210
  	bfqg_stats_update_group_wait_time(stats);
  }
a33801e8b   Luca Miccio   block, bfq: move ...
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
  void bfqg_stats_update_io_add(struct bfq_group *bfqg, struct bfq_queue *bfqq,
  			      unsigned int op)
  {
  	blkg_rwstat_add(&bfqg->stats.queued, op, 1);
  	bfqg_stats_end_empty_time(&bfqg->stats);
  	if (!(bfqq == ((struct bfq_data *)bfqg->bfqd)->in_service_queue))
  		bfqg_stats_set_start_group_wait_time(bfqg, bfqq_group(bfqq));
  }
  
  void bfqg_stats_update_io_remove(struct bfq_group *bfqg, unsigned int op)
  {
  	blkg_rwstat_add(&bfqg->stats.queued, op, -1);
  }
  
  void bfqg_stats_update_io_merged(struct bfq_group *bfqg, unsigned int op)
  {
  	blkg_rwstat_add(&bfqg->stats.merged, op, 1);
  }
84c7afceb   Omar Sandoval   block: use ktime_...
229
230
  void bfqg_stats_update_completion(struct bfq_group *bfqg, u64 start_time_ns,
  				  u64 io_start_time_ns, unsigned int op)
a33801e8b   Luca Miccio   block, bfq: move ...
231
232
  {
  	struct bfqg_stats *stats = &bfqg->stats;
84c7afceb   Omar Sandoval   block: use ktime_...
233
  	u64 now = ktime_get_ns();
a33801e8b   Luca Miccio   block, bfq: move ...
234

84c7afceb   Omar Sandoval   block: use ktime_...
235
  	if (now > io_start_time_ns)
a33801e8b   Luca Miccio   block, bfq: move ...
236
  		blkg_rwstat_add(&stats->service_time, op,
84c7afceb   Omar Sandoval   block: use ktime_...
237
238
  				now - io_start_time_ns);
  	if (io_start_time_ns > start_time_ns)
a33801e8b   Luca Miccio   block, bfq: move ...
239
  		blkg_rwstat_add(&stats->wait_time, op,
84c7afceb   Omar Sandoval   block: use ktime_...
240
  				io_start_time_ns - start_time_ns);
a33801e8b   Luca Miccio   block, bfq: move ...
241
  }
8060c47ba   Christoph Hellwig   block: rename CON...
242
  #else /* CONFIG_BFQ_CGROUP_DEBUG */
a33801e8b   Luca Miccio   block, bfq: move ...
243
244
245
246
247
  
  void bfqg_stats_update_io_add(struct bfq_group *bfqg, struct bfq_queue *bfqq,
  			      unsigned int op) { }
  void bfqg_stats_update_io_remove(struct bfq_group *bfqg, unsigned int op) { }
  void bfqg_stats_update_io_merged(struct bfq_group *bfqg, unsigned int op) { }
84c7afceb   Omar Sandoval   block: use ktime_...
248
249
  void bfqg_stats_update_completion(struct bfq_group *bfqg, u64 start_time_ns,
  				  u64 io_start_time_ns, unsigned int op) { }
a33801e8b   Luca Miccio   block, bfq: move ...
250
251
252
253
254
  void bfqg_stats_update_dequeue(struct bfq_group *bfqg) { }
  void bfqg_stats_set_start_empty_time(struct bfq_group *bfqg) { }
  void bfqg_stats_update_idle_time(struct bfq_group *bfqg) { }
  void bfqg_stats_set_start_idle_time(struct bfq_group *bfqg) { }
  void bfqg_stats_update_avg_queue_size(struct bfq_group *bfqg) { }
8060c47ba   Christoph Hellwig   block: rename CON...
255
  #endif /* CONFIG_BFQ_CGROUP_DEBUG */
a33801e8b   Luca Miccio   block, bfq: move ...
256
257
  
  #ifdef CONFIG_BFQ_GROUP_IOSCHED
ea25da480   Paolo Valente   block, bfq: split...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
  /*
   * blk-cgroup policy-related handlers
   * The following functions help in converting between blk-cgroup
   * internal structures and BFQ-specific structures.
   */
  
  static struct bfq_group *pd_to_bfqg(struct blkg_policy_data *pd)
  {
  	return pd ? container_of(pd, struct bfq_group, pd) : NULL;
  }
  
  struct blkcg_gq *bfqg_to_blkg(struct bfq_group *bfqg)
  {
  	return pd_to_blkg(&bfqg->pd);
  }
  
  static struct bfq_group *blkg_to_bfqg(struct blkcg_gq *blkg)
  {
  	return pd_to_bfqg(blkg_to_pd(blkg, &blkcg_policy_bfq));
  }
  
  /*
   * bfq_group handlers
   * The following functions help in navigating the bfq_group hierarchy
   * by allowing to find the parent of a bfq_group or the bfq_group
   * associated to a bfq_queue.
   */
  
  static struct bfq_group *bfqg_parent(struct bfq_group *bfqg)
  {
  	struct blkcg_gq *pblkg = bfqg_to_blkg(bfqg)->parent;
  
  	return pblkg ? blkg_to_bfqg(pblkg) : NULL;
  }
  
  struct bfq_group *bfqq_group(struct bfq_queue *bfqq)
  {
  	struct bfq_entity *group_entity = bfqq->entity.parent;
  
  	return group_entity ? container_of(group_entity, struct bfq_group,
  					   entity) :
  			      bfqq->bfqd->root_group;
  }
  
  /*
   * The following two functions handle get and put of a bfq_group by
   * wrapping the related blk-cgroup hooks.
   */
  
  static void bfqg_get(struct bfq_group *bfqg)
  {
8f9bebc33   Paolo Valente   block, bfq: acces...
309
  	bfqg->ref++;
ea25da480   Paolo Valente   block, bfq: split...
310
  }
dfb79af54   Bart Van Assche   bfq: Declare loca...
311
  static void bfqg_put(struct bfq_group *bfqg)
ea25da480   Paolo Valente   block, bfq: split...
312
  {
8f9bebc33   Paolo Valente   block, bfq: acces...
313
314
315
316
317
  	bfqg->ref--;
  
  	if (bfqg->ref == 0)
  		kfree(bfqg);
  }
2de791ab4   Dmitry Monakhov   bfq: fix blkio cg...
318
  static void bfqg_and_blkg_get(struct bfq_group *bfqg)
8f9bebc33   Paolo Valente   block, bfq: acces...
319
320
321
322
323
324
325
326
327
  {
  	/* see comments in bfq_bic_update_cgroup for why refcounting bfqg */
  	bfqg_get(bfqg);
  
  	blkg_get(bfqg_to_blkg(bfqg));
  }
  
  void bfqg_and_blkg_put(struct bfq_group *bfqg)
  {
8f9bebc33   Paolo Valente   block, bfq: acces...
328
  	blkg_put(bfqg_to_blkg(bfqg));
d5274b3cd   Konstantin Khlebnikov   block: bfq: swap ...
329
330
  
  	bfqg_put(bfqg);
ea25da480   Paolo Valente   block, bfq: split...
331
  }
fd41e6033   Tejun Heo   bfq-iosched: stop...
332
333
334
  void bfqg_stats_update_legacy_io(struct request_queue *q, struct request *rq)
  {
  	struct bfq_group *bfqg = blkg_to_bfqg(rq->bio->bi_blkg);
08802ed66   Hou Tao   bfq-iosched: Ensu...
335
336
  	if (!bfqg)
  		return;
fd41e6033   Tejun Heo   bfq-iosched: stop...
337
338
339
  	blkg_rwstat_add(&bfqg->stats.bytes, rq->cmd_flags, blk_rq_bytes(rq));
  	blkg_rwstat_add(&bfqg->stats.ios, rq->cmd_flags, 1);
  }
ea25da480   Paolo Valente   block, bfq: split...
340
341
342
  /* @stats = 0 */
  static void bfqg_stats_reset(struct bfqg_stats *stats)
  {
8060c47ba   Christoph Hellwig   block: rename CON...
343
  #ifdef CONFIG_BFQ_CGROUP_DEBUG
ea25da480   Paolo Valente   block, bfq: split...
344
345
346
347
  	/* queued stats shouldn't be cleared */
  	blkg_rwstat_reset(&stats->merged);
  	blkg_rwstat_reset(&stats->service_time);
  	blkg_rwstat_reset(&stats->wait_time);
c0ce79dca   Christoph Hellwig   blk-cgroup: move ...
348
349
350
351
352
353
354
  	bfq_stat_reset(&stats->time);
  	bfq_stat_reset(&stats->avg_queue_size_sum);
  	bfq_stat_reset(&stats->avg_queue_size_samples);
  	bfq_stat_reset(&stats->dequeue);
  	bfq_stat_reset(&stats->group_wait_time);
  	bfq_stat_reset(&stats->idle_time);
  	bfq_stat_reset(&stats->empty_time);
a33801e8b   Luca Miccio   block, bfq: move ...
355
  #endif
ea25da480   Paolo Valente   block, bfq: split...
356
357
358
359
360
361
362
  }
  
  /* @to += @from */
  static void bfqg_stats_add_aux(struct bfqg_stats *to, struct bfqg_stats *from)
  {
  	if (!to || !from)
  		return;
8060c47ba   Christoph Hellwig   block: rename CON...
363
  #ifdef CONFIG_BFQ_CGROUP_DEBUG
ea25da480   Paolo Valente   block, bfq: split...
364
365
366
367
  	/* queued stats shouldn't be cleared */
  	blkg_rwstat_add_aux(&to->merged, &from->merged);
  	blkg_rwstat_add_aux(&to->service_time, &from->service_time);
  	blkg_rwstat_add_aux(&to->wait_time, &from->wait_time);
c0ce79dca   Christoph Hellwig   blk-cgroup: move ...
368
369
370
  	bfq_stat_add_aux(&from->time, &from->time);
  	bfq_stat_add_aux(&to->avg_queue_size_sum, &from->avg_queue_size_sum);
  	bfq_stat_add_aux(&to->avg_queue_size_samples,
ea25da480   Paolo Valente   block, bfq: split...
371
  			  &from->avg_queue_size_samples);
c0ce79dca   Christoph Hellwig   blk-cgroup: move ...
372
373
374
375
  	bfq_stat_add_aux(&to->dequeue, &from->dequeue);
  	bfq_stat_add_aux(&to->group_wait_time, &from->group_wait_time);
  	bfq_stat_add_aux(&to->idle_time, &from->idle_time);
  	bfq_stat_add_aux(&to->empty_time, &from->empty_time);
a33801e8b   Luca Miccio   block, bfq: move ...
376
  #endif
ea25da480   Paolo Valente   block, bfq: split...
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
  }
  
  /*
   * Transfer @bfqg's stats to its parent's aux counts so that the ancestors'
   * recursive stats can still account for the amount used by this bfqg after
   * it's gone.
   */
  static void bfqg_stats_xfer_dead(struct bfq_group *bfqg)
  {
  	struct bfq_group *parent;
  
  	if (!bfqg) /* root_group */
  		return;
  
  	parent = bfqg_parent(bfqg);
0d945c1f9   Christoph Hellwig   block: remove the...
392
  	lockdep_assert_held(&bfqg_to_blkg(bfqg)->q->queue_lock);
ea25da480   Paolo Valente   block, bfq: split...
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
  
  	if (unlikely(!parent))
  		return;
  
  	bfqg_stats_add_aux(&parent->stats, &bfqg->stats);
  	bfqg_stats_reset(&bfqg->stats);
  }
  
  void bfq_init_entity(struct bfq_entity *entity, struct bfq_group *bfqg)
  {
  	struct bfq_queue *bfqq = bfq_entity_to_bfqq(entity);
  
  	entity->weight = entity->new_weight;
  	entity->orig_weight = entity->new_weight;
  	if (bfqq) {
  		bfqq->ioprio = bfqq->new_ioprio;
  		bfqq->ioprio_class = bfqq->new_ioprio_class;
8f9bebc33   Paolo Valente   block, bfq: acces...
410
411
412
413
414
  		/*
  		 * Make sure that bfqg and its associated blkg do not
  		 * disappear before entity.
  		 */
  		bfqg_and_blkg_get(bfqg);
ea25da480   Paolo Valente   block, bfq: split...
415
416
417
418
419
420
421
  	}
  	entity->parent = bfqg->my_entity; /* NULL for root group */
  	entity->sched_data = &bfqg->sched_data;
  }
  
  static void bfqg_stats_exit(struct bfqg_stats *stats)
  {
fd41e6033   Tejun Heo   bfq-iosched: stop...
422
423
  	blkg_rwstat_exit(&stats->bytes);
  	blkg_rwstat_exit(&stats->ios);
8060c47ba   Christoph Hellwig   block: rename CON...
424
  #ifdef CONFIG_BFQ_CGROUP_DEBUG
ea25da480   Paolo Valente   block, bfq: split...
425
426
427
428
  	blkg_rwstat_exit(&stats->merged);
  	blkg_rwstat_exit(&stats->service_time);
  	blkg_rwstat_exit(&stats->wait_time);
  	blkg_rwstat_exit(&stats->queued);
c0ce79dca   Christoph Hellwig   blk-cgroup: move ...
429
430
431
432
433
434
435
  	bfq_stat_exit(&stats->time);
  	bfq_stat_exit(&stats->avg_queue_size_sum);
  	bfq_stat_exit(&stats->avg_queue_size_samples);
  	bfq_stat_exit(&stats->dequeue);
  	bfq_stat_exit(&stats->group_wait_time);
  	bfq_stat_exit(&stats->idle_time);
  	bfq_stat_exit(&stats->empty_time);
a33801e8b   Luca Miccio   block, bfq: move ...
436
  #endif
ea25da480   Paolo Valente   block, bfq: split...
437
438
439
440
  }
  
  static int bfqg_stats_init(struct bfqg_stats *stats, gfp_t gfp)
  {
fd41e6033   Tejun Heo   bfq-iosched: stop...
441
442
443
  	if (blkg_rwstat_init(&stats->bytes, gfp) ||
  	    blkg_rwstat_init(&stats->ios, gfp))
  		return -ENOMEM;
8060c47ba   Christoph Hellwig   block: rename CON...
444
  #ifdef CONFIG_BFQ_CGROUP_DEBUG
ea25da480   Paolo Valente   block, bfq: split...
445
446
447
448
  	if (blkg_rwstat_init(&stats->merged, gfp) ||
  	    blkg_rwstat_init(&stats->service_time, gfp) ||
  	    blkg_rwstat_init(&stats->wait_time, gfp) ||
  	    blkg_rwstat_init(&stats->queued, gfp) ||
c0ce79dca   Christoph Hellwig   blk-cgroup: move ...
449
450
451
452
453
454
455
  	    bfq_stat_init(&stats->time, gfp) ||
  	    bfq_stat_init(&stats->avg_queue_size_sum, gfp) ||
  	    bfq_stat_init(&stats->avg_queue_size_samples, gfp) ||
  	    bfq_stat_init(&stats->dequeue, gfp) ||
  	    bfq_stat_init(&stats->group_wait_time, gfp) ||
  	    bfq_stat_init(&stats->idle_time, gfp) ||
  	    bfq_stat_init(&stats->empty_time, gfp)) {
ea25da480   Paolo Valente   block, bfq: split...
456
457
458
  		bfqg_stats_exit(stats);
  		return -ENOMEM;
  	}
a33801e8b   Luca Miccio   block, bfq: move ...
459
  #endif
ea25da480   Paolo Valente   block, bfq: split...
460
461
462
463
464
465
466
467
468
469
470
471
472
  
  	return 0;
  }
  
  static struct bfq_group_data *cpd_to_bfqgd(struct blkcg_policy_data *cpd)
  {
  	return cpd ? container_of(cpd, struct bfq_group_data, pd) : NULL;
  }
  
  static struct bfq_group_data *blkcg_to_bfqgd(struct blkcg *blkcg)
  {
  	return cpd_to_bfqgd(blkcg_to_cpd(blkcg, &blkcg_policy_bfq));
  }
dfb79af54   Bart Van Assche   bfq: Declare loca...
473
  static struct blkcg_policy_data *bfq_cpd_alloc(gfp_t gfp)
ea25da480   Paolo Valente   block, bfq: split...
474
475
476
477
478
479
480
481
  {
  	struct bfq_group_data *bgd;
  
  	bgd = kzalloc(sizeof(*bgd), gfp);
  	if (!bgd)
  		return NULL;
  	return &bgd->pd;
  }
dfb79af54   Bart Van Assche   bfq: Declare loca...
482
  static void bfq_cpd_init(struct blkcg_policy_data *cpd)
ea25da480   Paolo Valente   block, bfq: split...
483
484
485
486
487
488
  {
  	struct bfq_group_data *d = cpd_to_bfqgd(cpd);
  
  	d->weight = cgroup_subsys_on_dfl(io_cgrp_subsys) ?
  		CGROUP_WEIGHT_DFL : BFQ_WEIGHT_LEGACY_DFL;
  }
dfb79af54   Bart Van Assche   bfq: Declare loca...
489
  static void bfq_cpd_free(struct blkcg_policy_data *cpd)
ea25da480   Paolo Valente   block, bfq: split...
490
491
492
  {
  	kfree(cpd_to_bfqgd(cpd));
  }
cf09a8ee1   Tejun Heo   blkcg: pass @q an...
493
494
  static struct blkg_policy_data *bfq_pd_alloc(gfp_t gfp, struct request_queue *q,
  					     struct blkcg *blkcg)
ea25da480   Paolo Valente   block, bfq: split...
495
496
  {
  	struct bfq_group *bfqg;
cf09a8ee1   Tejun Heo   blkcg: pass @q an...
497
  	bfqg = kzalloc_node(sizeof(*bfqg), gfp, q->node);
ea25da480   Paolo Valente   block, bfq: split...
498
499
500
501
502
503
504
  	if (!bfqg)
  		return NULL;
  
  	if (bfqg_stats_init(&bfqg->stats, gfp)) {
  		kfree(bfqg);
  		return NULL;
  	}
8f9bebc33   Paolo Valente   block, bfq: acces...
505
506
  	/* see comments in bfq_bic_update_cgroup for why refcounting */
  	bfqg_get(bfqg);
ea25da480   Paolo Valente   block, bfq: split...
507
508
  	return &bfqg->pd;
  }
dfb79af54   Bart Van Assche   bfq: Declare loca...
509
  static void bfq_pd_init(struct blkg_policy_data *pd)
ea25da480   Paolo Valente   block, bfq: split...
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
  {
  	struct blkcg_gq *blkg = pd_to_blkg(pd);
  	struct bfq_group *bfqg = blkg_to_bfqg(blkg);
  	struct bfq_data *bfqd = blkg->q->elevator->elevator_data;
  	struct bfq_entity *entity = &bfqg->entity;
  	struct bfq_group_data *d = blkcg_to_bfqgd(blkg->blkcg);
  
  	entity->orig_weight = entity->weight = entity->new_weight = d->weight;
  	entity->my_sched_data = &bfqg->sched_data;
  	bfqg->my_entity = entity; /*
  				   * the root_group's will be set to NULL
  				   * in bfq_init_queue()
  				   */
  	bfqg->bfqd = bfqd;
  	bfqg->active_entities = 0;
  	bfqg->rq_pos_tree = RB_ROOT;
  }
dfb79af54   Bart Van Assche   bfq: Declare loca...
527
  static void bfq_pd_free(struct blkg_policy_data *pd)
ea25da480   Paolo Valente   block, bfq: split...
528
529
530
531
  {
  	struct bfq_group *bfqg = pd_to_bfqg(pd);
  
  	bfqg_stats_exit(&bfqg->stats);
8f9bebc33   Paolo Valente   block, bfq: acces...
532
  	bfqg_put(bfqg);
ea25da480   Paolo Valente   block, bfq: split...
533
  }
dfb79af54   Bart Van Assche   bfq: Declare loca...
534
  static void bfq_pd_reset_stats(struct blkg_policy_data *pd)
ea25da480   Paolo Valente   block, bfq: split...
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
  {
  	struct bfq_group *bfqg = pd_to_bfqg(pd);
  
  	bfqg_stats_reset(&bfqg->stats);
  }
  
  static void bfq_group_set_parent(struct bfq_group *bfqg,
  					struct bfq_group *parent)
  {
  	struct bfq_entity *entity;
  
  	entity = &bfqg->entity;
  	entity->parent = parent->my_entity;
  	entity->sched_data = &parent->sched_data;
  }
  
  static struct bfq_group *bfq_lookup_bfqg(struct bfq_data *bfqd,
  					 struct blkcg *blkcg)
  {
  	struct blkcg_gq *blkg;
  
  	blkg = blkg_lookup(blkcg, bfqd->queue);
  	if (likely(blkg))
  		return blkg_to_bfqg(blkg);
  	return NULL;
  }
  
  struct bfq_group *bfq_find_set_group(struct bfq_data *bfqd,
  				     struct blkcg *blkcg)
  {
  	struct bfq_group *bfqg, *parent;
  	struct bfq_entity *entity;
  
  	bfqg = bfq_lookup_bfqg(bfqd, blkcg);
  
  	if (unlikely(!bfqg))
  		return NULL;
  
  	/*
  	 * Update chain of bfq_groups as we might be handling a leaf group
  	 * which, along with some of its relatives, has not been hooked yet
  	 * to the private hierarchy of BFQ.
  	 */
  	entity = &bfqg->entity;
  	for_each_entity(entity) {
14afc5936   Carlo Nonato   block, bfq: fix o...
580
581
582
583
  		struct bfq_group *curr_bfqg = container_of(entity,
  						struct bfq_group, entity);
  		if (curr_bfqg != bfqd->root_group) {
  			parent = bfqg_parent(curr_bfqg);
ea25da480   Paolo Valente   block, bfq: split...
584
585
  			if (!parent)
  				parent = bfqd->root_group;
14afc5936   Carlo Nonato   block, bfq: fix o...
586
  			bfq_group_set_parent(curr_bfqg, parent);
ea25da480   Paolo Valente   block, bfq: split...
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
  		}
  	}
  
  	return bfqg;
  }
  
  /**
   * bfq_bfqq_move - migrate @bfqq to @bfqg.
   * @bfqd: queue descriptor.
   * @bfqq: the queue to move.
   * @bfqg: the group to move to.
   *
   * Move @bfqq to @bfqg, deactivating it from its old group and reactivating
   * it on the new one.  Avoid putting the entity on the old group idle tree.
   *
8f9bebc33   Paolo Valente   block, bfq: acces...
602
603
604
605
   * Must be called under the scheduler lock, to make sure that the blkg
   * owning @bfqg does not disappear (see comments in
   * bfq_bic_update_cgroup on guaranteeing the consistency of blkg
   * objects).
ea25da480   Paolo Valente   block, bfq: split...
606
607
608
609
610
   */
  void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
  		   struct bfq_group *bfqg)
  {
  	struct bfq_entity *entity = &bfqq->entity;
fd1bb3ae5   Paolo Valente   block, bfq: move ...
611
612
613
614
615
  	/*
  	 * Get extra reference to prevent bfqq from being freed in
  	 * next possible expire or deactivate.
  	 */
  	bfqq->ref++;
ea25da480   Paolo Valente   block, bfq: split...
616
617
618
619
620
621
622
623
624
625
626
627
  	/* If bfqq is empty, then bfq_bfqq_expire also invokes
  	 * bfq_del_bfqq_busy, thereby removing bfqq and its entity
  	 * from data structures related to current group. Otherwise we
  	 * need to remove bfqq explicitly with bfq_deactivate_bfqq, as
  	 * we do below.
  	 */
  	if (bfqq == bfqd->in_service_queue)
  		bfq_bfqq_expire(bfqd, bfqd->in_service_queue,
  				false, BFQQE_PREEMPTED);
  
  	if (bfq_bfqq_busy(bfqq))
  		bfq_deactivate_bfqq(bfqd, bfqq, false, false);
33a16a980   Paolo Valente   block, bfq: exten...
628
  	else if (entity->on_st_or_in_serv)
ea25da480   Paolo Valente   block, bfq: split...
629
  		bfq_put_idle_entity(bfq_entity_service_tree(entity), entity);
8f9bebc33   Paolo Valente   block, bfq: acces...
630
  	bfqg_and_blkg_put(bfqq_group(bfqq));
ea25da480   Paolo Valente   block, bfq: split...
631

ea25da480   Paolo Valente   block, bfq: split...
632
633
  	entity->parent = bfqg->my_entity;
  	entity->sched_data = &bfqg->sched_data;
8f9bebc33   Paolo Valente   block, bfq: acces...
634
635
  	/* pin down bfqg and its associated blkg  */
  	bfqg_and_blkg_get(bfqg);
ea25da480   Paolo Valente   block, bfq: split...
636
637
  
  	if (bfq_bfqq_busy(bfqq)) {
8cacc5ab3   Paolo Valente   block, bfq: do no...
638
639
  		if (unlikely(!bfqd->nonrot_with_queueing))
  			bfq_pos_tree_add_move(bfqd, bfqq);
ea25da480   Paolo Valente   block, bfq: split...
640
641
642
643
644
  		bfq_activate_bfqq(bfqd, bfqq);
  	}
  
  	if (!bfqd->in_service_queue && !bfqd->rq_in_driver)
  		bfq_schedule_dispatch(bfqd);
fd1bb3ae5   Paolo Valente   block, bfq: move ...
645
  	/* release extra ref taken above, bfqq may happen to be freed now */
ecedd3d7e   Paolo Valente   block, bfq: get e...
646
  	bfq_put_queue(bfqq);
ea25da480   Paolo Valente   block, bfq: split...
647
648
649
650
651
652
653
654
  }
  
  /**
   * __bfq_bic_change_cgroup - move @bic to @cgroup.
   * @bfqd: the queue descriptor.
   * @bic: the bic to move.
   * @blkcg: the blk-cgroup to move to.
   *
8f9bebc33   Paolo Valente   block, bfq: acces...
655
656
657
   * Move bic to blkcg, assuming that bfqd->lock is held; which makes
   * sure that the reference to cgroup is valid across the call (see
   * comments in bfq_bic_update_cgroup on this issue)
ea25da480   Paolo Valente   block, bfq: split...
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
   *
   * NOTE: an alternative approach might have been to store the current
   * cgroup in bfqq and getting a reference to it, reducing the lookup
   * time here, at the price of slightly more complex code.
   */
  static struct bfq_group *__bfq_bic_change_cgroup(struct bfq_data *bfqd,
  						struct bfq_io_cq *bic,
  						struct blkcg *blkcg)
  {
  	struct bfq_queue *async_bfqq = bic_to_bfqq(bic, 0);
  	struct bfq_queue *sync_bfqq = bic_to_bfqq(bic, 1);
  	struct bfq_group *bfqg;
  	struct bfq_entity *entity;
  
  	bfqg = bfq_find_set_group(bfqd, blkcg);
  
  	if (unlikely(!bfqg))
  		bfqg = bfqd->root_group;
  
  	if (async_bfqq) {
  		entity = &async_bfqq->entity;
  
  		if (entity->sched_data != &bfqg->sched_data) {
  			bic_set_bfqq(bic, NULL, 0);
c89977366   Paolo Valente   block, bfq: turn ...
682
  			bfq_release_process_ref(bfqd, async_bfqq);
ea25da480   Paolo Valente   block, bfq: split...
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
  		}
  	}
  
  	if (sync_bfqq) {
  		entity = &sync_bfqq->entity;
  		if (entity->sched_data != &bfqg->sched_data)
  			bfq_bfqq_move(bfqd, sync_bfqq, bfqg);
  	}
  
  	return bfqg;
  }
  
  void bfq_bic_update_cgroup(struct bfq_io_cq *bic, struct bio *bio)
  {
  	struct bfq_data *bfqd = bic_to_bfqd(bic);
  	struct bfq_group *bfqg = NULL;
  	uint64_t serial_nr;
  
  	rcu_read_lock();
0fe061b9f   Dennis Zhou   blkcg: fix ref co...
702
  	serial_nr = __bio_blkcg(bio)->css.serial_nr;
ea25da480   Paolo Valente   block, bfq: split...
703
704
705
706
707
708
709
  
  	/*
  	 * Check whether blkcg has changed.  The condition may trigger
  	 * spuriously on a newly created cic but there's no harm.
  	 */
  	if (unlikely(!bfqd) || likely(bic->blkcg_serial_nr == serial_nr))
  		goto out;
0fe061b9f   Dennis Zhou   blkcg: fix ref co...
710
  	bfqg = __bfq_bic_change_cgroup(bfqd, bic, __bio_blkcg(bio));
8f9bebc33   Paolo Valente   block, bfq: acces...
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
  	/*
  	 * Update blkg_path for bfq_log_* functions. We cache this
  	 * path, and update it here, for the following
  	 * reasons. Operations on blkg objects in blk-cgroup are
  	 * protected with the request_queue lock, and not with the
  	 * lock that protects the instances of this scheduler
  	 * (bfqd->lock). This exposes BFQ to the following sort of
  	 * race.
  	 *
  	 * The blkg_lookup performed in bfq_get_queue, protected
  	 * through rcu, may happen to return the address of a copy of
  	 * the original blkg. If this is the case, then the
  	 * bfqg_and_blkg_get performed in bfq_get_queue, to pin down
  	 * the blkg, is useless: it does not prevent blk-cgroup code
  	 * from destroying both the original blkg and all objects
  	 * directly or indirectly referred by the copy of the
  	 * blkg.
  	 *
  	 * On the bright side, destroy operations on a blkg invoke, as
  	 * a first step, hooks of the scheduler associated with the
  	 * blkg. And these hooks are executed with bfqd->lock held for
  	 * BFQ. As a consequence, for any blkg associated with the
  	 * request queue this instance of the scheduler is attached
  	 * to, we are guaranteed that such a blkg is not destroyed, and
  	 * that all the pointers it contains are consistent, while we
  	 * are holding bfqd->lock. A blkg_lookup performed with
  	 * bfqd->lock held then returns a fully consistent blkg, which
  	 * remains consistent until this lock is held.
  	 *
  	 * Thanks to the last fact, and to the fact that: (1) bfqg has
  	 * been obtained through a blkg_lookup in the above
  	 * assignment, and (2) bfqd->lock is being held, here we can
  	 * safely use the policy data for the involved blkg (i.e., the
  	 * field bfqg->pd) to get to the blkg associated with bfqg,
  	 * and then we can safely use any field of blkg. After we
  	 * release bfqd->lock, even just getting blkg through this
  	 * bfqg may cause dangling references to be traversed, as
  	 * bfqg->pd may not exist any more.
  	 *
  	 * In view of the above facts, here we cache, in the bfqg, any
  	 * blkg data we may need for this bic, and for its associated
  	 * bfq_queue. As of now, we need to cache only the path of the
  	 * blkg, which is used in the bfq_log_* functions.
  	 *
  	 * Finally, note that bfqg itself needs to be protected from
  	 * destruction on the blkg_free of the original blkg (which
  	 * invokes bfq_pd_free). We use an additional private
  	 * refcounter for bfqg, to let it disappear only after no
  	 * bfq_queue refers to it any longer.
  	 */
  	blkg_path(bfqg_to_blkg(bfqg), bfqg->blkg_path, sizeof(bfqg->blkg_path));
ea25da480   Paolo Valente   block, bfq: split...
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
  	bic->blkcg_serial_nr = serial_nr;
  out:
  	rcu_read_unlock();
  }
  
  /**
   * bfq_flush_idle_tree - deactivate any entity on the idle tree of @st.
   * @st: the service tree being flushed.
   */
  static void bfq_flush_idle_tree(struct bfq_service_tree *st)
  {
  	struct bfq_entity *entity = st->first_idle;
  
  	for (; entity ; entity = st->first_idle)
  		__bfq_deactivate_entity(entity, false);
  }
  
  /**
   * bfq_reparent_leaf_entity - move leaf entity to the root_group.
   * @bfqd: the device data structure with the root group.
576682fa5   Paolo Valente   block, bfq: make ...
782
783
   * @entity: the entity to move, if entity is a leaf; or the parent entity
   *	    of an active leaf entity to move, if entity is not a leaf.
ea25da480   Paolo Valente   block, bfq: split...
784
785
   */
  static void bfq_reparent_leaf_entity(struct bfq_data *bfqd,
576682fa5   Paolo Valente   block, bfq: make ...
786
787
  				     struct bfq_entity *entity,
  				     int ioprio_class)
ea25da480   Paolo Valente   block, bfq: split...
788
  {
576682fa5   Paolo Valente   block, bfq: make ...
789
790
791
792
793
794
795
796
  	struct bfq_queue *bfqq;
  	struct bfq_entity *child_entity = entity;
  
  	while (child_entity->my_sched_data) { /* leaf not reached yet */
  		struct bfq_sched_data *child_sd = child_entity->my_sched_data;
  		struct bfq_service_tree *child_st = child_sd->service_tree +
  			ioprio_class;
  		struct rb_root *child_active = &child_st->active;
ea25da480   Paolo Valente   block, bfq: split...
797

576682fa5   Paolo Valente   block, bfq: make ...
798
799
800
801
802
803
804
  		child_entity = bfq_entity_of(rb_first(child_active));
  
  		if (!child_entity)
  			child_entity = child_sd->in_service_entity;
  	}
  
  	bfqq = bfq_entity_to_bfqq(child_entity);
ea25da480   Paolo Valente   block, bfq: split...
805
806
807
808
  	bfq_bfqq_move(bfqd, bfqq, bfqd->root_group);
  }
  
  /**
576682fa5   Paolo Valente   block, bfq: make ...
809
   * bfq_reparent_active_queues - move to the root group all active queues.
ea25da480   Paolo Valente   block, bfq: split...
810
811
   * @bfqd: the device data structure with the root group.
   * @bfqg: the group to move from.
576682fa5   Paolo Valente   block, bfq: make ...
812
   * @st: the service tree to start the search from.
ea25da480   Paolo Valente   block, bfq: split...
813
   */
576682fa5   Paolo Valente   block, bfq: make ...
814
815
816
817
  static void bfq_reparent_active_queues(struct bfq_data *bfqd,
  				       struct bfq_group *bfqg,
  				       struct bfq_service_tree *st,
  				       int ioprio_class)
ea25da480   Paolo Valente   block, bfq: split...
818
819
  {
  	struct rb_root *active = &st->active;
576682fa5   Paolo Valente   block, bfq: make ...
820
  	struct bfq_entity *entity;
ea25da480   Paolo Valente   block, bfq: split...
821

576682fa5   Paolo Valente   block, bfq: make ...
822
823
  	while ((entity = bfq_entity_of(rb_first(active))))
  		bfq_reparent_leaf_entity(bfqd, entity, ioprio_class);
ea25da480   Paolo Valente   block, bfq: split...
824
825
826
  
  	if (bfqg->sched_data.in_service_entity)
  		bfq_reparent_leaf_entity(bfqd,
576682fa5   Paolo Valente   block, bfq: make ...
827
828
  					 bfqg->sched_data.in_service_entity,
  					 ioprio_class);
ea25da480   Paolo Valente   block, bfq: split...
829
830
831
832
833
834
835
836
837
838
  }
  
  /**
   * bfq_pd_offline - deactivate the entity associated with @pd,
   *		    and reparent its children entities.
   * @pd: descriptor of the policy going offline.
   *
   * blkio already grabs the queue_lock for us, so no need to use
   * RCU-based magic
   */
dfb79af54   Bart Van Assche   bfq: Declare loca...
839
  static void bfq_pd_offline(struct blkg_policy_data *pd)
ea25da480   Paolo Valente   block, bfq: split...
840
841
842
843
844
845
846
  {
  	struct bfq_service_tree *st;
  	struct bfq_group *bfqg = pd_to_bfqg(pd);
  	struct bfq_data *bfqd = bfqg->bfqd;
  	struct bfq_entity *entity = bfqg->my_entity;
  	unsigned long flags;
  	int i;
52257ffbf   Paolo Valente   block, bfq: put a...
847
  	spin_lock_irqsave(&bfqd->lock, flags);
ea25da480   Paolo Valente   block, bfq: split...
848
  	if (!entity) /* root group */
52257ffbf   Paolo Valente   block, bfq: put a...
849
  		goto put_async_queues;
ea25da480   Paolo Valente   block, bfq: split...
850

ea25da480   Paolo Valente   block, bfq: split...
851
852
853
854
855
856
857
858
  	/*
  	 * Empty all service_trees belonging to this group before
  	 * deactivating the group itself.
  	 */
  	for (i = 0; i < BFQ_IOPRIO_CLASSES; i++) {
  		st = bfqg->sched_data.service_tree + i;
  
  		/*
ea25da480   Paolo Valente   block, bfq: split...
859
860
861
862
863
864
865
866
867
868
869
  		 * It may happen that some queues are still active
  		 * (busy) upon group destruction (if the corresponding
  		 * processes have been forced to terminate). We move
  		 * all the leaf entities corresponding to these queues
  		 * to the root_group.
  		 * Also, it may happen that the group has an entity
  		 * in service, which is disconnected from the active
  		 * tree: it must be moved, too.
  		 * There is no need to put the sync queues, as the
  		 * scheduler has taken no reference.
  		 */
576682fa5   Paolo Valente   block, bfq: make ...
870
  		bfq_reparent_active_queues(bfqd, bfqg, st, i);
4d38a87fb   Paolo Valente   block, bfq: invok...
871
872
873
874
875
876
877
878
879
880
881
882
883
  
  		/*
  		 * The idle tree may still contain bfq_queues
  		 * belonging to exited task because they never
  		 * migrated to a different cgroup from the one being
  		 * destroyed now. In addition, even
  		 * bfq_reparent_active_queues() may happen to add some
  		 * entities to the idle tree. It happens if, in some
  		 * of the calls to bfq_bfqq_move() performed by
  		 * bfq_reparent_active_queues(), the queue to move is
  		 * empty and gets expired.
  		 */
  		bfq_flush_idle_tree(st);
ea25da480   Paolo Valente   block, bfq: split...
884
885
886
  	}
  
  	__bfq_deactivate_entity(entity, false);
52257ffbf   Paolo Valente   block, bfq: put a...
887
888
  
  put_async_queues:
ea25da480   Paolo Valente   block, bfq: split...
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
  	bfq_put_async_queues(bfqd, bfqg);
  
  	spin_unlock_irqrestore(&bfqd->lock, flags);
  	/*
  	 * @blkg is going offline and will be ignored by
  	 * blkg_[rw]stat_recursive_sum().  Transfer stats to the parent so
  	 * that they don't get lost.  If IOs complete after this point, the
  	 * stats for them will be lost.  Oh well...
  	 */
  	bfqg_stats_xfer_dead(bfqg);
  }
  
  void bfq_end_wr_async(struct bfq_data *bfqd)
  {
  	struct blkcg_gq *blkg;
  
  	list_for_each_entry(blkg, &bfqd->queue->blkg_list, q_node) {
  		struct bfq_group *bfqg = blkg_to_bfqg(blkg);
  
  		bfq_end_wr_async_queues(bfqd, bfqg);
  	}
  	bfq_end_wr_async_queues(bfqd, bfqd->root_group);
  }
795fe54c2   Fam Zheng   bfq: Add per-devi...
912
  static int bfq_io_show_weight_legacy(struct seq_file *sf, void *v)
ea25da480   Paolo Valente   block, bfq: split...
913
914
915
916
917
918
919
920
921
922
923
924
925
  {
  	struct blkcg *blkcg = css_to_blkcg(seq_css(sf));
  	struct bfq_group_data *bfqgd = blkcg_to_bfqgd(blkcg);
  	unsigned int val = 0;
  
  	if (bfqgd)
  		val = bfqgd->weight;
  
  	seq_printf(sf, "%u
  ", val);
  
  	return 0;
  }
795fe54c2   Fam Zheng   bfq: Add per-devi...
926
927
  static u64 bfqg_prfill_weight_device(struct seq_file *sf,
  				     struct blkg_policy_data *pd, int off)
5ff047e32   Fam Zheng   bfq: Extract bfq_...
928
  {
795fe54c2   Fam Zheng   bfq: Add per-devi...
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
  	struct bfq_group *bfqg = pd_to_bfqg(pd);
  
  	if (!bfqg->entity.dev_weight)
  		return 0;
  	return __blkg_prfill_u64(sf, pd, bfqg->entity.dev_weight);
  }
  
  static int bfq_io_show_weight(struct seq_file *sf, void *v)
  {
  	struct blkcg *blkcg = css_to_blkcg(seq_css(sf));
  	struct bfq_group_data *bfqgd = blkcg_to_bfqgd(blkcg);
  
  	seq_printf(sf, "default %u
  ", bfqgd->weight);
  	blkcg_print_blkgs(sf, blkcg, bfqg_prfill_weight_device,
  			  &blkcg_policy_bfq, 0, false);
  	return 0;
  }
  
  static void bfq_group_set_weight(struct bfq_group *bfqg, u64 weight, u64 dev_weight)
  {
  	weight = dev_weight ?: weight;
  
  	bfqg->entity.dev_weight = dev_weight;
5ff047e32   Fam Zheng   bfq: Extract bfq_...
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
  	/*
  	 * Setting the prio_changed flag of the entity
  	 * to 1 with new_weight == weight would re-set
  	 * the value of the weight to its ioprio mapping.
  	 * Set the flag only if necessary.
  	 */
  	if ((unsigned short)weight != bfqg->entity.new_weight) {
  		bfqg->entity.new_weight = (unsigned short)weight;
  		/*
  		 * Make sure that the above new value has been
  		 * stored in bfqg->entity.new_weight before
  		 * setting the prio_changed flag. In fact,
  		 * this flag may be read asynchronously (in
  		 * critical sections protected by a different
  		 * lock than that held here), and finding this
  		 * flag set may cause the execution of the code
  		 * for updating parameters whose value may
  		 * depend also on bfqg->entity.new_weight (in
  		 * __bfq_entity_update_weight_prio).
  		 * This barrier makes sure that the new value
  		 * of bfqg->entity.new_weight is correctly
  		 * seen in that code.
  		 */
  		smp_wmb();
  		bfqg->entity.prio_changed = 1;
  	}
  }
ea25da480   Paolo Valente   block, bfq: split...
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
  static int bfq_io_set_weight_legacy(struct cgroup_subsys_state *css,
  				    struct cftype *cftype,
  				    u64 val)
  {
  	struct blkcg *blkcg = css_to_blkcg(css);
  	struct bfq_group_data *bfqgd = blkcg_to_bfqgd(blkcg);
  	struct blkcg_gq *blkg;
  	int ret = -ERANGE;
  
  	if (val < BFQ_MIN_WEIGHT || val > BFQ_MAX_WEIGHT)
  		return ret;
  
  	ret = 0;
  	spin_lock_irq(&blkcg->lock);
  	bfqgd->weight = (unsigned short)val;
  	hlist_for_each_entry(blkg, &blkcg->blkg_list, blkcg_node) {
  		struct bfq_group *bfqg = blkg_to_bfqg(blkg);
5ff047e32   Fam Zheng   bfq: Extract bfq_...
997
  		if (bfqg)
795fe54c2   Fam Zheng   bfq: Add per-devi...
998
  			bfq_group_set_weight(bfqg, val, 0);
ea25da480   Paolo Valente   block, bfq: split...
999
1000
1001
1002
1003
  	}
  	spin_unlock_irq(&blkcg->lock);
  
  	return ret;
  }
795fe54c2   Fam Zheng   bfq: Add per-devi...
1004
1005
1006
  static ssize_t bfq_io_set_device_weight(struct kernfs_open_file *of,
  					char *buf, size_t nbytes,
  					loff_t off)
ea25da480   Paolo Valente   block, bfq: split...
1007
  {
795fe54c2   Fam Zheng   bfq: Add per-devi...
1008
1009
1010
1011
1012
  	int ret;
  	struct blkg_conf_ctx ctx;
  	struct blkcg *blkcg = css_to_blkcg(of_css(of));
  	struct bfq_group *bfqg;
  	u64 v;
ea25da480   Paolo Valente   block, bfq: split...
1013

795fe54c2   Fam Zheng   bfq: Add per-devi...
1014
  	ret = blkg_conf_prep(blkcg, &blkcg_policy_bfq, buf, &ctx);
ea25da480   Paolo Valente   block, bfq: split...
1015
1016
  	if (ret)
  		return ret;
795fe54c2   Fam Zheng   bfq: Add per-devi...
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
  	if (sscanf(ctx.body, "%llu", &v) == 1) {
  		/* require "default" on dfl */
  		ret = -ERANGE;
  		if (!v)
  			goto out;
  	} else if (!strcmp(strim(ctx.body), "default")) {
  		v = 0;
  	} else {
  		ret = -EINVAL;
  		goto out;
  	}
  
  	bfqg = blkg_to_bfqg(ctx.blkg);
  
  	ret = -ERANGE;
  	if (!v || (v >= BFQ_MIN_WEIGHT && v <= BFQ_MAX_WEIGHT)) {
  		bfq_group_set_weight(bfqg, bfqg->entity.weight, v);
  		ret = 0;
  	}
  out:
  	blkg_conf_finish(&ctx);
fc8ebd01d   Maciej S. Szmigiero   block, bfq: retur...
1038
  	return ret ?: nbytes;
ea25da480   Paolo Valente   block, bfq: split...
1039
  }
795fe54c2   Fam Zheng   bfq: Add per-devi...
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
  static ssize_t bfq_io_set_weight(struct kernfs_open_file *of,
  				 char *buf, size_t nbytes,
  				 loff_t off)
  {
  	char *endp;
  	int ret;
  	u64 v;
  
  	buf = strim(buf);
  
  	/* "WEIGHT" or "default WEIGHT" sets the default weight */
  	v = simple_strtoull(buf, &endp, 0);
  	if (*endp == '\0' || sscanf(buf, "default %llu", &v) == 1) {
  		ret = bfq_io_set_weight_legacy(of_css(of), NULL, v);
  		return ret ?: nbytes;
  	}
  
  	return bfq_io_set_device_weight(of, buf, nbytes, off);
  }
a557f1c7f   Tejun Heo   bfq-iosched: relo...
1059
  static int bfqg_print_rwstat(struct seq_file *sf, void *v)
ea25da480   Paolo Valente   block, bfq: split...
1060
  {
a557f1c7f   Tejun Heo   bfq-iosched: relo...
1061
1062
  	blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)), blkg_prfill_rwstat,
  			  &blkcg_policy_bfq, seq_cft(sf)->private, true);
ea25da480   Paolo Valente   block, bfq: split...
1063
1064
  	return 0;
  }
a557f1c7f   Tejun Heo   bfq-iosched: relo...
1065
1066
  static u64 bfqg_prfill_rwstat_recursive(struct seq_file *sf,
  					struct blkg_policy_data *pd, int off)
ea25da480   Paolo Valente   block, bfq: split...
1067
  {
a557f1c7f   Tejun Heo   bfq-iosched: relo...
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
  	struct blkg_rwstat_sample sum;
  
  	blkg_rwstat_recursive_sum(pd_to_blkg(pd), &blkcg_policy_bfq, off, &sum);
  	return __blkg_prfill_rwstat(sf, pd, &sum);
  }
  
  static int bfqg_print_rwstat_recursive(struct seq_file *sf, void *v)
  {
  	blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
  			  bfqg_prfill_rwstat_recursive, &blkcg_policy_bfq,
  			  seq_cft(sf)->private, true);
  	return 0;
  }
fd41e6033   Tejun Heo   bfq-iosched: stop...
1081
  #ifdef CONFIG_BFQ_CGROUP_DEBUG
a557f1c7f   Tejun Heo   bfq-iosched: relo...
1082
1083
1084
1085
  static int bfqg_print_stat(struct seq_file *sf, void *v)
  {
  	blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)), blkg_prfill_stat,
  			  &blkcg_policy_bfq, seq_cft(sf)->private, false);
ea25da480   Paolo Valente   block, bfq: split...
1086
1087
1088
1089
1090
1091
  	return 0;
  }
  
  static u64 bfqg_prfill_stat_recursive(struct seq_file *sf,
  				      struct blkg_policy_data *pd, int off)
  {
d6258980d   Christoph Hellwig   bfq-iosched: move...
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
  	struct blkcg_gq *blkg = pd_to_blkg(pd);
  	struct blkcg_gq *pos_blkg;
  	struct cgroup_subsys_state *pos_css;
  	u64 sum = 0;
  
  	lockdep_assert_held(&blkg->q->queue_lock);
  
  	rcu_read_lock();
  	blkg_for_each_descendant_pre(pos_blkg, pos_css, blkg) {
  		struct bfq_stat *stat;
  
  		if (!pos_blkg->online)
  			continue;
  
  		stat = (void *)blkg_to_pd(pos_blkg, &blkcg_policy_bfq) + off;
  		sum += bfq_stat_read(stat) + atomic64_read(&stat->aux_cnt);
  	}
  	rcu_read_unlock();
ea25da480   Paolo Valente   block, bfq: split...
1110
1111
  	return __blkg_prfill_u64(sf, pd, sum);
  }
ea25da480   Paolo Valente   block, bfq: split...
1112
1113
1114
1115
1116
1117
1118
  static int bfqg_print_stat_recursive(struct seq_file *sf, void *v)
  {
  	blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
  			  bfqg_prfill_stat_recursive, &blkcg_policy_bfq,
  			  seq_cft(sf)->private, false);
  	return 0;
  }
ea25da480   Paolo Valente   block, bfq: split...
1119
1120
1121
  static u64 bfqg_prfill_sectors(struct seq_file *sf, struct blkg_policy_data *pd,
  			       int off)
  {
fd41e6033   Tejun Heo   bfq-iosched: stop...
1122
1123
  	struct bfq_group *bfqg = blkg_to_bfqg(pd->blkg);
  	u64 sum = blkg_rwstat_total(&bfqg->stats.bytes);
ea25da480   Paolo Valente   block, bfq: split...
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
  
  	return __blkg_prfill_u64(sf, pd, sum >> 9);
  }
  
  static int bfqg_print_stat_sectors(struct seq_file *sf, void *v)
  {
  	blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
  			  bfqg_prfill_sectors, &blkcg_policy_bfq, 0, false);
  	return 0;
  }
  
  static u64 bfqg_prfill_sectors_recursive(struct seq_file *sf,
  					 struct blkg_policy_data *pd, int off)
  {
7af6fd911   Christoph Hellwig   blk-cgroup: intro...
1138
  	struct blkg_rwstat_sample tmp;
5d0b6e48c   Christoph Hellwig   blk-cgroup: pass ...
1139

fd41e6033   Tejun Heo   bfq-iosched: stop...
1140
1141
  	blkg_rwstat_recursive_sum(pd->blkg, &blkcg_policy_bfq,
  			offsetof(struct bfq_group, stats.bytes), &tmp);
ea25da480   Paolo Valente   block, bfq: split...
1142

7af6fd911   Christoph Hellwig   blk-cgroup: intro...
1143
1144
  	return __blkg_prfill_u64(sf, pd,
  		(tmp.cnt[BLKG_RWSTAT_READ] + tmp.cnt[BLKG_RWSTAT_WRITE]) >> 9);
ea25da480   Paolo Valente   block, bfq: split...
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
  }
  
  static int bfqg_print_stat_sectors_recursive(struct seq_file *sf, void *v)
  {
  	blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
  			  bfqg_prfill_sectors_recursive, &blkcg_policy_bfq, 0,
  			  false);
  	return 0;
  }
  
  static u64 bfqg_prfill_avg_queue_size(struct seq_file *sf,
  				      struct blkg_policy_data *pd, int off)
  {
  	struct bfq_group *bfqg = pd_to_bfqg(pd);
c0ce79dca   Christoph Hellwig   blk-cgroup: move ...
1159
  	u64 samples = bfq_stat_read(&bfqg->stats.avg_queue_size_samples);
ea25da480   Paolo Valente   block, bfq: split...
1160
1161
1162
  	u64 v = 0;
  
  	if (samples) {
c0ce79dca   Christoph Hellwig   blk-cgroup: move ...
1163
  		v = bfq_stat_read(&bfqg->stats.avg_queue_size_sum);
ea25da480   Paolo Valente   block, bfq: split...
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
  		v = div64_u64(v, samples);
  	}
  	__blkg_prfill_u64(sf, pd, v);
  	return 0;
  }
  
  /* print avg_queue_size */
  static int bfqg_print_avg_queue_size(struct seq_file *sf, void *v)
  {
  	blkcg_print_blkgs(sf, css_to_blkcg(seq_css(sf)),
  			  bfqg_prfill_avg_queue_size, &blkcg_policy_bfq,
  			  0, false);
  	return 0;
  }
8060c47ba   Christoph Hellwig   block: rename CON...
1178
  #endif /* CONFIG_BFQ_CGROUP_DEBUG */
ea25da480   Paolo Valente   block, bfq: split...
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
  
  struct bfq_group *bfq_create_group_hierarchy(struct bfq_data *bfqd, int node)
  {
  	int ret;
  
  	ret = blkcg_activate_policy(bfqd->queue, &blkcg_policy_bfq);
  	if (ret)
  		return NULL;
  
  	return blkg_to_bfqg(bfqd->queue->root_blkg);
  }
  
  struct blkcg_policy blkcg_policy_bfq = {
  	.dfl_cftypes		= bfq_blkg_files,
  	.legacy_cftypes		= bfq_blkcg_legacy_files,
  
  	.cpd_alloc_fn		= bfq_cpd_alloc,
  	.cpd_init_fn		= bfq_cpd_init,
  	.cpd_bind_fn	        = bfq_cpd_init,
  	.cpd_free_fn		= bfq_cpd_free,
  
  	.pd_alloc_fn		= bfq_pd_alloc,
  	.pd_init_fn		= bfq_pd_init,
  	.pd_offline_fn		= bfq_pd_offline,
  	.pd_free_fn		= bfq_pd_free,
  	.pd_reset_stats_fn	= bfq_pd_reset_stats,
  };
  
  struct cftype bfq_blkcg_legacy_files[] = {
  	{
  		.name = "bfq.weight",
cf8929885   Jens Axboe   cgroup/bfq: rever...
1210
  		.flags = CFTYPE_NOT_ON_ROOT,
795fe54c2   Fam Zheng   bfq: Add per-devi...
1211
  		.seq_show = bfq_io_show_weight_legacy,
ea25da480   Paolo Valente   block, bfq: split...
1212
1213
  		.write_u64 = bfq_io_set_weight_legacy,
  	},
795fe54c2   Fam Zheng   bfq: Add per-devi...
1214
1215
1216
1217
1218
1219
  	{
  		.name = "bfq.weight_device",
  		.flags = CFTYPE_NOT_ON_ROOT,
  		.seq_show = bfq_io_show_weight,
  		.write = bfq_io_set_weight,
  	},
ea25da480   Paolo Valente   block, bfq: split...
1220
1221
1222
  
  	/* statistics, covers only the tasks in the bfqg */
  	{
ea25da480   Paolo Valente   block, bfq: split...
1223
  		.name = "bfq.io_service_bytes",
fd41e6033   Tejun Heo   bfq-iosched: stop...
1224
1225
  		.private = offsetof(struct bfq_group, stats.bytes),
  		.seq_show = bfqg_print_rwstat,
ea25da480   Paolo Valente   block, bfq: split...
1226
1227
1228
  	},
  	{
  		.name = "bfq.io_serviced",
fd41e6033   Tejun Heo   bfq-iosched: stop...
1229
1230
  		.private = offsetof(struct bfq_group, stats.ios),
  		.seq_show = bfqg_print_rwstat,
ea25da480   Paolo Valente   block, bfq: split...
1231
  	},
8060c47ba   Christoph Hellwig   block: rename CON...
1232
  #ifdef CONFIG_BFQ_CGROUP_DEBUG
a33801e8b   Luca Miccio   block, bfq: move ...
1233
1234
1235
1236
1237
1238
1239
1240
1241
  	{
  		.name = "bfq.time",
  		.private = offsetof(struct bfq_group, stats.time),
  		.seq_show = bfqg_print_stat,
  	},
  	{
  		.name = "bfq.sectors",
  		.seq_show = bfqg_print_stat_sectors,
  	},
ea25da480   Paolo Valente   block, bfq: split...
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
  	{
  		.name = "bfq.io_service_time",
  		.private = offsetof(struct bfq_group, stats.service_time),
  		.seq_show = bfqg_print_rwstat,
  	},
  	{
  		.name = "bfq.io_wait_time",
  		.private = offsetof(struct bfq_group, stats.wait_time),
  		.seq_show = bfqg_print_rwstat,
  	},
  	{
  		.name = "bfq.io_merged",
  		.private = offsetof(struct bfq_group, stats.merged),
  		.seq_show = bfqg_print_rwstat,
  	},
  	{
  		.name = "bfq.io_queued",
  		.private = offsetof(struct bfq_group, stats.queued),
  		.seq_show = bfqg_print_rwstat,
  	},
8060c47ba   Christoph Hellwig   block: rename CON...
1262
  #endif /* CONFIG_BFQ_CGROUP_DEBUG */
ea25da480   Paolo Valente   block, bfq: split...
1263

636b8fe86   Angelo Ruocco   block, bfq: fix s...
1264
  	/* the same statistics which cover the bfqg and its descendants */
ea25da480   Paolo Valente   block, bfq: split...
1265
  	{
ea25da480   Paolo Valente   block, bfq: split...
1266
  		.name = "bfq.io_service_bytes_recursive",
fd41e6033   Tejun Heo   bfq-iosched: stop...
1267
1268
  		.private = offsetof(struct bfq_group, stats.bytes),
  		.seq_show = bfqg_print_rwstat_recursive,
ea25da480   Paolo Valente   block, bfq: split...
1269
1270
1271
  	},
  	{
  		.name = "bfq.io_serviced_recursive",
fd41e6033   Tejun Heo   bfq-iosched: stop...
1272
1273
  		.private = offsetof(struct bfq_group, stats.ios),
  		.seq_show = bfqg_print_rwstat_recursive,
ea25da480   Paolo Valente   block, bfq: split...
1274
  	},
8060c47ba   Christoph Hellwig   block: rename CON...
1275
  #ifdef CONFIG_BFQ_CGROUP_DEBUG
a33801e8b   Luca Miccio   block, bfq: move ...
1276
1277
1278
1279
1280
1281
1282
1283
1284
  	{
  		.name = "bfq.time_recursive",
  		.private = offsetof(struct bfq_group, stats.time),
  		.seq_show = bfqg_print_stat_recursive,
  	},
  	{
  		.name = "bfq.sectors_recursive",
  		.seq_show = bfqg_print_stat_sectors_recursive,
  	},
ea25da480   Paolo Valente   block, bfq: split...
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
  	{
  		.name = "bfq.io_service_time_recursive",
  		.private = offsetof(struct bfq_group, stats.service_time),
  		.seq_show = bfqg_print_rwstat_recursive,
  	},
  	{
  		.name = "bfq.io_wait_time_recursive",
  		.private = offsetof(struct bfq_group, stats.wait_time),
  		.seq_show = bfqg_print_rwstat_recursive,
  	},
  	{
  		.name = "bfq.io_merged_recursive",
  		.private = offsetof(struct bfq_group, stats.merged),
  		.seq_show = bfqg_print_rwstat_recursive,
  	},
  	{
  		.name = "bfq.io_queued_recursive",
  		.private = offsetof(struct bfq_group, stats.queued),
  		.seq_show = bfqg_print_rwstat_recursive,
  	},
  	{
  		.name = "bfq.avg_queue_size",
  		.seq_show = bfqg_print_avg_queue_size,
  	},
  	{
  		.name = "bfq.group_wait_time",
  		.private = offsetof(struct bfq_group, stats.group_wait_time),
  		.seq_show = bfqg_print_stat,
  	},
  	{
  		.name = "bfq.idle_time",
  		.private = offsetof(struct bfq_group, stats.idle_time),
  		.seq_show = bfqg_print_stat,
  	},
  	{
  		.name = "bfq.empty_time",
  		.private = offsetof(struct bfq_group, stats.empty_time),
  		.seq_show = bfqg_print_stat,
  	},
  	{
  		.name = "bfq.dequeue",
  		.private = offsetof(struct bfq_group, stats.dequeue),
  		.seq_show = bfqg_print_stat,
  	},
8060c47ba   Christoph Hellwig   block: rename CON...
1329
  #endif	/* CONFIG_BFQ_CGROUP_DEBUG */
ea25da480   Paolo Valente   block, bfq: split...
1330
1331
1332
1333
1334
1335
  	{ }	/* terminate */
  };
  
  struct cftype bfq_blkg_files[] = {
  	{
  		.name = "bfq.weight",
cf8929885   Jens Axboe   cgroup/bfq: rever...
1336
  		.flags = CFTYPE_NOT_ON_ROOT,
ea25da480   Paolo Valente   block, bfq: split...
1337
1338
1339
1340
1341
1342
1343
  		.seq_show = bfq_io_show_weight,
  		.write = bfq_io_set_weight,
  	},
  	{} /* terminate */
  };
  
  #else	/* CONFIG_BFQ_GROUP_IOSCHED */
ea25da480   Paolo Valente   block, bfq: split...
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
  void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
  		   struct bfq_group *bfqg) {}
  
  void bfq_init_entity(struct bfq_entity *entity, struct bfq_group *bfqg)
  {
  	struct bfq_queue *bfqq = bfq_entity_to_bfqq(entity);
  
  	entity->weight = entity->new_weight;
  	entity->orig_weight = entity->new_weight;
  	if (bfqq) {
  		bfqq->ioprio = bfqq->new_ioprio;
  		bfqq->ioprio_class = bfqq->new_ioprio_class;
  	}
  	entity->sched_data = &bfqg->sched_data;
  }
  
  void bfq_bic_update_cgroup(struct bfq_io_cq *bic, struct bio *bio) {}
  
  void bfq_end_wr_async(struct bfq_data *bfqd)
  {
  	bfq_end_wr_async_queues(bfqd, bfqd->root_group);
  }
  
  struct bfq_group *bfq_find_set_group(struct bfq_data *bfqd, struct blkcg *blkcg)
  {
  	return bfqd->root_group;
  }
  
  struct bfq_group *bfqq_group(struct bfq_queue *bfqq)
  {
  	return bfqq->bfqd->root_group;
  }
4d8340d0d   Paolo Valente   block, bfq: remov...
1376
1377
1378
  void bfqg_and_blkg_get(struct bfq_group *bfqg) {}
  
  void bfqg_and_blkg_put(struct bfq_group *bfqg) {}
ea25da480   Paolo Valente   block, bfq: split...
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
  struct bfq_group *bfq_create_group_hierarchy(struct bfq_data *bfqd, int node)
  {
  	struct bfq_group *bfqg;
  	int i;
  
  	bfqg = kmalloc_node(sizeof(*bfqg), GFP_KERNEL | __GFP_ZERO, node);
  	if (!bfqg)
  		return NULL;
  
  	for (i = 0; i < BFQ_IOPRIO_CLASSES; i++)
  		bfqg->sched_data.service_tree[i] = BFQ_SERVICE_TREE_INIT;
  
  	return bfqg;
  }
  #endif	/* CONFIG_BFQ_GROUP_IOSCHED */