From: David Dai <davidai@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>,
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>
Cc: David Dai <davidai@google.com>, Qais Yousef <qyousef@google.com>,
Quentin Perret <qperret@google.com>,
Saravana Kannan <saravanak@google.com>,
kernel-team@android.com, linux-kernel@vger.kernel.org
Subject: [RFC PATCH v1] sched/uclamp: Introduce SCHED_FLAG_RESET_UCLAMP_ON_FORK flag
Date: Sun, 16 Apr 2023 14:34:04 -0700 [thread overview]
Message-ID: <20230416213406.2966521-1-davidai@google.com> (raw)
A userspace service may manage uclamp dynamically for individual tasks and
a child task will unintentionally inherit a pesudo-random uclamp setting.
This could result in the child task being stuck with a static uclamp value
that results in poor performance or poor power.
Using SCHED_FLAG_RESET_ON_FORK is too coarse for this usecase and will
reset other useful scheduler attributes. Adding a
SCHED_FLAG_RESET_UCLAMP_ON_FORK will allow userspace to have finer control
over scheduler attributes of child processes.
Cc: Qais Yousef <qyousef@google.com>
Cc: Quentin Perret <qperret@google.com>
Cc: Saravana Kannan <saravanak@google.com>
Signed-off-by: David Dai <davidai@google.com>
---
include/linux/sched.h | 3 +++
include/uapi/linux/sched.h | 4 +++-
kernel/sched/core.c | 6 +++++-
tools/include/uapi/linux/sched.h | 4 +++-
4 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 63d242164b1a..b1676b9381f9 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -885,6 +885,9 @@ struct task_struct {
unsigned sched_reset_on_fork:1;
unsigned sched_contributes_to_load:1;
unsigned sched_migrated:1;
+#ifdef CONFIG_UCLAMP_TASK
+ unsigned sched_reset_uclamp_on_fork:1;
+#endif
/* Force alignment to the next boundary: */
unsigned :0;
diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h
index 3bac0a8ceab2..7515106e1f1a 100644
--- a/include/uapi/linux/sched.h
+++ b/include/uapi/linux/sched.h
@@ -132,12 +132,14 @@ struct clone_args {
#define SCHED_FLAG_KEEP_PARAMS 0x10
#define SCHED_FLAG_UTIL_CLAMP_MIN 0x20
#define SCHED_FLAG_UTIL_CLAMP_MAX 0x40
+#define SCHED_FLAG_RESET_UCLAMP_ON_FORK 0x80
#define SCHED_FLAG_KEEP_ALL (SCHED_FLAG_KEEP_POLICY | \
SCHED_FLAG_KEEP_PARAMS)
#define SCHED_FLAG_UTIL_CLAMP (SCHED_FLAG_UTIL_CLAMP_MIN | \
- SCHED_FLAG_UTIL_CLAMP_MAX)
+ SCHED_FLAG_UTIL_CLAMP_MAX | \
+ SCHED_FLAG_RESET_UCLAMP_ON_FORK)
#define SCHED_FLAG_ALL (SCHED_FLAG_RESET_ON_FORK | \
SCHED_FLAG_RECLAIM | \
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 0d18c3969f90..f2d5f7911855 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1943,6 +1943,10 @@ static void __setscheduler_uclamp(struct task_struct *p,
uclamp_se_set(&p->uclamp_req[UCLAMP_MAX],
attr->sched_util_max, true);
}
+
+ p->sched_reset_uclamp_on_fork = !!(attr->sched_flags &
+ SCHED_FLAG_RESET_UCLAMP_ON_FORK);
+
}
static void uclamp_fork(struct task_struct *p)
@@ -1956,7 +1960,7 @@ static void uclamp_fork(struct task_struct *p)
for_each_clamp_id(clamp_id)
p->uclamp[clamp_id].active = false;
- if (likely(!p->sched_reset_on_fork))
+ if (likely(!p->sched_reset_on_fork && !p->sched_reset_uclamp_on_fork))
return;
for_each_clamp_id(clamp_id) {
diff --git a/tools/include/uapi/linux/sched.h b/tools/include/uapi/linux/sched.h
index 3bac0a8ceab2..d52c59a2e0d0 100644
--- a/tools/include/uapi/linux/sched.h
+++ b/tools/include/uapi/linux/sched.h
@@ -132,12 +132,14 @@ struct clone_args {
#define SCHED_FLAG_KEEP_PARAMS 0x10
#define SCHED_FLAG_UTIL_CLAMP_MIN 0x20
#define SCHED_FLAG_UTIL_CLAMP_MAX 0x40
+#define SCHED_FLAG_RESET_UCLAMP_ON_FORK 0x80
#define SCHED_FLAG_KEEP_ALL (SCHED_FLAG_KEEP_POLICY | \
SCHED_FLAG_KEEP_PARAMS)
#define SCHED_FLAG_UTIL_CLAMP (SCHED_FLAG_UTIL_CLAMP_MIN | \
- SCHED_FLAG_UTIL_CLAMP_MAX)
+ SCHED_FLAG_UTIL_CLAMP_MAX | \
+ SCHED_FLAG_RESET_UCLAMP_ON_FORK)
#define SCHED_FLAG_ALL (SCHED_FLAG_RESET_ON_FORK | \
SCHED_FLAG_RECLAIM | \
--
2.40.0.634.g4ca3ef3211-goog
next reply other threads:[~2023-04-16 21:34 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-16 21:34 David Dai [this message]
2023-04-19 5:18 ` [RFC PATCH v1] sched/uclamp: Introduce SCHED_FLAG_RESET_UCLAMP_ON_FORK flag Dietmar Eggemann
2023-04-20 1:11 ` David Dai
2023-04-20 9:37 ` Dietmar Eggemann
2023-04-20 13:44 ` Vincent Guittot
2023-04-20 16:25 ` Saravana Kannan
2023-04-20 17:49 ` Qais Yousef
2023-04-21 15:10 ` Vincent Guittot
2023-04-28 11:44 ` Qais Yousef
2023-04-20 16:22 ` Saravana Kannan
2023-04-20 17:37 ` Qais Yousef
2023-04-19 17:54 ` Qais Yousef
2023-04-19 22:49 ` Saravana Kannan
2023-04-20 13:38 ` Qais Yousef
2023-04-28 11:57 ` Qais Yousef
2023-04-28 18:12 ` Saravana Kannan
2023-05-03 13:29 ` Qais Yousef
2023-05-03 15:55 ` Saravana Kannan
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=20230416213406.2966521-1-davidai@google.com \
--to=davidai@google.com \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=qperret@google.com \
--cc=qyousef@google.com \
--cc=rostedt@goodmis.org \
--cc=saravanak@google.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.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;
as well as URLs for NNTP newsgroup(s).