]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: plock: use an ARMv8 instruction barrier for the pause instruction
authorYour Name <you@example.com>
Sat, 28 Nov 2020 15:37:14 +0000 (15:37 +0000)
committerWilly Tarreau <w@1wt.eu>
Sun, 29 Nov 2020 13:53:33 +0000 (14:53 +0100)
As suggested by @AGSaidi in issue #958, on ARMv8 its convenient to use
an "isb" instruction in pl_cpu_relax() to improve fairness. Without it
I've met a few watchdog conditions on valid locks with 16 threads,
indicating that some threads couldn't manage to get it in 2 seconds. I
never happened again with it. In addition, the performance increased
by slightly more than 5% thanks to the reduced contention.

This should be backported as far as 2.2, possibly even 2.0.

include/import/atomic-ops.h

index 6fe4c78f4fb94aa3b4e3837b1a504a717fedc069..1d9c98ba51ee58e5ce18d882893a3f5ec10a80f7 100644 (file)
 #else
 /* generic implementations */
 
+#if defined(__aarch64__)
+
+/* This was shown to improve fairness on modern ARMv8 such as Neoverse N1 */
+#define pl_cpu_relax() do {                            \
+               asm volatile("isb" ::: "memory");       \
+       } while (0)
+
+#else
+
 #define pl_cpu_relax() do {             \
                asm volatile("");       \
        } while (0)
 
+#endif
+
 /* full memory barrier */
 #define pl_mb() do {                    \
                __sync_synchronize();   \