]> xenbits.xensource.com Git - xen.git/commit
x86: Use LOCK ADD instead of MFENCE for smp_mb()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 21 Sep 2020 12:17:30 +0000 (13:17 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 1 Oct 2020 10:14:22 +0000 (11:14 +0100)
commitde16a8fa0db7f1879442cf9cfe865eb2e9d98e6d
treebda34eabaec29649710649e798bf10f10adcce50
parent707eb41ae2dde4636261f631224c97e9c0b16b56
x86: Use LOCK ADD instead of MFENCE for smp_mb()

MFENCE is overly heavyweight for SMP semantics on WB memory, because it also
orders weaker cached writes, and flushes the WC buffers.

This technique was used as an optimisation in Java[1], and later adopted by
Linux[2] where it was measured to have a 60% performance improvement in VirtIO
benchmarks.

The stack is used because it is hot in the L1 cache, and a -4 offset is used
to avoid creating a false data dependency on live data.

For 64bit userspace, the Red Zone needs to be considered.  Use -32 to allow
for a reasonable quantity of Red Zone data, but still have a 50% chance of
hitting the same cache line as %rsp.

Fix up the 32 bit definitions in HVMLoader and libxc to avoid a false data
dependency.

[1] https://shipilev.net/blog/2014/on-the-fence-with-dependencies/
[2] https://git.kernel.org/torvalds/c/450cbdd0125cfa5d7bbf9e2a6b6961cc48d29730

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Wei Liu <wl@xen.org>
tools/firmware/hvmloader/util.h
tools/libs/ctrl/include/xenctrl.h
xen/include/asm-x86/system.h