From: Josh Don <joshdon@google.com>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>
Cc: Tejun Heo <tj@kernel.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Valentin Schneider <vschneid@redhat.com>,
linux-kernel@vger.kernel.org,
Xiangling Kong <xiangling@google.com>,
Josh Don <joshdon@google.com>
Subject: [PATCH 2/2] sched: add throttled time stat for throttled children
Date: Wed, 17 May 2023 18:34:14 -0700 [thread overview]
Message-ID: <20230518013414.3053254-2-joshdon@google.com> (raw)
In-Reply-To: <20230518013414.3053254-1-joshdon@google.com>
We currently export the total throttled time for cgroups that are given
a bandwidth limit. This patch extends this accounting to also account
the total time that each children cgroup has been throttled.
This is useful to understand the degree to which children have been
affected by the throttling control. Children which are not runnable
during the entire throttled period, for example, will not show any
self-throttling time during this period.
Signed-off-by: Josh Don <joshdon@google.com>
---
kernel/sched/core.c | 21 +++++++++++++++++++--
kernel/sched/fair.c | 17 +++++++++++++++++
kernel/sched/sched.h | 2 ++
3 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index a384344ec9ee..fcd702889fcb 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -11064,6 +11064,18 @@ static int __cfs_schedulable(struct task_group *tg, u64 period, u64 quota)
return ret;
}
+static u64 throttled_time_self(struct task_group *tg)
+{
+ int i;
+ u64 total = 0;
+
+ for_each_possible_cpu(i) {
+ total += READ_ONCE(tg->cfs_rq[i]->throttled_clock_self_time);
+ }
+
+ return total;
+}
+
static int cpu_cfs_stat_show(struct seq_file *sf, void *v)
{
struct task_group *tg = css_tg(seq_css(sf));
@@ -11072,6 +11084,7 @@ static int cpu_cfs_stat_show(struct seq_file *sf, void *v)
seq_printf(sf, "nr_periods %d\n", cfs_b->nr_periods);
seq_printf(sf, "nr_throttled %d\n", cfs_b->nr_throttled);
seq_printf(sf, "throttled_time %llu\n", cfs_b->throttled_time);
+ seq_printf(sf, "throttled_time_self %llu\n", throttled_time_self(tg));
if (schedstat_enabled() && tg != &root_task_group) {
struct sched_statistics *stats;
@@ -11204,20 +11217,24 @@ static int cpu_extra_stat_show(struct seq_file *sf,
{
struct task_group *tg = css_tg(css);
struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
- u64 throttled_usec, burst_usec;
+ u64 throttled_usec, burst_usec, throttled_self_usec;
throttled_usec = cfs_b->throttled_time;
do_div(throttled_usec, NSEC_PER_USEC);
+ throttled_self_usec = throttled_time_self(tg);
+ do_div(throttled_self_usec, NSEC_PER_USEC);
burst_usec = cfs_b->burst_time;
do_div(burst_usec, NSEC_PER_USEC);
seq_printf(sf, "nr_periods %d\n"
"nr_throttled %d\n"
"throttled_usec %llu\n"
+ "throttled_self_usec %llu\n"
"nr_bursts %d\n"
"burst_usec %llu\n",
cfs_b->nr_periods, cfs_b->nr_throttled,
- throttled_usec, cfs_b->nr_burst, burst_usec);
+ throttled_usec, throttled_self_usec, cfs_b->nr_burst,
+ burst_usec);
}
#endif
return 0;
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 85c2c0c3cab6..fd348b9421c1 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -4822,6 +4822,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
} else {
if (!cfs_rq->throttled_clock)
cfs_rq->throttled_clock = rq_clock(rq);
+ if (!cfs_rq->throttled_clock_self)
+ cfs_rq->throttled_clock_self = rq_clock(rq);
}
}
}
@@ -5327,6 +5329,17 @@ static int tg_unthrottle_up(struct task_group *tg, void *data)
list_add_leaf_cfs_rq(cfs_rq);
}
+ if (cfs_rq->throttled_clock_self) {
+ u64 delta = rq_clock(rq) - cfs_rq->throttled_clock_self;
+
+ cfs_rq->throttled_clock_self = 0;
+
+ if (SCHED_WARN_ON((s64)delta < 0))
+ delta = 0;
+
+ cfs_rq->throttled_clock_self_time += delta;
+ }
+
return 0;
}
@@ -5342,6 +5355,10 @@ static int tg_throttle_down(struct task_group *tg, void *data)
}
cfs_rq->throttle_count++;
+ SCHED_WARN_ON(cfs_rq->throttled_clock_self);
+ if (cfs_rq->nr_running)
+ cfs_rq->throttled_clock_self = rq_clock(rq);
+
return 0;
}
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 060616944d7a..ddc48b2f1fd0 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -642,6 +642,8 @@ struct cfs_rq {
u64 throttled_clock;
u64 throttled_clock_pelt;
u64 throttled_clock_pelt_time;
+ u64 throttled_clock_self;
+ u64 throttled_clock_self_time;
int throttled;
int throttle_count;
struct list_head throttled_list;
--
2.40.1.606.ga4b1b128d6-goog
next prev parent reply other threads:[~2023-05-18 1:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-18 1:34 [PATCH 1/2] sched: don't account throttle time for empty groups Josh Don
2023-05-18 1:34 ` Josh Don [this message]
2023-05-18 12:04 ` [PATCH 2/2] sched: add throttled time stat for throttled children kernel test robot
2023-05-23 21:44 ` Tejun Heo
2023-05-25 0:06 ` Josh Don
2023-05-18 8:20 ` [PATCH 1/2] sched: don't account throttle time for empty groups kernel test robot
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=20230518013414.3053254-2-joshdon@google.com \
--to=joshdon@google.com \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tj@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=xiangling@google.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®