Messages in this thread | | | Date | Wed, 18 Jan 2023 13:18:25 -0800 | From | Andrew Morton <> | Subject | Re: [PATCH] lib/genalloc: use try_cmpxchg in {set,clear}_bits_ll |
| |
On Wed, 18 Jan 2023 16:07:03 +0100 Uros Bizjak <ubizjak@gmail.com> wrote:
> Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in > {set,clear}_bits_ll. x86 CMPXCHG instruction returns success in ZF > flag, so this change saves a compare after cmpxchg (and related move > instruction in front of cmpxchg). > > Also, try_cmpxchg implicitly assigns old *ptr value to "old" > when cmpxchg fails. > > Note that the value from *ptr should be read using READ_ONCE to prevent > the compiler from merging, refetching or reordering the read. > > The patch also declares these two functions inline, to ensure inlining.
But why is that better? This adds a few hundred bytes more text, which has a cost.
| |