public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Shrikanth Hegde <sshegde@linux.ibm.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org, juri.lelli@redhat.com,
	dietmar.eggemann@arm.com, rostedt@goodmis.org,
	bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
	tj@kernel.org, void@manifault.com, arighi@nvidia.com,
	changwoo@igalia.com, sched-ext@lists.linux.dev, mingo@kernel.org,
	vincent.guittot@linaro.org
Subject: Re: [PATCH 2/5] sched/fair: Avoid rq->lock bouncing in sched_balance_newidle()
Date: Sun, 30 Nov 2025 00:29:00 +0530	[thread overview]
Message-ID: <b26d7ab3-e07b-407b-bb24-6741d4043315@linux.ibm.com> (raw)
In-Reply-To: <20251127154725.532469061@infradead.org>



On 11/27/25 9:09 PM, Peter Zijlstra wrote:
> While poking at this code recently I noted we do a pointless
> unlock+lock cycle in sched_balance_newidle(). We drop the rq->lock (so
> we can balance) but then instantly grab the same rq->lock again in
> sched_balance_update_blocked_averages().
> 
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
>   kernel/sched/fair.c |   27 ++++++++++++++++++---------
>   1 file changed, 18 insertions(+), 9 deletions(-)
> 
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -9902,15 +9902,11 @@ static unsigned long task_h_load(struct
>   }
>   #endif /* !CONFIG_FAIR_GROUP_SCHED */
>   
> -static void sched_balance_update_blocked_averages(int cpu)
> +static void __sched_balance_update_blocked_averages(struct rq *rq)
>   {
>   	bool decayed = false, done = true;
> -	struct rq *rq = cpu_rq(cpu);
> -	struct rq_flags rf;
>   
> -	rq_lock_irqsave(rq, &rf);
>   	update_blocked_load_tick(rq);
> -	update_rq_clock(rq);
>   
>   	decayed |= __update_blocked_others(rq, &done);
>   	decayed |= __update_blocked_fair(rq, &done);
> @@ -9918,7 +9914,15 @@ static void sched_balance_update_blocked
>   	update_blocked_load_status(rq, !done);
>   	if (decayed)
>   		cpufreq_update_util(rq, 0);
> -	rq_unlock_irqrestore(rq, &rf);
> +}
> +
> +static void sched_balance_update_blocked_averages(int cpu)
> +{
> +	struct rq *rq = cpu_rq(cpu);
> +
> +	guard(rq_lock_irqsave)(rq);
> +	update_rq_clock(rq);
> +	__sched_balance_update_blocked_averages(rq);
>   }
>   
>   /********** Helpers for sched_balance_find_src_group ************************/
> @@ -12865,12 +12869,17 @@ static int sched_balance_newidle(struct
>   	}
>   	rcu_read_unlock();
>   
> +	/*
> +	 * Include sched_balance_update_blocked_averages() in the cost
> +	 * calculation because it can be quite costly -- this ensures we skip
> +	 * it when avg_idle gets to be very low.
> +	 */
> +	t0 = sched_clock_cpu(this_cpu);
> +	__sched_balance_update_blocked_averages(this_rq);
> +

I think we do update_rq_clock earlier as early as __schedule.
no warnings seen.

Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com>


  reply	other threads:[~2025-11-29 18:59 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-27 15:39 [PATCH 0/5] sched: Random collection of patches Peter Zijlstra
2025-11-27 15:39 ` [PATCH 1/5] sched/fair: Fold the sched_avg update Peter Zijlstra
2025-12-14  7:46   ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2025-12-14  7:46   ` [tip: sched/core] <linux/compiler_types.h>: Add the __signed_scalar_typeof() helper tip-bot2 for Peter Zijlstra
2025-11-27 15:39 ` [PATCH 2/5] sched/fair: Avoid rq->lock bouncing in sched_balance_newidle() Peter Zijlstra
2025-11-29 18:59   ` Shrikanth Hegde [this message]
2025-12-14  7:46   ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2025-11-27 15:39 ` [PATCH 3/5] sched: Change rcu_dereference_check_sched_domain() to rcu-sched Peter Zijlstra
2025-11-28 10:57   ` Peter Zijlstra
2025-11-28 11:04     ` Peter Zijlstra
2025-11-28 11:21       ` Paul E. McKenney
2025-11-28 11:37         ` Peter Zijlstra
2025-12-14  7:46   ` [tip: sched/core] sched/fair: Remove superfluous rcu_read_lock() tip-bot2 for Peter Zijlstra
2025-11-27 15:39 ` [PATCH 4/5] sched: Add assertions to QUEUE_CLASS Peter Zijlstra
2025-12-14  7:46   ` [tip: sched/core] sched/core: " tip-bot2 for Peter Zijlstra
2025-12-18 10:09   ` [PATCH 4/5] sched: " Marek Szyprowski
2025-12-18 10:12     ` Peter Zijlstra
2025-11-27 15:39 ` [PATCH 5/5] sched: Rework sched_class::wakeup_preempt() and rq_modified_*() Peter Zijlstra
2025-11-28 13:26   ` Kuba Piecuch
2025-11-28 13:36     ` Peter Zijlstra
2025-11-28 13:44       ` Peter Zijlstra
2025-11-28 22:29   ` Andrea Righi
2025-11-29 18:08   ` Shrikanth Hegde
2025-11-30 11:32     ` Peter Zijlstra
2025-11-30 13:03       ` Shrikanth Hegde
2025-12-02 23:27   ` Tejun Heo
2025-12-14  7:46   ` [tip: sched/core] sched/core: " tip-bot2 for Peter Zijlstra
2025-12-15  6:07   ` error: implicit declaration of function ‘rq_modified_clear’ (was [PATCH 5/5] sched: Rework sched_class::wakeup_preempt() and rq_modified_*()) Thorsten Leemhuis
2025-12-15  7:12     ` Ingo Molnar
2025-12-15 11:51       ` Nathan Chancellor
2025-12-16  7:02         ` Thorsten Leemhuis
2025-12-16 18:40           ` Tejun Heo
2025-12-16 21:42             ` Peter Zijlstra
2025-12-17  9:58               ` Peter Zijlstra
2025-12-15  7:59   ` [tip: sched/core] sched/core: Rework sched_class::wakeup_preempt() and rq_modified_*() tip-bot2 for Peter Zijlstra
2025-12-17 10:02   ` tip-bot2 for Peter Zijlstra

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=b26d7ab3-e07b-407b-bb24-6741d4043315@linux.ibm.com \
    --to=sshegde@linux.ibm.com \
    --cc=arighi@nvidia.com \
    --cc=bsegall@google.com \
    --cc=changwoo@igalia.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=void@manifault.com \
    --cc=vschneid@redhat.com \
    /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