[RFC PATCH v3 5/6] sched/uclamp: Simplify uclamp_eff_value()

Hongyan Xia posted 6 patches 1 year, 9 months ago
[RFC PATCH v3 5/6] sched/uclamp: Simplify uclamp_eff_value()
Posted by Hongyan Xia 1 year, 9 months ago
The commit

sched: Remove all uclamp bucket logic

removes uclamp_rq_{inc/dec}() functions, so now p->uclamp contains the
correct values all the time after a uclamp_update_active() call, and
there's no need to toggle the boolean `active` after an update. As a
result, this function is fairly simple now and can live as a static
inline function.

Signed-off-by: Hongyan Xia <hongyan.xia2@arm.com>
---
 kernel/sched/core.c  | 13 ++++---------
 kernel/sched/sched.h | 14 ++++++++++++--
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 981ec9205fe8..876a4b05a3fe 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1500,21 +1500,15 @@ uclamp_eff_get(struct task_struct *p, enum uclamp_id clamp_id)
 	return uc_req;
 }
 
-unsigned long uclamp_eff_value(struct task_struct *p, enum uclamp_id clamp_id)
-{
-	if (!uclamp_is_used() || !p->uclamp[clamp_id].active)
-		return uclamp_none(clamp_id);
-
-	return p->uclamp[clamp_id].value;
-}
-
 static inline void
 uclamp_update_active_nolock(struct task_struct *p)
 {
 	enum uclamp_id clamp_id;
 
-	for_each_clamp_id(clamp_id)
+	for_each_clamp_id(clamp_id) {
 		p->uclamp[clamp_id] = uclamp_eff_get(p, clamp_id);
+		p->uclamp[clamp_id].active = 1;
+	}
 }
 
 static inline void
@@ -1772,6 +1766,7 @@ static void uclamp_fork(struct task_struct *p)
 		for_each_clamp_id(clamp_id) {
 			uclamp_se_set(&p->uclamp_req[clamp_id],
 				      uclamp_none(clamp_id), false);
+			p->uclamp[clamp_id].active = 0;
 		}
 	}
 
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index b99d176623e1..eb810cd9f3d9 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2999,8 +2999,6 @@ static inline unsigned long cpu_util_rt(struct rq *rq)
 #endif
 
 #ifdef CONFIG_UCLAMP_TASK
-unsigned long uclamp_eff_value(struct task_struct *p, enum uclamp_id clamp_id);
-
 static inline unsigned long root_cfs_util_uclamp(struct rq *rq)
 {
 	long ret = READ_ONCE(rq->cfs.avg.util_avg);
@@ -3023,6 +3021,18 @@ static inline bool uclamp_is_used(void)
 	return static_branch_likely(&sched_uclamp_used);
 }
 
+static inline unsigned long uclamp_eff_value(struct task_struct *p,
+					     enum uclamp_id clamp_id)
+{
+	if (uclamp_is_used() && p->uclamp[clamp_id].active)
+		return p->uclamp[clamp_id].value;
+
+	if (clamp_id == UCLAMP_MIN)
+		return 0;
+
+	return SCHED_CAPACITY_SCALE;
+}
+
 static inline void util_bias_enqueue(struct sched_avg *avg,
 				     struct task_struct *p)
 {
-- 
2.34.1
Re: [RFC PATCH v3 5/6] sched/uclamp: Simplify uclamp_eff_value()
Posted by Dietmar Eggemann 1 year, 8 months ago
On 07/05/2024 14:50, Hongyan Xia wrote:

[...]

> +static inline unsigned long uclamp_eff_value(struct task_struct *p,
> +					     enum uclamp_id clamp_id)
> +{
> +	if (uclamp_is_used() && p->uclamp[clamp_id].active)
> +		return p->uclamp[clamp_id].value;
> +
> +	if (clamp_id == UCLAMP_MIN)
> +		return 0;
> +
> +	return SCHED_CAPACITY_SCALE;

Why not keep using 'return uclamp_none(clamp_id)'  here?

[...]
Re: [RFC PATCH v3 5/6] sched/uclamp: Simplify uclamp_eff_value()
Posted by Hongyan Xia 1 year, 8 months ago
On 26/05/2024 23:52, Dietmar Eggemann wrote:
> On 07/05/2024 14:50, Hongyan Xia wrote:
> 
> [...]
> 
>> +static inline unsigned long uclamp_eff_value(struct task_struct *p,
>> +					     enum uclamp_id clamp_id)
>> +{
>> +	if (uclamp_is_used() && p->uclamp[clamp_id].active)
>> +		return p->uclamp[clamp_id].value;
>> +
>> +	if (clamp_id == UCLAMP_MIN)
>> +		return 0;
>> +
>> +	return SCHED_CAPACITY_SCALE;
> 
> Why not keep using 'return uclamp_none(clamp_id)'  here?

Reason is that uclamp_none() is in core.c.

I could move uclamp_none() into sched.h if needed.