Skip to contentSkip to conversation

block: Use try_cmpxchg in update_io_ticks

PATCH Applied Uros Bizjak 2 participants 2 messages Jul 12, 2022 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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.

---
v2: Split patch from the original big patch

---
 block/blk-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-core.c +1 -1
index 27fb1357ad4b..628b965356db 100644
@@ -987,7 +987,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) {
Signature · 1 line
2.35.3
maintainer Applied
#1 lore raw
Quoted 8 lines · Uros Bizjak

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.

[...]

Applied, thanks!

[1/1] block: Use try_cmpxchg in update_io_ticks

      commit: 939f9dd040fe1063d884f8f0f89b037093fe2341

Best regards,

Signature · 1 line
Jens Axboe