Re: [tip: sched/core] sched/fair: Skip sched_balance_running cmpxchg when balance is not due
From: Peter Zijlstra
Date: Tue Nov 18 2025 - 04:56:31 EST
And now with Nathan as a recipient..
On Tue, Nov 18, 2025 at 10:54:33AM +0100, Peter Zijlstra wrote:
> On Mon, Nov 17, 2025 at 10:55:07AM -0800, Tim Chen wrote:
>
> > > 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))
> >
> > Otherwise we should do atomic_cmpxchg_acquire() as below
>
> Yes, and I'm all mightily miffed all the compilers accept 0 (which is
> int) for an 'int *' argument without so much as a warning :/
>
> Nathan, you looked into this a bit yesterday, afaict there is:
>
> -Wzero-as-null-pointer-constant
>
> which is supposed to issue a warn here, but I can't get clang-22 to
> object :/ (GCC doesn't take that warning for C mode, only C++, perhaps
> that's the problem?).
>
> And then there is modernize-use-nullptr, but that objects to using NULL,
> although I suppose we could do:
>
> #define NULL nullptr
>
> to get around that. Except I also cannot get clangd to report on the
> issue.
>
> Help?