mshv: Use try_cmpxchg() instead of cmpxchg()
Subsystems (2)
PATCH 1/1 mshv: Use try_cmpxchg() instead of cmpxchg()
Use !try_cmpxchg() instead of cmpxchg (*ptr, old, new) != old. x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg().
The generated assembly code improves from e.g.:
415: 48 8b 44 24 30 mov 0x30(%rsp),%rax
41a: 48 8b 54 24 38 mov 0x38(%rsp),%rdx
41f: f0 49 0f b1 91 a8 02 lock cmpxchg %rdx,0x2a8(%r9)
426: 00 00
428: 48 3b 44 24 30 cmp 0x30(%rsp),%rax
42d: 0f 84 09 ff ff ff je 33c <...>to:
415: 48 8b 44 24 30 mov 0x30(%rsp),%rax
41a: 48 8b 54 24 38 mov 0x38(%rsp),%rdx
41f: f0 49 0f b1 91 a8 02 lock cmpxchg %rdx,0x2a8(%r9)
426: 00 00
428: 0f 84 0e ff ff ff je 33c <...>No functional change intended.
--- drivers/hv/hyperv_vmbus.h | 4 ++-- drivers/hv/mshv_eventfd.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/hv/hyperv_vmbus.h +2 -2
@@ -370,8 +370,8 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)* CHANNELMSG_UNLOAD_RESPONSE and we don't care about other messages * on crash. */ -if (cmpxchg (&msg->header.message_type, old_msg_type, -HVMSG_NONE ) != old_msg_type) +if (!try_cmpxchg (&msg->header.message_type, + &old_msg_type,HVMSG_NONE ))return ;/*
drivers/hv/mshv_eventfd.c +2 -2
@@ -128,8 +128,8 @@ static int mshv_vp_irq_try_set_vector(struct mshv_vp *vp, u32 vector) new_iv.vector[new_iv.vector_count++] = vector; -if (cmpxchg (&vp->vp_register_page->interrupt_vectors.as_uint64, - iv.as_uint64, new_iv.as_uint64) != iv.as_uint64) +if (!try_cmpxchg (&vp->vp_register_page->interrupt_vectors.as_uint64, + &iv.as_uint64, new_iv.as_uint64))return -EAGAIN ;return 0 ;
Signature · 1 line
2.53.0
PATCH RESEND 1/1 mshv: Use try_cmpxchg() instead of cmpxchg()
Use !try_cmpxchg() instead of cmpxchg (*ptr, old, new) != old. x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after CMPXCHG.
The generated assembly code improves from e.g.:
415: 48 8b 44 24 30 mov 0x30(%rsp),%rax
41a: 48 8b 54 24 38 mov 0x38(%rsp),%rdx
41f: f0 49 0f b1 91 a8 02 lock cmpxchg %rdx,0x2a8(%r9)
426: 00 00
428: 48 3b 44 24 30 cmp 0x30(%rsp),%rax
42d: 0f 84 09 ff ff ff je 33c <...>to:
415: 48 8b 44 24 30 mov 0x30(%rsp),%rax
41a: 48 8b 54 24 38 mov 0x38(%rsp),%rdx
41f: f0 49 0f b1 91 a8 02 lock cmpxchg %rdx,0x2a8(%r9)
426: 00 00
428: 0f 84 0e ff ff ff je 33c <...>No functional change intended.
--- drivers/hv/hyperv_vmbus.h | 4 ++-- drivers/hv/mshv_eventfd.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/hv/hyperv_vmbus.h +2 -2
@@ -370,8 +370,8 @@ static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)* CHANNELMSG_UNLOAD_RESPONSE and we don't care about other messages * on crash. */ -if (cmpxchg (&msg->header.message_type, old_msg_type, -HVMSG_NONE ) != old_msg_type) +if (!try_cmpxchg (&msg->header.message_type, + &old_msg_type,HVMSG_NONE ))return ;/*
drivers/hv/mshv_eventfd.c +2 -2
@@ -128,8 +128,8 @@ static int mshv_vp_irq_try_set_vector(struct mshv_vp *vp, u32 vector) new_iv.vector[new_iv.vector_count++] = vector; -if (cmpxchg (&vp->vp_register_page->interrupt_vectors.as_uint64, - iv.as_uint64, new_iv.as_uint64) != iv.as_uint64) +if (!try_cmpxchg (&vp->vp_register_page->interrupt_vectors.as_uint64, + &iv.as_uint64, new_iv.as_uint64))return -EAGAIN ;return 0 ;
Signature · 1 line
2.53.0
Quoted 21 lines · Uros Bizjak
Use !try_cmpxchg() instead of cmpxchg (*ptr, old, new) != old. x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after CMPXCHG.
The generated assembly code improves from e.g.:
415: 48 8b 44 24 30 mov 0x30(%rsp),%rax 41a: 48 8b 54 24 38 mov 0x38(%rsp),%rdx 41f: f0 49 0f b1 91 a8 02 lock cmpxchg %rdx,0x2a8(%r9) 426: 00 00 428: 48 3b 44 24 30 cmp 0x30(%rsp),%rax 42d: 0f 84 09 ff ff ff je 33c <...>to:
415: 48 8b 44 24 30 mov 0x30(%rsp),%rax 41a: 48 8b 54 24 38 mov 0x38(%rsp),%rdx 41f: f0 49 0f b1 91 a8 02 lock cmpxchg %rdx,0x2a8(%r9) 426: 00 00 428: 0f 84 0e ff ff ff je 33c <...>
Quoted 8 lines
No functional change intended.
Signed-off-by Uros Bizjak <[email protected]>Cc "K. Y. Srinivasan" <[email protected]>Cc Haiyang Zhang <[email protected]>Cc Wei Liu <[email protected]>Cc Dexuan Cui <[email protected]>Cc Long Li <[email protected]>
Applied. Thanks.