Skip to content

Commit 9d20ad7

Browse files
derklingIngo Molnar
authored andcommitted
sched/uclamp: Add uclamp_util_with()
So far uclamp_util() allows to clamp a specified utilization considering the clamp values requested by RUNNABLE tasks in a CPU. For the Energy Aware Scheduler (EAS) it is interesting to test how clamp values will change when a task is becoming RUNNABLE on a given CPU. For example, EAS is interested in comparing the energy impact of different scheduling decisions and the clamp values can play a role on that. Add uclamp_util_with() which allows to clamp a given utilization by considering the possible impact on CPU clamp values of a specified task. 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 982d9cd commit 9d20ad7

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

kernel/sched/core.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,19 @@ uclamp_eff_get(struct task_struct *p, unsigned int clamp_id)
880880
return uc_req;
881881
}
882882

883+
unsigned int uclamp_eff_value(struct task_struct *p, unsigned int clamp_id)
884+
{
885+
struct uclamp_se uc_eff;
886+
887+
/* Task currently refcounted: use back-annotated (effective) value */
888+
if (p->uclamp[clamp_id].active)
889+
return p->uclamp[clamp_id].value;
890+
891+
uc_eff = uclamp_eff_get(p, clamp_id);
892+
893+
return uc_eff.value;
894+
}
895+
883896
/*
884897
* When a task is enqueued on a rq, the clamp bucket currently defined by the
885898
* task's uclamp::bucket_id is refcounted on that rq. This also immediately

kernel/sched/sched.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,11 +2266,20 @@ static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {}
22662266
#endif /* CONFIG_CPU_FREQ */
22672267

22682268
#ifdef CONFIG_UCLAMP_TASK
2269-
static inline unsigned int uclamp_util(struct rq *rq, unsigned int util)
2269+
unsigned int uclamp_eff_value(struct task_struct *p, unsigned int clamp_id);
2270+
2271+
static __always_inline
2272+
unsigned int uclamp_util_with(struct rq *rq, unsigned int util,
2273+
struct task_struct *p)
22702274
{
22712275
unsigned int min_util = READ_ONCE(rq->uclamp[UCLAMP_MIN].value);
22722276
unsigned int max_util = READ_ONCE(rq->uclamp[UCLAMP_MAX].value);
22732277

2278+
if (p) {
2279+
min_util = max(min_util, uclamp_eff_value(p, UCLAMP_MIN));
2280+
max_util = max(max_util, uclamp_eff_value(p, UCLAMP_MAX));
2281+
}
2282+
22742283
/*
22752284
* Since CPU's {min,max}_util clamps are MAX aggregated considering
22762285
* RUNNABLE tasks with _different_ clamps, we can end up with an
@@ -2281,7 +2290,17 @@ static inline unsigned int uclamp_util(struct rq *rq, unsigned int util)
22812290

22822291
return clamp(util, min_util, max_util);
22832292
}
2293+
2294+
static inline unsigned int uclamp_util(struct rq *rq, unsigned int util)
2295+
{
2296+
return uclamp_util_with(rq, util, NULL);
2297+
}
22842298
#else /* CONFIG_UCLAMP_TASK */
2299+
static inline unsigned int uclamp_util_with(struct rq *rq, unsigned int util,
2300+
struct task_struct *p)
2301+
{
2302+
return util;
2303+
}
22852304
static inline unsigned int uclamp_util(struct rq *rq, unsigned int util)
22862305
{
22872306
return util;

0 commit comments

Comments
 (0)