linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/1] sched/uclamp: add SCHED_FLAG_UTIL_CLAMP_RESET flag to reset uclamp
@ 2020-10-12 16:31 Yun Hsiang
  2020-10-13  8:21 ` Patrick Bellasi
  2020-10-13 20:25 ` Dietmar Eggemann
  0 siblings, 2 replies; 12+ messages in thread
From: Yun Hsiang @ 2020-10-12 16:31 UTC (permalink / raw)
  To: dietmar.eggemann, peterz
  Cc: linux-kernel, qais.yousef, patrick.bellasi, Yun Hsiang

If the user wants to stop controlling uclamp and let the task inherit
the value from the group, we need a method to reset.

Add SCHED_FLAG_UTIL_CLAMP_RESET flag to allow the user to reset uclamp via
sched_setattr syscall.

Signed-off-by: Yun Hsiang <hsiang023167@gmail.com>
---
 include/uapi/linux/sched.h |  9 ++++++++-
 kernel/sched/core.c        | 16 ++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h
index 3bac0a8ceab2..a12e88c362d8 100644
--- a/include/uapi/linux/sched.h
+++ b/include/uapi/linux/sched.h
@@ -132,6 +132,9 @@ 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_UTIL_CLAMP_RESET_MIN	0x80
+#define SCHED_FLAG_UTIL_CLAMP_RESET_MAX	0x100
+
 
 #define SCHED_FLAG_KEEP_ALL	(SCHED_FLAG_KEEP_POLICY | \
 				 SCHED_FLAG_KEEP_PARAMS)
@@ -139,10 +142,14 @@ struct clone_args {
 #define SCHED_FLAG_UTIL_CLAMP	(SCHED_FLAG_UTIL_CLAMP_MIN | \
 				 SCHED_FLAG_UTIL_CLAMP_MAX)
 
+#define SCHED_FLAG_UTIL_CLAMP_RESET (SCHED_FLAG_UTIL_CLAMP_RESET_MIN | \
+					SCHED_FLAG_UTIL_CLAMP_RESET_MAX)
+
 #define SCHED_FLAG_ALL	(SCHED_FLAG_RESET_ON_FORK	| \
 			 SCHED_FLAG_RECLAIM		| \
 			 SCHED_FLAG_DL_OVERRUN		| \
 			 SCHED_FLAG_KEEP_ALL		| \
-			 SCHED_FLAG_UTIL_CLAMP)
+			 SCHED_FLAG_UTIL_CLAMP		| \
+			 SCHED_FLAG_UTIL_CLAMP_RESET)
 
 #endif /* _UAPI_LINUX_SCHED_H */
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 9a2fbf98fd6f..ed4cb412dde7 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1207,15 +1207,22 @@ static void __setscheduler_uclamp(struct task_struct *p,
 		uclamp_se_set(uc_se, clamp_value, false);
 	}
 
-	if (likely(!(attr->sched_flags & SCHED_FLAG_UTIL_CLAMP)))
+	if (likely(!(attr->sched_flags &
+			(SCHED_FLAG_UTIL_CLAMP | SCHED_FLAG_UTIL_CLAMP_RESET))))
 		return;
 
-	if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN) {
+	if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_RESET_MIN) {
+		uclamp_se_set(&p->uclamp_req[UCLAMP_MIN],
+			      0, false);
+	} else if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN) {
 		uclamp_se_set(&p->uclamp_req[UCLAMP_MIN],
 			      attr->sched_util_min, true);
 	}
 
-	if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MAX) {
+	if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_RESET_MAX) {
+		uclamp_se_set(&p->uclamp_req[UCLAMP_MAX],
+			      1024, false);
+	} else if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MAX) {
 		uclamp_se_set(&p->uclamp_req[UCLAMP_MAX],
 			      attr->sched_util_max, true);
 	}
@@ -4901,7 +4908,8 @@ static int __sched_setscheduler(struct task_struct *p,
 			goto change;
 		if (dl_policy(policy) && dl_param_changed(p, attr))
 			goto change;
-		if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP)
+		if (attr->sched_flags &
+				(SCHED_FLAG_UTIL_CLAMP | SCHED_FLAG_UTIL_CLAMP_RESET))
 			goto change;
 
 		p->sched_reset_on_fork = reset_on_fork;
-- 
2.25.1


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

end of thread, other threads:[~2020-10-15 12:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-12 16:31 [PATCH v2 1/1] sched/uclamp: add SCHED_FLAG_UTIL_CLAMP_RESET flag to reset uclamp Yun Hsiang
2020-10-13  8:21 ` Patrick Bellasi
2020-10-13 10:29   ` Qais Yousef
2020-10-13 11:46     ` Patrick Bellasi
2020-10-13 13:32       ` Qais Yousef
2020-10-13 16:52         ` Patrick Bellasi
2020-10-14 16:15           ` Yun Hsiang
2020-10-13 20:25 ` Dietmar Eggemann
2020-10-14 14:50   ` Patrick Bellasi
2020-10-15 11:53     ` Dietmar Eggemann
2020-10-14 15:00   ` Yun Hsiang
2020-10-15 11:56     ` Dietmar Eggemann

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).