Skip to contentSkip to conversation

sched/uclamp: Avoid setting cpu.uclamp.min bigger than cpu.uclamp.max

PATCH In review Xuewen Yan 4 participants 15 messages Jun 2, 2021 – Jun 8, 2021 Scheduler

lore
Share & tools
lore

Xuewen Yan

author
#0 lore raw

PATCH 1/1 sched/uclamp: Avoid setting cpu.uclamp.min bigger than cpu.uclamp.max

From: Xuewen Yan <[email protected]>

When setting cpu.uclamp.min/max in cgroup, there is no validating like uclamp_validate() in __sched_setscheduler(). It may cause the cpu.uclamp.min is bigger than cpu.uclamp.max.

Although there is protection in cpu_util_update_eff():
“eff[UCLAMP_MIN] = min(eff[UCLAMP_MIN], eff[UCLAMP_MAX])”, it's better not to let it happen.

Judging the uclamp value before setting uclamp_min/max, avoid the cpu.uclamp.min is bigger than cpu.uclamp.max.

---
 kernel/sched/core.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
kernel/sched/core.c +25 -1
index 5226cc26a095..520a2da40dc9 100644
@@ -8867,6 +8867,30 @@ static ssize_t cpu_uclamp_write(struct kernfs_open_file *of, char *buf,
 	rcu_read_lock();
 
 	tg = css_tg(of_css(of));
+
+	switch (clamp_id) {
+	case UCLAMP_MIN: {
+		unsigned int uc_req_max = tg->uclamp_req[UCLAMP_MAX].value;
+
+		if (req.util > uc_req_max) {
+			nbytes = -EINVAL;
+			goto unlock;
+		}
+		break;
+	}
+	case UCLAMP_MAX: {
+		unsigned int uc_req_min = tg->uclamp_req[UCLAMP_MIN].value;
+
+		if (req.util < uc_req_min) {
+			nbytes = -EINVAL;
+			goto unlock;
+		}
+		break;
+	}
+	default:
+		nbytes = -EINVAL;
+		goto unlock;
+	}
 	if (tg->uclamp_req[clamp_id].value != req.util)
 		uclamp_se_set(&tg->uclamp_req[clamp_id], req.util, false);
 
@@ -8878,7 +8902,7 @@ static ssize_t cpu_uclamp_write(struct kernfs_open_file *of, char *buf,
 
 	/* Update effective clamps to track the most restrictive value */
 	cpu_util_update_eff(of_css(of));
-
+unlock:
 	rcu_read_unlock();
 	mutex_unlock(&uclamp_mutex);
 
Signature · 1 line
2.25.1
#1 lore raw

+CC Patrick and Tejun

Quoted 5 lines · Xuewen Yan

From: Xuewen Yan <[email protected]>

When setting cpu.uclamp.min/max in cgroup, there is no validating like uclamp_validate() in __sched_setscheduler(). It may cause the cpu.uclamp.min is bigger than cpu.uclamp.max.

ISTR this was intentional. We also allow child groups to ask for whatever clamps they want, but that is always limited by the parent, and reflected in the 'effective' values, as per the cgroup delegation model.

Quoted 59 lines

Although there is protection in cpu_util_update_eff():
“eff[UCLAMP_MIN] = min(eff[UCLAMP_MIN], eff[UCLAMP_MAX])”, it's better not to let it happen.

Judging the uclamp value before setting uclamp_min/max, avoid the cpu.uclamp.min is bigger than cpu.uclamp.max.

---
 kernel/sched/core.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
kernel/sched/core.c +25 -1
index 5226cc26a095..520a2da40dc9 100644
@@ -8867,6 +8867,30 @@ static ssize_t cpu_uclamp_write(struct kernfs_open_file *of, char *buf,
 	rcu_read_lock();
 
 	tg = css_tg(of_css(of));
+
+	switch (clamp_id) {
+	case UCLAMP_MIN: {
+		unsigned int uc_req_max = tg->uclamp_req[UCLAMP_MAX].value;
+
+		if (req.util > uc_req_max) {
+			nbytes = -EINVAL;
+			goto unlock;
+		}
+		break;
+	}
+	case UCLAMP_MAX: {
+		unsigned int uc_req_min = tg->uclamp_req[UCLAMP_MIN].value;
+
+		if (req.util < uc_req_min) {
+			nbytes = -EINVAL;
+			goto unlock;
+		}
+		break;
+	}
+	default:
+		nbytes = -EINVAL;
+		goto unlock;
+	}
 	if (tg->uclamp_req[clamp_id].value != req.util)
 		uclamp_se_set(&tg->uclamp_req[clamp_id], req.util, false);
 
@@ -8878,7 +8902,7 @@ static ssize_t cpu_uclamp_write(struct kernfs_open_file *of, char *buf,
 
 	/* Update effective clamps to track the most restrictive value */
 	cpu_util_update_eff(of_css(of));
-
+unlock:
 	rcu_read_unlock();
 	mutex_unlock(&uclamp_mutex);
 
Signature · 1 line
2.25.1
author
#2 lore raw

+CC Qais

Hi Quentin

Quoted 6 lines · Quentin Perret

+CC Patrick and Tejun

Quoted 2 lines · Xuewen Yan

From: Xuewen Yan <[email protected]>

Quoted 7 lines
Quoted 3 lines

When setting cpu.uclamp.min/max in cgroup, there is no validating like uclamp_validate() in __sched_setscheduler(). It may cause the cpu.uclamp.min is bigger than cpu.uclamp.max.

ISTR this was intentional. We also allow child groups to ask for whatever clamps they want, but that is always limited by the parent, and reflected in the 'effective' values, as per the cgroup delegation model.

It does not affect the 'effective' value. That because there is protection in cpu_util_update_eff():
/* Ensure protection is always capped by limit */ eff[UCLAMP_MIN] = min(eff[UCLAMP_MIN], eff[UCLAMP_MAX]);

When users set the cpu.uclamp.min > cpu.uclamp.max:
cpu.uclamp.max = 50;
to set : cpu.uclamp.min = 60;
That would make the uclamp_req[UCLAMP_MIN].value = 1024* 60% = 614, uclamp_req[UCLAMP_MAX].value = 1024* 50% = 512;
But finally, the uclamp[UCLAMP_MIN].value = uclamp[UCLAMP_MAX].value = 1024* 50% = 512;

Is it deliberately set not to validate because of the above?

Quoted 57 lines
Quoted 57 lines

Although there is protection in cpu_util_update_eff():
“eff[UCLAMP_MIN] = min(eff[UCLAMP_MIN], eff[UCLAMP_MAX])”, it's better not to let it happen.

Judging the uclamp value before setting uclamp_min/max, avoid the cpu.uclamp.min is bigger than cpu.uclamp.max.

---
 kernel/sched/core.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
kernel/sched/core.c +25 -1
index 5226cc26a095..520a2da40dc9 100644
@@ -8867,6 +8867,30 @@ static ssize_t cpu_uclamp_write(struct kernfs_open_file *of, char *buf,
      rcu_read_lock();
 
      tg = css_tg(of_css(of));
+
+     switch (clamp_id) {
+     case UCLAMP_MIN: {
+             unsigned int uc_req_max = tg->uclamp_req[UCLAMP_MAX].value;
+
+             if (req.util > uc_req_max) {
+                     nbytes = -EINVAL;
+                     goto unlock;
+             }
+             break;
+     }
+     case UCLAMP_MAX: {
+             unsigned int uc_req_min = tg->uclamp_req[UCLAMP_MIN].value;
+
+             if (req.util < uc_req_min) {
+                     nbytes = -EINVAL;
+                     goto unlock;
+             }
+             break;
+     }
+     default:
+             nbytes = -EINVAL;
+             goto unlock;
+     }
      if (tg->uclamp_req[clamp_id].value != req.util)
              uclamp_se_set(&tg->uclamp_req[clamp_id], req.util, false);
 
@@ -8878,7 +8902,7 @@ static ssize_t cpu_uclamp_write(struct kernfs_open_file *of, char *buf,
 
      /* Update effective clamps to track the most restrictive value */
      cpu_util_update_eff(of_css(of));
-
+unlock:
      rcu_read_unlock();
      mutex_unlock(&uclamp_mutex);
 
Quoted 3 lines
Quoted 3 lines

--
2.25.1

When I change the code,I found the patch:

6938840392c89 ("sched/uclamp: Fix wrong implementation of cpu.uclamp.min")
https://lkml.kernel.org/r/[email protected]

kernel/sched/core.c +0 -0
index 6a5124c..f97eb73 100644
@@ -1405,7 +1405,6 @@ uclamp_tg_restrict(struct task_struct *p, enum

uclamp_id clamp_id)
{
struct uclamp_se uc_req = p->uclamp_req[clamp_id];
#ifdef CONFIG_UCLAMP_TASK_GROUP
- struct uclamp_se uc_max;

/*
* Tasks in autogroups or root task group will be
@@ -1416,9 +1415,23 @@ uclamp_tg_restrict(struct task_struct *p, enum uclamp_id clamp_id)
if (task_group(p) == &root_task_group)
return uc_req;

- uc_max = task_group(p)->uclamp[clamp_id];
- if (uc_req.value > uc_max.value || !uc_req.user_defined)
- return uc_max;
+ switch (clamp_id) {
+ case UCLAMP_MIN: {
+ struct uclamp_se uc_min = task_group(p)->uclamp[clamp_id];
+ if (uc_req.value < uc_min.value)
+ return uc_min;
+ break;
+ }
+ case UCLAMP_MAX: {
+ struct uclamp_se uc_max = task_group(p)->uclamp[clamp_id];
+ if (uc_req.value > uc_max.value)
+ return uc_max;
+ break;
+ }
+ default:
+ WARN_ON_ONCE(1);
+ break;
+ }
#endif

When the clamp_id = UCLAMP_MIN, why not judge the uc_req.value is bigger than task_group(p)->uclamp[UCLAMP_MAX] ?
Because when the p->uclamp_req[UCLAMP_MIN] > task_group(p)->uclamp[UCLAMP_MAX], the patch can not clamp the p->uclamp_req[UCLAMP_MIN/MAX] into [ task_group(p)->uclamp[UCLAMP_MAX], task_group(p)->uclamp[UCLAMP_MAX] ].

Thanks

#3 lore raw
Quoted 1 line · Xuewen Yan

+CC Qais

Thanks for the CC :)

Quoted 18 lines

Hi Quentin

Quoted 13 lines · Quentin Perret

+CC Patrick and Tejun

Quoted 5 lines · Xuewen Yan

From: Xuewen Yan <[email protected]>

When setting cpu.uclamp.min/max in cgroup, there is no validating like uclamp_validate() in __sched_setscheduler(). It may cause the cpu.uclamp.min is bigger than cpu.uclamp.max.

ISTR this was intentional. We also allow child groups to ask for whatever clamps they want, but that is always limited by the parent, and reflected in the 'effective' values, as per the cgroup delegation model.

As Quentin said. This intentional to comply with cgroup model.

See Limits and Protections sections in Documentation/admin-guide/cgroup-v2.rst

Specifically

"all configuration combinations are valid"

So user can set cpu.uclamp.min higher than cpu.uclamp.max. But when we apply the setting, cpu.uclamp.min will be capped by cpu.uclamp.max. I can see you found the cpu_util_update_eff() logic.

Quoted 14 lines

It does not affect the 'effective' value. That because there is protection in cpu_util_update_eff():
/* Ensure protection is always capped by limit */ eff[UCLAMP_MIN] = min(eff[UCLAMP_MIN], eff[UCLAMP_MAX]);

When users set the cpu.uclamp.min > cpu.uclamp.max:
cpu.uclamp.max = 50;
to set : cpu.uclamp.min = 60;
That would make the uclamp_req[UCLAMP_MIN].value = 1024* 60% = 614, uclamp_req[UCLAMP_MAX].value = 1024* 50% = 512;
But finally, the uclamp[UCLAMP_MIN].value = uclamp[UCLAMP_MAX].value = 1024* 50% = 512;

Quoted 1 line

Is it deliberately set not to validate because of the above?

Sorry I'm not following you here. What code paths were you trying to explain here?

Did you actually hit any problem here?

Thanks

--
Qais Yousef

#4 lore raw
Quoted 28 lines · Qais Yousef
Quoted 1 line · Xuewen Yan

+CC Qais

Thanks for the CC :)

Quoted 18 lines

Hi Quentin

Quoted 13 lines · Quentin Perret

+CC Patrick and Tejun

Quoted 5 lines · Xuewen Yan

From: Xuewen Yan <[email protected]>

When setting cpu.uclamp.min/max in cgroup, there is no validating like uclamp_validate() in __sched_setscheduler(). It may cause the cpu.uclamp.min is bigger than cpu.uclamp.max.

ISTR this was intentional. We also allow child groups to ask for whatever clamps they want, but that is always limited by the parent, and reflected in the 'effective' values, as per the cgroup delegation model.

As Quentin said. This intentional to comply with cgroup model.

See Limits and Protections sections in Documentation/admin-guide/cgroup-v2.rst

Quoted 7 lines

Specifically

"all configuration combinations are valid"

So user can set cpu.uclamp.min higher than cpu.uclamp.max. But when we apply the setting, cpu.uclamp.min will be capped by cpu.uclamp.max. I can see you found the cpu_util_update_eff() logic.

To support this:

Patrick had appropriate checks in his `[PATCH v10 12/16] sched/core:
uclamp: Extend CPU's cgroup controller`.

https://lkml.kernel.org/r/[email protected]

But is was discussed that cgroup v2 resource distribution model configurations (here protection/limit: uclamp_min/uclamp_max) should not be restricted.

Further down in this thread:

"... Limits always trump protection in effect of course but please don't limit what can be configured..."

author
#5 lore raw
Quoted 45 lines · Dietmar Eggemann
Quoted 28 lines · Qais Yousef
Quoted 1 line · Xuewen Yan

+CC Qais

Thanks for the CC :)

Quoted 18 lines

Hi Quentin

Quoted 13 lines · Quentin Perret

+CC Patrick and Tejun

Quoted 5 lines · Xuewen Yan

From: Xuewen Yan <[email protected]>

When setting cpu.uclamp.min/max in cgroup, there is no validating like uclamp_validate() in __sched_setscheduler(). It may cause the cpu.uclamp.min is bigger than cpu.uclamp.max.

ISTR this was intentional. We also allow child groups to ask for whatever clamps they want, but that is always limited by the parent, and reflected in the 'effective' values, as per the cgroup delegation model.

As Quentin said. This intentional to comply with cgroup model.

See Limits and Protections sections in Documentation/admin-guide/cgroup-v2.rst

Quoted 7 lines

Specifically

"all configuration combinations are valid"

So user can set cpu.uclamp.min higher than cpu.uclamp.max. But when we apply the setting, cpu.uclamp.min will be capped by cpu.uclamp.max. I can see you found the cpu_util_update_eff() logic.

To support this:

Patrick had appropriate checks in his `[PATCH v10 12/16] sched/core:
uclamp: Extend CPU's cgroup controller`.

https://lkml.kernel.org/r/[email protected]

Quoted 8 lines

But is was discussed that cgroup v2 resource distribution model configurations (here protection/limit: uclamp_min/uclamp_max) should not be restricted.

Further down in this thread:

"... Limits always trump protection in effect of course but please don't limit what can be configured..."

Okay, I have got it. Thanks a lot!

BR
xuewen.yan

author
#6 lore raw
In reply to Qais Yousef

Hi Qais,

Quoted 29 lines · Qais Yousef
Quoted 1 line · Xuewen Yan

+CC Qais

Thanks for the CC :)

Quoted 18 lines

Hi Quentin

Quoted 13 lines · Quentin Perret

+CC Patrick and Tejun

Quoted 5 lines · Xuewen Yan

From: Xuewen Yan <[email protected]>

When setting cpu.uclamp.min/max in cgroup, there is no validating like uclamp_validate() in __sched_setscheduler(). It may cause the cpu.uclamp.min is bigger than cpu.uclamp.max.

ISTR this was intentional. We also allow child groups to ask for whatever clamps they want, but that is always limited by the parent, and reflected in the 'effective' values, as per the cgroup delegation model.

As Quentin said. This intentional to comply with cgroup model.

See Limits and Protections sections in Documentation/admin-guide/cgroup-v2.rst

Quoted 8 lines

Specifically

"all configuration combinations are valid"

So user can set cpu.uclamp.min higher than cpu.uclamp.max. But when we apply the setting, cpu.uclamp.min will be capped by cpu.uclamp.max. I can see you found the cpu_util_update_eff() logic.

Thanks a lot for your patience to explain, sorry for my ignorance of Documentation/admin-guide/cgroup-v2.rst.

Quoted 14 lines
Quoted 14 lines

It does not affect the 'effective' value. That because there is protection in cpu_util_update_eff():
/* Ensure protection is always capped by limit */ eff[UCLAMP_MIN] = min(eff[UCLAMP_MIN], eff[UCLAMP_MAX]);

When users set the cpu.uclamp.min > cpu.uclamp.max:
cpu.uclamp.max = 50;
to set : cpu.uclamp.min = 60;
That would make the uclamp_req[UCLAMP_MIN].value = 1024* 60% = 614, uclamp_req[UCLAMP_MAX].value = 1024* 50% = 512;
But finally, the uclamp[UCLAMP_MIN].value = uclamp[UCLAMP_MAX].value = 1024* 50% = 512;

Quoted 6 lines
Quoted 1 line

Is it deliberately set not to validate because of the above?

Sorry I'm not following you here. What code paths were you trying to explain here?

Did you actually hit any problem here?

I just gave an example of the difference of uclamp_req and uclamp without my patch, and can ignore it.

Quoted 1 line

In addition,In your patch:
6938840392c89 ("sched/uclamp: Fix wrong implementation of cpu.uclamp.min")
https://lkml.kernel.org/r/[email protected]

+ switch (clamp_id) {
+ case UCLAMP_MIN: {
+ struct uclamp_se uc_min = task_group(p)->uclamp[clamp_id];
+ if (uc_req.value < uc_min.value)
+ return uc_min;
+ break;

When the clamp_id = UCLAMP_MIN, why not judge the uc_req.value is bigger than task_group(p)->uclamp[UCLAMP_MAX] ?
Because when the p->uclamp_req[UCLAMP_MIN] > task_group(p)->uclamp[UCLAMP_MAX], the patch can not clamp the p->uclamp_req[UCLAMP_MIN/MAX] into
[ task_group(p)->uclamp[UCLAMP_MAX], task_group(p)->uclamp[UCLAMP_MAX] ].

Is it necessary to fix it here?

Thanks
xuewen

#7 lore raw
Quoted 36 lines · Xuewen Yan

Hi Qais,

Quoted 33 lines · Qais Yousef
Quoted 1 line · Xuewen Yan

+CC Qais

Thanks for the CC :)

Quoted 18 lines

Hi Quentin

Quoted 13 lines · Quentin Perret

+CC Patrick and Tejun

Quoted 5 lines · Xuewen Yan

From: Xuewen Yan <[email protected]>

When setting cpu.uclamp.min/max in cgroup, there is no validating like uclamp_validate() in __sched_setscheduler(). It may cause the cpu.uclamp.min is bigger than cpu.uclamp.max.

ISTR this was intentional. We also allow child groups to ask for whatever clamps they want, but that is always limited by the parent, and reflected in the 'effective' values, as per the cgroup delegation model.

As Quentin said. This intentional to comply with cgroup model.

See Limits and Protections sections in Documentation/admin-guide/cgroup-v2.rst

Specifically

"all configuration combinations are valid"

Quoted 7 lines
Quoted 4 lines

So user can set cpu.uclamp.min higher than cpu.uclamp.max. But when we apply the setting, cpu.uclamp.min will be capped by cpu.uclamp.max. I can see you found the cpu_util_update_eff() logic.

Thanks a lot for your patience to explain, sorry for my ignorance of Documentation/admin-guide/cgroup-v2.rst.

No problem :)

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines

It does not affect the 'effective' value. That because there is protection in cpu_util_update_eff():
/* Ensure protection is always capped by limit */ eff[UCLAMP_MIN] = min(eff[UCLAMP_MIN], eff[UCLAMP_MAX]);

When users set the cpu.uclamp.min > cpu.uclamp.max:
cpu.uclamp.max = 50;
to set : cpu.uclamp.min = 60;
That would make the uclamp_req[UCLAMP_MIN].value = 1024* 60% = 614, uclamp_req[UCLAMP_MAX].value = 1024* 50% = 512;
But finally, the uclamp[UCLAMP_MIN].value = uclamp[UCLAMP_MAX].value = 1024* 50% = 512;

Is it deliberately set not to validate because of the above?

Quoted 7 lines
Quoted 4 lines

Sorry I'm not following you here. What code paths were you trying to explain here?

Did you actually hit any problem here?

I just gave an example of the difference of uclamp_req and uclamp without my patch, and can ignore it.

Cool.

Quoted 13 lines
Quoted 2 lines

In addition,In your patch:
6938840392c89 ("sched/uclamp: Fix wrong implementation of cpu.uclamp.min")
https://lkml.kernel.org/r/[email protected]

+ switch (clamp_id) {
+ case UCLAMP_MIN: {
+ struct uclamp_se uc_min = task_group(p)->uclamp[clamp_id];
+ if (uc_req.value < uc_min.value)
+ return uc_min;
+ break;

Quoted 2 lines

When the clamp_id = UCLAMP_MIN, why not judge the uc_req.value is bigger than task_group(p)->uclamp[UCLAMP_MAX] ?

Because of the requirement I pointed you to in cgroup-v2.rst. We must allow any value to be requested.

Ultimately if we had

	cpu.uclamp.min = 80
	cpu.uclamp.max = 50

then we want to remember the original request but make sure the effective value is capped.

For the user in the future modifies the values such that

cpu.uclamp.max = max

Then we want to remember cpu.uclamp.min = 80 and apply it since now the cpu.uclamp.max was relaxed to allow the boost value.

Quoted 5 lines

Because when the p->uclamp_req[UCLAMP_MIN] > task_group(p)->uclamp[UCLAMP_MAX], the patch can not clamp the p->uclamp_req[UCLAMP_MIN/MAX] into
[ task_group(p)->uclamp[UCLAMP_MAX], task_group(p)->uclamp[UCLAMP_MAX] ].

Is it necessary to fix it here?

Nope. We must allow any combination values to be accepted and remember them so if one changes we ensure the new effective value is updated accordingly. This is how cgroups API works.

Hope this makes sense.

Cheers

--
Qais Yousef

author
#8 lore raw

Hi Qais

Quoted 37 lines · Qais Yousef
Quoted 12 lines
Quoted 1 line

In addition,In your patch:
6938840392c89 ("sched/uclamp: Fix wrong implementation of cpu.uclamp.min")
https://lkml.kernel.org/r/[email protected]

+ switch (clamp_id) {
+ case UCLAMP_MIN: {
+ struct uclamp_se uc_min = task_group(p)->uclamp[clamp_id];
+ if (uc_req.value < uc_min.value)
+ return uc_min;
+ break;

Quoted 2 lines

When the clamp_id = UCLAMP_MIN, why not judge the uc_req.value is bigger than task_group(p)->uclamp[UCLAMP_MAX] ?

Because of the requirement I pointed you to in cgroup-v2.rst. We must allow any value to be requested.

Ultimately if we had

        cpu.uclamp.min = 80
        cpu.uclamp.max = 50

then we want to remember the original request but make sure the effective value is capped.

For the user in the future modifies the values such that

cpu.uclamp.max = max

Then we want to remember cpu.uclamp.min = 80 and apply it since now the cpu.uclamp.max was relaxed to allow the boost value.

Quoted 4 lines

Because when the p->uclamp_req[UCLAMP_MIN] > task_group(p)->uclamp[UCLAMP_MAX], the patch can not clamp the p->uclamp_req[UCLAMP_MIN/MAX] into
[ task_group(p)->uclamp[UCLAMP_MAX], task_group(p)->uclamp[UCLAMP_MAX] ].

Quoted 5 lines
Quoted 1 line

Is it necessary to fix it here?

Nope. We must allow any combination values to be accepted and remember them so if one changes we ensure the new effective value is updated accordingly. This is how cgroups API works.

Sorry. I may not have expressed it clearly. In your patch (which has not yet merged into the mainline):

6938840392c89 ("sched/uclamp: Fix wrong implementation of cpu.uclamp.min")
https://lkml.kernel.org/r/[email protected]

This patch will not affect p->uclamp_req, but consider the following situation:

tg->cpu.uclamp.min = 0
tg->cpu.uclamp.max = 50%

p->uclamp_req[UCLAMP_MIN] = 60%
p->uclamp_req[UCLAMP_MIN] = 80%

The function call process is as follows: uclamp_eff_value() -> uclamp_eff_get() ->uclamp_tg_restrict()

with your patch, the result is:

p->effective_uclamp_min = 60%
p->effective_uclamp_max = 50%

It would not affect the uclamp_task_util(p), but affect the rq:
when p enqueued:
rq->uclamp[UCLAMP_MIN] = 60%
rq->uclamp[UCLAMP_MIN] = 50%

futher more, in uclamp_rq_util_with() {
...

min_util = READ_ONCE(rq->uclamp[UCLAMP_MIN].value); //60% max_util = READ_ONCE(rq->uclamp[UCLAMP_MAX].value);//50%
...
if (unlikely(min_util >= max_util))
return min_util;

return clamp(util, min_util, max_util);
...
}
as a result, it would return 60%.

Thanks!
xuewen

#9 lore raw
Quoted 60 lines · Xuewen Yan

Hi Qais

Quoted 37 lines · Qais Yousef
Quoted 12 lines
Quoted 1 line

In addition,In your patch:
6938840392c89 ("sched/uclamp: Fix wrong implementation of cpu.uclamp.min")
https://lkml.kernel.org/r/[email protected]

+ switch (clamp_id) {
+ case UCLAMP_MIN: {
+ struct uclamp_se uc_min = task_group(p)->uclamp[clamp_id];
+ if (uc_req.value < uc_min.value)
+ return uc_min;
+ break;

Quoted 2 lines

When the clamp_id = UCLAMP_MIN, why not judge the uc_req.value is bigger than task_group(p)->uclamp[UCLAMP_MAX] ?

Because of the requirement I pointed you to in cgroup-v2.rst. We must allow any value to be requested.

Ultimately if we had

        cpu.uclamp.min = 80
        cpu.uclamp.max = 50

then we want to remember the original request but make sure the effective value is capped.

For the user in the future modifies the values such that

cpu.uclamp.max = max

Then we want to remember cpu.uclamp.min = 80 and apply it since now the cpu.uclamp.max was relaxed to allow the boost value.

Quoted 4 lines

Because when the p->uclamp_req[UCLAMP_MIN] > task_group(p)->uclamp[UCLAMP_MAX], the patch can not clamp the p->uclamp_req[UCLAMP_MIN/MAX] into
[ task_group(p)->uclamp[UCLAMP_MAX], task_group(p)->uclamp[UCLAMP_MAX] ].

Quoted 5 lines
Quoted 1 line

Is it necessary to fix it here?

Nope. We must allow any combination values to be accepted and remember them so if one changes we ensure the new effective value is updated accordingly. This is how cgroups API works.

Sorry. I may not have expressed it clearly. In your patch (which has not yet merged into the mainline):

6938840392c89 ("sched/uclamp: Fix wrong implementation of cpu.uclamp.min")
https://lkml.kernel.org/r/[email protected]

This patch will not affect p->uclamp_req, but consider the following situation:

tg->cpu.uclamp.min = 0
tg->cpu.uclamp.max = 50%

p->uclamp_req[UCLAMP_MIN] = 60%
p->uclamp_req[UCLAMP_MIN] = 80%

Quoted 7 lines

The function call process is as follows: uclamp_eff_value() -> uclamp_eff_get() ->uclamp_tg_restrict()

with your patch, the result is:

p->effective_uclamp_min = 60%
p->effective_uclamp_max = 50%

Are you saying my patch introduced a regression? If there's a bug I would not expect my patch to have had an impact in this area.

uclamp_tg_restrict() uses taskgroup(p)->uclamp[] which is the effective uclamp that is capped in cpu_util_update_eff().

Are you statically analyzing the code or this is the outcome of an experiment you ran on hardware?

Cheers

--
Qais Yousef

Quoted 22 lines

It would not affect the uclamp_task_util(p), but affect the rq:
when p enqueued:
rq->uclamp[UCLAMP_MIN] = 60%
rq->uclamp[UCLAMP_MIN] = 50%

futher more, in uclamp_rq_util_with() {
...

min_util = READ_ONCE(rq->uclamp[UCLAMP_MIN].value); //60% max_util = READ_ONCE(rq->uclamp[UCLAMP_MAX].value);//50%
...
if (unlikely(min_util >= max_util))
return min_util;

return clamp(util, min_util, max_util);
...
}
as a result, it would return 60%.

Thanks!
xuewen

#10 lore raw
In reply to Xuewen Yan
Quoted 82 lines · Xuewen Yan

Hi Qais

Quoted 37 lines · Qais Yousef
Quoted 12 lines
Quoted 1 line

In addition,In your patch:
6938840392c89 ("sched/uclamp: Fix wrong implementation of cpu.uclamp.min")
https://lkml.kernel.org/r/[email protected]

+ switch (clamp_id) {
+ case UCLAMP_MIN: {
+ struct uclamp_se uc_min = task_group(p)->uclamp[clamp_id];
+ if (uc_req.value < uc_min.value)
+ return uc_min;
+ break;

Quoted 2 lines

When the clamp_id = UCLAMP_MIN, why not judge the uc_req.value is bigger than task_group(p)->uclamp[UCLAMP_MAX] ?

Because of the requirement I pointed you to in cgroup-v2.rst. We must allow any value to be requested.

Ultimately if we had

        cpu.uclamp.min = 80
        cpu.uclamp.max = 50

then we want to remember the original request but make sure the effective value is capped.

For the user in the future modifies the values such that

cpu.uclamp.max = max

Then we want to remember cpu.uclamp.min = 80 and apply it since now the cpu.uclamp.max was relaxed to allow the boost value.

Quoted 4 lines

Because when the p->uclamp_req[UCLAMP_MIN] > task_group(p)->uclamp[UCLAMP_MAX], the patch can not clamp the p->uclamp_req[UCLAMP_MIN/MAX] into
[ task_group(p)->uclamp[UCLAMP_MAX], task_group(p)->uclamp[UCLAMP_MAX] ].

Quoted 5 lines
Quoted 1 line

Is it necessary to fix it here?

Nope. We must allow any combination values to be accepted and remember them so if one changes we ensure the new effective value is updated accordingly. This is how cgroups API works.

Sorry. I may not have expressed it clearly. In your patch (which has not yet merged into the mainline):

6938840392c89 ("sched/uclamp: Fix wrong implementation of cpu.uclamp.min")
https://lkml.kernel.org/r/[email protected]

This patch will not affect p->uclamp_req, but consider the following situation:

tg->cpu.uclamp.min = 0
tg->cpu.uclamp.max = 50%

p->uclamp_req[UCLAMP_MIN] = 60%
p->uclamp_req[UCLAMP_MIN] = 80%

The function call process is as follows: uclamp_eff_value() -> uclamp_eff_get() ->uclamp_tg_restrict()

with your patch, the result is:

p->effective_uclamp_min = 60%
p->effective_uclamp_max = 50%

It would not affect the uclamp_task_util(p), but affect the rq:
when p enqueued:
rq->uclamp[UCLAMP_MIN] = 60%
rq->uclamp[UCLAMP_MIN] = 50%

futher more, in uclamp_rq_util_with() {
...

min_util = READ_ONCE(rq->uclamp[UCLAMP_MIN].value); //60% max_util = READ_ONCE(rq->uclamp[UCLAMP_MAX].value);//50%
...
if (unlikely(min_util >= max_util))
return min_util;

Quoted 4 lines

return clamp(util, min_util, max_util);
...
}
as a result, it would return 60%.

Looking at this again now, I better understand what you were trying to say. I got confused that you were still arguing about cgroup inverted cpu.uclamp.min/max, but you're actually talking about something else.

It would be a lot easier to not cross talk threads and reply to my patch directly with this remark.

Anyways, still well spotted!

What you're saying is we need something like the patch below to ensure that the *task request* is within tg uclamp range, right? The worry is that the task's uclamp_min is higher than the tg's uclamp_min, so we end up with the inversion because of that which will not be corrected later.

Hmm I need to think a bit more about this..

Cheers

--
Qais Yousef

--->8---

kernel/sched/core.c +5 -17
index 9e9a5be35cde..e867813b9d5e 100644
@@ -1405,6 +1405,7 @@ uclamp_tg_restrict(struct task_struct *p, enum uclamp_id clamp_id)
 {
        struct uclamp_se uc_req = p->uclamp_req[clamp_id];
 #ifdef CONFIG_UCLAMP_TASK_GROUP
+       unsigned long uc_min, uc_max, val;
 
        /*
         * Tasks in autogroups or root task group will be
@@ -1415,23 +1416,10 @@ uclamp_tg_restrict(struct task_struct *p, enum uclamp_id clamp_id)
        if (task_group(p) == &root_task_group)
                return uc_req;
 
-       switch (clamp_id) {
-       case UCLAMP_MIN: {
-               struct uclamp_se uc_min = task_group(p)->uclamp[clamp_id];
-               if (uc_req.value < uc_min.value)
-                       return uc_min;
-               break;
-       }
-       case UCLAMP_MAX: {
-               struct uclamp_se uc_max = task_group(p)->uclamp[clamp_id];
-               if (uc_req.value > uc_max.value)
-                       return uc_max;
-               break;
-       }
-       default:
-               WARN_ON_ONCE(1);
-               break;
-       }
+       uc_min = task_group(p)->uclamp[UCLAMP_MIN].value;
+       uc_max = task_group(p)->uclamp[UCLAMP_MAX].value;
+       val = uc_req.value;
+       uc_req.value = clamp(val, uc_min, uc_max);
 #endif
 
        return uc_req;
author
#11 lore raw

First of all, sorry for the late reply..

Quoted 54 lines · Qais Yousef
Quoted 52 lines · Xuewen Yan

Hi Qais

Quoted 37 lines · Qais Yousef
Quoted 12 lines
Quoted 1 line

In addition,In your patch:
6938840392c89 ("sched/uclamp: Fix wrong implementation of cpu.uclamp.min")
https://lkml.kernel.org/r/[email protected]

+ switch (clamp_id) {
+ case UCLAMP_MIN: {
+ struct uclamp_se uc_min = task_group(p)->uclamp[clamp_id];
+ if (uc_req.value < uc_min.value)
+ return uc_min;
+ break;

Quoted 2 lines

When the clamp_id = UCLAMP_MIN, why not judge the uc_req.value is bigger than task_group(p)->uclamp[UCLAMP_MAX] ?

Because of the requirement I pointed you to in cgroup-v2.rst. We must allow any value to be requested.

Ultimately if we had

        cpu.uclamp.min = 80
        cpu.uclamp.max = 50

then we want to remember the original request but make sure the effective value is capped.

For the user in the future modifies the values such that

cpu.uclamp.max = max

Then we want to remember cpu.uclamp.min = 80 and apply it since now the cpu.uclamp.max was relaxed to allow the boost value.

Quoted 4 lines

Because when the p->uclamp_req[UCLAMP_MIN] > task_group(p)->uclamp[UCLAMP_MAX], the patch can not clamp the p->uclamp_req[UCLAMP_MIN/MAX] into
[ task_group(p)->uclamp[UCLAMP_MAX], task_group(p)->uclamp[UCLAMP_MAX] ].

Quoted 5 lines
Quoted 1 line

Is it necessary to fix it here?

Nope. We must allow any combination values to be accepted and remember them so if one changes we ensure the new effective value is updated accordingly. This is how cgroups API works.

Sorry. I may not have expressed it clearly. In your patch (which has not yet merged into the mainline):

6938840392c89 ("sched/uclamp: Fix wrong implementation of cpu.uclamp.min")
https://lkml.kernel.org/r/[email protected]

Quoted 7 lines
Quoted 7 lines

This patch will not affect p->uclamp_req, but consider the following situation:

tg->cpu.uclamp.min = 0
tg->cpu.uclamp.max = 50%

p->uclamp_req[UCLAMP_MIN] = 60%
p->uclamp_req[UCLAMP_MIN] = 80%

sorry, here should be
p->uclamp_req[UCLAMP_MIN] = 60%
p->uclamp_req[UCLAMP_MAX] = 80%

Quoted 6 lines
Quoted 6 lines

The function call process is as follows: uclamp_eff_value() -> uclamp_eff_get() ->uclamp_tg_restrict()

with your patch, the result is:

Quoted 7 lines
Quoted 7 lines

p->effective_uclamp_min = 60%
p->effective_uclamp_max = 50%

It would not affect the uclamp_task_util(p), but affect the rq:
when p enqueued:
rq->uclamp[UCLAMP_MIN] = 60%
rq->uclamp[UCLAMP_MIN] = 50%

sorry, here should be
rq->uclamp[UCLAMP_MIN] = 60%
rq->uclamp[UCLAMP_MAX] = 50%

Quoted 10 lines
Quoted 10 lines

futher more, in uclamp_rq_util_with() {
...

min_util = READ_ONCE(rq->uclamp[UCLAMP_MIN].value); //60% max_util = READ_ONCE(rq->uclamp[UCLAMP_MAX].value);//50%
...
if (unlikely(min_util >= max_util))
return min_util;

Quoted 8 lines
Quoted 4 lines

return clamp(util, min_util, max_util);
...
}
as a result, it would return 60%.

Looking at this again now, I better understand what you were trying to say. I got confused that you were still arguing about cgroup inverted cpu.uclamp.min/max, but you're actually talking about something else.

Generally speaking, this kind of situation does not basically exist, but I just consider all the situations that can occur when users use it.

Quoted 3 lines

It would be a lot easier to not cross talk threads and reply to my patch directly with this remark.

Sorry for the trouble because of my unfamiliar with the maillist, I will pay attention next time :)

Quoted 7 lines

Anyways, still well spotted!

What you're saying is we need something like the patch below to ensure that the *task request* is within tg uclamp range, right? The worry is that the task's uclamp_min is higher than the tg's uclamp_min, so we end up with the inversion because of that which will not be corrected later.

Yeah, the task's uclamp_min is higher than the tg's uclamp_max.

Quoted 37 lines

Hmm I need to think a bit more about this..

Cheers

--
Qais Yousef

--->8---

kernel/sched/core.c +1 -11
index 9e9a5be35cde..e867813b9d5e 100644
@@ -1405,6 +1405,7 @@ uclamp_tg_restrict(struct task_struct *p, enum uclamp_id clamp_id)
 {
        struct uclamp_se uc_req = p->uclamp_req[clamp_id];
 #ifdef CONFIG_UCLAMP_TASK_GROUP
+       unsigned long uc_min, uc_max, val;
 
        /*
         * Tasks in autogroups or root task group will be
@@ -1415,23 +1416,10 @@ uclamp_tg_restrict(struct task_struct *p, enum uclamp_id clamp_id)
        if (task_group(p) == &root_task_group)
                return uc_req;
 
-       switch (clamp_id) {
-       case UCLAMP_MIN: {
-               struct uclamp_se uc_min = task_group(p)->uclamp[clamp_id];
-               if (uc_req.value < uc_min.value)
-                       return uc_min;
-               break;
-       }
-       case UCLAMP_MAX: {
-               struct uclamp_se uc_max = task_group(p)->uclamp[clamp_id];
-               if (uc_req.value > uc_max.value)
-                       return uc_max;

kernel/sched/core.c uclamp_tg_restrict(struct task_struct *p, enum uclamp_id clamp_id) · line 1422

Quoted 10 lines
kernel/sched/core.c +4 -6
-               break;
-       }
-       default:
-               WARN_ON_ONCE(1);
-               break;
-       }
+       uc_min = task_group(p)->uclamp[UCLAMP_MIN].value;
+       uc_max = task_group(p)->uclamp[UCLAMP_MAX].value;
+       val = uc_req.value;
+       uc_req.value = clamp(val, uc_min, uc_max);

This is not a good solution, because it just clamp the uc_req.value, but the uc_req.bucket_id is not changed.

kernel/sched/core.c uclamp_tg_restrict(struct task_struct *p, enum uclamp_id clamp_id) · line 1425

Quoted 4 lines
kernel/sched/core.c +0 -0
 #endif
 
        return uc_req;

Thanks!
xuewen

#12 lore raw
Quoted 7 lines · Xuewen Yan
Quoted 3 lines

Looking at this again now, I better understand what you were trying to say. I got confused that you were still arguing about cgroup inverted cpu.uclamp.min/max, but you're actually talking about something else.

Generally speaking, this kind of situation does not basically exist, but I just consider all the situations that can occur when users use it.

+1

Quoted 6 lines
Quoted 4 lines

It would be a lot easier to not cross talk threads and reply to my patch directly with this remark.

Sorry for the trouble because of my unfamiliar with the maillist, I will pay attention next time :)

Not really a problem, it was just a bit confusing to get the right context :)

Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+       uc_min = task_group(p)->uclamp[UCLAMP_MIN].value;
+       uc_max = task_group(p)->uclamp[UCLAMP_MAX].value;
+       val = uc_req.value;
+       uc_req.value = clamp(val, uc_min, uc_max);

This is not a good solution, because it just clamp the uc_req.value, but the uc_req.bucket_id is not changed.

This is what I actually have now. I did move to using uclamp_se_set(). I also needed to modify uclamp_update_active_tasks() so that both uclamp_min/max unconditionally.

I still need to sleep on it to make sure I haven't missed something else, but it looks fine so far.

Thanks!

--
Qais Yousef

--->8---

kernel/sched/core.c +15 -28
index 9e9a5be35cde..1d2d3e6648a6 100644
@@ -1403,38 +1403,28 @@ static void uclamp_sync_util_min_rt_default(void)
 static inline struct uclamp_se
 uclamp_tg_restrict(struct task_struct *p, enum uclamp_id clamp_id)
 {
-       struct uclamp_se uc_req = p->uclamp_req[clamp_id];
+       /* Copy by value as we could modify it */
+       struct uclamp_se uc_eff = p->uclamp_req[clamp_id];
 #ifdef CONFIG_UCLAMP_TASK_GROUP
+       unsigned long tg_min, tg_max, value;
 
        /*
         * Tasks in autogroups or root task group will be
         * restricted by system defaults.
         */
        if (task_group_is_autogroup(task_group(p)))
-               return uc_req;
+               return uc_eff;
        if (task_group(p) == &root_task_group)
-               return uc_req;
+               return uc_eff;
 
-       switch (clamp_id) {
-       case UCLAMP_MIN: {
-               struct uclamp_se uc_min = task_group(p)->uclamp[clamp_id];
-               if (uc_req.value < uc_min.value)
-                       return uc_min;
-               break;
-       }
-       case UCLAMP_MAX: {
-               struct uclamp_se uc_max = task_group(p)->uclamp[clamp_id];
-               if (uc_req.value > uc_max.value)
-                       return uc_max;
-               break;
-       }
-       default:
-               WARN_ON_ONCE(1);
-               break;
-       }
+       tg_min = task_group(p)->uclamp[UCLAMP_MIN].value;
+       tg_max = task_group(p)->uclamp[UCLAMP_MAX].value;
+       value = uc_eff.value;
+       value = clamp(value, tg_min, tg_max);
+       uclamp_se_set(&uc_eff, value, false);
 #endif
 
-       return uc_req;
+       return uc_eff;
 }
 
 /*
@@ -1661,8 +1651,7 @@ uclamp_update_active(struct task_struct *p, enum uclamp_id clamp_id)
 
 #ifdef CONFIG_UCLAMP_TASK_GROUP
 static inline void
-uclamp_update_active_tasks(struct cgroup_subsys_state *css,
-                          unsigned int clamps)
+uclamp_update_active_tasks(struct cgroup_subsys_state *css)
 {
        enum uclamp_id clamp_id;
        struct css_task_iter it;
@@ -1670,10 +1659,8 @@ uclamp_update_active_tasks(struct cgroup_subsys_state *css,
 
        css_task_iter_start(css, 0, &it);
        while ((p = css_task_iter_next(&it))) {
-               for_each_clamp_id(clamp_id) {
-                       if ((0x1 << clamp_id) & clamps)
-                               uclamp_update_active(p, clamp_id);
-               }
+               for_each_clamp_id(clamp_id)
+                       uclamp_update_active(p, clamp_id);
        }
        css_task_iter_end(&it);
 }
@@ -9626,7 +9613,7 @@ static void cpu_util_update_eff(struct cgroup_subsys_state *css)
                }
 
                /* Immediately update descendants RUNNABLE tasks */
-               uclamp_update_active_tasks(css, clamps);
+               uclamp_update_active_tasks(css);
        }
 }
author
#13 lore raw

Hi

Quoted 40 lines · Qais Yousef

--->8---

kernel/sched/core.c +5 -15
index 9e9a5be35cde..1d2d3e6648a6 100644
@@ -1403,38 +1403,28 @@ static void uclamp_sync_util_min_rt_default(void)
 static inline struct uclamp_se
 uclamp_tg_restrict(struct task_struct *p, enum uclamp_id clamp_id)
 {
-       struct uclamp_se uc_req = p->uclamp_req[clamp_id];
+       /* Copy by value as we could modify it */
+       struct uclamp_se uc_eff = p->uclamp_req[clamp_id];
 #ifdef CONFIG_UCLAMP_TASK_GROUP
+       unsigned long tg_min, tg_max, value;
 
        /*
         * Tasks in autogroups or root task group will be
         * restricted by system defaults.
         */
        if (task_group_is_autogroup(task_group(p)))
-               return uc_req;
+               return uc_eff;
        if (task_group(p) == &root_task_group)
-               return uc_req;
+               return uc_eff;
 
-       switch (clamp_id) {
-       case UCLAMP_MIN: {
-               struct uclamp_se uc_min = task_group(p)->uclamp[clamp_id];
-               if (uc_req.value < uc_min.value)
-                       return uc_min;
-               break;
-       }
-       case UCLAMP_MAX: {
-               struct uclamp_se uc_max = task_group(p)->uclamp[clamp_id];
-               if (uc_req.value > uc_max.value)
-                       return uc_max;
-               break;

kernel/sched/core.c static void uclamp_sync_util_min_rt_default(void) · line 1424

Quoted 10 lines
kernel/sched/core.c +5 -5
-       }
-       default:
-               WARN_ON_ONCE(1);
-               break;
-       }
+       tg_min = task_group(p)->uclamp[UCLAMP_MIN].value;
+       tg_max = task_group(p)->uclamp[UCLAMP_MAX].value;
+       value = uc_eff.value;
+       value = clamp(value, tg_min, tg_max);
+       uclamp_se_set(&uc_eff, value, false);

Is it reasonable to set user_defined to be false here?

Quoted 31 lines
kernel/sched/core.c +4 -7
 #endif
 
-       return uc_req;
+       return uc_eff;
 }
 
 /*
@@ -1661,8 +1651,7 @@ uclamp_update_active(struct task_struct *p, enum uclamp_id clamp_id)
 
 #ifdef CONFIG_UCLAMP_TASK_GROUP
 static inline void
-uclamp_update_active_tasks(struct cgroup_subsys_state *css,
-                          unsigned int clamps)
+uclamp_update_active_tasks(struct cgroup_subsys_state *css)
 {
        enum uclamp_id clamp_id;
        struct css_task_iter it;
@@ -1670,10 +1659,8 @@ uclamp_update_active_tasks(struct cgroup_subsys_state *css,
 
        css_task_iter_start(css, 0, &it);
        while ((p = css_task_iter_next(&it))) {
-               for_each_clamp_id(clamp_id) {
-                       if ((0x1 << clamp_id) & clamps)
-                               uclamp_update_active(p, clamp_id);
-               }
+               for_each_clamp_id(clamp_id)
+                       uclamp_update_active(p, clamp_id);
        }
        css_task_iter_end(&it);
 }

kernel/sched/core.c static void cpu_util_update_eff(struct cgroup_subsys_state *css) · line 9618

Quoted 7 lines
kernel/sched/core.c +1 -1
@@ -9626,7 +9613,7 @@ static void cpu_util_update_eff(struct cgroup_subsys_state *css)
                }
 
                /* Immediately update descendants RUNNABLE tasks */
-               uclamp_update_active_tasks(css, clamps);
+               uclamp_update_active_tasks(css);
        }
 }

Would you resend another email? maybe it would be better to resend an email with a new subject?

BR
xuewen

#14 lore raw
Quoted 47 lines · Xuewen Yan

Hi

Quoted 44 lines · Qais Yousef

--->8---

kernel/sched/core.c +5 -19
index 9e9a5be35cde..1d2d3e6648a6 100644
@@ -1403,38 +1403,28 @@ static void uclamp_sync_util_min_rt_default(void)
 static inline struct uclamp_se
 uclamp_tg_restrict(struct task_struct *p, enum uclamp_id clamp_id)
 {
-       struct uclamp_se uc_req = p->uclamp_req[clamp_id];
+       /* Copy by value as we could modify it */
+       struct uclamp_se uc_eff = p->uclamp_req[clamp_id];
 #ifdef CONFIG_UCLAMP_TASK_GROUP
+       unsigned long tg_min, tg_max, value;
 
        /*
         * Tasks in autogroups or root task group will be
         * restricted by system defaults.
         */
        if (task_group_is_autogroup(task_group(p)))
-               return uc_req;
+               return uc_eff;
        if (task_group(p) == &root_task_group)
-               return uc_req;
+               return uc_eff;
 
-       switch (clamp_id) {
-       case UCLAMP_MIN: {
-               struct uclamp_se uc_min = task_group(p)->uclamp[clamp_id];
-               if (uc_req.value < uc_min.value)
-                       return uc_min;
-               break;
-       }
-       case UCLAMP_MAX: {
-               struct uclamp_se uc_max = task_group(p)->uclamp[clamp_id];
-               if (uc_req.value > uc_max.value)
-                       return uc_max;
-               break;
-       }
-       default:
-               WARN_ON_ONCE(1);
-               break;
Quoted 8 lines

kernel/sched/core.c static void uclamp_sync_util_min_rt_default(void) · line 1424

Quoted 6 lines
kernel/sched/core.c +5 -1
-       }
+       tg_min = task_group(p)->uclamp[UCLAMP_MIN].value;
+       tg_max = task_group(p)->uclamp[UCLAMP_MAX].value;
+       value = uc_eff.value;
+       value = clamp(value, tg_min, tg_max);
+       uclamp_se_set(&uc_eff, value, false);

Is it reasonable to set user_defined to be false here?

Yep, it doesn't really matter for the effective value. It matters for the actual task request.

Quoted 34 lines
Quoted 34 lines
kernel/sched/core.c +4 -7
 #endif
 
-       return uc_req;
+       return uc_eff;
 }
 
 /*
@@ -1661,8 +1651,7 @@ uclamp_update_active(struct task_struct *p, enum uclamp_id clamp_id)
 
 #ifdef CONFIG_UCLAMP_TASK_GROUP
 static inline void
-uclamp_update_active_tasks(struct cgroup_subsys_state *css,
-                          unsigned int clamps)
+uclamp_update_active_tasks(struct cgroup_subsys_state *css)
 {
        enum uclamp_id clamp_id;
        struct css_task_iter it;
@@ -1670,10 +1659,8 @@ uclamp_update_active_tasks(struct cgroup_subsys_state *css,
 
        css_task_iter_start(css, 0, &it);
        while ((p = css_task_iter_next(&it))) {
-               for_each_clamp_id(clamp_id) {
-                       if ((0x1 << clamp_id) & clamps)
-                               uclamp_update_active(p, clamp_id);
-               }
+               for_each_clamp_id(clamp_id)
+                       uclamp_update_active(p, clamp_id);
        }
        css_task_iter_end(&it);
 }
@@ -9626,7 +9613,7 @@ static void cpu_util_update_eff(struct cgroup_subsys_state *css)
                }
 
Quoted 8 lines

kernel/sched/core.c static void cpu_util_update_eff(struct cgroup_subsys_state *css) · line 9618

Quoted 5 lines
kernel/sched/core.c +1 -1
                /* Immediately update descendants RUNNABLE tasks */
-               uclamp_update_active_tasks(css, clamps);
+               uclamp_update_active_tasks(css);
        }
 }

Would you resend another email? maybe it would be better to resend an email with a new subject?

Yeah I will do a proper posting. But I need to stare at this a bit more then will do.

Thanks

--
Qais Yousef