mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kayra Cizmeci <kayracizmeci@gmail.com>
To: Qais Yousef <qyousef@layalina.io>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	 Vincent Guittot <vincent.guittot@linaro.org>,
	Christian Loehle <christian.loehle@arm.com>,
	 Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	 John Stultz <jstultz@google.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/2] sched/uclamp: Use wrappers instead of open coding UCLAMP_FLAG_IDLE
Date: Fri, 30 Oct 2026 17:57:21 +0300	[thread overview]
Message-ID: <auSuIMloNE_R2T8z@scheduler.schedules> (raw)
In-Reply-To: <20261029131354.11030-3-qyousef@layalina.io>

On Thu, Oct 29, 2026 at 01:13:54PM +0000, Qais Yousef wrote:

Hi Qais,

> 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.
> 
> Signed-off-by: Qais Yousef <qyousef@layalina.io>
> ---
>  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 c6780358a7975..a2035d66270b9 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -1626,7 +1626,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;
>  	}
>  
> @@ -1637,7 +1637,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);
> @@ -1890,8 +1890,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)
> @@ -1930,8 +1930,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
> @@ -2122,7 +2122,7 @@ void 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 d87bdbd2121df..4706f73838a86 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -3743,6 +3743,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.53.0
> 

Looks good to me.


Reviewed-by: Kayra Cizmeci <kayracizmeci@gmail.com>


Thanks,

Kayra


      reply	other threads:[~2026-10-30 14:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29 13:13 [PATCH v4 0/2] Fix uclamp race against non atomic static key enable Qais Yousef
2026-10-29 13:13 ` [PATCH v4 1/2] sched/uclamp: Fix race condition leading to imbalanced uclamp_rq Qais Yousef
2026-10-29 15:58   ` Christian Loehle
2026-10-29 23:43     ` Qais Yousef
2026-10-30 10:50       ` Christian Loehle
2026-10-30 11:28         ` Qais Yousef
2026-10-30 12:15           ` Peter Zijlstra
2026-10-30 12:41             ` Qais Yousef
2026-10-30 13:21               ` Christian Loehle
2026-10-30 14:13                 ` Peter Zijlstra
2026-10-29 13:13 ` [PATCH v4 2/2] sched/uclamp: Use wrappers instead of open coding UCLAMP_FLAG_IDLE Qais Yousef
2026-10-30 14:57   ` Kayra Cizmeci [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=auSuIMloNE_R2T8z@scheduler.schedules \
    --to=kayracizmeci@gmail.com \
    --cc=christian.loehle@arm.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=jstultz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=qyousef@layalina.io \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®