[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230118131825.c6daea81ea1e2dc6aa014f38@linux-foundation.org>
Date: Wed, 18 Jan 2023 13:18:25 -0800
From: Andrew Morton <akpm@...ux-foundation.org>
To: Uros Bizjak <ubizjak@...il.com>
Cc: linux-kernel@...r.kernel.org
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@...il.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.
Powered by blists - more mailing lists