All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched: Fix UCLAMP_FLAG_IDLE setting
@ 2021-06-09 14:33 Quentin Perret
  2021-06-09 14:37 ` Quentin Perret
  2021-06-10 10:00 ` Qais Yousef
  0 siblings, 2 replies; 4+ messages in thread
From: Quentin Perret @ 2021-06-09 14:33 UTC (permalink / raw)
  To: mingo, peterz, vincent.guittot, dietmar.eggemann, qais.yousef,
	rickyiu, wvw, patrick.bellasi
  Cc: linux-kernel, kernel-team, Quentin Perret

The UCLAMP_FLAG_IDLE flag is set on a runqueue when dequeueing the last
active task to maintain the last uclamp.max and prevent blocked util
from suddenly becoming visible.

However, there is an asymmetry in how the flag is set and cleared which
can lead to having the flag set whilst there are active task on the rq.
Specifically, the flag is set in the uclamp_rq_inc() path, which is
called at enqueue time, but cleared in the uclamp_rq_dec_id() which is
called both when dequeueing and task _and_ during cgroup migrations.

Fix this by setting the flag in the uclamp_rq_inc_id() path to ensure
things remain symmetrical.

Reported-by: Rick Yiu <rickyiu@google.com>
Signed-off-by: Quentin Perret <qperret@google.com>
---
 kernel/sched/core.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 5226cc26a095..3b213402798e 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -980,6 +980,7 @@ static inline void uclamp_idle_reset(struct rq *rq, enum uclamp_id clamp_id,
 	if (!(rq->uclamp_flags & UCLAMP_FLAG_IDLE))
 		return;
 
+	rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE;
 	WRITE_ONCE(rq->uclamp[clamp_id].value, clamp_value);
 }
 
@@ -1252,10 +1253,6 @@ static inline void uclamp_rq_inc(struct rq *rq, struct task_struct *p)
 
 	for_each_clamp_id(clamp_id)
 		uclamp_rq_inc_id(rq, p, clamp_id);
-
-	/* Reset clamp idle holding when there is one RUNNABLE task */
-	if (rq->uclamp_flags & UCLAMP_FLAG_IDLE)
-		rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE;
 }
 
 static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p)
-- 
2.32.0.272.g935e593368-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] sched: Fix UCLAMP_FLAG_IDLE setting
  2021-06-09 14:33 [PATCH] sched: Fix UCLAMP_FLAG_IDLE setting Quentin Perret
@ 2021-06-09 14:37 ` Quentin Perret
  2021-06-10 10:00 ` Qais Yousef
  1 sibling, 0 replies; 4+ messages in thread
From: Quentin Perret @ 2021-06-09 14:37 UTC (permalink / raw)
  To: mingo, peterz, vincent.guittot, dietmar.eggemann, qais.yousef,
	rickyiu, wvw, patrick.bellasi
  Cc: linux-kernel, kernel-team

On Wednesday 09 Jun 2021 at 14:33:39 (+0000), Quentin Perret wrote:
> The UCLAMP_FLAG_IDLE flag is set on a runqueue when dequeueing the last
> active task to maintain the last uclamp.max and prevent blocked util
> from suddenly becoming visible.
> 
> However, there is an asymmetry in how the flag is set and cleared which
> can lead to having the flag set whilst there are active task on the rq.
> Specifically, the flag is set in the uclamp_rq_inc() path, which is
> called at enqueue time, but cleared in the uclamp_rq_dec_id() which is
> called both when dequeueing and task _and_ during cgroup migrations.
> 
> Fix this by setting the flag in the uclamp_rq_inc_id() path to ensure
> things remain symmetrical.
> 
> Reported-by: Rick Yiu <rickyiu@google.com>
> Signed-off-by: Quentin Perret <qperret@google.com>

Argh, and I think this wants

Fixes: e496187da710 ("sched/uclamp: Enforce last task's UCLAMP_MAX")

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] sched: Fix UCLAMP_FLAG_IDLE setting
  2021-06-09 14:33 [PATCH] sched: Fix UCLAMP_FLAG_IDLE setting Quentin Perret
  2021-06-09 14:37 ` Quentin Perret
@ 2021-06-10 10:00 ` Qais Yousef
  2021-06-10 10:27   ` Quentin Perret
  1 sibling, 1 reply; 4+ messages in thread
From: Qais Yousef @ 2021-06-10 10:00 UTC (permalink / raw)
  To: Quentin Perret
  Cc: mingo, peterz, vincent.guittot, dietmar.eggemann, rickyiu, wvw,
	patrick.bellasi, linux-kernel, kernel-team

On 06/09/21 14:33, Quentin Perret wrote:
> The UCLAMP_FLAG_IDLE flag is set on a runqueue when dequeueing the last
> active task to maintain the last uclamp.max and prevent blocked util
> from suddenly becoming visible.
> 
> However, there is an asymmetry in how the flag is set and cleared which
> can lead to having the flag set whilst there are active task on the rq.
> Specifically, the flag is set in the uclamp_rq_inc() path, which is
> called at enqueue time, but cleared in the uclamp_rq_dec_id() which is

It is actually the other way around. It is cleared in uclamp_rq_inc() and
set in uclamp_rq_dec_id().

> called both when dequeueing and task _and_ during cgroup migrations.

Is it cgroup migrations or when cgroup uclamp values are updated you mean?

It is worth being direct and mention that uclamp_update_active() will perform
uclamp_rq_dec/inc_id() when the cgroup uclamp values are updated, which would
end up with the flag set but not cleared in this path.

> 
> Fix this by setting the flag in the uclamp_rq_inc_id() path to ensure
> things remain symmetrical.
> 
> Reported-by: Rick Yiu <rickyiu@google.com>
> Signed-off-by: Quentin Perret <qperret@google.com>
> ---

With the commit message fixed.

Reviewed-by: Qais Yousef <qais.yousef@arm.com>

Thanks!

--
Qais Yousef

>  kernel/sched/core.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 5226cc26a095..3b213402798e 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -980,6 +980,7 @@ static inline void uclamp_idle_reset(struct rq *rq, enum uclamp_id clamp_id,
>  	if (!(rq->uclamp_flags & UCLAMP_FLAG_IDLE))
>  		return;
>  
> +	rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE;
>  	WRITE_ONCE(rq->uclamp[clamp_id].value, clamp_value);
>  }
>  
> @@ -1252,10 +1253,6 @@ static inline void uclamp_rq_inc(struct rq *rq, struct task_struct *p)
>  
>  	for_each_clamp_id(clamp_id)
>  		uclamp_rq_inc_id(rq, p, clamp_id);
> -
> -	/* Reset clamp idle holding when there is one RUNNABLE task */
> -	if (rq->uclamp_flags & UCLAMP_FLAG_IDLE)
> -		rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE;
>  }
>  
>  static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p)
> -- 
> 2.32.0.272.g935e593368-goog
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] sched: Fix UCLAMP_FLAG_IDLE setting
  2021-06-10 10:00 ` Qais Yousef
@ 2021-06-10 10:27   ` Quentin Perret
  0 siblings, 0 replies; 4+ messages in thread
From: Quentin Perret @ 2021-06-10 10:27 UTC (permalink / raw)
  To: Qais Yousef
  Cc: mingo, peterz, vincent.guittot, dietmar.eggemann, rickyiu, wvw,
	patrick.bellasi, linux-kernel, kernel-team

On Thursday 10 Jun 2021 at 11:00:39 (+0100), Qais Yousef wrote:
> On 06/09/21 14:33, Quentin Perret wrote:
> > The UCLAMP_FLAG_IDLE flag is set on a runqueue when dequeueing the last
> > active task to maintain the last uclamp.max and prevent blocked util
> > from suddenly becoming visible.
> > 
> > However, there is an asymmetry in how the flag is set and cleared which
> > can lead to having the flag set whilst there are active task on the rq.
> > Specifically, the flag is set in the uclamp_rq_inc() path, which is
> > called at enqueue time, but cleared in the uclamp_rq_dec_id() which is
> 
> It is actually the other way around. It is cleared in uclamp_rq_inc() and
> set in uclamp_rq_dec_id().
> 
> > called both when dequeueing and task _and_ during cgroup migrations.
> 
> Is it cgroup migrations or when cgroup uclamp values are updated you mean?
> 
> It is worth being direct and mention that uclamp_update_active() will perform
> uclamp_rq_dec/inc_id() when the cgroup uclamp values are updated, which would
> end up with the flag set but not cleared in this path.

Yep, that's the problematic path.

> > 
> > Fix this by setting the flag in the uclamp_rq_inc_id() path to ensure
> > things remain symmetrical.
> > 
> > Reported-by: Rick Yiu <rickyiu@google.com>
> > Signed-off-by: Quentin Perret <qperret@google.com>
> > ---
> 
> With the commit message fixed.

Ack, this commit message is a mess, I'll rewrite.

> Reviewed-by: Qais Yousef <qais.yousef@arm.com>


Thanks!
Quentin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-10 10:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09 14:33 [PATCH] sched: Fix UCLAMP_FLAG_IDLE setting Quentin Perret
2021-06-09 14:37 ` Quentin Perret
2021-06-10 10:00 ` Qais Yousef
2021-06-10 10:27   ` Quentin Perret

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.