]> git.baikalelectronics.ru Git - kernel.git/commit
sbitmap: Use atomic_long_try_cmpxchg in __sbitmap_queue_get_batch
authorUros Bizjak <ubizjak@gmail.com>
Thu, 8 Sep 2022 15:12:00 +0000 (17:12 +0200)
committerJens Axboe <axboe@kernel.dk>
Thu, 8 Sep 2022 15:22:42 +0000 (09:22 -0600)
commitde4b3c3b18c99256b96b01736b88b3360e5ab57a
tree2cf72382f2a2bbedf515081f5fb6d4513742b82a
parentd4c7740083f3313ba70e1d9da9dacbf0b8a99d09
sbitmap: Use atomic_long_try_cmpxchg in __sbitmap_queue_get_batch

Use atomic_long_try_cmpxchg instead of
atomic_long_cmpxchg (*ptr, old, new) == old in __sbitmap_queue_get_batch.
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, atomic_long_cmpxchg implicitly assigns old *ptr value to "old"
when cmpxchg fails, enabling further code simplifications, e.g.
an extra memory read can be avoided in the loop.

No functional change intended.

Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Link: https://lore.kernel.org/r/20220908151200.9993-1-ubizjak@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
lib/sbitmap.c