[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251127140942.GW4067720@noisy.programming.kicks-ass.net>
Date: Thu, 27 Nov 2025 15:09:42 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: K Prateek Nayak <kprateek.nayak@....com>
Cc: Tim Chen <tim.c.chen@...ux.intel.com>,
Shrikanth Hegde <sshegde@...ux.ibm.com>,
linux-kernel@...r.kernel.org, linux-tip-commits@...r.kernel.org,
Chen Yu <yu.c.chen@...el.com>,
Vincent Guittot <vincent.guittot@...aro.org>,
Srikar Dronamraju <srikar@...ux.ibm.com>,
Mohini Narkhede <mohini.narkhede@...el.com>, x86@...nel.org
Subject: Re: [tip: sched/core] sched/fair: Skip sched_balance_running cmpxchg
when balance is not due
On Tue, Nov 18, 2025 at 12:30:36AM +0530, K Prateek Nayak wrote:
> On 11/18/2025 12:25 AM, Tim Chen wrote:
> >> I wondered what is really different since the tim's v4 boots fine.
> >> There is try instead in the tip, i think that is messing it since likely
> >> we are dereferencing 0?
> >>
> >>
> >> With this diff it boots fine.
> >>
> >> ---
> >> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> >> index aaa47ece6a8e..01814b10b833 100644
> >> --- a/kernel/sched/fair.c
> >> +++ b/kernel/sched/fair.c
> >> @@ -11841,7 +11841,7 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq,
> >> }
> >>
> >> if (!need_unlock && (sd->flags & SD_SERIALIZE)) {
> >> - if (!atomic_try_cmpxchg_acquire(&sched_balance_running, 0, 1))
> >
> > The second argument of atomic_try_cmpxchg_acquire is "int *old" while that of atomic_cmpxchg_acquire
> > is "int old". So the above check would result in NULL pointer access. Probably have
> > to do something like the following to use atomic_try_cmpxchg_acquire()
> >
> > int zero = 0;
> > if (!atomic_try_cmpxchg_acquire(&sched_balance_running, &zero, 1))
>
> Peter seems to have refreshed tip:sched/core with above but is
> there any advantage of using atomic_try_cmpxchg_acquire() as
> opposed to plain old atomic_cmpxchg_acquire() and then checking
> the old value it returns?
>
> That zero variable serves no other purpose and is a bit of an
> eyesore IMO.
Yeah, its not ideal. It should generate slightly saner code, since the
compiler can now use the condition codes set by cmpxchg instead of
having to do an extra compare.
Powered by blists - more mailing lists