Skip to content

Commit 1a00d99

Browse files
derklingIngo Molnar
authored andcommitted
sched/uclamp: Set default clamps for RT tasks
By default FAIR tasks start without clamps, i.e. neither boosted nor capped, and they run at the best frequency matching their utilization demand. This default behavior does not fit RT tasks which instead are expected to run at the maximum available frequency, if not otherwise required by explicitly capping them. Enforce the correct behavior for RT tasks by setting util_min to max whenever: 1. the task is switched to the RT class and it does not already have a user-defined clamp value assigned. 2. an RT task is forked from a parent with RESET_ON_FORK set. NOTE: utilization clamp values are cross scheduling class attributes and thus they are never changed/reset once a value has been explicitly defined from user-space. Signed-off-by: Patrick Bellasi <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Alessio Balsini <[email protected]> Cc: Dietmar Eggemann <[email protected]> Cc: Joel Fernandes <[email protected]> Cc: Juri Lelli <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Morten Rasmussen <[email protected]> Cc: Paul Turner <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Quentin Perret <[email protected]> Cc: Rafael J . Wysocki <[email protected]> Cc: Steve Muckle <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Todd Kjos <[email protected]> Cc: Vincent Guittot <[email protected]> Cc: Viresh Kumar <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent a87498a commit 1a00d99

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

kernel/sched/core.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,27 @@ static int uclamp_validate(struct task_struct *p,
10621062
static void __setscheduler_uclamp(struct task_struct *p,
10631063
const struct sched_attr *attr)
10641064
{
1065+
unsigned int clamp_id;
1066+
1067+
/*
1068+
* On scheduling class change, reset to default clamps for tasks
1069+
* without a task-specific value.
1070+
*/
1071+
for_each_clamp_id(clamp_id) {
1072+
struct uclamp_se *uc_se = &p->uclamp_req[clamp_id];
1073+
unsigned int clamp_value = uclamp_none(clamp_id);
1074+
1075+
/* Keep using defined clamps across class changes */
1076+
if (uc_se->user_defined)
1077+
continue;
1078+
1079+
/* By default, RT tasks always get 100% boost */
1080+
if (unlikely(rt_task(p) && clamp_id == UCLAMP_MIN))
1081+
clamp_value = uclamp_none(UCLAMP_MAX);
1082+
1083+
uclamp_se_set(uc_se, clamp_value, false);
1084+
}
1085+
10651086
if (likely(!(attr->sched_flags & SCHED_FLAG_UTIL_CLAMP)))
10661087
return;
10671088

@@ -1087,8 +1108,13 @@ static void uclamp_fork(struct task_struct *p)
10871108
return;
10881109

10891110
for_each_clamp_id(clamp_id) {
1090-
uclamp_se_set(&p->uclamp_req[clamp_id],
1091-
uclamp_none(clamp_id), false);
1111+
unsigned int clamp_value = uclamp_none(clamp_id);
1112+
1113+
/* By default, RT tasks always get 100% boost */
1114+
if (unlikely(rt_task(p) && clamp_id == UCLAMP_MIN))
1115+
clamp_value = uclamp_none(UCLAMP_MAX);
1116+
1117+
uclamp_se_set(&p->uclamp_req[clamp_id], clamp_value, false);
10921118
}
10931119
}
10941120

0 commit comments

Comments
 (0)