From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Dave Hansen <dave.hansen@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>, Uros Bizjak <ubizjak@gmail.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, Dennis Zhou <dennis@kernel.org>,
Tejun Heo <tj@kernel.org>, Christoph Lameter <cl@linux.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>
Subject: Re: [PATCH v1 1/1] x86/percpu: Cast -1 to argument type when comparing in percpu_add_op()
Date: Wed, 23 Oct 2024 17:24:52 +0300 [thread overview]
Message-ID: <ZxkHNDB6EcA7PouV@smile.fi.intel.com> (raw)
In-Reply-To: <c22fd9c5-6727-46c2-a811-784315edf7cb@intel.com>
On Tue, Oct 22, 2024 at 12:53:01PM -0700, Dave Hansen wrote:
> On 10/17/24 11:18, Peter Zijlstra wrote:
> > On Wed, Oct 16, 2024 at 12:44:18PM -0700, Dave Hansen wrote:
...
> >> Would anybody hate if we broke this up a bit, like:
> >>
> >> const typeof(var) _val = val;
> >> const int paoconst = __builtin_constant_p(val);
> >> const int paoinc = paoconst && ((_val) == 1);
> >> const int paodec = paoconst && ((_val) == (typeof(var))-1);
> >>
> >> and then did
> >>
> >> if (paoinc)
> >> percpu_unary_op(size, qual, "inc", var);
> >> ...
> > I think that is an overall improvement. Proceed! 🙂
>
> I poked at this a bit:
Thanks for looking into this!
> > https://git.kernel.org/pub/scm/linux/kernel/git/daveh/devel.git/commit/?h=testme&id=30e0899c6ab7fe1134e4b96db963f0be89b1dd5a
>
> I believe it functions fine. But it surprised me with a few things.
> Here's one. I assumed that doing an add((unsigned)-1) would be rare.
> It's not. It's actually pretty common because this:
>
> #define this_cpu_sub(pcp, val) this_cpu_add(pcp, -(typeof(pcp))(val))
>
> ends up causing problems when 'pcp' is an unsigned type. For example,
> in this chain:
>
> mem_cgroup_exit ->
> obj_cgroup_put ->
> percpu_ref_put ->
> percpu_ref_put_many(ref, 1) ->
> this_cpu_sub
>
> the compiler can see the '1' constant. It effectively expands to:
>
> this_cpu_add(pcp, -(unsigned long)(1))
>
> With the old code, gcc manages to generate a 'dec'. Clang generates an
> 'add'. With my hack above both compilers generate an 'add'. This
> actually matters in some code that seems potentially rather performance
> sensitive:
>
> add/remove: 0/0 grow/shrink: 219/9 up/down: 755/-141 (614)
> Function old new delta
> flush_end_io 905 1070 +165
> x86_pmu_cancel_txn 242 338 +96
> lru_add 554 594 +40
> mlock_folio_batch 3264 3300 +36
> compaction_alloc 3813 3838 +25
> tcp_leave_memory_pressure 86 110 +24
> account_guest_time 270 287 +17
> ...
>
> So I think Peter's version was the best. It shuts up clang and also
> preserves the existing (good) gcc 'sub' behavior. I'll send it out for
> real in a bit, but I'm thinking of something like the attached patch.
I am fine as long as you keep the (added) test cases and maybe even extend
them. I dunno how you will go with the fact that Andrew applied my version
already.
...
> This can be quickly reproduced by setting CONFIG_WERROR=y and running:
>
> make W=1 CC=clang-14 net/ipv4/tcp_output.o
Hint: You can use LLVM=-14 instead of CC=clang-14.
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2024-10-23 14:25 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-05 17:03 [PATCH v1 1/1] x86/percpu: Cast -1 to argument type when comparing in percpu_add_op() Andy Shevchenko
2024-10-16 13:37 ` Andy Shevchenko
2024-10-16 15:44 ` Dave Hansen
2024-10-16 17:03 ` Nick Desaulniers
2024-10-16 18:06 ` Andy Shevchenko
2024-10-16 18:20 ` Andy Shevchenko
2024-10-16 19:43 ` Dave Hansen
2024-10-16 19:20 ` Peter Zijlstra
2024-10-16 19:44 ` Dave Hansen
2024-10-17 18:18 ` Peter Zijlstra
2024-10-18 12:21 ` Andy Shevchenko
2024-10-22 19:53 ` Dave Hansen
2024-10-22 23:24 ` Christoph Lameter (Ampere)
2024-10-23 17:15 ` Dave Hansen
2024-10-23 21:40 ` H. Peter Anvin
2024-10-23 14:24 ` Andy Shevchenko [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=ZxkHNDB6EcA7PouV@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=bp@alien8.de \
--cc=cl@linux.com \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=dennis@kernel.org \
--cc=hpa@zytor.com \
--cc=justinstitt@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=llvm@lists.linux.dev \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=ubizjak@gmail.com \
--cc=x86@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.