Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: K. Y. Srinivasan <kys@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Dexuan Cui <decui@microsoft.com>
Cc: Long Li <longli@microsoft.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>

authored by

Uros Bizjak and committed by
Wei Liu
05976960 705d01c8

+4 -4
+2 -2
drivers/hv/hyperv_vmbus.h
··· 370 370 * CHANNELMSG_UNLOAD_RESPONSE and we don't care about other messages 371 371 * on crash. 372 372 */ 373 - if (cmpxchg(&msg->header.message_type, old_msg_type, 374 - HVMSG_NONE) != old_msg_type) 373 + if (!try_cmpxchg(&msg->header.message_type, 374 + &old_msg_type, HVMSG_NONE)) 375 375 return; 376 376 377 377 /*
+2 -2
drivers/hv/mshv_eventfd.c
··· 129 129 130 130 new_iv.vector[new_iv.vector_count++] = vector; 131 131 132 - if (cmpxchg(&vp->vp_register_page->interrupt_vectors.as_uint64, 133 - iv.as_uint64, new_iv.as_uint64) != iv.as_uint64) 132 + if (!try_cmpxchg(&vp->vp_register_page->interrupt_vectors.as_uint64, 133 + &iv.as_uint64, new_iv.as_uint64)) 134 134 return -EAGAIN; 135 135 136 136 return 0;