lkml.org 
[lkml]   [2023]   [Jan]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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.

\
 
 \ /
  Last update: 2023-03-26 23:46    [W:0.103 / U:0.144 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site