cgroup: cpu.stats reset counters support
PATCH 1/1 cgroup: cpu.stats reset counters support
This patch allows the cpu.stats values to be reset in cgroups without having to remove and recreate it. I wrote this patch because I've had use cases where resetting the counters made it much easier to read, and it may help with custom userland scripts when parsing statistics.
Many other components of cgroups allows stats to be reset, such as cpuacct.stats. To reset the stats counters, simply echo 0 > cpu.stats
kernel/sched/core.c 2016-02-15 13:48:14.439443599 -0600 renamed from kernel/sched/core.c.orig 2016-02-15 13:47:22.359443599 -0600 +17 -0
@@ -8629,6 +8629,22 @@ static int cpu_stats_show(struct seq_fil return 0; } + +static int cpu_stats_reset(struct cgroup_subsys_state *css, struct cftype *cft, + u64 reset) +{ + struct task_group *tg = css_tg(css); + struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth; + + raw_spin_lock(&cfs_b->lock); + cfs_b->nr_periods = 0; + cfs_b->nr_throttled = 0; + cfs_b->throttled_time = 0; + raw_spin_unlock(&cfs_b->lock); + + return 0; +} + #endif /* CONFIG_CFS_BANDWIDTH */ #endif /* CONFIG_FAIR_GROUP_SCHED */
@@ -8680,6 +8696,7 @@ static struct cftype cpu_files[] = { { .name = "stat", .seq_show = cpu_stats_show, + .write_u64 = cpu_stats_reset, }, #endif #ifdef CONFIG_RT_GROUP_SCHED
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 3 lines · David Collins
This patch allows the cpu.stats values to be reset in cgroups without having to remove and recreate it. I wrote this patch because I've had use cases where resetting the counters made it much easier to read, and it may help with custom userland scripts when parsing statistics.
Many other components of cgroups allows stats to be reset, such as cpuacct.stats. To reset the stats counters, simply
echo 0 > cpu.stats
Please don't do this. The right thing to do is to read accumluative values from userland and calculate the delta. Going forward, no other cgroup stat files are gonna support resetting.
Thanks.
Signature · 1 line
tejun