Skip to content

Commit babbe17

Browse files
derklingIngo Molnar
authored andcommitted
sched/uclamp: Update CPU's refcount on TG's clamp changes
On updates of task group (TG) clamp values, ensure that these new values are enforced on all RUNNABLE tasks of the task group, i.e. all RUNNABLE tasks are immediately boosted and/or capped as requested. Do that each time we update effective clamps from cpu_util_update_eff(). Use the *cgroup_subsys_state (css) to walk the list of tasks in each affected TG and update their RUNNABLE tasks. Update each task by using the same mechanism used for cpu affinity masks updates, i.e. by taking the rq lock. Signed-off-by: Patrick Bellasi <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Michal Koutny <[email protected]> Acked-by: Tejun Heo <[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: 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 3eac870 commit babbe17

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

kernel/sched/core.c

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,54 @@ static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p)
10431043
uclamp_rq_dec_id(rq, p, clamp_id);
10441044
}
10451045

1046+
static inline void
1047+
uclamp_update_active(struct task_struct *p, unsigned int clamp_id)
1048+
{
1049+
struct rq_flags rf;
1050+
struct rq *rq;
1051+
1052+
/*
1053+
* Lock the task and the rq where the task is (or was) queued.
1054+
*
1055+
* We might lock the (previous) rq of a !RUNNABLE task, but that's the
1056+
* price to pay to safely serialize util_{min,max} updates with
1057+
* enqueues, dequeues and migration operations.
1058+
* This is the same locking schema used by __set_cpus_allowed_ptr().
1059+
*/
1060+
rq = task_rq_lock(p, &rf);
1061+
1062+
/*
1063+
* Setting the clamp bucket is serialized by task_rq_lock().
1064+
* If the task is not yet RUNNABLE and its task_struct is not
1065+
* affecting a valid clamp bucket, the next time it's enqueued,
1066+
* it will already see the updated clamp bucket value.
1067+
*/
1068+
if (!p->uclamp[clamp_id].active) {
1069+
uclamp_rq_dec_id(rq, p, clamp_id);
1070+
uclamp_rq_inc_id(rq, p, clamp_id);
1071+
}
1072+
1073+
task_rq_unlock(rq, p, &rf);
1074+
}
1075+
1076+
static inline void
1077+
uclamp_update_active_tasks(struct cgroup_subsys_state *css,
1078+
unsigned int clamps)
1079+
{
1080+
struct css_task_iter it;
1081+
struct task_struct *p;
1082+
unsigned int clamp_id;
1083+
1084+
css_task_iter_start(css, 0, &it);
1085+
while ((p = css_task_iter_next(&it))) {
1086+
for_each_clamp_id(clamp_id) {
1087+
if ((0x1 << clamp_id) & clamps)
1088+
uclamp_update_active(p, clamp_id);
1089+
}
1090+
}
1091+
css_task_iter_end(&it);
1092+
}
1093+
10461094
#ifdef CONFIG_UCLAMP_TASK_GROUP
10471095
static void cpu_util_update_eff(struct cgroup_subsys_state *css);
10481096
static void uclamp_update_root_tg(void)
@@ -7160,8 +7208,13 @@ static void cpu_util_update_eff(struct cgroup_subsys_state *css)
71607208
uc_se[clamp_id].bucket_id = uclamp_bucket_id(eff[clamp_id]);
71617209
clamps |= (0x1 << clamp_id);
71627210
}
7163-
if (!clamps)
7211+
if (!clamps) {
71647212
css = css_rightmost_descendant(css);
7213+
continue;
7214+
}
7215+
7216+
/* Immediately update descendants RUNNABLE tasks */
7217+
uclamp_update_active_tasks(css, clamps);
71657218
}
71667219
}
71677220

0 commit comments

Comments
 (0)