31
31
static struct cgroup_subsys_state *blkiocg_create(struct cgroup_subsys *,
33
static int blkiocg_can_attach(struct cgroup_subsys *, struct cgroup *,
34
struct task_struct *, bool);
35
static void blkiocg_attach(struct cgroup_subsys *, struct cgroup *,
36
struct cgroup *, struct task_struct *, bool);
33
static int blkiocg_can_attach_task(struct cgroup *, struct task_struct *);
34
static void blkiocg_attach_task(struct cgroup *, struct task_struct *);
37
35
static void blkiocg_destroy(struct cgroup_subsys *, struct cgroup *);
38
36
static int blkiocg_populate(struct cgroup_subsys *, struct cgroup *);
372
377
EXPORT_SYMBOL_GPL(blkiocg_update_io_remove_stats);
374
void blkiocg_update_timeslice_used(struct blkio_group *blkg, unsigned long time)
379
void blkiocg_update_timeslice_used(struct blkio_group *blkg, unsigned long time,
380
unsigned long unaccounted_time)
376
382
unsigned long flags;
378
384
spin_lock_irqsave(&blkg->stats_lock, flags);
379
385
blkg->stats.time += time;
386
#ifdef CONFIG_DEBUG_BLK_CGROUP
387
blkg->stats.unaccounted_time += unaccounted_time;
380
389
spin_unlock_irqrestore(&blkg->stats_lock, flags);
382
391
EXPORT_SYMBOL_GPL(blkiocg_update_timeslice_used);
394
* should be called under rcu read lock or queue lock to make sure blkg pointer
384
397
void blkiocg_update_dispatch_stats(struct blkio_group *blkg,
385
398
uint64_t bytes, bool direction, bool sync)
387
struct blkio_group_stats *stats;
400
struct blkio_group_stats_cpu *stats_cpu;
388
401
unsigned long flags;
390
spin_lock_irqsave(&blkg->stats_lock, flags);
391
stats = &blkg->stats;
392
stats->sectors += bytes >> 9;
393
blkio_add_stat(stats->stat_arr[BLKIO_STAT_SERVICED], 1, direction,
395
blkio_add_stat(stats->stat_arr[BLKIO_STAT_SERVICE_BYTES], bytes,
397
spin_unlock_irqrestore(&blkg->stats_lock, flags);
404
* Disabling interrupts to provide mutual exclusion between two
405
* writes on same cpu. It probably is not needed for 64bit. Not
406
* optimizing that case yet.
408
local_irq_save(flags);
410
stats_cpu = this_cpu_ptr(blkg->stats_cpu);
412
u64_stats_update_begin(&stats_cpu->syncp);
413
stats_cpu->sectors += bytes >> 9;
414
blkio_add_stat(stats_cpu->stat_arr_cpu[BLKIO_STAT_CPU_SERVICED],
416
blkio_add_stat(stats_cpu->stat_arr_cpu[BLKIO_STAT_CPU_SERVICE_BYTES],
417
bytes, direction, sync);
418
u64_stats_update_end(&stats_cpu->syncp);
419
local_irq_restore(flags);
399
421
EXPORT_SYMBOL_GPL(blkiocg_update_dispatch_stats);
418
440
EXPORT_SYMBOL_GPL(blkiocg_update_completion_stats);
442
/* Merged stats are per cpu. */
420
443
void blkiocg_update_io_merged_stats(struct blkio_group *blkg, bool direction,
446
struct blkio_group_stats_cpu *stats_cpu;
423
447
unsigned long flags;
425
spin_lock_irqsave(&blkg->stats_lock, flags);
426
blkio_add_stat(blkg->stats.stat_arr[BLKIO_STAT_MERGED], 1, direction,
428
spin_unlock_irqrestore(&blkg->stats_lock, flags);
450
* Disabling interrupts to provide mutual exclusion between two
451
* writes on same cpu. It probably is not needed for 64bit. Not
452
* optimizing that case yet.
454
local_irq_save(flags);
456
stats_cpu = this_cpu_ptr(blkg->stats_cpu);
458
u64_stats_update_begin(&stats_cpu->syncp);
459
blkio_add_stat(stats_cpu->stat_arr_cpu[BLKIO_STAT_CPU_MERGED], 1,
461
u64_stats_update_end(&stats_cpu->syncp);
462
local_irq_restore(flags);
430
464
EXPORT_SYMBOL_GPL(blkiocg_update_io_merged_stats);
467
* This function allocates the per cpu stats for blkio_group. Should be called
468
* from sleepable context as alloc_per_cpu() requires that.
470
int blkio_alloc_blkg_stats(struct blkio_group *blkg)
472
/* Allocate memory for per cpu stats */
473
blkg->stats_cpu = alloc_percpu(struct blkio_group_stats_cpu);
474
if (!blkg->stats_cpu)
478
EXPORT_SYMBOL_GPL(blkio_alloc_blkg_stats);
432
480
void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
433
481
struct blkio_group *blkg, void *key, dev_t dev,
434
482
enum blkio_policy_id plid)
500
548
EXPORT_SYMBOL_GPL(blkiocg_lookup_group);
550
static void blkio_reset_stats_cpu(struct blkio_group *blkg)
552
struct blkio_group_stats_cpu *stats_cpu;
555
* Note: On 64 bit arch this should not be an issue. This has the
556
* possibility of returning some inconsistent value on 32bit arch
557
* as 64bit update on 32bit is non atomic. Taking care of this
558
* corner case makes code very complicated, like sending IPIs to
559
* cpus, taking care of stats of offline cpus etc.
561
* reset stats is anyway more of a debug feature and this sounds a
562
* corner case. So I am not complicating the code yet until and
563
* unless this becomes a real issue.
565
for_each_possible_cpu(i) {
566
stats_cpu = per_cpu_ptr(blkg->stats_cpu, i);
567
stats_cpu->sectors = 0;
568
for(j = 0; j < BLKIO_STAT_CPU_NR; j++)
569
for (k = 0; k < BLKIO_STAT_TOTAL; k++)
570
stats_cpu->stat_arr_cpu[j][k] = 0;
503
575
blkiocg_reset_stats(struct cgroup *cgroup, struct cftype *cftype, u64 val)
669
static uint64_t blkio_read_stat_cpu(struct blkio_group *blkg,
670
enum stat_type_cpu type, enum stat_sub_type sub_type)
673
struct blkio_group_stats_cpu *stats_cpu;
676
for_each_possible_cpu(cpu) {
678
stats_cpu = per_cpu_ptr(blkg->stats_cpu, cpu);
681
start = u64_stats_fetch_begin(&stats_cpu->syncp);
682
if (type == BLKIO_STAT_CPU_SECTORS)
683
tval = stats_cpu->sectors;
685
tval = stats_cpu->stat_arr_cpu[type][sub_type];
686
} while(u64_stats_fetch_retry(&stats_cpu->syncp, start));
694
static uint64_t blkio_get_stat_cpu(struct blkio_group *blkg,
695
struct cgroup_map_cb *cb, dev_t dev, enum stat_type_cpu type)
697
uint64_t disk_total, val;
698
char key_str[MAX_KEY_LEN];
699
enum stat_sub_type sub_type;
701
if (type == BLKIO_STAT_CPU_SECTORS) {
702
val = blkio_read_stat_cpu(blkg, type, 0);
703
return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, val, cb, dev);
706
for (sub_type = BLKIO_STAT_READ; sub_type < BLKIO_STAT_TOTAL;
708
blkio_get_key_name(sub_type, dev, key_str, MAX_KEY_LEN, false);
709
val = blkio_read_stat_cpu(blkg, type, sub_type);
710
cb->fill(cb, key_str, val);
713
disk_total = blkio_read_stat_cpu(blkg, type, BLKIO_STAT_READ) +
714
blkio_read_stat_cpu(blkg, type, BLKIO_STAT_WRITE);
716
blkio_get_key_name(BLKIO_STAT_TOTAL, dev, key_str, MAX_KEY_LEN, false);
717
cb->fill(cb, key_str, disk_total);
592
721
/* This should be called with blkg->stats_lock held */
593
722
static uint64_t blkio_get_stat(struct blkio_group *blkg,
594
723
struct cgroup_map_cb *cb, dev_t dev, enum stat_type type)
600
729
if (type == BLKIO_STAT_TIME)
601
730
return blkio_fill_stat(key_str, MAX_KEY_LEN - 1,
602
731
blkg->stats.time, cb, dev);
603
if (type == BLKIO_STAT_SECTORS)
732
#ifdef CONFIG_DEBUG_BLK_CGROUP
733
if (type == BLKIO_STAT_UNACCOUNTED_TIME)
604
734
return blkio_fill_stat(key_str, MAX_KEY_LEN - 1,
605
blkg->stats.sectors, cb, dev);
606
#ifdef CONFIG_DEBUG_BLK_CGROUP
735
blkg->stats.unaccounted_time, cb, dev);
607
736
if (type == BLKIO_STAT_AVG_QUEUE_SIZE) {
608
737
uint64_t sum = blkg->stats.avg_queue_size_sum;
609
738
uint64_t samples = blkg->stats.avg_queue_size_samples;
1103
1237
case BLKIO_PROP_time:
1104
1238
return blkio_read_blkg_stats(blkcg, cft, cb,
1105
BLKIO_STAT_TIME, 0);
1239
BLKIO_STAT_TIME, 0, 0);
1106
1240
case BLKIO_PROP_sectors:
1107
1241
return blkio_read_blkg_stats(blkcg, cft, cb,
1108
BLKIO_STAT_SECTORS, 0);
1242
BLKIO_STAT_CPU_SECTORS, 0, 1);
1109
1243
case BLKIO_PROP_io_service_bytes:
1110
1244
return blkio_read_blkg_stats(blkcg, cft, cb,
1111
BLKIO_STAT_SERVICE_BYTES, 1);
1245
BLKIO_STAT_CPU_SERVICE_BYTES, 1, 1);
1112
1246
case BLKIO_PROP_io_serviced:
1113
1247
return blkio_read_blkg_stats(blkcg, cft, cb,
1114
BLKIO_STAT_SERVICED, 1);
1248
BLKIO_STAT_CPU_SERVICED, 1, 1);
1115
1249
case BLKIO_PROP_io_service_time:
1116
1250
return blkio_read_blkg_stats(blkcg, cft, cb,
1117
BLKIO_STAT_SERVICE_TIME, 1);
1251
BLKIO_STAT_SERVICE_TIME, 1, 0);
1118
1252
case BLKIO_PROP_io_wait_time:
1119
1253
return blkio_read_blkg_stats(blkcg, cft, cb,
1120
BLKIO_STAT_WAIT_TIME, 1);
1254
BLKIO_STAT_WAIT_TIME, 1, 0);
1121
1255
case BLKIO_PROP_io_merged:
1122
1256
return blkio_read_blkg_stats(blkcg, cft, cb,
1123
BLKIO_STAT_MERGED, 1);
1257
BLKIO_STAT_CPU_MERGED, 1, 1);
1124
1258
case BLKIO_PROP_io_queued:
1125
1259
return blkio_read_blkg_stats(blkcg, cft, cb,
1126
BLKIO_STAT_QUEUED, 1);
1260
BLKIO_STAT_QUEUED, 1, 0);
1127
1261
#ifdef CONFIG_DEBUG_BLK_CGROUP
1262
case BLKIO_PROP_unaccounted_time:
1263
return blkio_read_blkg_stats(blkcg, cft, cb,
1264
BLKIO_STAT_UNACCOUNTED_TIME, 0, 0);
1128
1265
case BLKIO_PROP_dequeue:
1129
1266
return blkio_read_blkg_stats(blkcg, cft, cb,
1130
BLKIO_STAT_DEQUEUE, 0);
1267
BLKIO_STAT_DEQUEUE, 0, 0);
1131
1268
case BLKIO_PROP_avg_queue_size:
1132
1269
return blkio_read_blkg_stats(blkcg, cft, cb,
1133
BLKIO_STAT_AVG_QUEUE_SIZE, 0);
1270
BLKIO_STAT_AVG_QUEUE_SIZE, 0, 0);
1134
1271
case BLKIO_PROP_group_wait_time:
1135
1272
return blkio_read_blkg_stats(blkcg, cft, cb,
1136
BLKIO_STAT_GROUP_WAIT_TIME, 0);
1273
BLKIO_STAT_GROUP_WAIT_TIME, 0, 0);
1137
1274
case BLKIO_PROP_idle_time:
1138
1275
return blkio_read_blkg_stats(blkcg, cft, cb,
1139
BLKIO_STAT_IDLE_TIME, 0);
1276
BLKIO_STAT_IDLE_TIME, 0, 0);
1140
1277
case BLKIO_PROP_empty_time:
1141
1278
return blkio_read_blkg_stats(blkcg, cft, cb,
1142
BLKIO_STAT_EMPTY_TIME, 0);
1279
BLKIO_STAT_EMPTY_TIME, 0, 0);