Commit 939f9dd0 authored by Uros Bizjak's avatar Uros Bizjak Committed by Jens Axboe

block: Use try_cmpxchg in update_io_ticks

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: default avatarUros Bizjak <ubizjak@gmail.com>
Cc: Jens Axboe <axboe@kernel.dk>
Link: https://lore.kernel.org/r/20220712152741.7324-1-ubizjak@gmail.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent f4b1e27d
...@@ -943,7 +943,7 @@ void update_io_ticks(struct block_device *part, unsigned long now, bool end) ...@@ -943,7 +943,7 @@ void update_io_ticks(struct block_device *part, unsigned long now, bool end)
again: again:
stamp = READ_ONCE(part->bd_stamp); stamp = READ_ONCE(part->bd_stamp);
if (unlikely(time_after(now, 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); __part_stat_add(part, io_ticks, end ? now - stamp : 1);
} }
if (part->bd_partno) { if (part->bd_partno) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment