Re: [PATCH 2/2] sched/uclamp: Use wrappers instead of open coding UCLAMP_FLAG_IDLE

From: Vincent Guittot

Date: Fri Nov 27 2026 - 08:13:49 EST


On Fri, 27 Nov 2026 at 12:13, Christian Loehle <christian.loehle@xxxxxxx> wrote:
>
> From: Qais Yousef <qyousef@xxxxxxxxxxx>
>
> We already have uclamp_rq_is_idle(), but it wasn't used everywhere.
> Replace open coding with the function and add new wrapper to set and
> clear the flag which enhances readability.
>
> Reviewed-by: Kayra Cizmeci <kayracizmeci@xxxxxxxxx>
> Signed-off-by: Qais Yousef <qyousef@xxxxxxxxxxx>
> Signed-off-by: Christian Loehle <christian.loehle@xxxxxxx>

Reviewed-by: Vincent Guittot <vincent.guittot@xxxxxxxxxx>

> ---
> kernel/sched/core.c | 14 +++++++-------
> kernel/sched/sched.h | 10 ++++++++++
> 2 files changed, 17 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index fadad7d3f3a2..4bbb095a6d19 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -1644,7 +1644,7 @@ uclamp_idle_value(struct rq *rq, enum uclamp_id clamp_id,
> * max-clamp.
> */
> if (clamp_id == UCLAMP_MAX) {
> - rq->uclamp_flags |= UCLAMP_FLAG_IDLE;
> + uclamp_rq_set_idle(rq);
> return clamp_value;
> }
>
> @@ -1655,7 +1655,7 @@ static inline void uclamp_idle_reset(struct rq *rq, enum uclamp_id clamp_id,
> unsigned int clamp_value)
> {
> /* Reset max-clamp retention only on idle exit */
> - if (!(rq->uclamp_flags & UCLAMP_FLAG_IDLE))
> + if (!uclamp_rq_is_idle(rq))
> return;
>
> uclamp_rq_set(rq, clamp_id, clamp_value);
> @@ -1882,8 +1882,8 @@ static inline void uclamp_rq_inc(struct rq *rq, struct task_struct *p, int flags
> 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;
> + if (uclamp_rq_is_idle(rq))
> + uclamp_rq_clear_idle(rq);
> }
>
> static inline void uclamp_rq_dec(struct rq *rq, struct task_struct *p)
> @@ -1922,8 +1922,8 @@ static inline void uclamp_rq_reinc_id(struct rq *rq, struct task_struct *p,
> * Make sure to clear the idle flag if we've transiently reached 0
> * active tasks on rq.
> */
> - if (clamp_id == UCLAMP_MAX && (rq->uclamp_flags & UCLAMP_FLAG_IDLE))
> - rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE;
> + if (clamp_id == UCLAMP_MAX && uclamp_rq_is_idle(rq))
> + uclamp_rq_clear_idle(rq);
> }
>
> static inline void
> @@ -2114,7 +2114,7 @@ static void __init init_uclamp_rq(struct rq *rq)
> };
> }
>
> - rq->uclamp_flags = UCLAMP_FLAG_IDLE;
> + uclamp_rq_set_idle(rq);
> }
>
> static void __init init_uclamp(void)
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index 804c70317637..982d47fbe9b7 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -3799,6 +3799,16 @@ static inline void uclamp_rq_set(struct rq *rq, enum uclamp_id clamp_id,
> WRITE_ONCE(rq->uclamp[clamp_id].value, value);
> }
>
> +static inline void uclamp_rq_set_idle(struct rq *rq)
> +{
> + rq->uclamp_flags |= UCLAMP_FLAG_IDLE;
> +}
> +
> +static inline void uclamp_rq_clear_idle(struct rq *rq)
> +{
> + rq->uclamp_flags &= ~UCLAMP_FLAG_IDLE;
> +}
> +
> static inline bool uclamp_rq_is_idle(struct rq *rq)
> {
> return rq->uclamp_flags & UCLAMP_FLAG_IDLE;
> --
> 2.34.1
>