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>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Yury Norov" <yury.norov@gmail.com>,
"Abel Wu" <wuyun.abel@bytedance.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Bitao Hu" <yaoma@linux.alibaba.com>,
"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 3/3] cgroup/rstat: Add run_delay accounting for cgroups
Date: Sat, 25 Jan 2025 13:25:12 +0800 [thread overview]
Message-ID: <20250125052521.19487-4-wuyun.abel@bytedance.com> (raw)
In-Reply-To: <20250125052521.19487-1-wuyun.abel@bytedance.com>
The per-task and per-cpu accounting have already been tracked by
t->sched_info.run_delay and rq->rq_sched_info.run_delay respectively.
Extends this to also include cgroups.
The PSI indicator, "some" of cpu.pressure, loses the insight into how
severely that cgroup is stalled. Say 100 tasks or just 1 task that gets
stalled at a certain point will show no difference in "some" pressure.
IOW "some" is a flat value that not weighted by the severity (e.g. # of
tasks).
Only cgroup v2 is supported. Similar to the task accounting, the cgroup
accounting requires that CONFIG_SCHED_INFO is enabled.
Signed-off-by: Abel Wu <wuyun.abel@bytedance.com>
---
Documentation/admin-guide/cgroup-v2.rst | 1 +
include/linux/cgroup-defs.h | 3 +++
include/linux/kernel_stat.h | 14 ++++++++++++++
kernel/cgroup/rstat.c | 17 +++++++++++++++++
kernel/sched/cputime.c | 12 ++++++++++++
kernel/sched/stats.h | 2 ++
6 files changed, 49 insertions(+)
diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst
index 315ede811c9d..440c3800c49c 100644
--- a/Documentation/admin-guide/cgroup-v2.rst
+++ b/Documentation/admin-guide/cgroup-v2.rst
@@ -1100,6 +1100,7 @@ All time durations are in microseconds.
- usage_usec
- user_usec
- system_usec
+ - run_delay_usec (requires CONFIG_SCHED_INFO)
and the following five when the controller is enabled:
diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
index 1b20d2d8ef7c..287366e60414 100644
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -328,6 +328,9 @@ struct cgroup_base_stat {
u64 forceidle_sum;
#endif
u64 ntime;
+#ifdef CONFIG_SCHED_INFO
+ u64 run_delay;
+#endif
};
/*
diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h
index b97ce2df376f..256b1a55de62 100644
--- a/include/linux/kernel_stat.h
+++ b/include/linux/kernel_stat.h
@@ -31,6 +31,15 @@ enum cpu_usage_stat {
CPUTIME_FORCEIDLE,
#endif
NR_STATS,
+
+#ifdef CONFIG_SCHED_INFO
+ /*
+ * Instead of cputime, run_delay is tracked through
+ * sched_info by task and rq, so there is no need to
+ * enlarge the cpustat[] array.
+ */
+ CPUTIME_RUN_DELAY,
+#endif
};
struct kernel_cpustat {
@@ -141,4 +150,9 @@ extern void account_idle_ticks(unsigned long ticks);
extern void __account_forceidle_time(struct task_struct *tsk, u64 delta);
#endif
+#ifdef CONFIG_SCHED_INFO
+extern void account_run_delay_time(struct task_struct *tsk, u64 delta);
+extern u64 get_cpu_run_delay(int cpu);
+#endif
+
#endif /* _LINUX_KERNEL_STAT_H */
diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
index dc6acab00d69..c7f9397a714e 100644
--- a/kernel/cgroup/rstat.c
+++ b/kernel/cgroup/rstat.c
@@ -445,6 +445,9 @@ static void cgroup_base_stat_add(struct cgroup_base_stat *dst_bstat,
dst_bstat->forceidle_sum += src_bstat->forceidle_sum;
#endif
dst_bstat->ntime += src_bstat->ntime;
+#ifdef CONFIG_SCHED_INFO
+ dst_bstat->run_delay += src_bstat->run_delay;
+#endif
}
static void cgroup_base_stat_sub(struct cgroup_base_stat *dst_bstat,
@@ -457,6 +460,9 @@ static void cgroup_base_stat_sub(struct cgroup_base_stat *dst_bstat,
dst_bstat->forceidle_sum -= src_bstat->forceidle_sum;
#endif
dst_bstat->ntime -= src_bstat->ntime;
+#ifdef CONFIG_SCHED_INFO
+ dst_bstat->run_delay -= src_bstat->run_delay;
+#endif
}
static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu)
@@ -551,6 +557,11 @@ void __cgroup_account_cputime_field(struct cgroup *cgrp,
case CPUTIME_FORCEIDLE:
rstatc->bstat.forceidle_sum += delta_exec;
break;
+#endif
+#ifdef CONFIG_SCHED_INFO
+ case CPUTIME_RUN_DELAY:
+ rstatc->bstat.run_delay += delta_exec;
+ break;
#endif
default:
break;
@@ -596,6 +607,9 @@ static void root_cgroup_cputime(struct cgroup_base_stat *bstat)
bstat->forceidle_sum += cpustat[CPUTIME_FORCEIDLE];
#endif
bstat->ntime += cpustat[CPUTIME_NICE];
+#ifdef CONFIG_SCHED_INFO
+ bstat->run_delay += get_cpu_run_delay(i);
+#endif
}
}
@@ -611,6 +625,9 @@ static struct bstat_entry {
BSTAT_ENTRY("nice_usec", ntime),
#ifdef CONFIG_SCHED_CORE
BSTAT_ENTRY("core_sched.force_idle_usec", forceidle_sum),
+#endif
+#ifdef CONFIG_SCHED_INFO
+ BSTAT_ENTRY("run_delay_usec", run_delay),
#endif
{ NULL } /* must be at end */
#undef BSTAT_ENTRY
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 5d9143dd0879..e6be57cdb54e 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -243,6 +243,18 @@ void __account_forceidle_time(struct task_struct *p, u64 delta)
}
#endif
+#ifdef CONFIG_SCHED_INFO
+void account_run_delay_time(struct task_struct *p, u64 delta)
+{
+ cgroup_account_cputime_field(p, CPUTIME_RUN_DELAY, delta);
+}
+
+u64 get_cpu_run_delay(int cpu)
+{
+ return cpu_rq(cpu)->rq_sched_info.run_delay;
+}
+#endif
+
/*
* When a guest is interrupted for a longer amount of time, missed clock
* ticks are not redelivered later. Due to that, this function may on
diff --git a/kernel/sched/stats.h b/kernel/sched/stats.h
index 6ade91bce63e..b21a2c4b9c54 100644
--- a/kernel/sched/stats.h
+++ b/kernel/sched/stats.h
@@ -249,6 +249,7 @@ static inline void sched_info_dequeue(struct rq *rq, struct task_struct *t)
t->sched_info.last_queued = 0;
t->sched_info.run_delay += delta;
+ account_run_delay_time(t, delta);
rq_sched_info_dequeue(rq, delta);
}
@@ -271,6 +272,7 @@ static void sched_info_arrive(struct rq *rq, struct task_struct *t)
t->sched_info.last_arrival = now;
t->sched_info.pcount++;
+ account_run_delay_time(t, delta);
rq_sched_info_arrive(rq, delta);
}
--
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 ` [PATCH v2 2/3] cgroup/rstat: Cleanup cpu.stat once for all Abel Wu
2025-01-27 20:17 ` Tejun Heo
2025-01-29 4:47 ` Abel Wu
2025-01-25 5:25 ` Abel Wu [this message]
2025-01-27 14:10 ` [PATCH v2 3/3] cgroup/rstat: Add run_delay accounting for cgroups 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-4-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®