All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] block: Use try_cmpxchg in update_io_ticks
@ 2022-07-12 15:27 Uros Bizjak
  2022-07-12 20:40 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Uros Bizjak @ 2022-07-12 15:27 UTC (permalink / raw)
  To: linux-block, linux-kernel; +Cc: Uros Bizjak, Jens Axboe

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>
---
v2: Split patch from the original big patch
---
 block/blk-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index 27fb1357ad4b..628b965356db 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -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) {
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] block: Use try_cmpxchg in update_io_ticks
  2022-07-12 15:27 [PATCH v2] block: Use try_cmpxchg in update_io_ticks Uros Bizjak
@ 2022-07-12 20:40 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2022-07-12 20:40 UTC (permalink / raw)
  To: linux-kernel, ubizjak, linux-block

On Tue, 12 Jul 2022 17:27:41 +0200, Uros Bizjak wrote:
> 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,
-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-12 20:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-12 15:27 [PATCH v2] block: Use try_cmpxchg in update_io_ticks Uros Bizjak
2022-07-12 20:40 ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.