]> git.baikalelectronics.ru Git - kernel.git/commitdiff
block: Use try_cmpxchg in update_io_ticks
authorUros Bizjak <ubizjak@gmail.com>
Tue, 12 Jul 2022 15:27:41 +0000 (17:27 +0200)
committerJens Axboe <axboe@kernel.dk>
Tue, 12 Jul 2022 20:39:06 +0000 (14:39 -0600)
Use try_cmpxchg instead of cmpxchg (*ptr, old, new) == old in
update_io_ticks. x86 CMPXCHG instruction returns success in ZF flag,
so this change saves a compare after cmpxchg (and related
move instruction in front of cmpxchg).

No functional change intended.

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

index b530ce7b370c43bf54b3e0e90576663f1d94238d..8365996a8ef80271e43fbccc12a8932e80a3a34a 100644 (file)
@@ -943,7 +943,7 @@ void update_io_ticks(struct block_device *part, unsigned long now, bool end)
 again:
        stamp = READ_ONCE(part->bd_stamp);
        if (unlikely(time_after(now, stamp))) {
-               if (likely(cmpxchg(&part->bd_stamp, stamp, now) == stamp))
+               if (likely(try_cmpxchg(&part->bd_stamp, &stamp, now)))
                        __part_stat_add(part, io_ticks, end ? now - stamp : 1);
        }
        if (part->bd_partno) {