locking/qspinlock: Enhance pvqspinlock performance
Subsystems (3)
v8 cover locking/qspinlock: Enhance pvqspinlock performance
v7->v8:
- Annotated the use of each _acquire/_release variants in qspinlock.c.
- Used the available pending bit in the lock stealing patch to disable lock stealing when the queue head vCPU is actively spinning on the lock to avoid lock starvation.
- Restructured the lock stealing patch to reduce code duplication.
- Verified that the waitcnt processing will be compiled away if QUEUED_LOCK_STAT isn't enabled.
v6->v7:
- Removed arch/x86/include/asm/qspinlock.h from patch 1.
- Removed the unconditional PV kick patch as it has been merged into tip.
- Changed the pvstat_inc() API to add a new condition parameter.
- Added comments and rearrange code in patch 4 to clarify where lock stealing happened.
- In patch 5, removed the check for pv_wait count when deciding when to wait early.
- Updated copyrights and email address.
v5->v6:
- Added a new patch 1 to relax the cmpxchg and xchg operations in the native code path to reduce performance overhead on non-x86 architectures.
- Updated the unconditional PV kick patch as suggested by PeterZ.
- Added a new patch to allow one lock stealing attempt at slowpath entry point to reduce performance penalty due to lock waiter preemption.
- Removed the pending bit and kick-ahead patches as they didn't show any noticeable performance improvement on top of the lock stealing patch.
- Simplified the adaptive spinning patch as the lock stealing patch allows more aggressive pv_wait() without much performance penalty in non-overcommitted VMs.
v4->v5:
- Rebased the patch to the latest tip tree.
- Corrected the comments and commit log for patch 1.
- Removed the v4 patch 5 as PV kick deferment is no longer needed with the new tip tree.
- Simplified the adaptive spinning patch (patch 6) & improve its performance a bit further.
- Re-ran the benchmark test with the new patch.
v3->v4:
- Patch 1: add comment about possible racing condition in PV unlock.
- Patch 2: simplified the pv_pending_lock() function as suggested by Davidlohr.
- Move PV unlock optimization patch forward to patch 4 & rerun performance test.
v2->v3:
- Moved deferred kicking enablement patch forward & move back the kick-ahead patch to make the effect of kick-ahead more visible.
- Reworked patch 6 to make it more readable.
- Reverted back to use state as a tri-state variable instead of adding an additional bistate variable.
- Added performance data for different values of PV_KICK_AHEAD_MAX.
- Add a new patch to optimize PV unlock code path performance.
v1->v2:
- Take out the queued unfair lock patches
- Add a patch to simplify the PV unlock code
- Move pending bit and statistics collection patches to the front
- Keep vCPU kicking in pv_kick_node(), but defer it to unlock time when appropriate.
- Change the wait-early patch to use adaptive spinning to better balance the difference effect on normal and over-committed guests.
- Add patch-to-patch performance changes in the patch commit logs.
This patchset tries to improve the performance of both regular and over-commmitted VM guests. The adaptive spinning patch was inspired by the "Do Virtual Machines Really Scale?" blog from Sanidhya Kashyap.
Patch 1 relaxes the memory order restriction of atomic operations by using less restrictive _acquire and _release variants of cmpxchg() and xchg(). This will reduce performance overhead when ported to other non-x86 architectures.
Patch 2 optimizes the PV unlock code path performance for x86-64 architecture.
Patch 3 allows the collection of various count data that are useful to see what is happening in the system. They do add a bit of overhead when enabled slowing performance a tiny bit.
Patch 4 allows one lock stealing attempt at slowpath entry. This causes a pretty big performance improvement for over-committed VM guests.
Patch 5 enables adaptive spinning in the queue nodes. This patch leads to further performance improvement in over-committed guest, though it is not as big as the previous patch.
Waiman Long (5):
locking/qspinlock: Use _acquire/_release versions of cmpxchg & xchg locking/pvqspinlock, x86: Optimize PV unlock code path locking/pvqspinlock: Collect slowpath lock statistics locking/pvqspinlock: Allow 1 lock stealing attempt locking/pvqspinlock: Queue node adaptive spinning
arch/x86/Kconfig | 9 + arch/x86/include/asm/qspinlock_paravirt.h | 59 +++++ include/asm-generic/qspinlock.h | 9 +- kernel/locking/qspinlock.c | 63 ++++-- kernel/locking/qspinlock_paravirt.h | 375 ++++++++++++++++++++++++++--- 5 files changed, 456 insertions(+), 59 deletions(-)
PATCH v8 1/5 locking/qspinlock: Use _acquire/_release versions of cmpxchg & xchg
This patch replaces the cmpxchg() and xchg() calls in the native qspinlock code with the more relaxed _acquire or _release versions of those calls to enable other architectures to adopt queued spinlocks with less memory barrier performance overhead.
--- include/asm-generic/qspinlock.h | 9 +++++---- kernel/locking/qspinlock.c | 29 ++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 9 deletions(-)
include/asm-generic/qspinlock.h +5 -4
@@ -12,8 +12,9 @@* GNU General Public License for more details. * * (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P. +* (C) Copyright 2015 Hewlett-Packard Enterprise Development LP * -* Authors: Waiman Long <[email protected]> +* Authors: Waiman Long <[email protected]> */ #ifndef __ASM_GENERIC_QSPINLOCK_H#define __ASM_GENERIC_QSPINLOCK_H
@@ -62,7 +63,7 @@ static __always_inline int queued_spin_is_contended(struct qspinlock *lock) static __always_inline int queued_spin_trylock(struct qspinlock *lock) {if (!atomic_read (&lock->val) && - (atomic_cmpxchg (&lock->val,0 , _Q_LOCKED_VAL) ==0 )) + (atomic_cmpxchg_acquire (&lock->val,0 , _Q_LOCKED_VAL) ==0 ))return 1 ;return 0 ; }
@@ -77,7 +78,7 @@ static __always_inline void queued_spin_lock(struct qspinlock *lock) {u32 val; - val =atomic_cmpxchg (&lock->val,0 , _Q_LOCKED_VAL); + val =atomic_cmpxchg_acquire (&lock->val,0 , _Q_LOCKED_VAL);if (likely (val ==0 ))return ;queued_spin_lock_slowpath (lock, val);
@@ -93,7 +94,7 @@ static __always_inline void queued_spin_unlock(struct qspinlock *lock)/* * smp_mb__before_atomic() in order to guarantee release semantics */ -smp_mb__before_atomic_dec (); +smp_mb__before_atomic (); atomic_sub(_Q_LOCKED_VAL, &lock->val); }#endif
kernel/locking/qspinlock.c +24 -5
@@ -14,8 +14,9 @@* (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P. * (C) Copyright 2013-2014 Red Hat, Inc. * (C) Copyright 2015 Intel Corp. +* (C) Copyright 2015 Hewlett-Packard Enterprise Development LP * -* Authors: Waiman Long <[email protected]> +* Authors: Waiman Long <[email protected]> * Peter Zijlstra <[email protected]> */
@@ -176,7 +177,12 @@ static __always_inline u32 xchg_tail(struct qspinlock *lock, u32 tail) {struct __qspinlock *l = (void *)lock; -return (u32 )xchg (&l->tail, tail >> _Q_TAIL_OFFSET) << _Q_TAIL_OFFSET; +/* +* Use release semantics to make sure that the MCS node is properly +* initialized before changing the tail code. +*/ +return (u32 )xchg_release (&l->tail, + tail >> _Q_TAIL_OFFSET) << _Q_TAIL_OFFSET; }#else /* _Q_PENDING_BITS == 8 */
@@ -208,7 +214,11 @@ static __always_inline u32 xchg_tail(struct qspinlock *lock, u32 tail)for (;;) { new = (val & _Q_LOCKED_PENDING_MASK) | tail; - old =atomic_cmpxchg (&lock->val, val, new); +/* +* Use release semantics to make sure that the MCS node is +* properly initialized before changing the tail code. +*/ + old =atomic_cmpxchg_release (&lock->val, val, new);if (old == val)break ;
@@ -319,7 +329,11 @@ void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)if (val == new) new |= _Q_PENDING_VAL; - old =atomic_cmpxchg (&lock->val, val, new); +/* +* Acquire semantic is required here as the function may +* return immediately if the lock was free. +*/ + old =atomic_cmpxchg_acquire (&lock->val, val, new);if (old == val)break ;
@@ -426,7 +440,12 @@ queue:set_locked (lock);break ; } - old =atomic_cmpxchg (&lock->val, val, _Q_LOCKED_VAL); +/* +* The smp_load_acquire() call above has provided the necessary +* acquire semantics required for locking. At most two +* iterations of this loop may be ran. +*/ + old =atomic_cmpxchg_relaxed (&lock->val, val, _Q_LOCKED_VAL);if (old == val) goto release;/* No contention */
Signature · 1 line
1.7.1
Re: [PATCH tip/locking/core v8 1/5] locking/qspinlock: Use _acquire/_release versions of cmpxchg & xchg
Hi Waiman,
Quoted 45 lines · Waiman Long
This patch replaces the
cmpxchg()andxchg()calls in the native qspinlock code with the more relaxed_acquireor_releaseversions of those calls to enable other architectures to adopt queued spinlocks with less memory barrier performance overhead.Signed-off-by Waiman Long <[email protected]>--- include/asm-generic/qspinlock.h | 9 +++++---- kernel/locking/qspinlock.c | 29 ++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 9 deletions(-)include/asm-generic/qspinlock.h +4
-3@@ -12,8 +12,9 @@* GNU General Public License for more details. * * (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P. +* (C) Copyright 2015 Hewlett-Packard Enterprise Development LP * -* Authors: Waiman Long <[email protected]> +* Authors: Waiman Long <[email protected]> */ #ifndef __ASM_GENERIC_QSPINLOCK_H#define __ASM_GENERIC_QSPINLOCK_H@@ -62,7 +63,7 @@ static __always_inline int queued_spin_is_contended(struct qspinlock *lock) static __always_inline int queued_spin_trylock(struct qspinlock *lock) {if (!atomic_read (&lock->val) && - (atomic_cmpxchg (&lock->val,0 , _Q_LOCKED_VAL) ==0 )) + (atomic_cmpxchg_acquire (&lock->val,0 , _Q_LOCKED_VAL) ==0 ))return 1 ;return 0 ; }@@ -77,7 +78,7 @@ static __always_inline void queued_spin_lock(struct qspinlock *lock) {u32 val; - val =atomic_cmpxchg (&lock->val,0 , _Q_LOCKED_VAL); + val =atomic_cmpxchg_acquire (&lock->val,0 , _Q_LOCKED_VAL);if (likely (val ==0 ))return ;queued_spin_lock_slowpath (lock, val);
include/asm-generic/qspinlock.h static __always_inline void queued_spin_unlock(struct qspinlock *lock) · line 98
Quoted 6 lines
include/asm-generic/qspinlock.h +1
-1@@ -93,7 +94,7 @@ static __always_inline void queued_spin_unlock(struct qspinlock *lock)/* * smp_mb__before_atomic() in order to guarantee release semantics */ -smp_mb__before_atomic_dec (); +smp_mb__before_atomic ();atomic_sub (_Q_LOCKED_VAL, &lock->val);
Just be curious, you don't use atomic_sub_release() here on purpose?
Regards,
Boqun
Quoted 2 lines
include/asm-generic/qspinlock.h +0
-0}#endif
Re: [PATCH tip/locking/core v8 1/5] locking/qspinlock: Use _acquire/_release versions of cmpxchg & xchg
Quoted 9 lines · Boqun Feng
include/asm-generic/qspinlock.h static __always_inline void queued_spin_unlock(struct qspinlock *lock) · line 98
Quoted 7 lines
include/asm-generic/qspinlock.h +1
-1@@ -93,7 +94,7 @@ static __always_inline void queued_spin_unlock(struct qspinlock *lock)/* * smp_mb__before_atomic() in order to guarantee release semantics */ -smp_mb__before_atomic_dec (); +smp_mb__before_atomic ();atomic_sub (_Q_LOCKED_VAL, &lock->val);Just be curious, you don't use
atomic_sub_release()here on purpose?
atomic_sub() does not imply barriers, so there's no relaxed variants; that's only for _return() (and such) to the caller.
Thanks,
Davidlohr
Re: [PATCH tip/locking/core v8 1/5] locking/qspinlock: Use _acquire/_release versions of cmpxchg & xchg
Quoted 12 lines · Davidlohr Bueso
Quoted 9 lines · Boqun Feng
include/asm-generic/qspinlock.h static __always_inline void queued_spin_unlock(struct qspinlock *lock) · line 98
Quoted 7 lines
include/asm-generic/qspinlock.h +1
-1@@ -93,7 +94,7 @@ static __always_inline void queued_spin_unlock(struct qspinlock *lock)/* * smp_mb__before_atomic() in order to guarantee release semantics */ -smp_mb__before_atomic_dec (); +smp_mb__before_atomic ();atomic_sub (_Q_LOCKED_VAL, &lock->val);Just be curious, you don't use
atomic_sub_release()here on purpose?
Quoted 3 lines
atomic_sub()does not imply barriers, so there's no relaxed variants; that's only for_return()(and such) to the caller.
Ah.. my mistake ;-(
Thank you.
Regards,
Boqun
Quoted 2 lines
Thanks,
Davidlohr
PATCH v8 2/5 locking/pvqspinlock, x86: Optimize PV unlock code path
In reply to Waiman LongThe unlock function in queued spinlocks was optimized for better performance on bare metal systems at the expense of virtualized guests.
For x86-64 systems, the unlock call needs to go through a PV_CALLEE_SAVE_REGS_THUNK() which saves and restores 8 64-bit registers before calling the real __pv_queued_spin_unlock() function. The thunk code may also be in a separate cacheline from __pv_queued_spin_unlock().
This patch optimizes the PV unlock code path by:
1) Moving the unlock slowpath code from the fastpath into a separate __pv_queued_spin_unlock_slowpath() function to make the fastpath as simple as possible..
2) For x86-64, hand-coded an assembly function to combine the register saving thunk code with the fastpath code. Only registers that are used in the fastpath will be saved and restored. If the fastpath fails, the slowpath function will be called via another PV_CALLEE_SAVE_REGS_THUNK(). For 32-bit, it falls back to the C __pv_queued_spin_unlock() code as the thunk saves and restores only one 32-bit register.
With a microbenchmark of 5M lock-unlock loop, the table below shows the execution times before and after the patch with different number of threads in a VM running on a 32-core Westmere-EX box with x86-64 4.2-rc1 based kernels:
Threads Before patch After patch % Change
------- ------------ ----------- --------
1 134.1 ms 119.3 ms -11%
2 1286 ms 953 ms -26%
3 3715 ms 3480 ms -6.3%
4 4092 ms 3764 ms -8.0%--- arch/x86/include/asm/qspinlock_paravirt.h | 59 +++++++++++++++++++++++++++++ kernel/locking/qspinlock_paravirt.h | 43 +++++++++++++-------- 2 files changed, 86 insertions(+), 16 deletions(-)
arch/x86/include/asm/qspinlock_paravirt.h +59 -0
@@ -1,6 +1,65 @@#ifndef __ASM_QSPINLOCK_PARAVIRT_H#define __ASM_QSPINLOCK_PARAVIRT_H +/* +* For x86-64, PV_CALLEE_SAVE_REGS_THUNK() saves and restores 8 64-bit +* registers. For i386, however, only 1 32-bit register needs to be saved +* and restored. So an optimized version of __pv_queued_spin_unlock() is +* hand-coded for 64-bit, but it isn't worthwhile to do it for 32-bit. +*/ +#ifdef CONFIG_64BIT + +PV_CALLEE_SAVE_REGS_THUNK (__pv_queued_spin_unlock_slowpath); +#define __pv_queued_spin_unlock __pv_queued_spin_unlock +#define PV_UNLOCK "__raw_callee_save___pv_queued_spin_unlock" +#define PV_UNLOCK_SLOWPATH "__raw_callee_save___pv_queued_spin_unlock_slowpath" + +/* +* Optimized assembly version of __raw_callee_save___pv_queued_spin_unlock +* which combines the registers saving trunk and the body of the following +* C code: +* +* void __pv_queued_spin_unlock(struct qspinlock *lock) +* { +* struct __qspinlock *l = (void *)lock; +* u8 lockval = cmpxchg(&l->locked, _Q_LOCKED_VAL, 0); +* +* if (likely(lockval == _Q_LOCKED_VAL)) +* return; +* pv_queued_spin_unlock_slowpath(lock, lockval); +* } +* +* For x86-64, +* rdi = lock (first argument) +* rsi = lockval (second argument) +* rdx = internal variable (set to 0) +*/ +asm (".pushsection .text;" +".globl " PV_UNLOCK ";" +".align 4,0x90;" +PV_UNLOCK ": " +"push %rdx;" +"mov $0x1,%eax;" +"xor %edx,%edx;" +"lock cmpxchg %dl,(%rdi);" +"cmp $0x1,%al;" +"jne .slowpath;" +"pop %rdx;" +"ret;" +".slowpath: " +"push %rsi;" +"movzbl %al,%esi;" +"call " PV_UNLOCK_SLOWPATH ";" +"pop %rsi;" +"pop %rdx;" +"ret;" +".size " PV_UNLOCK ", .-" PV_UNLOCK ";" +".popsection" ); + +#else /* CONFIG_64BIT */ + +extern void __pv_queued_spin_unlock (struct qspinlock *lock);PV_CALLEE_SAVE_REGS_THUNK (__pv_queued_spin_unlock); +#endif /* CONFIG_64BIT */ #endif
kernel/locking/qspinlock_paravirt.h +27 -16
62 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v8 3/5 locking/pvqspinlock: Collect slowpath lock statistics
In reply to Waiman LongThis patch enables the accumulation of kicking and waiting related PV qspinlock statistics when the new QUEUED_LOCK_STAT configuration option is selected. It also enables the collection of data which enable us to calculate the kicking and wakeup latencies which have a heavy dependency on the CPUs being used.
Debugfs is used for managing the statistics counts for its simplicity. It has the limitation that per-cpu statistic counters cannot be used. Therefore, atomic instructions will be needed to update the counters. This introduces a certain amount of performance overhead when this feature is enabled.
The measured latencies for different CPUs are:
CPU Wakeup Kicking --- ------ ------- Haswell-EX 63.6us 7.4us Westmere-EX 67.6us 9.3us
The measured latencies varied a bit from run-to-run. The wakeup latency is much higher than the kicking latency.
A sample of statistics counts after system bootup (with vCPU overcommit) was:
hash_hops_count=9001
kick_latencies=138047878
kick_unlock_count=9001
kick_wait_count=9000
spurious_wakeup=3
wait_again_count=2
wait_head_count=10
wait_node_count=8994
wake_latencies=713195944
--- arch/x86/Kconfig | 9 ++ kernel/locking/qspinlock_paravirt.h | 169 +++++++++++++++++++++++++++++++++- 2 files changed, 173 insertions(+), 5 deletions(-)
arch/x86/Kconfig +9 -0
@@ -721,6 +721,15 @@ config PARAVIRT_SPINLOCKS If you are unsure how to answer this question, answer Y. +config QUEUED_LOCK_STAT + bool "Paravirt queued lock statistics" + depends on PARAVIRT && DEBUG_FS && QUEUED_SPINLOCKS + ---help--- + Enable the collection of statistical data on the behavior of + paravirtualized queued spinlocks and report them on debugfs. + There will be a slight performance overhead when this option + is enabled. + source "arch/x86/xen/Kconfig" config KVM_GUEST
kernel/locking/qspinlock_paravirt.h +164 -5
240 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v8 4/5 locking/pvqspinlock: Allow 1 lock stealing attempt
In reply to Waiman LongThis patch allows one attempt for the lock waiter to steal the lock when entering the PV slowpath. To prevent lock starvation, the pending bit will be set by the queue head vCPU when it is in the active lock spinning loop to disable any lock stealing attempt. This helps to reduce the performance penalty caused by lock waiter preemption while not having much of the downsides of a real unfair lock.
The pv_wait_head() function was renamed as pv_wait_head_lock() as it was modified to acquire the lock before returning. This is necessary because of possible lock stealing attempts from other tasks.
Linux kernel builds were run in KVM guest on an 8-socket, 4 cores/socket Westmere-EX system and a 4-socket, 8 cores/socket Haswell-EX system. Both systems are configured to have 32 physical CPUs. The kernel build times before and after the patch were:
Westmere Haswell
Patch 32 vCPUs 48 vCPUs 32 vCPUs 48 vCPUs ----- -------- -------- -------- -------- Before patch 3m15.6s 10m56.1s 1m44.1s 5m29.1s
After patch 3m02.3s 5m00.2s 1m43.7s 3m03.5s
For the overcommited case (48 vCPUs), this patch is able to reduce kernel build time by more than 54% for Westmere and 44% for Haswell.
--- kernel/locking/qspinlock.c | 29 ++++++-- kernel/locking/qspinlock_paravirt.h | 126 +++++++++++++++++++++++++++++------ 2 files changed, 125 insertions(+), 30 deletions(-)
kernel/locking/qspinlock.c +21 -8
@@ -251,15 +251,16 @@ static __always_inline void __pv_init_node(struct mcs_spinlock *node) { } static __always_inline void __pv_wait_node(struct mcs_spinlock *node) { } static __always_inline void __pv_kick_node(struct qspinlock *lock,struct mcs_spinlock *node) { } -static __always_inline void __pv_wait_head(struct qspinlock *lock, -struct mcs_spinlock *node) { } +static __always_inline u32 __pv_wait_head_lock(struct qspinlock *lock, +struct mcs_spinlock *node) + {return 0 ; }#define pv_enabled () false#define pv_init_node __pv_init_node#define pv_wait_node __pv_wait_node#define pv_kick_node __pv_kick_node -#define pv_wait_head __pv_wait_head +#define pv_wait_head_lock __pv_wait_head_lock#ifdef CONFIG_PARAVIRT_SPINLOCKS #define queued_spin_lock_slowpath native_queued_spin_lock_slowpath
@@ -420,10 +421,22 @@ queue:* sequentiality; this is because the set_locked() function below * does not imply a full barrier. * +* The PV pv_wait_head_lock function, if active, will acquire the lock +* and return a non-zero value. So we have to skip the +* smp_load_acquire() call. As the next PV queue head hasn't been +* designated yet, there is no way for the locked value to become +* _Q_SLOW_VAL. So both the redundant set_locked() and the +* atomic_cmpxchg_relaxed() calls will be safe. The cost of the +* redundant set_locked() call below should be negligible, too. +* +* If PV isn't active, 0 will be returned instead. */ -pv_wait_head (lock, node); -while ((val =smp_load_acquire (&lock->val.counter)) & _Q_LOCKED_PENDING_MASK) -cpu_relax (); + val =pv_wait_head_lock (lock, node); +if (!val) { +while ((val =smp_load_acquire (&lock->val.counter)) + & _Q_LOCKED_PENDING_MASK) +cpu_relax (); + }/* * claim the lock:
@@ -436,7 +449,7 @@ queue:* to grab the lock. */ for (;;) { -if (val != tail) { +if ((val & _Q_TAIL_MASK) != tail) {set_locked (lock);break ; }
@@ -481,7 +494,7 @@ EXPORT_SYMBOL(queued_spin_lock_slowpath);#undef pv_init_node#undef pv_wait_node#undef pv_kick_node -#undef pv_wait_head +#undef pv_wait_head_lock#undef queued_spin_lock_slowpath#define queued_spin_lock_slowpath __pv_queued_spin_lock_slowpath
kernel/locking/qspinlock_paravirt.h +104 -22
208 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v8 5/5 locking/pvqspinlock: Queue node adaptive spinning
In reply to Waiman LongIn an overcommitted guest where some vCPUs have to be halted to make forward progress in other areas, it is highly likely that a vCPU later in the spinlock queue will be spinning while the ones earlier in the queue would have been halted. The spinning in the later vCPUs is then just a waste of precious CPU cycles because they are not going to get the lock soon as the earlier ones have to be woken up and take their turn to get the lock.
This patch implements an adaptive spinning mechanism where the vCPU will call pv_wait() if the previous vCPU is not running.
Linux kernel builds were run in KVM guest on an 8-socket, 4 cores/socket Westmere-EX system and a 4-socket, 8 cores/socket Haswell-EX system. Both systems are configured to have 32 physical CPUs. The kernel build times before and after the patch were:
Westmere Haswell
Patch 32 vCPUs 48 vCPUs 32 vCPUs 48 vCPUs
----- -------- -------- -------- --------
Before patch 3m02.3s 5m00.2s 1m43.7s 3m03.5s After patch 3m03.0s 4m37.5s 1m43.0s 2m47.2s
For 32 vCPUs, this patch doesn't cause any noticeable change in performance. For 48 vCPUs (over-committed), there is about 8% performance improvement.
--- kernel/locking/qspinlock.c | 5 ++- kernel/locking/qspinlock_paravirt.h | 47 +++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 4 deletions(-)
kernel/locking/qspinlock.c +3 -2
@@ -248,7 +248,8 @@ static __always_inline void set_locked(struct qspinlock *lock)*/ static __always_inline void __pv_init_node(struct mcs_spinlock *node) { } -static __always_inline void __pv_wait_node(struct mcs_spinlock *node) { } +static __always_inline void __pv_wait_node(struct mcs_spinlock *node, +struct mcs_spinlock *prev) { } static __always_inline void __pv_kick_node(struct qspinlock *lock,struct mcs_spinlock *node) { } static __always_inline u32 __pv_wait_head_lock(struct qspinlock *lock,
@@ -406,7 +407,7 @@ queue: prev =decode_tail (old);WRITE_ONCE (prev->next, node); -pv_wait_node (node); +pv_wait_node (node, prev);arch_mcs_spin_lock_contended (&node->locked); }
kernel/locking/qspinlock_paravirt.h +45 -2
104 lines not on this page · raw message
Signature · 1 line
1.7.1