All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cgroup: cpu.stats reset counters support
@ 2016-02-15 21:14 David Collins
       [not found] ` <56C23F9D.2020705-GOU7F2WGkdXPplzRYGY9Cw@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: David Collins @ 2016-02-15 21:14 UTC (permalink / raw)
  To: cgroups-u79uwXL29TY76Z2rM5mHXA, tj-DgEjT+Ai2ygdnm+yROfE0A,
	david-PnRKb+1yrG7L5xMBEfyS8A

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`

--- linux/kernel/sched/core.c.orig    2016-02-15 13:47:22.359443599 -0600
+++ linux/kernel/sched/core.c    2016-02-15 13:48:14.439443599 -0600
@@ -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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-15 21:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-15 21:14 [PATCH] cgroup: cpu.stats reset counters support David Collins
     [not found] ` <56C23F9D.2020705-GOU7F2WGkdXPplzRYGY9Cw@public.gmane.org>
2016-02-15 21:15   ` Tejun Heo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.