From: Abel Wu <wuyun.abel@bytedance.com>
To: "Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Ingo Molnar" <mingo@redhat.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Juri Lelli" <juri.lelli@redhat.com>,
"Vincent Guittot" <vincent.guittot@linaro.org>,
"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Ben Segall" <bsegall@google.com>, "Mel Gorman" <mgorman@suse.de>,
"Valentin Schneider" <vschneid@redhat.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Bitao Hu" <yaoma@linux.alibaba.com>,
"Yury Norov" <yury.norov@gmail.com>,
"Abel Wu" <wuyun.abel@bytedance.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Chen Ridong" <chenridong@huawei.com>
Cc: cgroups@vger.kernel.org (open list:CONTROL GROUP (CGROUP)),
linux-doc@vger.kernel.org (open list:DOCUMENTATION),
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v2 2/3] cgroup/rstat: Cleanup cpu.stat once for all
Date: Sat, 25 Jan 2025 13:25:11 +0800 [thread overview]
Message-ID: <20250125052521.19487-3-wuyun.abel@bytedance.com> (raw)
In-Reply-To: <20250125052521.19487-1-wuyun.abel@bytedance.com>
There were efforts like b824766504e4 ("cgroup/rstat: add force idle show helper")
to escape from #ifdef hells, and there could be new stats coming out in
the future, let's clean it up once for all.
Signed-off-by: Abel Wu <wuyun.abel@bytedance.com>
---
kernel/cgroup/rstat.c | 47 ++++++++++++++++++++++++-------------------
1 file changed, 26 insertions(+), 21 deletions(-)
diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
index c2784c317cdd..dc6acab00d69 100644
--- a/kernel/cgroup/rstat.c
+++ b/kernel/cgroup/rstat.c
@@ -599,21 +599,39 @@ static void root_cgroup_cputime(struct cgroup_base_stat *bstat)
}
}
+static struct bstat_entry {
+ const char *name;
+ const int offset;
+} bstats[] = {
+#define BSTAT_ENTRY(name, field) \
+ { name, offsetof(struct cgroup_base_stat, field) }
+ BSTAT_ENTRY("usage_usec", cputime.sum_exec_runtime),
+ BSTAT_ENTRY("user_usec", cputime.utime),
+ BSTAT_ENTRY("system_usec", cputime.stime),
+ BSTAT_ENTRY("nice_usec", ntime),
+#ifdef CONFIG_SCHED_CORE
+ BSTAT_ENTRY("core_sched.force_idle_usec", forceidle_sum),
+#endif
+ { NULL } /* must be at end */
+#undef BSTAT_ENTRY
+};
-static void cgroup_force_idle_show(struct seq_file *seq, struct cgroup_base_stat *bstat)
+static void cgroup_bstat_entry_show(struct seq_file *seq,
+ struct cgroup_base_stat *bstat,
+ struct bstat_entry *entry)
{
-#ifdef CONFIG_SCHED_CORE
- u64 forceidle_time = bstat->forceidle_sum;
+ u64 *val;
- do_div(forceidle_time, NSEC_PER_USEC);
- seq_printf(seq, "core_sched.force_idle_usec %llu\n", forceidle_time);
-#endif
+ val = (void *)bstat + entry->offset;
+ do_div(*val, NSEC_PER_USEC);
+ seq_printf(seq, "%s %llu\n", entry->name, *val);
}
void cgroup_base_stat_cputime_show(struct seq_file *seq)
{
struct cgroup *cgrp = seq_css(seq)->cgroup;
struct cgroup_base_stat bstat;
+ struct bstat_entry *e;
if (cgroup_parent(cgrp)) {
cgroup_rstat_flush_hold(cgrp);
@@ -625,21 +643,8 @@ void cgroup_base_stat_cputime_show(struct seq_file *seq)
root_cgroup_cputime(&bstat);
}
- do_div(bstat.cputime.sum_exec_runtime, NSEC_PER_USEC);
- do_div(bstat.cputime.utime, NSEC_PER_USEC);
- do_div(bstat.cputime.stime, NSEC_PER_USEC);
- do_div(bstat.ntime, NSEC_PER_USEC);
-
- seq_printf(seq, "usage_usec %llu\n"
- "user_usec %llu\n"
- "system_usec %llu\n"
- "nice_usec %llu\n",
- bstat.cputime.sum_exec_runtime,
- bstat.cputime.utime,
- bstat.cputime.stime,
- bstat.ntime);
-
- cgroup_force_idle_show(seq, &bstat);
+ for (e = bstats; e->name; e++)
+ cgroup_bstat_entry_show(seq, &bstat, e);
}
/* Add bpf kfuncs for cgroup_rstat_updated() and cgroup_rstat_flush() */
--
2.37.3
next prev parent reply other threads:[~2025-01-25 5:26 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-25 5:25 [PATCH v2 0/3] Fix and cleanup and extend cpu.stat Abel Wu
2025-01-25 5:25 ` [PATCH v2 1/3] cgroup/rstat: Fix forceidle time in cpu.stat Abel Wu
2025-01-25 5:25 ` Abel Wu [this message]
2025-01-27 20:17 ` [PATCH v2 2/3] cgroup/rstat: Cleanup cpu.stat once for all Tejun Heo
2025-01-29 4:47 ` Abel Wu
2025-01-25 5:25 ` [PATCH v2 3/3] cgroup/rstat: Add run_delay accounting for cgroups Abel Wu
2025-01-27 14:10 ` Michal Koutný
2025-01-29 4:48 ` Abel Wu
2025-02-10 15:38 ` Michal Koutný
2025-02-10 16:20 ` Tejun Heo
2025-02-10 18:25 ` Johannes Weiner
2025-02-12 15:17 ` Abel Wu
2025-02-21 15:36 ` Michal Koutný
2025-02-12 15:14 ` Abel Wu
2025-02-12 15:12 ` Abel Wu
2025-02-03 8:11 ` [PATCH v2 0/3] Fix and cleanup and extend cpu.stat Abel Wu
2025-02-04 20:46 ` Tejun Heo
2025-02-05 2:42 ` Abel Wu
2025-02-10 8:51 ` Abel Wu
2025-02-19 2:34 ` Abel Wu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250125052521.19487-3-wuyun.abel@bytedance.com \
--to=wuyun.abel@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=bsegall@google.com \
--cc=cgroups@vger.kernel.org \
--cc=chenridong@huawei.com \
--cc=corbet@lwn.net \
--cc=dietmar.eggemann@arm.com \
--cc=hannes@cmpxchg.org \
--cc=juri.lelli@redhat.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=mkoutny@suse.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=yaoma@linux.alibaba.com \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®