qspinlock: a 4-byte queue spinlock with PV support
Subsystems (8)
v13 cover qspinlock: a 4-byte queue spinlock with PV support
v12->v13:
- Change patch 9 to generate separate versions of the queue_spin_lock_slowpath functions for bare metal and PV guest. This reduces the performance impact of the PV code on bare metal systems.
v11->v12:
- Based on PeterZ's version of the qspinlock patch
(https://lkml.org/lkml/2014/6/15/63).
- Incorporated many of the review comments from Konrad Wilk and Paolo Bonzini.
- The pvqspinlock code is largely from my previous version with PeterZ's way of going from queue tail to head and his idea of using callee saved calls to KVM and XEN codes.
v10->v11:
- Use a simple test-and-set unfair lock to simplify the code, but performance may suffer a bit for large guest with many CPUs.
- Take out Raghavendra KT's test results as the unfair lock changes may render some of his results invalid.
- Add PV support without increasing the size of the core queue node structure.
- Other minor changes to address some of the feedback comments.
v9->v10:
- Make some minor changes to qspinlock.c to accommodate review feedback.
- Change author to PeterZ for 2 of the patches.
- Include Raghavendra KT's test results in patch 18.
v8->v9:
- Integrate PeterZ's version of the queue spinlock patch with some
modification:
http://lkml.kernel.org/r/[email protected] - Break the more complex patches into smaller ones to ease review effort.
- Fix a racing condition in the PV qspinlock code.
v7->v8:
- Remove one unneeded atomic operation from the slowpath, thus improving performance.
- Simplify some of the codes and add more comments.
- Test for X86_FEATURE_HYPERVISOR CPU feature bit to enable/disable unfair lock.
- Reduce unfair lock slowpath lock stealing frequency depending on its distance from the queue head.
- Add performance data for IvyBridge-EX CPU.
v6->v7:
- Remove an atomic operation from the 2-task contending code
- Shorten the names of some macros
- Make the queue waiter to attempt to steal lock when unfair lock is enabled.
- Remove lock holder kick from the PV code and fix a race condition
- Run the unfair lock & PV code on overcommitted KVM guests to collect performance data.
v5->v6:
- Change the optimized 2-task contending code to make it fairer at the expense of a bit of performance.
- Add a patch to support unfair queue spinlock for Xen.
- Modify the PV qspinlock code to follow what was done in the PV ticketlock.
- Add performance data for the unfair lock as well as the PV support code.
v4->v5:
- Move the optimized 2-task contending code to the generic file to enable more architectures to use it without code duplication.
- Address some of the style-related comments by PeterZ.
- Allow the use of unfair queue spinlock in a real para-virtualized execution environment.
- Add para-virtualization support to the qspinlock code by ensuring that the lock holder and queue head stay alive as much as possible.
v3->v4:
- Remove debugging code and fix a configuration error
- Simplify the qspinlock structure and streamline the code to make it perform a bit better
- Add an x86 version of asm/qspinlock.h for holding x86 specific optimization.
- Add an optimized x86 code path for 2 contending tasks to improve low contention performance.
v2->v3:
- Simplify the code by using numerous mode only without an unfair option.
- Use the latest smp_load_acquire()/smp_store_release() barriers.
- Move the queue spinlock code to kernel/locking.
- Make the use of queue spinlock the default for x86-64 without user configuration.
- Additional performance tuning.
v1->v2:
- Add some more comments to document what the code does.
- Add a numerous CPU mode to support >= 16K CPUs
- Add a configuration option to allow lock stealing which can further improve performance in many cases.
- Enable wakeup of queue head CPU at unlock time for non-numerous CPU mode.
This patch set has 3 different sections:
1) Patches 1-6: Introduces a queue-based spinlock implementation that can replace the default ticket spinlock without increasing the size of the spinlock data structure. As a result, critical kernel data structures that embed spinlock won't increase in size and break data alignments.
2) Patch 7: Enables the use of unfair lock in a virtual guest. This can resolve some of the locking related performance issues due to the fact that the next CPU to get the lock may have been scheduled out for a period of time.
3) Patches 8-11: Enable qspinlock para-virtualization support by halting the waiting CPUs after spinning for a certain amount of time. The unlock code will detect the a sleeping waiter and wake it up. This is essentially the same logic as the PV ticketlock code.
The queue spinlock has slightly better performance than the ticket spinlock in uncontended case. Its performance can be much better with moderate to heavy contention. This patch has the potential of improving the performance of all the workloads that have moderate to heavy spinlock contention.
The queue spinlock is especially suitable for NUMA machines with at least 2 sockets. Though even at the 2-socket level, there can be significant speedup depending on the workload. I got report that the queue spinlock patch can improve the performance of an I/O and interrupt intensive stress test with a lot of spinlock contention on a 2-socket system by up to 20%.
The purpose of this patch set is not to solve any particular spinlock contention problems. Those need to be solved by refactoring the code to make more efficient use of the lock or finer granularity ones. The main purpose is to make the lock contention problems more tolerable until someone can spend the time and effort to fix them.
Peter Zijlstra (3):
qspinlock: Add pending bit
qspinlock: Optimize for smaller NR_CPUS
qspinlock: Revert to test-and-set on hypervisors
Waiman Long (8):
qspinlock: A simple generic 4-byte queue spinlock qspinlock, x86: Enable x86-64 to use queue spinlock
qspinlock: Extract out code snippets for the next patch
qspinlock: Use a simple write to grab the lock qspinlock, x86: Rename paravirt_ticketlocks_enabled pvqspinlock, x86: Add para-virtualization support pvqspinlock, x86: Enable PV qspinlock for KVM pvqspinlock, x86: Enable PV qspinlock for XEN
arch/x86/Kconfig | 1 + arch/x86/include/asm/paravirt.h | 19 ++ arch/x86/include/asm/paravirt_types.h | 20 ++ arch/x86/include/asm/pvqspinlock.h | 411 ++++++++++++++++++++++++++++ arch/x86/include/asm/qspinlock.h | 104 +++++++ arch/x86/include/asm/spinlock.h | 9 +- arch/x86/include/asm/spinlock_types.h | 4 + arch/x86/kernel/kvm.c | 140 ++++++++++- arch/x86/kernel/paravirt-spinlocks.c | 10 +- arch/x86/xen/spinlock.c | 151 ++++++++++- include/asm-generic/qspinlock.h | 127 +++++++++ include/asm-generic/qspinlock_types.h | 79 ++++++ kernel/Kconfig.locks | 7 + kernel/locking/Makefile | 1 + kernel/locking/mcs_spinlock.h | 1 + kernel/locking/qspinlock.c | 473 +++++++++++++++++++++++++++++++++ 16 files changed, 1545 insertions(+), 12 deletions(-) create mode 100644 arch/x86/include/asm/pvqspinlock.h create mode 100644 arch/x86/include/asm/qspinlock.h create mode 100644 include/asm-generic/qspinlock.h create mode 100644 include/asm-generic/qspinlock_types.h create mode 100644 kernel/locking/qspinlock.c
PATCH v13 1/11 qspinlock: A simple generic 4-byte queue spinlock
This patch introduces a new generic queue spinlock implementation that can serve as an alternative to the default ticket spinlock. Compared with the ticket spinlock, this queue spinlock should be almost as fair as the ticket spinlock. It has about the same speed in single-thread and it can be much faster in high contention situations especially when the spinlock is embedded within the data structure to be protected.
Only in light to moderate contention where the average queue depth is around 1-3 will this queue spinlock be potentially a bit slower due to the higher slowpath overhead.
This queue spinlock is especially suit to NUMA machines with a large number of cores as the chance of spinlock contention is much higher in those machines. The cost of contention is also higher because of slower inter-node memory traffic.
Due to the fact that spinlocks are acquired with preemption disabled, the process will not be migrated to another CPU while it is trying to get a spinlock. Ignoring interrupt handling, a CPU can only be contending in one spinlock at any one time. Counting soft IRQ, hard IRQ and NMI, a CPU can only have a maximum of 4 concurrent lock waiting activities. By allocating a set of per-cpu queue nodes and used them to form a waiting queue, we can encode the queue node address into a much smaller 24-bit size (including CPU number and queue node index) leaving one byte for the lock.
Please note that the queue node is only needed when waiting for the lock. Once the lock is acquired, the queue node can be released to be used later.
--- include/asm-generic/qspinlock.h | 118 +++++++++++++++++++ include/asm-generic/qspinlock_types.h | 58 +++++++++ kernel/Kconfig.locks | 7 + kernel/locking/Makefile | 1 + kernel/locking/mcs_spinlock.h | 1 + kernel/locking/qspinlock.c | 207 +++++++++++++++++++++++++++++++++ 6 files changed, 392 insertions(+), 0 deletions(-) create mode 100644 include/asm-generic/qspinlock.h create mode 100644 include/asm-generic/qspinlock_types.h create mode 100644 kernel/locking/qspinlock.c
include/asm-generic/qspinlock.h new file +118 -0
@@ -0,0 +1,118 @@ +/* +* Queue spinlock +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* (C) Copyright 2013-2014 Hewlett-Packard Development Company, L.P. +* +* Authors: Waiman Long <[email protected]> +*/ +#ifndef __ASM_GENERIC_QSPINLOCK_H +#define __ASM_GENERIC_QSPINLOCK_H + +#include <asm-generic/qspinlock_types.h> + +/** +* queue_spin_is_locked - is the spinlock locked? +* @lock: Pointer to queue spinlock structure +* Return: 1 if it is locked, 0 otherwise +*/ +static __always_inline int queue_spin_is_locked(struct qspinlock *lock) +{ +return atomic_read (&lock->val); +} + +/** +* queue_spin_value_unlocked - is the spinlock structure unlocked? +* @lock: queue spinlock structure +* Return: 1 if it is unlocked, 0 otherwise +* +* N.B. Whenever there are tasks waiting for the lock, it is considered +* locked wrt the lockref code to avoid lock stealing by the lockref +* code and change things underneath the lock. This also allows some +* optimizations to be applied without conflict with lockref. +*/ +static __always_inline int queue_spin_value_unlocked(struct qspinlock lock) +{ +return !atomic_read (&lock.val); +} + +/** +* queue_spin_is_contended - check if the lock is contended +* @lock : Pointer to queue spinlock structure +* Return: 1 if lock contended, 0 otherwise +*/ +static __always_inline int queue_spin_is_contended(struct qspinlock *lock) +{ +return atomic_read (&lock->val) & ~_Q_LOCKED_MASK; +} +/** +* queue_spin_trylock - try to acquire the queue spinlock +* @lock : Pointer to queue spinlock structure +* Return: 1 if lock acquired, 0 if failed +*/ +static __always_inline int queue_spin_trylock(struct qspinlock *lock) +{ +if (!atomic_read (&lock->val) && + (atomic_cmpxchg (&lock->val,0 , _Q_LOCKED_VAL) ==0 )) +return 1 ; +return 0 ; +} + +extern void queue_spin_lock_slowpath (struct qspinlock *lock,u32 val); + +/** +* queue_spin_lock - acquire a queue spinlock +* @lock: Pointer to queue spinlock structure +*/ +static __always_inline void queue_spin_lock(struct qspinlock *lock) +{ +u32 val; + + val =atomic_cmpxchg (&lock->val,0 , _Q_LOCKED_VAL); +if (likely (val ==0 )) +return ; +queue_spin_lock_slowpath (lock, val); +} + +#ifndef queue_spin_unlock +/** +* queue_spin_unlock - release a queue spinlock +* @lock : Pointer to queue spinlock structure +*/ +static __always_inline void queue_spin_unlock(struct qspinlock *lock) +{ +/* +* smp_mb__before_atomic() in order to guarantee release semantics +*/ +smp_mb__before_atomic_dec (); +atomic_sub (_Q_LOCKED_VAL, &lock->val); +} +#endif + +/* +* Initializier +*/ +#define __ARCH_SPIN_LOCK_UNLOCKED { ATOMIC_INIT(0) } + +/* +* Remapping spinlock architecture specific functions to the corresponding +* queue spinlock functions. +*/ +#define arch_spin_is_locked (l) queue_spin_is_locked(l) +#define arch_spin_is_contended (l) queue_spin_is_contended(l) +#define arch_spin_value_unlocked (l) queue_spin_value_unlocked(l) +#define arch_spin_lock (l) queue_spin_lock(l) +#define arch_spin_trylock (l) queue_spin_trylock(l) +#define arch_spin_unlock (l) queue_spin_unlock(l) +#define arch_spin_lock_flags (l, f) queue_spin_lock(l) + +#endif /* __ASM_GENERIC_QSPINLOCK_H */
include/asm-generic/qspinlock_types.h new file +58 -0
58 lines not on this page · raw message
kernel/Kconfig.locks +7 -0
@@ -231,6 +231,13 @@ config RWSEM_SPIN_ON_OWNER def_bool y depends on SMP && RWSEM_XCHGADD_ALGORITHM && ARCH_SUPPORTS_ATOMIC_RMW +config ARCH_USE_QUEUE_SPINLOCK + bool + +config QUEUE_SPINLOCK + def_bool y if ARCH_USE_QUEUE_SPINLOCK + depends on SMP && !PARAVIRT_SPINLOCKS + config ARCH_USE_QUEUE_RWLOCK bool
kernel/locking/Makefile +1 -0
@@ -16,6 +16,7 @@ endif obj-$(CONFIG_SMP) += spinlock.o obj-$(CONFIG_SMP) += lglock.o obj-$(CONFIG_PROVE_LOCKING) += spinlock.o +obj-$(CONFIG_QUEUE_SPINLOCK) += qspinlock.o obj-$(CONFIG_RT_MUTEXES) += rtmutex.o obj-$(CONFIG_DEBUG_RT_MUTEXES) += rtmutex-debug.o obj-$(CONFIG_RT_MUTEX_TESTER) += rtmutex-tester.o
kernel/locking/mcs_spinlock.h +1 -0
@@ -17,6 +17,7 @@struct mcs_spinlock {struct mcs_spinlock *next;int locked;/* 1 if lock acquired */ +int count;/* nesting count, see qspinlock.c */ };#ifndef arch_mcs_spin_lock_contended
kernel/locking/qspinlock.c new file +207 -0
207 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v13 1/11 qspinlock: A simple generic 4-byte queue spinlock
In reply to Waiman LongThis patch introduces a new generic queue spinlock implementation that can serve as an alternative to the default ticket spinlock. Compared with the ticket spinlock, this queue spinlock should be almost as fair as the ticket spinlock. It has about the same speed in single-thread and it can be much faster in high contention situations especially when the spinlock is embedded within the data structure to be protected.
Only in light to moderate contention where the average queue depth is around 1-3 will this queue spinlock be potentially a bit slower due to the higher slowpath overhead.
This queue spinlock is especially suit to NUMA machines with a large number of cores as the chance of spinlock contention is much higher in those machines. The cost of contention is also higher because of slower inter-node memory traffic.
Due to the fact that spinlocks are acquired with preemption disabled, the process will not be migrated to another CPU while it is trying to get a spinlock. Ignoring interrupt handling, a CPU can only be contending in one spinlock at any one time. Counting soft IRQ, hard IRQ and NMI, a CPU can only have a maximum of 4 concurrent lock waiting activities. By allocating a set of per-cpu queue nodes and used them to form a waiting queue, we can encode the queue node address into a much smaller 24-bit size (including CPU number and queue node index) leaving one byte for the lock.
Please note that the queue node is only needed when waiting for the lock. Once the lock is acquired, the queue node can be released to be used later.
--- include/asm-generic/qspinlock.h | 118 +++++++++++++++++++ include/asm-generic/qspinlock_types.h | 58 +++++++++ kernel/Kconfig.locks | 7 + kernel/locking/Makefile | 1 + kernel/locking/mcs_spinlock.h | 1 + kernel/locking/qspinlock.c | 207 +++++++++++++++++++++++++++++++++ 6 files changed, 392 insertions(+), 0 deletions(-) create mode 100644 include/asm-generic/qspinlock.h create mode 100644 include/asm-generic/qspinlock_types.h create mode 100644 kernel/locking/qspinlock.c
include/asm-generic/qspinlock.h new file +118 -0
@@ -0,0 +1,118 @@ +/* +* Queue spinlock +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* (C) Copyright 2013-2014 Hewlett-Packard Development Company, L.P. +* +* Authors: Waiman Long <[email protected]> +*/ +#ifndef __ASM_GENERIC_QSPINLOCK_H +#define __ASM_GENERIC_QSPINLOCK_H + +#include <asm-generic/qspinlock_types.h> + +/** +* queue_spin_is_locked - is the spinlock locked? +* @lock: Pointer to queue spinlock structure +* Return: 1 if it is locked, 0 otherwise +*/ +static __always_inline int queue_spin_is_locked(struct qspinlock *lock) +{ +return atomic_read (&lock->val); +} + +/** +* queue_spin_value_unlocked - is the spinlock structure unlocked? +* @lock: queue spinlock structure +* Return: 1 if it is unlocked, 0 otherwise +* +* N.B. Whenever there are tasks waiting for the lock, it is considered +* locked wrt the lockref code to avoid lock stealing by the lockref +* code and change things underneath the lock. This also allows some +* optimizations to be applied without conflict with lockref. +*/ +static __always_inline int queue_spin_value_unlocked(struct qspinlock lock) +{ +return !atomic_read (&lock.val); +} + +/** +* queue_spin_is_contended - check if the lock is contended +* @lock : Pointer to queue spinlock structure +* Return: 1 if lock contended, 0 otherwise +*/ +static __always_inline int queue_spin_is_contended(struct qspinlock *lock) +{ +return atomic_read (&lock->val) & ~_Q_LOCKED_MASK; +} +/** +* queue_spin_trylock - try to acquire the queue spinlock +* @lock : Pointer to queue spinlock structure +* Return: 1 if lock acquired, 0 if failed +*/ +static __always_inline int queue_spin_trylock(struct qspinlock *lock) +{ +if (!atomic_read (&lock->val) && + (atomic_cmpxchg (&lock->val,0 , _Q_LOCKED_VAL) ==0 )) +return 1 ; +return 0 ; +} + +extern void queue_spin_lock_slowpath (struct qspinlock *lock,u32 val); + +/** +* queue_spin_lock - acquire a queue spinlock +* @lock: Pointer to queue spinlock structure +*/ +static __always_inline void queue_spin_lock(struct qspinlock *lock) +{ +u32 val; + + val =atomic_cmpxchg (&lock->val,0 , _Q_LOCKED_VAL); +if (likely (val ==0 )) +return ; +queue_spin_lock_slowpath (lock, val); +} + +#ifndef queue_spin_unlock +/** +* queue_spin_unlock - release a queue spinlock +* @lock : Pointer to queue spinlock structure +*/ +static __always_inline void queue_spin_unlock(struct qspinlock *lock) +{ +/* +* smp_mb__before_atomic() in order to guarantee release semantics +*/ +smp_mb__before_atomic_dec (); +atomic_sub (_Q_LOCKED_VAL, &lock->val); +} +#endif + +/* +* Initializier +*/ +#define __ARCH_SPIN_LOCK_UNLOCKED { ATOMIC_INIT(0) } + +/* +* Remapping spinlock architecture specific functions to the corresponding +* queue spinlock functions. +*/ +#define arch_spin_is_locked (l) queue_spin_is_locked(l) +#define arch_spin_is_contended (l) queue_spin_is_contended(l) +#define arch_spin_value_unlocked (l) queue_spin_value_unlocked(l) +#define arch_spin_lock (l) queue_spin_lock(l) +#define arch_spin_trylock (l) queue_spin_trylock(l) +#define arch_spin_unlock (l) queue_spin_unlock(l) +#define arch_spin_lock_flags (l, f) queue_spin_lock(l) + +#endif /* __ASM_GENERIC_QSPINLOCK_H */
include/asm-generic/qspinlock_types.h new file +58 -0
58 lines not on this page · raw message
kernel/Kconfig.locks +7 -0
@@ -231,6 +231,13 @@ config RWSEM_SPIN_ON_OWNER def_bool y depends on SMP && RWSEM_XCHGADD_ALGORITHM && ARCH_SUPPORTS_ATOMIC_RMW +config ARCH_USE_QUEUE_SPINLOCK + bool + +config QUEUE_SPINLOCK + def_bool y if ARCH_USE_QUEUE_SPINLOCK + depends on SMP && !PARAVIRT_SPINLOCKS + config ARCH_USE_QUEUE_RWLOCK bool
kernel/locking/Makefile +1 -0
@@ -16,6 +16,7 @@ endif obj-$(CONFIG_SMP) += spinlock.o obj-$(CONFIG_SMP) += lglock.o obj-$(CONFIG_PROVE_LOCKING) += spinlock.o +obj-$(CONFIG_QUEUE_SPINLOCK) += qspinlock.o obj-$(CONFIG_RT_MUTEXES) += rtmutex.o obj-$(CONFIG_DEBUG_RT_MUTEXES) += rtmutex-debug.o obj-$(CONFIG_RT_MUTEX_TESTER) += rtmutex-tester.o
kernel/locking/mcs_spinlock.h +1 -0
@@ -17,6 +17,7 @@struct mcs_spinlock {struct mcs_spinlock *next;int locked;/* 1 if lock acquired */ +int count;/* nesting count, see qspinlock.c */ };#ifndef arch_mcs_spin_lock_contended
kernel/locking/qspinlock.c new file +207 -0
207 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v13 2/11 qspinlock, x86: Enable x86-64 to use queue spinlock
In reply to Waiman LongThis patch makes the necessary changes at the x86 architecture specific layer to enable the use of queue spinlock for x86-64. As x86-32 machines are typically not multi-socket. The benefit of queue spinlock may not be apparent. So queue spinlock is not enabled.
Currently, there is some incompatibilities between the para-virtualized spinlock code (which hard-codes the use of ticket spinlock) and the queue spinlock. Therefore, the use of queue spinlock is disabled when the para-virtualized spinlock is enabled.
The arch/x86/include/asm/qspinlock.h header file includes some x86 specific optimization which will make the queue spinlock code perform better than the generic implementation.
--- arch/x86/Kconfig | 1 + arch/x86/include/asm/qspinlock.h | 25 +++++++++++++++++++++++++ arch/x86/include/asm/spinlock.h | 5 +++++ arch/x86/include/asm/spinlock_types.h | 4 ++++ 4 files changed, 35 insertions(+), 0 deletions(-) create mode 100644 arch/x86/include/asm/qspinlock.h
arch/x86/Kconfig +1 -0
@@ -122,6 +122,7 @@ config X86 select MODULES_USE_ELF_RELA if X86_64 select CLONE_BACKWARDS if X86_32 select ARCH_USE_BUILTIN_BSWAP + select ARCH_USE_QUEUE_SPINLOCK select ARCH_USE_QUEUE_RWLOCK select OLD_SIGSUSPEND3 if X86_32 || IA32_EMULATION select OLD_SIGACTION if X86_32
arch/x86/include/asm/qspinlock.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef _ASM_X86_QSPINLOCK_H +#define _ASM_X86_QSPINLOCK_H + +#include <asm-generic/qspinlock_types.h> + +#ifndef CONFIG_X86_PPRO_FENCE + +#define queue_spin_unlock queue_spin_unlock +/** +* queue_spin_unlock - release a queue spinlock +* @lock : Pointer to queue spinlock structure +* +* An effective smp_store_release() on the least-significant byte. +*/ +static inline void queue_spin_unlock (struct qspinlock *lock) +{ +barrier (); +ACCESS_ONCE (*(u8 *)lock) =0 ; +} + +#endif /* !CONFIG_X86_PPRO_FENCE */ + +#include <asm-generic/qspinlock.h> + +#endif /* _ASM_X86_QSPINLOCK_H */
arch/x86/include/asm/spinlock.h +5 -0
@@ -42,6 +42,10 @@extern struct static_key paravirt_ticketlocks_enabled; static __always_inline bool static_key_false(struct static_key *key); +#ifdef CONFIG_QUEUE_SPINLOCK +#include <asm/qspinlock.h> +#else +#ifdef CONFIG_PARAVIRT_SPINLOCKS static inline void __ticket_enter_slowpath (arch_spinlock_t *lock)
@@ -180,6 +184,7 @@ static __always_inline void arch_spin_lock_flags(arch_spinlock_t *lock, {arch_spin_lock (lock); } +#endif /* CONFIG_QUEUE_SPINLOCK */ static inline void arch_spin_unlock_wait (arch_spinlock_t *lock) {
arch/x86/include/asm/spinlock_types.h +4 -0
@@ -23,6 +23,9 @@ typedef u32 __ticketpair_t;#define TICKET_SHIFT (sizeof(__ticket_t) * 8) +#ifdef CONFIG_QUEUE_SPINLOCK +#include <asm-generic/qspinlock_types.h> +#else typedef struct arch_spinlock { union { __ticketpair_t head_tail;
@@ -33,6 +36,7 @@ typedef struct arch_spinlock { } arch_spinlock_t;#define __ARCH_SPIN_LOCK_UNLOCKED { { 0 } } +#endif /* CONFIG_QUEUE_SPINLOCK */ #include <asm-generic/qrwlock_types.h>
Signature · 1 line
1.7.1
PATCH v13 2/11 qspinlock, x86: Enable x86-64 to use queue spinlock
In reply to Waiman LongThis patch makes the necessary changes at the x86 architecture specific layer to enable the use of queue spinlock for x86-64. As x86-32 machines are typically not multi-socket. The benefit of queue spinlock may not be apparent. So queue spinlock is not enabled.
Currently, there is some incompatibilities between the para-virtualized spinlock code (which hard-codes the use of ticket spinlock) and the queue spinlock. Therefore, the use of queue spinlock is disabled when the para-virtualized spinlock is enabled.
The arch/x86/include/asm/qspinlock.h header file includes some x86 specific optimization which will make the queue spinlock code perform better than the generic implementation.
--- arch/x86/Kconfig | 1 + arch/x86/include/asm/qspinlock.h | 25 +++++++++++++++++++++++++ arch/x86/include/asm/spinlock.h | 5 +++++ arch/x86/include/asm/spinlock_types.h | 4 ++++ 4 files changed, 35 insertions(+), 0 deletions(-) create mode 100644 arch/x86/include/asm/qspinlock.h
arch/x86/Kconfig +1 -0
@@ -122,6 +122,7 @@ config X86 select MODULES_USE_ELF_RELA if X86_64 select CLONE_BACKWARDS if X86_32 select ARCH_USE_BUILTIN_BSWAP + select ARCH_USE_QUEUE_SPINLOCK select ARCH_USE_QUEUE_RWLOCK select OLD_SIGSUSPEND3 if X86_32 || IA32_EMULATION select OLD_SIGACTION if X86_32
arch/x86/include/asm/qspinlock.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef _ASM_X86_QSPINLOCK_H +#define _ASM_X86_QSPINLOCK_H + +#include <asm-generic/qspinlock_types.h> + +#ifndef CONFIG_X86_PPRO_FENCE + +#define queue_spin_unlock queue_spin_unlock +/** +* queue_spin_unlock - release a queue spinlock +* @lock : Pointer to queue spinlock structure +* +* An effective smp_store_release() on the least-significant byte. +*/ +static inline void queue_spin_unlock (struct qspinlock *lock) +{ +barrier (); +ACCESS_ONCE (*(u8 *)lock) =0 ; +} + +#endif /* !CONFIG_X86_PPRO_FENCE */ + +#include <asm-generic/qspinlock.h> + +#endif /* _ASM_X86_QSPINLOCK_H */
arch/x86/include/asm/spinlock.h +5 -0
@@ -42,6 +42,10 @@extern struct static_key paravirt_ticketlocks_enabled; static __always_inline bool static_key_false(struct static_key *key); +#ifdef CONFIG_QUEUE_SPINLOCK +#include <asm/qspinlock.h> +#else +#ifdef CONFIG_PARAVIRT_SPINLOCKS static inline void __ticket_enter_slowpath (arch_spinlock_t *lock)
@@ -180,6 +184,7 @@ static __always_inline void arch_spin_lock_flags(arch_spinlock_t *lock, {arch_spin_lock (lock); } +#endif /* CONFIG_QUEUE_SPINLOCK */ static inline void arch_spin_unlock_wait (arch_spinlock_t *lock) {
arch/x86/include/asm/spinlock_types.h +4 -0
@@ -23,6 +23,9 @@ typedef u32 __ticketpair_t;#define TICKET_SHIFT (sizeof(__ticket_t) * 8) +#ifdef CONFIG_QUEUE_SPINLOCK +#include <asm-generic/qspinlock_types.h> +#else typedef struct arch_spinlock { union { __ticketpair_t head_tail;
@@ -33,6 +36,7 @@ typedef struct arch_spinlock { } arch_spinlock_t;#define __ARCH_SPIN_LOCK_UNLOCKED { { 0 } } +#endif /* CONFIG_QUEUE_SPINLOCK */ #include <asm-generic/qrwlock_types.h>
Signature · 1 line
1.7.1
PATCH v13 3/11 qspinlock: Add pending bit
In reply to Waiman LongFrom: Peter Zijlstra <[email protected]>
Because the qspinlock needs to touch a second cacheline (the per-cpu mcs_nodes[]); add a pending bit and allow a single in-word spinner before we punt to the second cacheline.
It is possible so observe the pending bit without the locked bit when the last owner has just released but the pending owner has not yet taken ownership.
In this case we would normally queue -- because the pending bit is already taken. However, in this case the pending bit is guaranteed to be released 'soon', therefore wait for it and avoid queueing.
--- include/asm-generic/qspinlock_types.h | 12 +++- kernel/locking/qspinlock.c | 119 +++++++++++++++++++++++++++------ 2 files changed, 107 insertions(+), 24 deletions(-)
include/asm-generic/qspinlock_types.h +9 -3
@@ -36,8 +36,9 @@ typedef struct qspinlock {* Bitfields in the atomic value: * * 0- 7: locked byte -* 8- 9: tail index -* 10-31: tail cpu (+1) +* 8: pending +* 9-10: tail index +* 11-31: tail cpu (+1) */ #define _Q_SET_MASK (type) (((1U << _Q_ ## type ## _BITS) - 1)\ << _Q_ ## type ## _OFFSET)
@@ -45,7 +46,11 @@ typedef struct qspinlock {#define _Q_LOCKED_BITS 8#define _Q_LOCKED_MASK _Q_SET_MASK(LOCKED) -#define _Q_TAIL_IDX_OFFSET (_Q_LOCKED_OFFSET + _Q_LOCKED_BITS) +#define _Q_PENDING_OFFSET (_Q_LOCKED_OFFSET + _Q_LOCKED_BITS) +#define _Q_PENDING_BITS 1 +#define _Q_PENDING_MASK _Q_SET_MASK(PENDING) + +#define _Q_TAIL_IDX_OFFSET (_Q_PENDING_OFFSET + _Q_PENDING_BITS)#define _Q_TAIL_IDX_BITS 2#define _Q_TAIL_IDX_MASK _Q_SET_MASK(TAIL_IDX)
@@ -54,5 +59,6 @@ typedef struct qspinlock {#define _Q_TAIL_CPU_MASK _Q_SET_MASK(TAIL_CPU)#define _Q_LOCKED_VAL (1U << _Q_LOCKED_OFFSET) +#define _Q_PENDING_VAL (1U << _Q_PENDING_OFFSET)#endif /* __ASM_GENERIC_QSPINLOCK_TYPES_H */
kernel/locking/qspinlock.c +98 -21
168 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v13 3/11 qspinlock: Add pending bit
In reply to Waiman LongFrom: Peter Zijlstra <[email protected]>
Because the qspinlock needs to touch a second cacheline (the per-cpu mcs_nodes[]); add a pending bit and allow a single in-word spinner before we punt to the second cacheline.
It is possible so observe the pending bit without the locked bit when the last owner has just released but the pending owner has not yet taken ownership.
In this case we would normally queue -- because the pending bit is already taken. However, in this case the pending bit is guaranteed to be released 'soon', therefore wait for it and avoid queueing.
--- include/asm-generic/qspinlock_types.h | 12 +++- kernel/locking/qspinlock.c | 119 +++++++++++++++++++++++++++------ 2 files changed, 107 insertions(+), 24 deletions(-)
include/asm-generic/qspinlock_types.h +9 -3
@@ -36,8 +36,9 @@ typedef struct qspinlock {* Bitfields in the atomic value: * * 0- 7: locked byte -* 8- 9: tail index -* 10-31: tail cpu (+1) +* 8: pending +* 9-10: tail index +* 11-31: tail cpu (+1) */ #define _Q_SET_MASK (type) (((1U << _Q_ ## type ## _BITS) - 1)\ << _Q_ ## type ## _OFFSET)
@@ -45,7 +46,11 @@ typedef struct qspinlock {#define _Q_LOCKED_BITS 8#define _Q_LOCKED_MASK _Q_SET_MASK(LOCKED) -#define _Q_TAIL_IDX_OFFSET (_Q_LOCKED_OFFSET + _Q_LOCKED_BITS) +#define _Q_PENDING_OFFSET (_Q_LOCKED_OFFSET + _Q_LOCKED_BITS) +#define _Q_PENDING_BITS 1 +#define _Q_PENDING_MASK _Q_SET_MASK(PENDING) + +#define _Q_TAIL_IDX_OFFSET (_Q_PENDING_OFFSET + _Q_PENDING_BITS)#define _Q_TAIL_IDX_BITS 2#define _Q_TAIL_IDX_MASK _Q_SET_MASK(TAIL_IDX)
@@ -54,5 +59,6 @@ typedef struct qspinlock {#define _Q_TAIL_CPU_MASK _Q_SET_MASK(TAIL_CPU)#define _Q_LOCKED_VAL (1U << _Q_LOCKED_OFFSET) +#define _Q_PENDING_VAL (1U << _Q_PENDING_OFFSET)#endif /* __ASM_GENERIC_QSPINLOCK_TYPES_H */
kernel/locking/qspinlock.c +98 -21
168 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v13 4/11 qspinlock: Extract out code snippets for the next patch
In reply to Waiman LongThis is a preparatory patch that extracts out the following 2 code snippets to prepare for the next performance optimization patch.
1) the logic for the exchange of new and previous tail code words into a new xchg_tail() function.
2) the logic for clearing the pending bit and setting the locked bit into a new clear_pending_set_locked() function.
This patch also simplifies the trylock operation before queuing by calling queue_spin_trylock() directly.
--- include/asm-generic/qspinlock_types.h | 2 + kernel/locking/qspinlock.c | 91 +++++++++++++++++++++----------- 2 files changed, 62 insertions(+), 31 deletions(-)
include/asm-generic/qspinlock_types.h +2 -0
@@ -58,6 +58,8 @@ typedef struct qspinlock {#define _Q_TAIL_CPU_BITS (32 - _Q_TAIL_CPU_OFFSET)#define _Q_TAIL_CPU_MASK _Q_SET_MASK(TAIL_CPU) +#define _Q_TAIL_MASK (_Q_TAIL_IDX_MASK | _Q_TAIL_CPU_MASK) +#define _Q_LOCKED_VAL (1U << _Q_LOCKED_OFFSET)#define _Q_PENDING_VAL (1U << _Q_PENDING_OFFSET)
kernel/locking/qspinlock.c +60 -31
118 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v13 4/11 qspinlock: Extract out code snippets for the next patch
In reply to Waiman LongThis is a preparatory patch that extracts out the following 2 code snippets to prepare for the next performance optimization patch.
1) the logic for the exchange of new and previous tail code words into a new xchg_tail() function.
2) the logic for clearing the pending bit and setting the locked bit into a new clear_pending_set_locked() function.
This patch also simplifies the trylock operation before queuing by calling queue_spin_trylock() directly.
--- include/asm-generic/qspinlock_types.h | 2 + kernel/locking/qspinlock.c | 91 +++++++++++++++++++++----------- 2 files changed, 62 insertions(+), 31 deletions(-)
include/asm-generic/qspinlock_types.h +2 -0
@@ -58,6 +58,8 @@ typedef struct qspinlock {#define _Q_TAIL_CPU_BITS (32 - _Q_TAIL_CPU_OFFSET)#define _Q_TAIL_CPU_MASK _Q_SET_MASK(TAIL_CPU) +#define _Q_TAIL_MASK (_Q_TAIL_IDX_MASK | _Q_TAIL_CPU_MASK) +#define _Q_LOCKED_VAL (1U << _Q_LOCKED_OFFSET)#define _Q_PENDING_VAL (1U << _Q_PENDING_OFFSET)
kernel/locking/qspinlock.c +60 -31
118 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v13 5/11 qspinlock: Optimize for smaller NR_CPUS
In reply to Waiman LongFrom: Peter Zijlstra <[email protected]>
When we allow for a max NR_CPUS < 2^14 we can optimize the pending wait-acquire and the xchg_tail() operations.
By growing the pending bit to a byte, we reduce the tail to 16bit. This means we can use xchg16 for the tail part and do away with all the repeated compxchg() operations.
This in turn allows us to unconditionally acquire; the locked state as observed by the wait loops cannot change. And because both locked and pending are now a full byte we can use simple stores for the state transition, obviating one atomic operation entirely.
This optimization is needed to make the qspinlock achieve performance parity with ticket spinlock at light load.
All this is horribly broken on Alpha pre EV56 (and any other arch that cannot do single-copy atomic byte stores).
--- include/asm-generic/qspinlock_types.h | 13 ++++++ kernel/locking/qspinlock.c | 71 ++++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 1 deletions(-)
include/asm-generic/qspinlock_types.h +13 -0
@@ -35,6 +35,14 @@ typedef struct qspinlock {/* * Bitfields in the atomic value: * +* When NR_CPUS < 16K +* 0- 7: locked byte +* 8: pending +* 9-15: not used +* 16-17: tail index +* 18-31: tail cpu (+1) +* +* When NR_CPUS >= 16K * 0- 7: locked byte * 8: pending * 9-10: tail index
@@ -47,7 +55,11 @@ typedef struct qspinlock {#define _Q_LOCKED_MASK _Q_SET_MASK(LOCKED)#define _Q_PENDING_OFFSET (_Q_LOCKED_OFFSET + _Q_LOCKED_BITS) +#if CONFIG_NR_CPUS < (1U <<14 ) +#define _Q_PENDING_BITS 8 +#else #define _Q_PENDING_BITS 1 +#endif #define _Q_PENDING_MASK _Q_SET_MASK(PENDING)#define _Q_TAIL_IDX_OFFSET (_Q_PENDING_OFFSET + _Q_PENDING_BITS)
@@ -58,6 +70,7 @@ typedef struct qspinlock {#define _Q_TAIL_CPU_BITS (32 - _Q_TAIL_CPU_OFFSET)#define _Q_TAIL_CPU_MASK _Q_SET_MASK(TAIL_CPU) +#define _Q_TAIL_OFFSET _Q_TAIL_IDX_OFFSET#define _Q_TAIL_MASK (_Q_TAIL_IDX_MASK | _Q_TAIL_CPU_MASK)#define _Q_LOCKED_VAL (1U << _Q_LOCKED_OFFSET)
kernel/locking/qspinlock.c +70 -1
102 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v13 5/11 qspinlock: Optimize for smaller NR_CPUS
In reply to Waiman LongFrom: Peter Zijlstra <[email protected]>
When we allow for a max NR_CPUS < 2^14 we can optimize the pending wait-acquire and the xchg_tail() operations.
By growing the pending bit to a byte, we reduce the tail to 16bit. This means we can use xchg16 for the tail part and do away with all the repeated compxchg() operations.
This in turn allows us to unconditionally acquire; the locked state as observed by the wait loops cannot change. And because both locked and pending are now a full byte we can use simple stores for the state transition, obviating one atomic operation entirely.
This optimization is needed to make the qspinlock achieve performance parity with ticket spinlock at light load.
All this is horribly broken on Alpha pre EV56 (and any other arch that cannot do single-copy atomic byte stores).
--- include/asm-generic/qspinlock_types.h | 13 ++++++ kernel/locking/qspinlock.c | 71 ++++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 1 deletions(-)
include/asm-generic/qspinlock_types.h +13 -0
@@ -35,6 +35,14 @@ typedef struct qspinlock {/* * Bitfields in the atomic value: * +* When NR_CPUS < 16K +* 0- 7: locked byte +* 8: pending +* 9-15: not used +* 16-17: tail index +* 18-31: tail cpu (+1) +* +* When NR_CPUS >= 16K * 0- 7: locked byte * 8: pending * 9-10: tail index
@@ -47,7 +55,11 @@ typedef struct qspinlock {#define _Q_LOCKED_MASK _Q_SET_MASK(LOCKED)#define _Q_PENDING_OFFSET (_Q_LOCKED_OFFSET + _Q_LOCKED_BITS) +#if CONFIG_NR_CPUS < (1U <<14 ) +#define _Q_PENDING_BITS 8 +#else #define _Q_PENDING_BITS 1 +#endif #define _Q_PENDING_MASK _Q_SET_MASK(PENDING)#define _Q_TAIL_IDX_OFFSET (_Q_PENDING_OFFSET + _Q_PENDING_BITS)
@@ -58,6 +70,7 @@ typedef struct qspinlock {#define _Q_TAIL_CPU_BITS (32 - _Q_TAIL_CPU_OFFSET)#define _Q_TAIL_CPU_MASK _Q_SET_MASK(TAIL_CPU) +#define _Q_TAIL_OFFSET _Q_TAIL_IDX_OFFSET#define _Q_TAIL_MASK (_Q_TAIL_IDX_MASK | _Q_TAIL_CPU_MASK)#define _Q_LOCKED_VAL (1U << _Q_LOCKED_OFFSET)
kernel/locking/qspinlock.c +70 -1
102 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v13 6/11 qspinlock: Use a simple write to grab the lock
In reply to Waiman LongCurrently, atomic_cmpxchg() is used to get the lock. However, this is not really necessary if there is more than one task in the queue and the queue head don't need to reset the tail code. For that case, a simple write to set the lock bit is enough as the queue head will be the only one eligible to get the lock as long as it checks that both the lock and pending bits are not set. The current pending bit waiting code will ensure that the bit will not be set as soon as the tail code in the lock is set.
With that change, the are some slight improvement in the performance of the queue spinlock in the 5M loop micro-benchmark run on a 4-socket Westere-EX machine as shown in the tables below.
[Standalone/Embedded - same node]
# of tasks Before patch After patch %Change
---------- ----------- ---------- -------
3 2324/2321 2248/2265 -3%/-2%
4 2890/2896 2819/2831 -2%/-2%
5 3611/3595 3522/3512 -2%/-2%
6 4281/4276 4173/4160 -3%/-3%
7 5018/5001 4875/4861 -3%/-3%
8 5759/5750 5563/5568 -3%/-3%[Standalone/Embedded - different nodes]
# of tasks Before patch After patch %Change
---------- ----------- ---------- -------
3 12242/12237 12087/12093 -1%/-1%
4 10688/10696 10507/10521 -2%/-2%It was also found that this change produced a much bigger performance improvement in the newer IvyBridge-EX chip and was essentially to close the performance gap between the ticket spinlock and queue spinlock.
The disk workload of the AIM7 benchmark was run on a 4-socket Westmere-EX machine with both ext4 and xfs RAM disks at 3000 users on a 3.14 based kernel. The results of the test runs were:
AIM7 XFS Disk Test
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- ticketlock 5678233 3.17 96.61 5.81 qspinlock 5750799 3.13 94.83 5.97
AIM7 EXT4 Disk Test
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- ticketlock 1114551 16.15 509.72 7.11 qspinlock 2184466 8.24 232.99 6.01
The ext4 filesystem run had a much higher spinlock contention than the xfs filesystem run.
The "ebizzy -m" test was also run with the following results:
kernel records/s Real Time Sys Time Usr Time ----- --------- --------- -------- -------- ticketlock 2075 10.00 216.35 3.49 qspinlock 3023 10.00 198.20 4.80
--- kernel/locking/qspinlock.c | 59 ++++++++++++++++++++++++++++++++------------ 1 files changed, 43 insertions(+), 16 deletions(-)
kernel/locking/qspinlock.c +43 -16
@@ -103,24 +103,33 @@ static inline struct mcs_spinlock *decode_tail(u32 tail)* By using the whole 2nd least significant byte for the pending bit, we * can allow better optimization of the lock acquisition for the pending * bit holder. +* +* This internal structure is also used by the set_locked function which +* is not restricted to _Q_PENDING_BITS == 8. */ -#if _Q_PENDING_BITS ==8 -struct __qspinlock {union {atomic_t val; -struct {#ifdef __LITTLE_ENDIAN +u8 locked; +struct {u16 locked_pending;u16 tail; + };#else +struct {u16 tail;u16 locked_pending; -#endif }; +struct { +u8 reserved[3 ]; +u8 locked; + }; +#endif }; }; +#if _Q_PENDING_BITS ==8 /** * clear_pending_set_locked - take ownership and clear the pending bit. * @lock: Pointer to queue spinlock structure
@@ -207,6 +216,19 @@ static __always_inline u32 xchg_tail(struct qspinlock *lock, u32 tail)#endif /* _Q_PENDING_BITS == 8 */ /** +* set_locked - Set the lock bit and own the lock +* @lock: Pointer to queue spinlock structure +* +* *,*,0 -> *,0,1 +*/ +static __always_inline void set_locked(struct qspinlock *lock) +{ +struct __qspinlock *l = (void *)lock; + +ACCESS_ONCE (l->locked) = _Q_LOCKED_VAL; +} + +/** * queue_spin_lock_slowpath - acquire the queue spinlock * @lock: Pointer to queue spinlock structure * @val: Current value of the queue spinlock 32-bit word
@@ -339,10 +361,13 @@ queue:/* * we're at the head of the waitqueue, wait for the owner & pending to * go away. +* Load-acquired is used here because the set_locked() +* function below may not be a full memory barrier. * * *,x,y -> *,0,0 */ -while ((val =atomic_read (&lock->val)) & _Q_LOCKED_PENDING_MASK) +while ((val =smp_load_acquire (&lock->val.counter)) & + _Q_LOCKED_PENDING_MASK)cpu_relax ();/*
@@ -350,15 +375,19 @@ queue:* * n,0,0 -> 0,0,1 : lock, uncontended * *,0,0 -> *,0,1 : lock, contended +* +* If the queue head is the only one in the queue (lock value == tail), +* clear the tail code and grab the lock. Otherwise, we only need +* to grab the lock. */ for (;;) { - new = _Q_LOCKED_VAL; -if (val != tail) - new |= val; - - old =atomic_cmpxchg (&lock->val, val, new); -if (old == val) +if (val != tail) { +set_locked (lock);break ; + } + old =atomic_cmpxchg (&lock->val, val, _Q_LOCKED_VAL); +if (old == val) + goto release;/* No contention */ val = old; }
@@ -366,12 +395,10 @@ queue:/* * contended path; wait for next, release. */ -if (new != _Q_LOCKED_VAL) { -while (!(next =ACCESS_ONCE (node->next))) -cpu_relax (); +while (!(next =ACCESS_ONCE (node->next))) +cpu_relax (); -arch_mcs_spin_unlock_contended (&next->locked); - } +arch_mcs_spin_unlock_contended (&next->locked); release:/*
Signature · 1 line
1.7.1
PATCH v13 6/11 qspinlock: Use a simple write to grab the lock
In reply to Waiman LongCurrently, atomic_cmpxchg() is used to get the lock. However, this is not really necessary if there is more than one task in the queue and the queue head don't need to reset the tail code. For that case, a simple write to set the lock bit is enough as the queue head will be the only one eligible to get the lock as long as it checks that both the lock and pending bits are not set. The current pending bit waiting code will ensure that the bit will not be set as soon as the tail code in the lock is set.
With that change, the are some slight improvement in the performance of the queue spinlock in the 5M loop micro-benchmark run on a 4-socket Westere-EX machine as shown in the tables below.
[Standalone/Embedded - same node]
# of tasks Before patch After patch %Change
---------- ----------- ---------- -------
3 2324/2321 2248/2265 -3%/-2%
4 2890/2896 2819/2831 -2%/-2%
5 3611/3595 3522/3512 -2%/-2%
6 4281/4276 4173/4160 -3%/-3%
7 5018/5001 4875/4861 -3%/-3%
8 5759/5750 5563/5568 -3%/-3%[Standalone/Embedded - different nodes]
# of tasks Before patch After patch %Change
---------- ----------- ---------- -------
3 12242/12237 12087/12093 -1%/-1%
4 10688/10696 10507/10521 -2%/-2%It was also found that this change produced a much bigger performance improvement in the newer IvyBridge-EX chip and was essentially to close the performance gap between the ticket spinlock and queue spinlock.
The disk workload of the AIM7 benchmark was run on a 4-socket Westmere-EX machine with both ext4 and xfs RAM disks at 3000 users on a 3.14 based kernel. The results of the test runs were:
AIM7 XFS Disk Test
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- ticketlock 5678233 3.17 96.61 5.81 qspinlock 5750799 3.13 94.83 5.97
AIM7 EXT4 Disk Test
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- ticketlock 1114551 16.15 509.72 7.11 qspinlock 2184466 8.24 232.99 6.01
The ext4 filesystem run had a much higher spinlock contention than the xfs filesystem run.
The "ebizzy -m" test was also run with the following results:
kernel records/s Real Time Sys Time Usr Time ----- --------- --------- -------- -------- ticketlock 2075 10.00 216.35 3.49 qspinlock 3023 10.00 198.20 4.80
--- kernel/locking/qspinlock.c | 59 ++++++++++++++++++++++++++++++++------------ 1 files changed, 43 insertions(+), 16 deletions(-)
kernel/locking/qspinlock.c +43 -16
@@ -103,24 +103,33 @@ static inline struct mcs_spinlock *decode_tail(u32 tail)* By using the whole 2nd least significant byte for the pending bit, we * can allow better optimization of the lock acquisition for the pending * bit holder. +* +* This internal structure is also used by the set_locked function which +* is not restricted to _Q_PENDING_BITS == 8. */ -#if _Q_PENDING_BITS ==8 -struct __qspinlock {union {atomic_t val; -struct {#ifdef __LITTLE_ENDIAN +u8 locked; +struct {u16 locked_pending;u16 tail; + };#else +struct {u16 tail;u16 locked_pending; -#endif }; +struct { +u8 reserved[3 ]; +u8 locked; + }; +#endif }; }; +#if _Q_PENDING_BITS ==8 /** * clear_pending_set_locked - take ownership and clear the pending bit. * @lock: Pointer to queue spinlock structure
@@ -207,6 +216,19 @@ static __always_inline u32 xchg_tail(struct qspinlock *lock, u32 tail)#endif /* _Q_PENDING_BITS == 8 */ /** +* set_locked - Set the lock bit and own the lock +* @lock: Pointer to queue spinlock structure +* +* *,*,0 -> *,0,1 +*/ +static __always_inline void set_locked(struct qspinlock *lock) +{ +struct __qspinlock *l = (void *)lock; + +ACCESS_ONCE (l->locked) = _Q_LOCKED_VAL; +} + +/** * queue_spin_lock_slowpath - acquire the queue spinlock * @lock: Pointer to queue spinlock structure * @val: Current value of the queue spinlock 32-bit word
@@ -339,10 +361,13 @@ queue:/* * we're at the head of the waitqueue, wait for the owner & pending to * go away. +* Load-acquired is used here because the set_locked() +* function below may not be a full memory barrier. * * *,x,y -> *,0,0 */ -while ((val =atomic_read (&lock->val)) & _Q_LOCKED_PENDING_MASK) +while ((val =smp_load_acquire (&lock->val.counter)) & + _Q_LOCKED_PENDING_MASK)cpu_relax ();/*
@@ -350,15 +375,19 @@ queue:* * n,0,0 -> 0,0,1 : lock, uncontended * *,0,0 -> *,0,1 : lock, contended +* +* If the queue head is the only one in the queue (lock value == tail), +* clear the tail code and grab the lock. Otherwise, we only need +* to grab the lock. */ for (;;) { - new = _Q_LOCKED_VAL; -if (val != tail) - new |= val; - - old =atomic_cmpxchg (&lock->val, val, new); -if (old == val) +if (val != tail) { +set_locked (lock);break ; + } + old =atomic_cmpxchg (&lock->val, val, _Q_LOCKED_VAL); +if (old == val) + goto release;/* No contention */ val = old; }
@@ -366,12 +395,10 @@ queue:/* * contended path; wait for next, release. */ -if (new != _Q_LOCKED_VAL) { -while (!(next =ACCESS_ONCE (node->next))) -cpu_relax (); +while (!(next =ACCESS_ONCE (node->next))) +cpu_relax (); -arch_mcs_spin_unlock_contended (&next->locked); - } +arch_mcs_spin_unlock_contended (&next->locked); release:/*
Signature · 1 line
1.7.1
PATCH v13 7/11 qspinlock: Revert to test-and-set on hypervisors
In reply to Waiman LongFrom: Peter Zijlstra <[email protected]>
When we detect a hypervisor (!paravirt, see qspinlock paravirt support patches), revert to a simple test-and-set lock to avoid the horrors of queue preemption.
--- arch/x86/include/asm/qspinlock.h | 14 ++++++++++++++ include/asm-generic/qspinlock.h | 7 +++++++ kernel/locking/qspinlock.c | 3 +++ 3 files changed, 24 insertions(+), 0 deletions(-)
arch/x86/include/asm/qspinlock.h +14 -0
@@ -1,6 +1,7 @@#ifndef _ASM_X86_QSPINLOCK_H#define _ASM_X86_QSPINLOCK_H +#include <asm/cpufeature.h> #include <asm-generic/qspinlock_types.h> #ifndef CONFIG_X86_PPRO_FENCE
@@ -20,6 +21,19 @@ static inline void queue_spin_unlock(struct qspinlock *lock)#endif /* !CONFIG_X86_PPRO_FENCE */ +#define virt_queue_spin_lock virt_queue_spin_lock + +static inline bool virt_queue_spin_lock (struct qspinlock *lock) +{ +if (!static_cpu_has (X86_FEATURE_HYPERVISOR )) +return false; + +while (atomic_cmpxchg (&lock->val,0 , _Q_LOCKED_VAL) !=0 ) +cpu_relax (); + +return true; +} +#include <asm-generic/qspinlock.h> #endif /* _ASM_X86_QSPINLOCK_H */
include/asm-generic/qspinlock.h +7 -0
@@ -98,6 +98,13 @@ static __always_inline void queue_spin_unlock(struct qspinlock *lock) }#endif +#ifndef virt_queue_spin_lock +static __always_inline bool virt_queue_spin_lock(struct qspinlock *lock) +{ +return false; +} +#endif +/* * Initializier */
kernel/locking/qspinlock.c +3 -0
@@ -257,6 +257,9 @@ void queue_spin_lock_slowpath(struct qspinlock *lock, u32 val)BUILD_BUG_ON (CONFIG_NR_CPUS >= (1U << _Q_TAIL_CPU_BITS)); +if (virt_queue_spin_lock (lock)) +return ; +/* * wait for in-progress pending->locked hand-overs *
Signature · 1 line
1.7.1
PATCH v13 7/11 qspinlock: Revert to test-and-set on hypervisors
In reply to Waiman LongFrom: Peter Zijlstra <[email protected]>
When we detect a hypervisor (!paravirt, see qspinlock paravirt support patches), revert to a simple test-and-set lock to avoid the horrors of queue preemption.
--- arch/x86/include/asm/qspinlock.h | 14 ++++++++++++++ include/asm-generic/qspinlock.h | 7 +++++++ kernel/locking/qspinlock.c | 3 +++ 3 files changed, 24 insertions(+), 0 deletions(-)
arch/x86/include/asm/qspinlock.h +14 -0
@@ -1,6 +1,7 @@#ifndef _ASM_X86_QSPINLOCK_H#define _ASM_X86_QSPINLOCK_H +#include <asm/cpufeature.h> #include <asm-generic/qspinlock_types.h> #ifndef CONFIG_X86_PPRO_FENCE
@@ -20,6 +21,19 @@ static inline void queue_spin_unlock(struct qspinlock *lock)#endif /* !CONFIG_X86_PPRO_FENCE */ +#define virt_queue_spin_lock virt_queue_spin_lock + +static inline bool virt_queue_spin_lock (struct qspinlock *lock) +{ +if (!static_cpu_has (X86_FEATURE_HYPERVISOR )) +return false; + +while (atomic_cmpxchg (&lock->val,0 , _Q_LOCKED_VAL) !=0 ) +cpu_relax (); + +return true; +} +#include <asm-generic/qspinlock.h> #endif /* _ASM_X86_QSPINLOCK_H */
include/asm-generic/qspinlock.h +7 -0
@@ -98,6 +98,13 @@ static __always_inline void queue_spin_unlock(struct qspinlock *lock) }#endif +#ifndef virt_queue_spin_lock +static __always_inline bool virt_queue_spin_lock(struct qspinlock *lock) +{ +return false; +} +#endif +/* * Initializier */
kernel/locking/qspinlock.c +3 -0
@@ -257,6 +257,9 @@ void queue_spin_lock_slowpath(struct qspinlock *lock, u32 val)BUILD_BUG_ON (CONFIG_NR_CPUS >= (1U << _Q_TAIL_CPU_BITS)); +if (virt_queue_spin_lock (lock)) +return ; +/* * wait for in-progress pending->locked hand-overs *
Signature · 1 line
1.7.1
PATCH v13 7/11 qspinlock: Revert to test-and-set on hypervisors
In reply to Waiman LongFrom: Peter Zijlstra <[email protected]>
When we detect a hypervisor (!paravirt, see qspinlock paravirt support patches), revert to a simple test-and-set lock to avoid the horrors of queue preemption.
--- arch/x86/include/asm/qspinlock.h | 14 ++++++++++++++ include/asm-generic/qspinlock.h | 7 +++++++ kernel/locking/qspinlock.c | 3 +++ 3 files changed, 24 insertions(+), 0 deletions(-)
arch/x86/include/asm/qspinlock.h +14 -0
@@ -1,6 +1,7 @@#ifndef _ASM_X86_QSPINLOCK_H#define _ASM_X86_QSPINLOCK_H +#include <asm/cpufeature.h> #include <asm-generic/qspinlock_types.h> #ifndef CONFIG_X86_PPRO_FENCE
@@ -20,6 +21,19 @@ static inline void queue_spin_unlock(struct qspinlock *lock)#endif /* !CONFIG_X86_PPRO_FENCE */ +#define virt_queue_spin_lock virt_queue_spin_lock + +static inline bool virt_queue_spin_lock (struct qspinlock *lock) +{ +if (!static_cpu_has (X86_FEATURE_HYPERVISOR )) +return false; + +while (atomic_cmpxchg (&lock->val,0 , _Q_LOCKED_VAL) !=0 ) +cpu_relax (); + +return true; +} +#include <asm-generic/qspinlock.h> #endif /* _ASM_X86_QSPINLOCK_H */
include/asm-generic/qspinlock.h +7 -0
@@ -98,6 +98,13 @@ static __always_inline void queue_spin_unlock(struct qspinlock *lock) }#endif +#ifndef virt_queue_spin_lock +static __always_inline bool virt_queue_spin_lock(struct qspinlock *lock) +{ +return false; +} +#endif +/* * Initializier */
kernel/locking/qspinlock.c +3 -0
@@ -257,6 +257,9 @@ void queue_spin_lock_slowpath(struct qspinlock *lock, u32 val)BUILD_BUG_ON (CONFIG_NR_CPUS >= (1U << _Q_TAIL_CPU_BITS)); +if (virt_queue_spin_lock (lock)) +return ; +/* * wait for in-progress pending->locked hand-overs *
Signature · 1 line
1.7.1
PATCH v13 8/11 qspinlock, x86: Rename paravirt_ticketlocks_enabled
In reply to Waiman LongThis patch renames the paravirt_ticketlocks_enabled static key to a more generic paravirt_spinlocks_enabled name.
--- arch/x86/include/asm/spinlock.h | 4 ++-- arch/x86/kernel/kvm.c | 2 +- arch/x86/kernel/paravirt-spinlocks.c | 4 ++-- arch/x86/xen/spinlock.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-)
arch/x86/include/asm/spinlock.h +2 -2
@@ -39,7 +39,7 @@/* How long a lock should spin before we consider blocking */ #define SPIN_THRESHOLD (1 << 15) -extern struct static_key paravirt_ticketlocks_enabled; +extern struct static_key paravirt_spinlocks_enabled; static __always_inline bool static_key_false(struct static_key *key);#ifdef CONFIG_QUEUE_SPINLOCK
@@ -150,7 +150,7 @@ static inline void __ticket_unlock_slowpath(arch_spinlock_t *lock, static __always_inline void arch_spin_unlock(arch_spinlock_t *lock) {if (TICKET_SLOWPATH_FLAG && -static_key_false (¶virt_ticketlocks_enabled)) { +static_key_false (¶virt_spinlocks_enabled)) {arch_spinlock_t prev; prev = *lock;
arch/x86/kernel/kvm.c +1 -1
@@ -827,7 +827,7 @@ static __init int kvm_spinlock_init_jump(void)if (!kvm_para_has_feature (KVM_FEATURE_PV_UNHALT ))return 0 ; -static_key_slow_inc (¶virt_ticketlocks_enabled); +static_key_slow_inc (¶virt_spinlocks_enabled);printk (KERN_INFO "KVM setup paravirtual spinlock\n" );return 0 ;
arch/x86/kernel/paravirt-spinlocks.c +2 -2
@@ -16,5 +16,5 @@ struct pv_lock_ops pv_lock_ops = { };EXPORT_SYMBOL (pv_lock_ops); -struct static_key paravirt_ticketlocks_enabled =STATIC_KEY_INIT_FALSE ; -EXPORT_SYMBOL (paravirt_ticketlocks_enabled); +struct static_key paravirt_spinlocks_enabled =STATIC_KEY_INIT_FALSE ; +EXPORT_SYMBOL (paravirt_spinlocks_enabled);
arch/x86/xen/spinlock.c +1 -1
@@ -293,7 +293,7 @@ static __init int xen_init_spinlocks_jump(void)if (!xen_domain ())return 0 ; -static_key_slow_inc (¶virt_ticketlocks_enabled); +static_key_slow_inc (¶virt_spinlocks_enabled);return 0 ; }early_initcall (xen_init_spinlocks_jump);
Signature · 1 line
1.7.1
PATCH v13 8/11 qspinlock, x86: Rename paravirt_ticketlocks_enabled
In reply to Waiman LongThis patch renames the paravirt_ticketlocks_enabled static key to a more generic paravirt_spinlocks_enabled name.
--- arch/x86/include/asm/spinlock.h | 4 ++-- arch/x86/kernel/kvm.c | 2 +- arch/x86/kernel/paravirt-spinlocks.c | 4 ++-- arch/x86/xen/spinlock.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-)
arch/x86/include/asm/spinlock.h +2 -2
@@ -39,7 +39,7 @@/* How long a lock should spin before we consider blocking */ #define SPIN_THRESHOLD (1 << 15) -extern struct static_key paravirt_ticketlocks_enabled; +extern struct static_key paravirt_spinlocks_enabled; static __always_inline bool static_key_false(struct static_key *key);#ifdef CONFIG_QUEUE_SPINLOCK
@@ -150,7 +150,7 @@ static inline void __ticket_unlock_slowpath(arch_spinlock_t *lock, static __always_inline void arch_spin_unlock(arch_spinlock_t *lock) {if (TICKET_SLOWPATH_FLAG && -static_key_false (¶virt_ticketlocks_enabled)) { +static_key_false (¶virt_spinlocks_enabled)) {arch_spinlock_t prev; prev = *lock;
arch/x86/kernel/kvm.c +1 -1
@@ -827,7 +827,7 @@ static __init int kvm_spinlock_init_jump(void)if (!kvm_para_has_feature (KVM_FEATURE_PV_UNHALT ))return 0 ; -static_key_slow_inc (¶virt_ticketlocks_enabled); +static_key_slow_inc (¶virt_spinlocks_enabled);printk (KERN_INFO "KVM setup paravirtual spinlock\n" );return 0 ;
arch/x86/kernel/paravirt-spinlocks.c +2 -2
@@ -16,5 +16,5 @@ struct pv_lock_ops pv_lock_ops = { };EXPORT_SYMBOL (pv_lock_ops); -struct static_key paravirt_ticketlocks_enabled =STATIC_KEY_INIT_FALSE ; -EXPORT_SYMBOL (paravirt_ticketlocks_enabled); +struct static_key paravirt_spinlocks_enabled =STATIC_KEY_INIT_FALSE ; +EXPORT_SYMBOL (paravirt_spinlocks_enabled);
arch/x86/xen/spinlock.c +1 -1
@@ -293,7 +293,7 @@ static __init int xen_init_spinlocks_jump(void)if (!xen_domain ())return 0 ; -static_key_slow_inc (¶virt_ticketlocks_enabled); +static_key_slow_inc (¶virt_spinlocks_enabled);return 0 ; }early_initcall (xen_init_spinlocks_jump);
Signature · 1 line
1.7.1
PATCH v13 8/11 qspinlock, x86: Rename paravirt_ticketlocks_enabled
In reply to Waiman LongThis patch renames the paravirt_ticketlocks_enabled static key to a more generic paravirt_spinlocks_enabled name.
--- arch/x86/include/asm/spinlock.h | 4 ++-- arch/x86/kernel/kvm.c | 2 +- arch/x86/kernel/paravirt-spinlocks.c | 4 ++-- arch/x86/xen/spinlock.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-)
arch/x86/include/asm/spinlock.h +2 -2
@@ -39,7 +39,7 @@/* How long a lock should spin before we consider blocking */ #define SPIN_THRESHOLD (1 << 15) -extern struct static_key paravirt_ticketlocks_enabled; +extern struct static_key paravirt_spinlocks_enabled; static __always_inline bool static_key_false(struct static_key *key);#ifdef CONFIG_QUEUE_SPINLOCK
@@ -150,7 +150,7 @@ static inline void __ticket_unlock_slowpath(arch_spinlock_t *lock, static __always_inline void arch_spin_unlock(arch_spinlock_t *lock) {if (TICKET_SLOWPATH_FLAG && -static_key_false (¶virt_ticketlocks_enabled)) { +static_key_false (¶virt_spinlocks_enabled)) {arch_spinlock_t prev; prev = *lock;
arch/x86/kernel/kvm.c +1 -1
@@ -827,7 +827,7 @@ static __init int kvm_spinlock_init_jump(void)if (!kvm_para_has_feature (KVM_FEATURE_PV_UNHALT ))return 0 ; -static_key_slow_inc (¶virt_ticketlocks_enabled); +static_key_slow_inc (¶virt_spinlocks_enabled);printk (KERN_INFO "KVM setup paravirtual spinlock\n" );return 0 ;
arch/x86/kernel/paravirt-spinlocks.c +2 -2
@@ -16,5 +16,5 @@ struct pv_lock_ops pv_lock_ops = { };EXPORT_SYMBOL (pv_lock_ops); -struct static_key paravirt_ticketlocks_enabled =STATIC_KEY_INIT_FALSE ; -EXPORT_SYMBOL (paravirt_ticketlocks_enabled); +struct static_key paravirt_spinlocks_enabled =STATIC_KEY_INIT_FALSE ; +EXPORT_SYMBOL (paravirt_spinlocks_enabled);
arch/x86/xen/spinlock.c +1 -1
@@ -293,7 +293,7 @@ static __init int xen_init_spinlocks_jump(void)if (!xen_domain ())return 0 ; -static_key_slow_inc (¶virt_ticketlocks_enabled); +static_key_slow_inc (¶virt_spinlocks_enabled);return 0 ; }early_initcall (xen_init_spinlocks_jump);
Signature · 1 line
1.7.1
PATCH v13 9/11 pvqspinlock, x86: Add para-virtualization support
In reply to Waiman LongThis patch adds para-virtualization support to the queue spinlock code base with minimal impact to the native case. There are some minor code changes in the generic qspinlock.c file which should be usable in other architectures. The other code changes are specific to x86 processors and so are all put under the arch/x86 directory.
On the lock side, the slowpath code is split into 2 separate functions generated from the same code - one for bare metal and one for PV guest. The switching is done in the _raw_spin_lock* functions. This makes sure that the performance impact to the bare metal case is minimal, just a few NOPs in the _raw_spin_lock* functions. In the PV slowpath code, there are 2 paravirt callee saved calls that minimize register pressure.
On the unlock side, however, the disabling of unlock function inlining does have some slight impact on bare metal performance.
The actual paravirt code comes in 5 parts;
- init_node; this initializes the extra data members required for PV state. PV state data is kept 1 cacheline ahead of the regular data.
- link_and_wait_node; this replaces the regular MCS queuing code. CPU halting can happen if the wait is too long.
- wait_head; this waits until the lock is avialable and the CPU will be halted if the wait is too long.
- wait_check; this is called after acquiring the lock to see if the next queue head CPU is halted. If this is the case, the lock bit is changed to indicate the queue head will have to be kicked on unlock.
- queue_unlock; this routine has a jump label to check if paravirt is enabled. If yes, it has to do an atomic cmpxchg to clear the lock bit or call the slowpath function to kick the queue head cpu.
Tracking the head is done in two parts, firstly the pv_wait_head will store its cpu number in whichever node is pointed to by the tail part of the lock word. Secondly, pv_link_and_wait_node() will propagate the existing head from the old to the new tail node.
--- arch/x86/include/asm/paravirt.h | 19 ++ arch/x86/include/asm/paravirt_types.h | 20 ++ arch/x86/include/asm/pvqspinlock.h | 411 +++++++++++++++++++++++++++++++++ arch/x86/include/asm/qspinlock.h | 71 ++++++- arch/x86/kernel/paravirt-spinlocks.c | 6 + include/asm-generic/qspinlock.h | 2 + kernel/locking/qspinlock.c | 69 +++++- 7 files changed, 591 insertions(+), 7 deletions(-) create mode 100644 arch/x86/include/asm/pvqspinlock.h
arch/x86/include/asm/paravirt.h +19 -0
@@ -712,6 +712,24 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx, #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS) +#ifdef CONFIG_QUEUE_SPINLOCK + +static __always_inline void pv_kick_cpu(int cpu) +{ + PVOP_VCALLEE1(pv_lock_ops.kick_cpu, cpu); +} + +static __always_inline void pv_lockwait(u8 *lockbyte) +{ + PVOP_VCALLEE1(pv_lock_ops.lockwait, lockbyte); +} + +static __always_inline void pv_lockstat(enum pv_lock_stats type) +{ + PVOP_VCALLEE1(pv_lock_ops.lockstat, type); +} + +#else static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock, __ticket_t ticket) {
@@ -723,6 +741,7 @@ static __always_inline void __ticket_unlock_kick(struct arch_spinlock *lock, {PVOP_VCALL2 (pv_lock_ops.unlock_kick, lock, ticket); } +#endif #endif
arch/x86/include/asm/paravirt_types.h +20 -0
@@ -326,6 +326,9 @@ struct pv_mmu_ops { phys_addr_t phys, pgprot_t flags); }; +struct mcs_spinlock ; +struct qspinlock ; +struct arch_spinlock ;#ifdef CONFIG_SMP #include <asm/spinlock_types.h>
@@ -333,9 +336,26 @@ struct arch_spinlock;typedef u16 __ticket_t ;#endif +#ifdef CONFIG_QUEUE_SPINLOCK +enum pv_lock_stats { +PV_HALT_QHEAD ,/* Queue head halting */ +PV_HALT_QNODE ,/* Other queue node halting */ +PV_HALT_ABORT ,/* Halting aborted */ +PV_WAKE_KICKED ,/* Wakeup by kicking */ +PV_WAKE_SPURIOUS ,/* Spurious wakeup */ +PV_KICK_NOHALT /* Kick but CPU not halted */ +}; +#endif +struct pv_lock_ops { +#ifdef CONFIG_QUEUE_SPINLOCK +struct paravirt_callee_save kick_cpu; +struct paravirt_callee_save lockstat; +struct paravirt_callee_save lockwait; +#else struct paravirt_callee_save lock_spinning;void (*unlock_kick)(struct arch_spinlock *lock,__ticket_t ticket); +#endif };/* This contains all the paravirt structures: we get a convenient
arch/x86/include/asm/pvqspinlock.h new file +411 -0
411 lines not on this page · raw message
arch/x86/include/asm/qspinlock.h +68 -3
89 lines not on this page · raw message
arch/x86/kernel/paravirt-spinlocks.c +6 -0
@@ -10,9 +10,15 @@ struct pv_lock_ops pv_lock_ops = {#ifdef CONFIG_SMP +#ifdef CONFIG_QUEUE_SPINLOCK + .kick_cpu = __PV_IS_CALLEE_SAVE(paravirt_nop), + .lockstat = __PV_IS_CALLEE_SAVE(paravirt_nop), + .lockwait = __PV_IS_CALLEE_SAVE(paravirt_nop), +#else .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop), .unlock_kick = paravirt_nop,#endif +#endif };EXPORT_SYMBOL (pv_lock_ops);
include/asm-generic/qspinlock.h +2 -0
@@ -67,6 +67,7 @@ static __always_inline int queue_spin_trylock(struct qspinlock *lock)return 0 ; } +#ifndef queue_spin_lockextern void queue_spin_lock_slowpath (struct qspinlock *lock,u32 val);/**
@@ -82,6 +83,7 @@ static __always_inline void queue_spin_lock(struct qspinlock *lock)return ; queue_spin_lock_slowpath(lock, val); } +#endif #ifndef queue_spin_unlock/**
kernel/locking/qspinlock.c +65 -4
127 lines not on this page · raw message
Signature · 1 line
1.7.1
Peter Zijlstra
maintainerRe: [PATCH v13 09/11] pvqspinlock, x86: Add para-virtualization support
Quoted 1 line · Waiman Long
arch/x86/include/asm/pvqspinlock.h | 411 +++++++++++++++++++++++++++++++++
I do wonder why all this needs to live in x86..
Quoted 7 lines
arch/x86/include/asm/paravirt.h +6
-0+#ifdef CONFIG_QUEUE_SPINLOCK + +static __always_inline void pv_kick_cpu(int cpu) +{ +PVOP_VCALLEE1 (pv_lock_ops.kick_cpu, cpu); +}
arch/x86/include/asm/paravirt.h static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx, · line 730
Quoted 10 lines
arch/x86/include/asm/paravirt.h +10
-0+ +static __always_inline void pv_lockwait(u8 *lockbyte) +{ +PVOP_VCALLEE1 (pv_lock_ops.lockwait, lockbyte); +} + +static __always_inline void pv_lockstat(enum pv_lock_stats type) +{ +PVOP_VCALLEE1 (pv_lock_ops.lockstat, type); +}
Why are any of these PV ops? they're only called from other pv_*() functions. What's the point of pv ops you only call from pv code?
Quoted 5 lines
+/*
+ * Queue Spinlock Para-Virtualization (PV) Support
+ *
+ * The PV support code for queue spinlock is roughly the same as that
+ * of the ticket spinlock.
Relative comments are bad, esp. since we'll make the ticket code go away if this works, at which point this is a reference into a black hole.
Quoted 8 lines
Each CPU waiting for the lock will spin until it
+ * reaches a threshold. When that happens, it will put itself to a halt state
+ * so that the hypervisor can reuse the CPU cycles in some other guests as
+ * well as returning other hold-up CPUs faster.
Quoted 5 lines
+/**
+ *queue_spin_lock- acquire a queue spinlock
+ * @lock: Pointer to queue spinlock structure
+ *
+ * N.B.INLINE_SPIN_LOCKshould not be enabled whenPARAVIRT_SPINLOCKis on.
One should write a compile time fail for that, not a comment.
arch/x86/include/asm/qspinlock.h line 53
Quoted 13 lines
+ */
arch/x86/include/asm/qspinlock.h +12
-0+static __always_inline void queue_spin_lock(struct qspinlock *lock) +{ +u32 val; + + val =atomic_cmpxchg (&lock->val,0 , _Q_LOCKED_VAL); +if (likely (val ==0 )) +return ; +if (static_key_false (¶virt_spinlocks_enabled)) +pv_queue_spin_lock_slowpath (lock, val); +else +queue_spin_lock_slowpath (lock, val); +}
No, this is just vile.. _that_ is what we have PV ops for. And at that point its the same function it was before the PV stuff, so that whole inline thing is then gone.
arch/x86/include/asm/qspinlock.h line 65
Quoted 11 lines
arch/x86/include/asm/qspinlock.h +6
-0+extern void queue_spin_unlock_slowpath (struct qspinlock *lock); +/** * queue_spin_unlock - release a queue spinlock * @lock : Pointer to queue spinlock structure * * An effective smp_store_release() on the least-significant byte. +* +* Inlining of the unlock function is disabled when CONFIG_PARAVIRT_SPINLOCKS +* is defined. So _raw_spin_unlock() will be the only call site that will +* have to be patched.
again if you hard rely on the not inlining make a build fail not a comment.
Quoted 6 lines
*/
static inline voidqueue_spin_unlock(struct qspinlock *lock){arch/x86/include/asm/qspinlock.h +2
-0barrier (); +if (!static_key_false (¶virt_spinlocks_enabled)) { +native_spin_unlock (lock);
arch/x86/include/asm/qspinlock.h line 81
Quoted 10 lines
arch/x86/include/asm/qspinlock.h +9
-0+return ; + } +/* +* Need to atomically clear the lock byte to avoid racing with +* queue head waiter trying to set _QLOCK_LOCKED_SLOWPATH. +*/ +if (unlikely (cmpxchg ((u8 *)lock, _Q_LOCKED_VAL,0 ) != _Q_LOCKED_VAL)) +queue_spin_unlock_slowpath (lock); +}
Idem, that static key stuff is wrong, use PV ops to switch between unlock paths.
Quoted 12 lines
kernel/locking/qspinlock.c +1
-1@@ -354,7 +394,7 @@ queue:* if there was a previous node; link it and wait until reaching the * head of the waitqueue. */ -if (old & _Q_TAIL_MASK) { +if (!pv_link_and_wait_node (old, node) && (old & _Q_TAIL_MASK)) { prev =decode_tail (old);ACCESS_ONCE (prev->next) = node;@@ -369,9 +409,11 @@ queue:* * *,x,y -> *,0,0 */
kernel/locking/qspinlock.c queue: · line 419
Quoted 10 lines
kernel/locking/qspinlock.c +4
-2-while ((val =smp_load_acquire (&lock->val.counter)) & - _Q_LOCKED_PENDING_MASK) + val =pv_wait_head (lock, node); +while (val & _Q_LOCKED_PENDING_MASK) {cpu_relax (); + val =smp_load_acquire (&lock->val.counter); + }/* * claim the lock:
Please make the pv_*() calls return void and reduce to NOPs. This keeps the logic invariant of the pv stuff.
Re: [PATCH v13 09/11] pvqspinlock, x86: Add para-virtualization support
Quoted 4 lines · Peter Zijlstra
Quoted 1 line · Waiman Long
arch/x86/include/asm/pvqspinlock.h | 411 +++++++++++++++++++++++++++++++++I do wonder why all this needs to live in x86..
I haven't looked into the para-virtualization code in other architectures to see if my PV code is equally applicable there. That is why I put it under the x86 directory. If other architectures decide to use qspinlock with paravirtualization, we may need to pull out some common code, if any, back to kernel/locking.
Quoted 11 lines
Quoted 11 lines
arch/x86/include/asm/paravirt.h +10
-0+#ifdef CONFIG_QUEUE_SPINLOCK + +static __always_inline void pv_kick_cpu(int cpu) +{ +PVOP_VCALLEE1 (pv_lock_ops.kick_cpu, cpu); +} + +static __always_inline void pv_lockwait(u8 *lockbyte) +{ +PVOP_VCALLEE1 (pv_lock_ops.lockwait, lockbyte);
Quoted 8 lines
arch/x86/include/asm/paravirt.h static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx, · line 730
Quoted 6 lines
arch/x86/include/asm/paravirt.h +6
-0+} + +static __always_inline void pv_lockstat(enum pv_lock_stats type) +{ +PVOP_VCALLEE1 (pv_lock_ops.lockstat, type); +}Why are any of these PV ops? they're only called from other pv_*() functions. What's the point of pv ops you only call from pv code?
It is the same reason that you made them PV ops in your patch. Even when PV is on, the code won't need to call any of the PV ops most of the time. So it is just a matter of optimizing the most common case at the expense of performance in the rare case that the CPU need to be halt and woken up which will be bad performance-wise anyway However, if you think they should be regular function pointers, I am fine with that too.
Quoted 7 lines
Quoted 5 lines
+/*
+ * Queue Spinlock Para-Virtualization (PV) Support
+ *
+ * The PV support code for queue spinlock is roughly the same as that
+ * of the ticket spinlock.Relative comments are bad, esp. since we'll make the ticket code go away if this works, at which point this is a reference into a black hole.
Thank for the suggestion, I will remove that when I need to revise the patch.
Quoted 7 lines
Quoted 4 lines
Each CPU waiting for the lock will spin until it
+ * reaches a threshold. When that happens, it will put itself to a halt state
+ * so that the hypervisor can reuse the CPU cycles in some other guests as
+ * well as returning other hold-up CPUs faster.
Quoted 6 lines
Quoted 5 lines
+/**
+ *queue_spin_lock- acquire a queue spinlock
+ * @lock: Pointer to queue spinlock structure
+ *
+ * N.B.INLINE_SPIN_LOCKshould not be enabled whenPARAVIRT_SPINLOCKis on.One should write a compile time fail for that, not a comment.
Will do that.
Quoted 8 lines
Quoted 8 lines
+ */
arch/x86/include/asm/qspinlock.h +7
-0+static __always_inline void queue_spin_lock(struct qspinlock *lock) +{ +u32 val; + + val =atomic_cmpxchg (&lock->val,0 , _Q_LOCKED_VAL); +if (likely (val ==0 )) +return ;
Quoted 8 lines
arch/x86/include/asm/qspinlock.h line 53
Quoted 5 lines
arch/x86/include/asm/qspinlock.h +5
-0+if (static_key_false (¶virt_spinlocks_enabled)) +pv_queue_spin_lock_slowpath (lock, val); +else +queue_spin_lock_slowpath (lock, val); +}No, this is just vile.. _that_ is what we have PV ops for. And at that point its the same function it was before the PV stuff, so that whole inline thing is then gone.
I did that because in all the architectures except s390, the lock functions are not inlined. They live in the _raw_spin_lock* defined in kernel/locking/spinlock.c. The unlock functions, on the other hand, are all inlined except when PV spinlock is enabled. So adding a check for the jump label won't change any of the status quo.
Quoted 5 lines
Quoted 5 lines
arch/x86/include/asm/qspinlock.h +2
-0+extern void queue_spin_unlock_slowpath (struct qspinlock *lock); +/** * queue_spin_unlock - release a queue spinlock * @lock : Pointer to queue spinlock structure
Quoted 8 lines
Quoted 6 lines
*
* An effectivesmp_store_release()on the least-significant byte.
+ *
+ * Inlining of the unlock function is disabled whenCONFIG_PARAVIRT_SPINLOCKS
+ * is defined. So_raw_spin_unlock()will be the only call site that will
+ * have to be patched.again if you hard rely on the not inlining make a build fail not a comment.
Will do that.
Quoted 9 lines
Quoted 9 lines
*/ static inline void queue_spin_unlock(struct qspinlock *lock) { barrier();arch/x86/include/asm/qspinlock.h +4
-0+if (!static_key_false (¶virt_spinlocks_enabled)) { +native_spin_unlock (lock); +return ; + }
Quoted 9 lines
arch/x86/include/asm/qspinlock.h line 81
Quoted 7 lines
arch/x86/include/asm/qspinlock.h +7
-0+/* +* Need to atomically clear the lock byte to avoid racing with +* queue head waiter trying to set _QLOCK_LOCKED_SLOWPATH. +*/ +if (unlikely (cmpxchg ((u8 *)lock, _Q_LOCKED_VAL,0 ) != _Q_LOCKED_VAL)) +queue_spin_unlock_slowpath (lock); +}Idem, that static key stuff is wrong, use PV ops to switch between unlock paths.
As said in my previous emails, the PV ops call site patching code doesn't work well with locking. First of all, the native_patch() function was called even in a KVM PV guest. Some unlock calls happened before the paravirt_spinlocks_enabled jump label was set up. It occurs to me that call site patching is done the first time the call site is used. At least for those early unlock calls, there is no way to figure out if it should use the native fast path or the PV slow path. The only possible workaround that I can think of is to use a variable (if available) that signal the end of the bootup init phase, we can then defer the call site patching until the init phase has passed.
This is a rather complicated solution which may not worth the slight benefit of a faster unlock call in the native case.
Quoted 20 lines
Quoted 20 lines
kernel/locking/qspinlock.c +5
-3@@ -354,7 +394,7 @@ queue:* if there was a previous node; link it and wait until reaching the * head of the waitqueue. */ -if (old& _Q_TAIL_MASK) { +if (!pv_link_and_wait_node (old, node)&& (old& _Q_TAIL_MASK)) { prev =decode_tail (old);ACCESS_ONCE (prev->next) = node;@@ -369,9 +409,11 @@ queue:* * *,x,y -> *,0,0 */ -while ((val =smp_load_acquire (&lock->val.counter))& - _Q_LOCKED_PENDING_MASK) + val =pv_wait_head (lock, node); +while (val& _Q_LOCKED_PENDING_MASK) {cpu_relax (); + val =smp_load_acquire (&lock->val.counter); + }
Quoted 4 lines
kernel/locking/qspinlock.c queue: · line 419
Quoted 2 lines
kernel/locking/qspinlock.c +0
-0/* * claim the lock: Please make the pv_*() calls return void and reduce to NOPs. This keeps the logic invariant of the pv stuff.
In my patch, the two pv_*() calls above serve as replacements of the waiting code. Making them return void and reduce to NOPs will cause what Konrad said doing the same operation twice which is not ideal from a performance point of view for the PV version. Is putting the pre-PV code in the comment help to clarify what the code should be before the PV stuff?
-Longman
Re: [PATCH v13 09/11] pvqspinlock, x86: Add para-virtualization support
In reply to Peter ZijlstraQuoted 4 lines · Peter Zijlstra
Quoted 1 line · Waiman Long
arch/x86/include/asm/pvqspinlock.h | 411 +++++++++++++++++++++++++++++++++I do wonder why all this needs to live in x86..
I haven't looked into the para-virtualization code in other architectures to see if my PV code is equally applicable there. That is why I put it under the x86 directory. If other architectures decide to use qspinlock with paravirtualization, we may need to pull out some common code, if any, back to kernel/locking.
Quoted 11 lines
Quoted 11 lines
arch/x86/include/asm/paravirt.h +10
-0+#ifdef CONFIG_QUEUE_SPINLOCK + +static __always_inline void pv_kick_cpu(int cpu) +{ +PVOP_VCALLEE1 (pv_lock_ops.kick_cpu, cpu); +} + +static __always_inline void pv_lockwait(u8 *lockbyte) +{ +PVOP_VCALLEE1 (pv_lock_ops.lockwait, lockbyte);
Quoted 8 lines
arch/x86/include/asm/paravirt.h static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx, · line 730
Quoted 6 lines
arch/x86/include/asm/paravirt.h +6
-0+} + +static __always_inline void pv_lockstat(enum pv_lock_stats type) +{ +PVOP_VCALLEE1 (pv_lock_ops.lockstat, type); +}Why are any of these PV ops? they're only called from other pv_*() functions. What's the point of pv ops you only call from pv code?
It is the same reason that you made them PV ops in your patch. Even when PV is on, the code won't need to call any of the PV ops most of the time. So it is just a matter of optimizing the most common case at the expense of performance in the rare case that the CPU need to be halt and woken up which will be bad performance-wise anyway However, if you think they should be regular function pointers, I am fine with that too.
Quoted 7 lines
Quoted 5 lines
+/*
+ * Queue Spinlock Para-Virtualization (PV) Support
+ *
+ * The PV support code for queue spinlock is roughly the same as that
+ * of the ticket spinlock.Relative comments are bad, esp. since we'll make the ticket code go away if this works, at which point this is a reference into a black hole.
Thank for the suggestion, I will remove that when I need to revise the patch.
Quoted 7 lines
Quoted 4 lines
Each CPU waiting for the lock will spin until it
+ * reaches a threshold. When that happens, it will put itself to a halt state
+ * so that the hypervisor can reuse the CPU cycles in some other guests as
+ * well as returning other hold-up CPUs faster.
Quoted 6 lines
Quoted 5 lines
+/**
+ *queue_spin_lock- acquire a queue spinlock
+ * @lock: Pointer to queue spinlock structure
+ *
+ * N.B.INLINE_SPIN_LOCKshould not be enabled whenPARAVIRT_SPINLOCKis on.One should write a compile time fail for that, not a comment.
Will do that.
Quoted 8 lines
Quoted 8 lines
+ */
arch/x86/include/asm/qspinlock.h +7
-0+static __always_inline void queue_spin_lock(struct qspinlock *lock) +{ +u32 val; + + val =atomic_cmpxchg (&lock->val,0 , _Q_LOCKED_VAL); +if (likely (val ==0 )) +return ;
Quoted 8 lines
arch/x86/include/asm/qspinlock.h line 53
Quoted 5 lines
arch/x86/include/asm/qspinlock.h +5
-0+if (static_key_false (¶virt_spinlocks_enabled)) +pv_queue_spin_lock_slowpath (lock, val); +else +queue_spin_lock_slowpath (lock, val); +}No, this is just vile.. _that_ is what we have PV ops for. And at that point its the same function it was before the PV stuff, so that whole inline thing is then gone.
I did that because in all the architectures except s390, the lock functions are not inlined. They live in the _raw_spin_lock* defined in kernel/locking/spinlock.c. The unlock functions, on the other hand, are all inlined except when PV spinlock is enabled. So adding a check for the jump label won't change any of the status quo.
Quoted 5 lines
Quoted 5 lines
arch/x86/include/asm/qspinlock.h +2
-0+extern void queue_spin_unlock_slowpath (struct qspinlock *lock); +/** * queue_spin_unlock - release a queue spinlock * @lock : Pointer to queue spinlock structure
Quoted 8 lines
Quoted 6 lines
*
* An effectivesmp_store_release()on the least-significant byte.
+ *
+ * Inlining of the unlock function is disabled whenCONFIG_PARAVIRT_SPINLOCKS
+ * is defined. So_raw_spin_unlock()will be the only call site that will
+ * have to be patched.again if you hard rely on the not inlining make a build fail not a comment.
Will do that.
Quoted 9 lines
Quoted 9 lines
*/ static inline void queue_spin_unlock(struct qspinlock *lock) { barrier();arch/x86/include/asm/qspinlock.h +4
-0+if (!static_key_false (¶virt_spinlocks_enabled)) { +native_spin_unlock (lock); +return ; + }
Quoted 9 lines
arch/x86/include/asm/qspinlock.h line 81
Quoted 7 lines
arch/x86/include/asm/qspinlock.h +7
-0+/* +* Need to atomically clear the lock byte to avoid racing with +* queue head waiter trying to set _QLOCK_LOCKED_SLOWPATH. +*/ +if (unlikely (cmpxchg ((u8 *)lock, _Q_LOCKED_VAL,0 ) != _Q_LOCKED_VAL)) +queue_spin_unlock_slowpath (lock); +}Idem, that static key stuff is wrong, use PV ops to switch between unlock paths.
As said in my previous emails, the PV ops call site patching code doesn't work well with locking. First of all, the native_patch() function was called even in a KVM PV guest. Some unlock calls happened before the paravirt_spinlocks_enabled jump label was set up. It occurs to me that call site patching is done the first time the call site is used. At least for those early unlock calls, there is no way to figure out if it should use the native fast path or the PV slow path. The only possible workaround that I can think of is to use a variable (if available) that signal the end of the bootup init phase, we can then defer the call site patching until the init phase has passed.
This is a rather complicated solution which may not worth the slight benefit of a faster unlock call in the native case.
Quoted 20 lines
Quoted 20 lines
kernel/locking/qspinlock.c +5
-3@@ -354,7 +394,7 @@ queue:* if there was a previous node; link it and wait until reaching the * head of the waitqueue. */ -if (old& _Q_TAIL_MASK) { +if (!pv_link_and_wait_node (old, node)&& (old& _Q_TAIL_MASK)) { prev =decode_tail (old);ACCESS_ONCE (prev->next) = node;@@ -369,9 +409,11 @@ queue:* * *,x,y -> *,0,0 */ -while ((val =smp_load_acquire (&lock->val.counter))& - _Q_LOCKED_PENDING_MASK) + val =pv_wait_head (lock, node); +while (val& _Q_LOCKED_PENDING_MASK) {cpu_relax (); + val =smp_load_acquire (&lock->val.counter); + }
Quoted 4 lines
kernel/locking/qspinlock.c queue: · line 419
Quoted 2 lines
kernel/locking/qspinlock.c +0
-0/* * claim the lock: Please make the pv_*() calls return void and reduce to NOPs. This keeps the logic invariant of the pv stuff.
In my patch, the two pv_*() calls above serve as replacements of the waiting code. Making them return void and reduce to NOPs will cause what Konrad said doing the same operation twice which is not ideal from a performance point of view for the PV version. Is putting the pre-PV code in the comment help to clarify what the code should be before the PV stuff?
-Longman
Peter Zijlstra
maintainerRe: [PATCH v13 09/11] pvqspinlock, x86: Add para-virtualization support
In reply to Waiman LongQuoted 1 line · Waiman Long
arch/x86/include/asm/pvqspinlock.h | 411 +++++++++++++++++++++++++++++++++
I do wonder why all this needs to live in x86..
Quoted 7 lines
arch/x86/include/asm/paravirt.h +6
-0+#ifdef CONFIG_QUEUE_SPINLOCK + +static __always_inline void pv_kick_cpu(int cpu) +{ +PVOP_VCALLEE1 (pv_lock_ops.kick_cpu, cpu); +}
arch/x86/include/asm/paravirt.h static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx, · line 730
Quoted 10 lines
arch/x86/include/asm/paravirt.h +10
-0+ +static __always_inline void pv_lockwait(u8 *lockbyte) +{ +PVOP_VCALLEE1 (pv_lock_ops.lockwait, lockbyte); +} + +static __always_inline void pv_lockstat(enum pv_lock_stats type) +{ +PVOP_VCALLEE1 (pv_lock_ops.lockstat, type); +}
Why are any of these PV ops? they're only called from other pv_*() functions. What's the point of pv ops you only call from pv code?
Quoted 5 lines
+/*
+ * Queue Spinlock Para-Virtualization (PV) Support
+ *
+ * The PV support code for queue spinlock is roughly the same as that
+ * of the ticket spinlock.
Relative comments are bad, esp. since we'll make the ticket code go away if this works, at which point this is a reference into a black hole.
Quoted 8 lines
Each CPU waiting for the lock will spin until it
+ * reaches a threshold. When that happens, it will put itself to a halt state
+ * so that the hypervisor can reuse the CPU cycles in some other guests as
+ * well as returning other hold-up CPUs faster.
Quoted 5 lines
+/**
+ *queue_spin_lock- acquire a queue spinlock
+ * @lock: Pointer to queue spinlock structure
+ *
+ * N.B.INLINE_SPIN_LOCKshould not be enabled whenPARAVIRT_SPINLOCKis on.
One should write a compile time fail for that, not a comment.
arch/x86/include/asm/qspinlock.h line 53
Quoted 13 lines
+ */
arch/x86/include/asm/qspinlock.h +12
-0+static __always_inline void queue_spin_lock(struct qspinlock *lock) +{ +u32 val; + + val =atomic_cmpxchg (&lock->val,0 , _Q_LOCKED_VAL); +if (likely (val ==0 )) +return ; +if (static_key_false (¶virt_spinlocks_enabled)) +pv_queue_spin_lock_slowpath (lock, val); +else +queue_spin_lock_slowpath (lock, val); +}
No, this is just vile.. _that_ is what we have PV ops for. And at that point its the same function it was before the PV stuff, so that whole inline thing is then gone.
arch/x86/include/asm/qspinlock.h line 65
Quoted 11 lines
arch/x86/include/asm/qspinlock.h +6
-0+extern void queue_spin_unlock_slowpath (struct qspinlock *lock); +/** * queue_spin_unlock - release a queue spinlock * @lock : Pointer to queue spinlock structure * * An effective smp_store_release() on the least-significant byte. +* +* Inlining of the unlock function is disabled when CONFIG_PARAVIRT_SPINLOCKS +* is defined. So _raw_spin_unlock() will be the only call site that will +* have to be patched.
again if you hard rely on the not inlining make a build fail not a comment.
Quoted 6 lines
*/
static inline voidqueue_spin_unlock(struct qspinlock *lock){arch/x86/include/asm/qspinlock.h +2
-0barrier (); +if (!static_key_false (¶virt_spinlocks_enabled)) { +native_spin_unlock (lock);
arch/x86/include/asm/qspinlock.h line 81
Quoted 10 lines
arch/x86/include/asm/qspinlock.h +9
-0+return ; + } +/* +* Need to atomically clear the lock byte to avoid racing with +* queue head waiter trying to set _QLOCK_LOCKED_SLOWPATH. +*/ +if (unlikely (cmpxchg ((u8 *)lock, _Q_LOCKED_VAL,0 ) != _Q_LOCKED_VAL)) +queue_spin_unlock_slowpath (lock); +}
Idem, that static key stuff is wrong, use PV ops to switch between unlock paths.
Quoted 12 lines
kernel/locking/qspinlock.c +1
-1@@ -354,7 +394,7 @@ queue:* if there was a previous node; link it and wait until reaching the * head of the waitqueue. */ -if (old & _Q_TAIL_MASK) { +if (!pv_link_and_wait_node (old, node) && (old & _Q_TAIL_MASK)) { prev =decode_tail (old);ACCESS_ONCE (prev->next) = node;@@ -369,9 +409,11 @@ queue:* * *,x,y -> *,0,0 */
kernel/locking/qspinlock.c queue: · line 419
Quoted 10 lines
kernel/locking/qspinlock.c +4
-2-while ((val =smp_load_acquire (&lock->val.counter)) & - _Q_LOCKED_PENDING_MASK) + val =pv_wait_head (lock, node); +while (val & _Q_LOCKED_PENDING_MASK) {cpu_relax (); + val =smp_load_acquire (&lock->val.counter); + }/* * claim the lock:
Please make the pv_*() calls return void and reduce to NOPs. This keeps the logic invariant of the pv stuff.
Re: [PATCH v13 09/11] pvqspinlock, x86: Add para-virtualization support
In reply to Waiman LongQuoted 138 lines · Waiman Long
This patch adds para-virtualization support to the queue spinlock code base with minimal impact to the native case. There are some minor code changes in the generic
qspinlock.cfile which should be usable in other architectures. The other code changes are specific to x86 processors and so are all put under thearch/x86directory.On the lock side, the slowpath code is split into 2 separate functions generated from the same code - one for bare metal and one for PV guest. The switching is done in the _raw_spin_lock* functions. This makes sure that the performance impact to the bare metal case is minimal, just a few NOPs in the _raw_spin_lock* functions. In the PV slowpath code, there are 2 paravirt callee saved calls that minimize register pressure.
On the unlock side, however, the disabling of unlock function inlining does have some slight impact on bare metal performance.
The actual paravirt code comes in 5 parts;
-
init_node; this initializes the extra data members required for PV state. PV state data is kept 1 cacheline ahead of the regular data.-
link_and_wait_node; this replaces the regular MCS queuing code. CPU halting can happen if the wait is too long.-
wait_head; this waits until the lock is avialable and the CPU will be halted if the wait is too long.-
wait_check; this is called after acquiring the lock to see if the next queue head CPU is halted. If this is the case, the lock bit is changed to indicate the queue head will have to be kicked on unlock.-
queue_unlock; this routine has a jump label to check if paravirt is enabled. If yes, it has to do an atomic cmpxchg to clear the lock bit or call the slowpath function to kick the queue head cpu.Tracking the head is done in two parts, firstly the
pv_wait_headwill store its cpu number in whichever node is pointed to by the tail part of the lock word. Secondly,pv_link_and_wait_node()will propagate the existing head from the old to the new tail node.Signed-off-by Waiman Long <[email protected]>--- arch/x86/include/asm/paravirt.h | 19 ++ arch/x86/include/asm/paravirt_types.h | 20 ++ arch/x86/include/asm/pvqspinlock.h | 411 +++++++++++++++++++++++++++++++++ arch/x86/include/asm/qspinlock.h | 71 ++++++- arch/x86/kernel/paravirt-spinlocks.c | 6 + include/asm-generic/qspinlock.h | 2 + kernel/locking/qspinlock.c | 69 +++++- 7 files changed, 591 insertions(+), 7 deletions(-) create mode 100644 arch/x86/include/asm/pvqspinlock.harch/x86/include/asm/paravirt.h +19
-0@@ -712,6 +712,24 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx, #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS) +#ifdef CONFIG_QUEUE_SPINLOCK + +static __always_inline void pv_kick_cpu(int cpu) +{ + PVOP_VCALLEE1(pv_lock_ops.kick_cpu, cpu); +} + +static __always_inline void pv_lockwait(u8 *lockbyte) +{ + PVOP_VCALLEE1(pv_lock_ops.lockwait, lockbyte); +} + +static __always_inline void pv_lockstat(enum pv_lock_stats type) +{ + PVOP_VCALLEE1(pv_lock_ops.lockstat, type); +} + +#else static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock, __ticket_t ticket) {@@ -723,6 +741,7 @@ static __always_inline void __ticket_unlock_kick(struct arch_spinlock *lock, {PVOP_VCALL2 (pv_lock_ops.unlock_kick, lock, ticket); } +#endif #endif arch/x86/include/asm/paravirt_types.h +20
-0@@ -326,6 +326,9 @@ struct pv_mmu_ops { phys_addr_t phys, pgprot_t flags); }; +struct mcs_spinlock ; +struct qspinlock ; +struct arch_spinlock ;#ifdef CONFIG_SMP #include <asm/spinlock_types.h> @@ -333,9 +336,26 @@ struct arch_spinlock;typedef u16 __ticket_t ;#endif +#ifdef CONFIG_QUEUE_SPINLOCK +enum pv_lock_stats { +PV_HALT_QHEAD ,/* Queue head halting */ +PV_HALT_QNODE ,/* Other queue node halting */ +PV_HALT_ABORT ,/* Halting aborted */ +PV_WAKE_KICKED ,/* Wakeup by kicking */ +PV_WAKE_SPURIOUS ,/* Spurious wakeup */ +PV_KICK_NOHALT /* Kick but CPU not halted */ +}; +#endif +struct pv_lock_ops { +#ifdef CONFIG_QUEUE_SPINLOCK +struct paravirt_callee_save kick_cpu; +struct paravirt_callee_save lockstat; +struct paravirt_callee_save lockwait; +#else struct paravirt_callee_save lock_spinning;void (*unlock_kick)(struct arch_spinlock *lock,__ticket_t ticket); +#endif };/* This contains all the paravirt structures: we get a convenient arch/x86/include/asm/pvqspinlock.h new file +1
-0@@ -0,0 +1,411 @@ +#ifndef _ASM_X86_PVQSPINLOCK_H
arch/x86/include/asm/pvqspinlock.h line 11
Quoted 10 lines
arch/x86/include/asm/pvqspinlock.h new file +10
-0+#define _ASM_X86_PVQSPINLOCK_H + +/* +* Queue Spinlock Para-Virtualization (PV) Support +* +* The PV support code for queue spinlock is roughly the same as that +* of the ticket spinlock. Each CPU waiting for the lock will spin until it +* reaches a threshold. When that happens, it will put itself to a halt state +* so that the hypervisor can reuse the CPU cycles in some other guests as +* well as returning other hold-up CPUs faster.
Kind of. There is a lot more of going to sleep here than the PV ticketlock. In there the CPU would go to sleep and wait until it was its turn in. Here we need go to sleep when we are at the queue and then wake up to move a bit.
That means the next in the line has at least two halt and wakeups?
How does it compare to the PV ticketlocks that exists right now?
Re: [PATCH v13 09/11] pvqspinlock, x86: Add para-virtualization support
In reply to Waiman LongQuoted 138 lines · Waiman Long
This patch adds para-virtualization support to the queue spinlock code base with minimal impact to the native case. There are some minor code changes in the generic
qspinlock.cfile which should be usable in other architectures. The other code changes are specific to x86 processors and so are all put under thearch/x86directory.On the lock side, the slowpath code is split into 2 separate functions generated from the same code - one for bare metal and one for PV guest. The switching is done in the _raw_spin_lock* functions. This makes sure that the performance impact to the bare metal case is minimal, just a few NOPs in the _raw_spin_lock* functions. In the PV slowpath code, there are 2 paravirt callee saved calls that minimize register pressure.
On the unlock side, however, the disabling of unlock function inlining does have some slight impact on bare metal performance.
The actual paravirt code comes in 5 parts;
-
init_node; this initializes the extra data members required for PV state. PV state data is kept 1 cacheline ahead of the regular data.-
link_and_wait_node; this replaces the regular MCS queuing code. CPU halting can happen if the wait is too long.-
wait_head; this waits until the lock is avialable and the CPU will be halted if the wait is too long.-
wait_check; this is called after acquiring the lock to see if the next queue head CPU is halted. If this is the case, the lock bit is changed to indicate the queue head will have to be kicked on unlock.-
queue_unlock; this routine has a jump label to check if paravirt is enabled. If yes, it has to do an atomic cmpxchg to clear the lock bit or call the slowpath function to kick the queue head cpu.Tracking the head is done in two parts, firstly the
pv_wait_headwill store its cpu number in whichever node is pointed to by the tail part of the lock word. Secondly,pv_link_and_wait_node()will propagate the existing head from the old to the new tail node.Signed-off-by Waiman Long <[email protected]>--- arch/x86/include/asm/paravirt.h | 19 ++ arch/x86/include/asm/paravirt_types.h | 20 ++ arch/x86/include/asm/pvqspinlock.h | 411 +++++++++++++++++++++++++++++++++ arch/x86/include/asm/qspinlock.h | 71 ++++++- arch/x86/kernel/paravirt-spinlocks.c | 6 + include/asm-generic/qspinlock.h | 2 + kernel/locking/qspinlock.c | 69 +++++- 7 files changed, 591 insertions(+), 7 deletions(-) create mode 100644 arch/x86/include/asm/pvqspinlock.harch/x86/include/asm/paravirt.h +19
-0@@ -712,6 +712,24 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx, #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS) +#ifdef CONFIG_QUEUE_SPINLOCK + +static __always_inline void pv_kick_cpu(int cpu) +{ + PVOP_VCALLEE1(pv_lock_ops.kick_cpu, cpu); +} + +static __always_inline void pv_lockwait(u8 *lockbyte) +{ + PVOP_VCALLEE1(pv_lock_ops.lockwait, lockbyte); +} + +static __always_inline void pv_lockstat(enum pv_lock_stats type) +{ + PVOP_VCALLEE1(pv_lock_ops.lockstat, type); +} + +#else static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock, __ticket_t ticket) {@@ -723,6 +741,7 @@ static __always_inline void __ticket_unlock_kick(struct arch_spinlock *lock, {PVOP_VCALL2 (pv_lock_ops.unlock_kick, lock, ticket); } +#endif #endif arch/x86/include/asm/paravirt_types.h +20
-0@@ -326,6 +326,9 @@ struct pv_mmu_ops { phys_addr_t phys, pgprot_t flags); }; +struct mcs_spinlock ; +struct qspinlock ; +struct arch_spinlock ;#ifdef CONFIG_SMP #include <asm/spinlock_types.h> @@ -333,9 +336,26 @@ struct arch_spinlock;typedef u16 __ticket_t ;#endif +#ifdef CONFIG_QUEUE_SPINLOCK +enum pv_lock_stats { +PV_HALT_QHEAD ,/* Queue head halting */ +PV_HALT_QNODE ,/* Other queue node halting */ +PV_HALT_ABORT ,/* Halting aborted */ +PV_WAKE_KICKED ,/* Wakeup by kicking */ +PV_WAKE_SPURIOUS ,/* Spurious wakeup */ +PV_KICK_NOHALT /* Kick but CPU not halted */ +}; +#endif +struct pv_lock_ops { +#ifdef CONFIG_QUEUE_SPINLOCK +struct paravirt_callee_save kick_cpu; +struct paravirt_callee_save lockstat; +struct paravirt_callee_save lockwait; +#else struct paravirt_callee_save lock_spinning;void (*unlock_kick)(struct arch_spinlock *lock,__ticket_t ticket); +#endif };/* This contains all the paravirt structures: we get a convenient arch/x86/include/asm/pvqspinlock.h new file +1
-0@@ -0,0 +1,411 @@ +#ifndef _ASM_X86_PVQSPINLOCK_H
arch/x86/include/asm/pvqspinlock.h line 11
Quoted 10 lines
arch/x86/include/asm/pvqspinlock.h new file +10
-0+#define _ASM_X86_PVQSPINLOCK_H + +/* +* Queue Spinlock Para-Virtualization (PV) Support +* +* The PV support code for queue spinlock is roughly the same as that +* of the ticket spinlock. Each CPU waiting for the lock will spin until it +* reaches a threshold. When that happens, it will put itself to a halt state +* so that the hypervisor can reuse the CPU cycles in some other guests as +* well as returning other hold-up CPUs faster.
Kind of. There is a lot more of going to sleep here than the PV ticketlock. In there the CPU would go to sleep and wait until it was its turn in. Here we need go to sleep when we are at the queue and then wake up to move a bit.
That means the next in the line has at least two halt and wakeups?
How does it compare to the PV ticketlocks that exists right now?
PATCH v13 9/11 pvqspinlock, x86: Add para-virtualization support
In reply to Waiman LongThis patch adds para-virtualization support to the queue spinlock code base with minimal impact to the native case. There are some minor code changes in the generic qspinlock.c file which should be usable in other architectures. The other code changes are specific to x86 processors and so are all put under the arch/x86 directory.
On the lock side, the slowpath code is split into 2 separate functions generated from the same code - one for bare metal and one for PV guest. The switching is done in the _raw_spin_lock* functions. This makes sure that the performance impact to the bare metal case is minimal, just a few NOPs in the _raw_spin_lock* functions. In the PV slowpath code, there are 2 paravirt callee saved calls that minimize register pressure.
On the unlock side, however, the disabling of unlock function inlining does have some slight impact on bare metal performance.
The actual paravirt code comes in 5 parts;
- init_node; this initializes the extra data members required for PV state. PV state data is kept 1 cacheline ahead of the regular data.
- link_and_wait_node; this replaces the regular MCS queuing code. CPU halting can happen if the wait is too long.
- wait_head; this waits until the lock is avialable and the CPU will be halted if the wait is too long.
- wait_check; this is called after acquiring the lock to see if the next queue head CPU is halted. If this is the case, the lock bit is changed to indicate the queue head will have to be kicked on unlock.
- queue_unlock; this routine has a jump label to check if paravirt is enabled. If yes, it has to do an atomic cmpxchg to clear the lock bit or call the slowpath function to kick the queue head cpu.
Tracking the head is done in two parts, firstly the pv_wait_head will store its cpu number in whichever node is pointed to by the tail part of the lock word. Secondly, pv_link_and_wait_node() will propagate the existing head from the old to the new tail node.
--- arch/x86/include/asm/paravirt.h | 19 ++ arch/x86/include/asm/paravirt_types.h | 20 ++ arch/x86/include/asm/pvqspinlock.h | 411 +++++++++++++++++++++++++++++++++ arch/x86/include/asm/qspinlock.h | 71 ++++++- arch/x86/kernel/paravirt-spinlocks.c | 6 + include/asm-generic/qspinlock.h | 2 + kernel/locking/qspinlock.c | 69 +++++- 7 files changed, 591 insertions(+), 7 deletions(-) create mode 100644 arch/x86/include/asm/pvqspinlock.h
arch/x86/include/asm/paravirt.h +19 -0
@@ -712,6 +712,24 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx, #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS) +#ifdef CONFIG_QUEUE_SPINLOCK + +static __always_inline void pv_kick_cpu(int cpu) +{ + PVOP_VCALLEE1(pv_lock_ops.kick_cpu, cpu); +} + +static __always_inline void pv_lockwait(u8 *lockbyte) +{ + PVOP_VCALLEE1(pv_lock_ops.lockwait, lockbyte); +} + +static __always_inline void pv_lockstat(enum pv_lock_stats type) +{ + PVOP_VCALLEE1(pv_lock_ops.lockstat, type); +} + +#else static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock, __ticket_t ticket) {
@@ -723,6 +741,7 @@ static __always_inline void __ticket_unlock_kick(struct arch_spinlock *lock, {PVOP_VCALL2 (pv_lock_ops.unlock_kick, lock, ticket); } +#endif #endif
arch/x86/include/asm/paravirt_types.h +20 -0
@@ -326,6 +326,9 @@ struct pv_mmu_ops { phys_addr_t phys, pgprot_t flags); }; +struct mcs_spinlock ; +struct qspinlock ; +struct arch_spinlock ;#ifdef CONFIG_SMP #include <asm/spinlock_types.h>
@@ -333,9 +336,26 @@ struct arch_spinlock;typedef u16 __ticket_t ;#endif +#ifdef CONFIG_QUEUE_SPINLOCK +enum pv_lock_stats { +PV_HALT_QHEAD ,/* Queue head halting */ +PV_HALT_QNODE ,/* Other queue node halting */ +PV_HALT_ABORT ,/* Halting aborted */ +PV_WAKE_KICKED ,/* Wakeup by kicking */ +PV_WAKE_SPURIOUS ,/* Spurious wakeup */ +PV_KICK_NOHALT /* Kick but CPU not halted */ +}; +#endif +struct pv_lock_ops { +#ifdef CONFIG_QUEUE_SPINLOCK +struct paravirt_callee_save kick_cpu; +struct paravirt_callee_save lockstat; +struct paravirt_callee_save lockwait; +#else struct paravirt_callee_save lock_spinning;void (*unlock_kick)(struct arch_spinlock *lock,__ticket_t ticket); +#endif };/* This contains all the paravirt structures: we get a convenient
arch/x86/include/asm/pvqspinlock.h new file +411 -0
411 lines not on this page · raw message
arch/x86/include/asm/qspinlock.h +68 -3
89 lines not on this page · raw message
arch/x86/kernel/paravirt-spinlocks.c +6 -0
@@ -10,9 +10,15 @@ struct pv_lock_ops pv_lock_ops = {#ifdef CONFIG_SMP +#ifdef CONFIG_QUEUE_SPINLOCK + .kick_cpu = __PV_IS_CALLEE_SAVE(paravirt_nop), + .lockstat = __PV_IS_CALLEE_SAVE(paravirt_nop), + .lockwait = __PV_IS_CALLEE_SAVE(paravirt_nop), +#else .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop), .unlock_kick = paravirt_nop,#endif +#endif };EXPORT_SYMBOL (pv_lock_ops);
include/asm-generic/qspinlock.h +2 -0
@@ -67,6 +67,7 @@ static __always_inline int queue_spin_trylock(struct qspinlock *lock)return 0 ; } +#ifndef queue_spin_lockextern void queue_spin_lock_slowpath (struct qspinlock *lock,u32 val);/**
@@ -82,6 +83,7 @@ static __always_inline void queue_spin_lock(struct qspinlock *lock)return ; queue_spin_lock_slowpath(lock, val); } +#endif #ifndef queue_spin_unlock/**
kernel/locking/qspinlock.c +65 -4
127 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v13 10/11 pvqspinlock, x86: Enable PV qspinlock for KVM
In reply to Waiman LongThis patch adds the necessary KVM specific code to allow KVM to support the CPU halting and kicking operations needed by the queue spinlock PV code.
Two KVM guests of 20 CPU cores (2 nodes) were created for performance testing in one of the following three configurations:
1) Only 1 VM is active
2) Both VMs are active and they share the same 20 physical CPUs
(200% overcommit)
The tests run included the disk workload of the AIM7 benchmark on both ext4 and xfs RAM disks at 3000 users on a 3.17 based kernel. The "ebizzy -m" test and futextest was was also run and its performance data were recorded. With two VMs running, the "idle=poll" kernel option was added to simulate a busy guest. If PV qspinlock is not enabled, unfairlock will be used automically in a guest.
AIM7 XFS Disk Test (no overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 2542373 7.08 98.95 5.44 PV qspinlock 2549575 7.06 98.63 5.40
unfairlock 2616279 6.91 97.05 5.42
AIM7 XFS Disk Test (200% overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 644468 27.93 415.22 6.33 PV qspinlock 645624 27.88 419.84 0.39
unfairlock 695518 25.88 377.40 4.09
AIM7 EXT4 Disk Test (no overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 1995565 9.02 103.67 5.76 PV qspinlock 2011173 8.95 102.15 5.40
unfairlock 2066590 8.71 98.13 5.46
AIM7 EXT4 Disk Test (200% overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 478341 37.63 495.81 30.78 PV qspinlock 474058 37.97 475.74 30.95
unfairlock 560224 32.13 398.43 26.27
For the AIM7 disk workload, both PV ticketlock and qspinlock have about the same performance. The unfairlock performs slightly better than the PV lock.
EBIZZY-m Test (no overcommit)
kernel Rec/s Real Time Sys Time Usr Time ----- ----- --------- -------- -------- PV ticketlock 3255 10.00 60.65 3.62 PV qspinlock 3318 10.00 54.27 3.60
unfairlock 2833 10.00 26.66 3.09
EBIZZY-m Test (200% overcommit)
kernel Rec/s Real Time Sys Time Usr Time ----- ----- --------- -------- -------- PV ticketlock 841 10.00 71.03 2.37 PV qspinlock 834 10.00 68.27 2.39
unfairlock 865 10.00 27.08 1.51
futextest (no overcommit)
kernel kops/s ----- ------ PV ticketlock 11523 PV qspinlock 12328
unfairlock 9478
futextest (200% overcommit)
kernel kops/s
----- ------
PV ticketlock 7276
PV qspinlock 7095
unfairlock 5614
The ebizzy and futextest have much higher spinlock contention than the AIM7 disk workload. In this case, the unfairlock performs worse than both the PV ticketlock and qspinlock. The performance of the 2 PV locks are comparable.
--- arch/x86/kernel/kvm.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++- kernel/Kconfig.locks | 2 +- 2 files changed, 138 insertions(+), 2 deletions(-)
arch/x86/kernel/kvm.c +137 -1
@@ -568,7 +568,7 @@ arch_initcall(activate_jump_labels);#ifdef CONFIG_PARAVIRT_SPINLOCKS /* Kick a cpu by its apicid. Used to wake up a halted vcpu */ -static void kvm_kick_cpu (int cpu) +void kvm_kick_cpu (int cpu) {int apicid;unsigned long flags =0 ;
@@ -576,7 +576,9 @@ static void kvm_kick_cpu(int cpu) apicid =per_cpu (x86_cpu_to_apicid, cpu);kvm_hypercall2 (KVM_HC_KICK_CPU , flags, apicid); } +PV_CALLEE_SAVE_REGS_THUNK (kvm_kick_cpu); +#ifndef CONFIG_QUEUE_SPINLOCK enum kvm_contention_stat {TAKEN_SLOW , TAKEN_SLOW_PICKUP,
@@ -804,6 +806,132 @@ static void kvm_unlock_kick(struct arch_spinlock *lock, __ticket_t ticket) } } } +#else /* !CONFIG_QUEUE_SPINLOCK */ + +#ifdef CONFIG_KVM_DEBUG_FS +static struct dentry *d_spin_debug; +static struct dentry *d_kvm_debug; +static u32 kick_nohlt_stats;/* Kick but not halt count */ +static u32 halt_qhead_stats;/* Queue head halting count */ +static u32 halt_qnode_stats;/* Queue node halting count */ +static u32 halt_abort_stats;/* Halting abort count */ +static u32 wake_kick_stats;/* Wakeup by kicking count */ +static u32 wake_spur_stats;/* Spurious wakeup count */ +static u64 time_blocked;/* Total blocking time */ + +static int __init kvm_spinlock_debugfs (void ) +{ + d_kvm_debug =debugfs_create_dir ("kvm-guest" ,NULL ); +if (!d_kvm_debug) { +printk (KERN_WARNING +"Could not create 'kvm' debugfs directory\n" ); +return -ENOMEM ; + } + d_spin_debug =debugfs_create_dir ("spinlocks" , d_kvm_debug); + +debugfs_create_u32 ("kick_nohlt_stats" , +0644 , d_spin_debug, &kick_nohlt_stats); +debugfs_create_u32 ("halt_qhead_stats" , +0644 , d_spin_debug, &halt_qhead_stats); +debugfs_create_u32 ("halt_qnode_stats" , +0644 , d_spin_debug, &halt_qnode_stats); +debugfs_create_u32 ("halt_abort_stats" , +0644 , d_spin_debug, &halt_abort_stats); +debugfs_create_u32 ("wake_kick_stats" , +0644 , d_spin_debug, &wake_kick_stats); +debugfs_create_u32 ("wake_spur_stats" , +0644 , d_spin_debug, &wake_spur_stats); +debugfs_create_u64 ("time_blocked" , +0644 , d_spin_debug, &time_blocked); +return 0 ; +} + +static inline void kvm_halt_stats (enum pv_lock_stats type) +{ +if (type ==PV_HALT_QHEAD ) +add_smp (&halt_qhead_stats,1 ); +else if (type ==PV_HALT_QNODE ) +add_smp (&halt_qnode_stats,1 ); +else /* type == PV_HALT_ABORT */ +add_smp (&halt_abort_stats,1 ); +} + +void kvm_lock_stats (enum pv_lock_stats type) +{ +if (type ==PV_WAKE_KICKED ) +add_smp (&wake_kick_stats,1 ); +else if (type ==PV_WAKE_SPURIOUS ) +add_smp (&wake_spur_stats,1 ); +else /* type == PV_KICK_NOHALT */ +add_smp (&kick_nohlt_stats,1 ); +} +PV_CALLEE_SAVE_REGS_THUNK (kvm_lock_stats); + +static inline u64 spin_time_start (void ) +{ +return sched_clock (); +} + +static inline void spin_time_accum_blocked (u64 start) +{ +u64 delta; + + delta =sched_clock () - start; +add_smp (&time_blocked, delta); +} + +fs_initcall (kvm_spinlock_debugfs); + +#else /* CONFIG_KVM_DEBUG_FS */ +static inline void kvm_halt_stats (enum pv_lock_stats type) +{ +} + +static inline u64 spin_time_start (void ) +{ +return 0 ; +} + +static inline void spin_time_accum_blocked (u64 start) +{ +} +#endif /* CONFIG_KVM_DEBUG_FS */ + +/* +* Halt the current CPU & release it back to the host +*/ +void kvm_halt_cpu (u8 *lockbyte) +{ +unsigned long flags; +u64 start; + +if (in_nmi ()) +return ; + +/* +* Make sure an interrupt handler can't upset things in a +* partially setup state. +*/ +local_irq_save (flags); +/* +* Don't halt if the lock byte is defined and is free +*/ +if (lockbyte && !ACCESS_ONCE (*lockbyte)) { +kvm_halt_stats (PV_HALT_ABORT ); + goto out; + } + start =spin_time_start (); +kvm_halt_stats (lockbyte ?PV_HALT_QHEAD :PV_HALT_QNODE ); +if (arch_irqs_disabled_flags (flags)) +halt (); +else +safe_halt (); +spin_time_accum_blocked (start); +out: +local_irq_restore (flags); +} +PV_CALLEE_SAVE_REGS_THUNK (kvm_halt_cpu); +#endif /* !CONFIG_QUEUE_SPINLOCK */ /* * Setup pv_lock_ops to exploit KVM_FEATURE_PV_UNHALT if present.
@@ -816,8 +944,16 @@ void __init kvm_spinlock_init(void)if (!kvm_para_has_feature (KVM_FEATURE_PV_UNHALT ))return ; +#ifdef CONFIG_QUEUE_SPINLOCK + pv_lock_ops.kick_cpu =PV_CALLEE_SAVE (kvm_kick_cpu); + pv_lock_ops.lockwait =PV_CALLEE_SAVE (kvm_halt_cpu); +#ifdef CONFIG_KVM_DEBUG_FS + pv_lock_ops.lockstat =PV_CALLEE_SAVE (kvm_lock_stats); +#endif +#else pv_lock_ops.lock_spinning =PV_CALLEE_SAVE (kvm_lock_spinning); pv_lock_ops.unlock_kick = kvm_unlock_kick; +#endif }static __init int kvm_spinlock_init_jump (void )
kernel/Kconfig.locks +1 -1
@@ -236,7 +236,7 @@ config ARCH_USE_QUEUE_SPINLOCK config QUEUE_SPINLOCK def_bool y if ARCH_USE_QUEUE_SPINLOCK - depends on SMP && !PARAVIRT_SPINLOCKS + depends on SMP && (!PARAVIRT_SPINLOCKS || !XEN) config ARCH_USE_QUEUE_RWLOCK bool
Signature · 1 line
1.7.1
Re: [PATCH v13 10/11] pvqspinlock, x86: Enable PV qspinlock for KVM
Quoted 8 lines · Waiman Long
This patch adds the necessary KVM specific code to allow KVM to support the CPU halting and kicking operations needed by the queue spinlock PV code.
Two KVM guests of 20 CPU cores (2 nodes) were created for performance testing in one of the following three configurations:
1) Only 1 VM is active
2) Both VMs are active and they share the same 20 physical CPUs
Quoted 8 lines
(200% overcommit)The tests run included the disk workload of the AIM7 benchmark on both ext4 and xfs RAM disks at 3000 users on a 3.17 based kernel. The "ebizzy -m" test and futextest was was also run and its performance data were recorded. With two VMs running, the "idle=poll" kernel option was added to simulate a busy guest. If PV qspinlock is not enabled, unfairlock will be used automically in a guest.
What is the unfairlock? Isn't it just using a bytelock at this point?
Re: [PATCH v13 10/11] pvqspinlock, x86: Enable PV qspinlock for KVM
In reply to Waiman LongQuoted 8 lines · Waiman Long
This patch adds the necessary KVM specific code to allow KVM to support the CPU halting and kicking operations needed by the queue spinlock PV code.
Two KVM guests of 20 CPU cores (2 nodes) were created for performance testing in one of the following three configurations:
1) Only 1 VM is active
2) Both VMs are active and they share the same 20 physical CPUs
Quoted 8 lines
(200% overcommit)The tests run included the disk workload of the AIM7 benchmark on both ext4 and xfs RAM disks at 3000 users on a 3.17 based kernel. The "ebizzy -m" test and futextest was was also run and its performance data were recorded. With two VMs running, the "idle=poll" kernel option was added to simulate a busy guest. If PV qspinlock is not enabled, unfairlock will be used automically in a guest.
What is the unfairlock? Isn't it just using a bytelock at this point?
Re: [PATCH v13 10/11] pvqspinlock, x86: Enable PV qspinlock for KVM
In reply to Waiman LongQuoted 5 lines · Waiman Long
AIM7 XFS Disk Test (no overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 2542373 7.08 98.95 5.44 PV qspinlock 2549575 7.06 98.63 5.40
Quoted 7 lines
unfairlock 2616279 6.91 97.05 5.42
AIM7 XFS Disk Test (200% overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 644468 27.93 415.22 6.33 PV qspinlock 645624 27.88 419.84 0.39
That number is made up by what? ----------------------------^^^^
Quoted 14 lines
unfairlock 695518 25.88 377.40 4.09
AIM7 EXT4 Disk Test (no overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 1995565 9.02 103.67 5.76 PV qspinlock 2011173 8.95 102.15 5.40unfairlock 2066590 8.71 98.13 5.46
AIM7 EXT4 Disk Test (200% overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 478341 37.63 495.81 30.78 PV qspinlock 474058 37.97 475.74 30.95
Quoted 5 lines
unfairlock 560224 32.13 398.43 26.27
For the AIM7 disk workload, both PV ticketlock and qspinlock have about the same performance. The unfairlock performs slightly better than the PV lock.
Slightly?
Taking the PV locks, which are basically the same for the existing ticket locks and your new fangled qlocks as a reference then the so called 'unfair locks' which are just the native locks w/o the PV nonsense are fundamentally better up to a whopping 18% in the ext4/200% overcommit case. See below.
Quoted 28 lines
EBIZZY-m Test (no overcommit)
kernel Rec/s Real Time Sys Time Usr Time ----- ----- --------- -------- -------- PV ticketlock 3255 10.00 60.65 3.62 PV qspinlock 3318 10.00 54.27 3.60unfairlock 2833 10.00 26.66 3.09
EBIZZY-m Test (200% overcommit)
kernel Rec/s Real Time Sys Time Usr Time ----- ----- --------- -------- -------- PV ticketlock 841 10.00 71.03 2.37 PV qspinlock 834 10.00 68.27 2.39unfairlock 865 10.00 27.08 1.51
futextest (no overcommit)
kernel kops/s ----- ------ PV ticketlock 11523 PV qspinlock 12328unfairlock 9478
futextest (200% overcommit)
kernel kops/s
----- ------
PV ticketlock 7276
PV qspinlock 7095
unfairlock 5614
Quoted 4 lines
The ebizzy and futextest have much higher spinlock contention than the AIM7 disk workload. In this case, the unfairlock performs worse than both the PV ticketlock and qspinlock. The performance of the 2 PV locks are comparable.
While I can see that the PV lock stuff performs 13% better for the ebizzy no overcommit case, what about the very interresting numbers for the same test with 200% overcommit?
The regular lock has a slightly better performance, but significantly less sys/usr time. How do you explain that?
'Lies, damned lies and statistics' comes to my mind.
Thanks,
tglx
Re: [PATCH v13 10/11] pvqspinlock, x86: Enable PV qspinlock for KVM
In reply to Waiman LongQuoted 5 lines · Waiman Long
AIM7 XFS Disk Test (no overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 2542373 7.08 98.95 5.44 PV qspinlock 2549575 7.06 98.63 5.40
Quoted 7 lines
unfairlock 2616279 6.91 97.05 5.42
AIM7 XFS Disk Test (200% overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 644468 27.93 415.22 6.33 PV qspinlock 645624 27.88 419.84 0.39
That number is made up by what? ----------------------------^^^^
Quoted 14 lines
unfairlock 695518 25.88 377.40 4.09
AIM7 EXT4 Disk Test (no overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 1995565 9.02 103.67 5.76 PV qspinlock 2011173 8.95 102.15 5.40unfairlock 2066590 8.71 98.13 5.46
AIM7 EXT4 Disk Test (200% overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 478341 37.63 495.81 30.78 PV qspinlock 474058 37.97 475.74 30.95
Quoted 5 lines
unfairlock 560224 32.13 398.43 26.27
For the AIM7 disk workload, both PV ticketlock and qspinlock have about the same performance. The unfairlock performs slightly better than the PV lock.
Slightly?
Taking the PV locks, which are basically the same for the existing ticket locks and your new fangled qlocks as a reference then the so called 'unfair locks' which are just the native locks w/o the PV nonsense are fundamentally better up to a whopping 18% in the ext4/200% overcommit case. See below.
Quoted 28 lines
EBIZZY-m Test (no overcommit)
kernel Rec/s Real Time Sys Time Usr Time ----- ----- --------- -------- -------- PV ticketlock 3255 10.00 60.65 3.62 PV qspinlock 3318 10.00 54.27 3.60unfairlock 2833 10.00 26.66 3.09
EBIZZY-m Test (200% overcommit)
kernel Rec/s Real Time Sys Time Usr Time ----- ----- --------- -------- -------- PV ticketlock 841 10.00 71.03 2.37 PV qspinlock 834 10.00 68.27 2.39unfairlock 865 10.00 27.08 1.51
futextest (no overcommit)
kernel kops/s ----- ------ PV ticketlock 11523 PV qspinlock 12328unfairlock 9478
futextest (200% overcommit)
kernel kops/s
----- ------
PV ticketlock 7276
PV qspinlock 7095
unfairlock 5614
Quoted 4 lines
The ebizzy and futextest have much higher spinlock contention than the AIM7 disk workload. In this case, the unfairlock performs worse than both the PV ticketlock and qspinlock. The performance of the 2 PV locks are comparable.
While I can see that the PV lock stuff performs 13% better for the ebizzy no overcommit case, what about the very interresting numbers for the same test with 200% overcommit?
The regular lock has a slightly better performance, but significantly less sys/usr time. How do you explain that?
'Lies, damned lies and statistics' comes to my mind.
Thanks,
tglx
PATCH v13 10/11 pvqspinlock, x86: Enable PV qspinlock for KVM
In reply to Waiman LongThis patch adds the necessary KVM specific code to allow KVM to support the CPU halting and kicking operations needed by the queue spinlock PV code.
Two KVM guests of 20 CPU cores (2 nodes) were created for performance testing in one of the following three configurations:
1) Only 1 VM is active
2) Both VMs are active and they share the same 20 physical CPUs
(200% overcommit)
The tests run included the disk workload of the AIM7 benchmark on both ext4 and xfs RAM disks at 3000 users on a 3.17 based kernel. The "ebizzy -m" test and futextest was was also run and its performance data were recorded. With two VMs running, the "idle=poll" kernel option was added to simulate a busy guest. If PV qspinlock is not enabled, unfairlock will be used automically in a guest.
AIM7 XFS Disk Test (no overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 2542373 7.08 98.95 5.44 PV qspinlock 2549575 7.06 98.63 5.40
unfairlock 2616279 6.91 97.05 5.42
AIM7 XFS Disk Test (200% overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 644468 27.93 415.22 6.33 PV qspinlock 645624 27.88 419.84 0.39
unfairlock 695518 25.88 377.40 4.09
AIM7 EXT4 Disk Test (no overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 1995565 9.02 103.67 5.76 PV qspinlock 2011173 8.95 102.15 5.40
unfairlock 2066590 8.71 98.13 5.46
AIM7 EXT4 Disk Test (200% overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 478341 37.63 495.81 30.78 PV qspinlock 474058 37.97 475.74 30.95
unfairlock 560224 32.13 398.43 26.27
For the AIM7 disk workload, both PV ticketlock and qspinlock have about the same performance. The unfairlock performs slightly better than the PV lock.
EBIZZY-m Test (no overcommit)
kernel Rec/s Real Time Sys Time Usr Time ----- ----- --------- -------- -------- PV ticketlock 3255 10.00 60.65 3.62 PV qspinlock 3318 10.00 54.27 3.60
unfairlock 2833 10.00 26.66 3.09
EBIZZY-m Test (200% overcommit)
kernel Rec/s Real Time Sys Time Usr Time ----- ----- --------- -------- -------- PV ticketlock 841 10.00 71.03 2.37 PV qspinlock 834 10.00 68.27 2.39
unfairlock 865 10.00 27.08 1.51
futextest (no overcommit)
kernel kops/s ----- ------ PV ticketlock 11523 PV qspinlock 12328
unfairlock 9478
futextest (200% overcommit)
kernel kops/s
----- ------
PV ticketlock 7276
PV qspinlock 7095
unfairlock 5614
The ebizzy and futextest have much higher spinlock contention than the AIM7 disk workload. In this case, the unfairlock performs worse than both the PV ticketlock and qspinlock. The performance of the 2 PV locks are comparable.
--- arch/x86/kernel/kvm.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++- kernel/Kconfig.locks | 2 +- 2 files changed, 138 insertions(+), 2 deletions(-)
arch/x86/kernel/kvm.c +137 -1
@@ -568,7 +568,7 @@ arch_initcall(activate_jump_labels);#ifdef CONFIG_PARAVIRT_SPINLOCKS /* Kick a cpu by its apicid. Used to wake up a halted vcpu */ -static void kvm_kick_cpu (int cpu) +void kvm_kick_cpu (int cpu) {int apicid;unsigned long flags =0 ;
@@ -576,7 +576,9 @@ static void kvm_kick_cpu(int cpu) apicid =per_cpu (x86_cpu_to_apicid, cpu);kvm_hypercall2 (KVM_HC_KICK_CPU , flags, apicid); } +PV_CALLEE_SAVE_REGS_THUNK (kvm_kick_cpu); +#ifndef CONFIG_QUEUE_SPINLOCK enum kvm_contention_stat {TAKEN_SLOW , TAKEN_SLOW_PICKUP,
@@ -804,6 +806,132 @@ static void kvm_unlock_kick(struct arch_spinlock *lock, __ticket_t ticket) } } } +#else /* !CONFIG_QUEUE_SPINLOCK */ + +#ifdef CONFIG_KVM_DEBUG_FS +static struct dentry *d_spin_debug; +static struct dentry *d_kvm_debug; +static u32 kick_nohlt_stats;/* Kick but not halt count */ +static u32 halt_qhead_stats;/* Queue head halting count */ +static u32 halt_qnode_stats;/* Queue node halting count */ +static u32 halt_abort_stats;/* Halting abort count */ +static u32 wake_kick_stats;/* Wakeup by kicking count */ +static u32 wake_spur_stats;/* Spurious wakeup count */ +static u64 time_blocked;/* Total blocking time */ + +static int __init kvm_spinlock_debugfs (void ) +{ + d_kvm_debug =debugfs_create_dir ("kvm-guest" ,NULL ); +if (!d_kvm_debug) { +printk (KERN_WARNING +"Could not create 'kvm' debugfs directory\n" ); +return -ENOMEM ; + } + d_spin_debug =debugfs_create_dir ("spinlocks" , d_kvm_debug); + +debugfs_create_u32 ("kick_nohlt_stats" , +0644 , d_spin_debug, &kick_nohlt_stats); +debugfs_create_u32 ("halt_qhead_stats" , +0644 , d_spin_debug, &halt_qhead_stats); +debugfs_create_u32 ("halt_qnode_stats" , +0644 , d_spin_debug, &halt_qnode_stats); +debugfs_create_u32 ("halt_abort_stats" , +0644 , d_spin_debug, &halt_abort_stats); +debugfs_create_u32 ("wake_kick_stats" , +0644 , d_spin_debug, &wake_kick_stats); +debugfs_create_u32 ("wake_spur_stats" , +0644 , d_spin_debug, &wake_spur_stats); +debugfs_create_u64 ("time_blocked" , +0644 , d_spin_debug, &time_blocked); +return 0 ; +} + +static inline void kvm_halt_stats (enum pv_lock_stats type) +{ +if (type ==PV_HALT_QHEAD ) +add_smp (&halt_qhead_stats,1 ); +else if (type ==PV_HALT_QNODE ) +add_smp (&halt_qnode_stats,1 ); +else /* type == PV_HALT_ABORT */ +add_smp (&halt_abort_stats,1 ); +} + +void kvm_lock_stats (enum pv_lock_stats type) +{ +if (type ==PV_WAKE_KICKED ) +add_smp (&wake_kick_stats,1 ); +else if (type ==PV_WAKE_SPURIOUS ) +add_smp (&wake_spur_stats,1 ); +else /* type == PV_KICK_NOHALT */ +add_smp (&kick_nohlt_stats,1 ); +} +PV_CALLEE_SAVE_REGS_THUNK (kvm_lock_stats); + +static inline u64 spin_time_start (void ) +{ +return sched_clock (); +} + +static inline void spin_time_accum_blocked (u64 start) +{ +u64 delta; + + delta =sched_clock () - start; +add_smp (&time_blocked, delta); +} + +fs_initcall (kvm_spinlock_debugfs); + +#else /* CONFIG_KVM_DEBUG_FS */ +static inline void kvm_halt_stats (enum pv_lock_stats type) +{ +} + +static inline u64 spin_time_start (void ) +{ +return 0 ; +} + +static inline void spin_time_accum_blocked (u64 start) +{ +} +#endif /* CONFIG_KVM_DEBUG_FS */ + +/* +* Halt the current CPU & release it back to the host +*/ +void kvm_halt_cpu (u8 *lockbyte) +{ +unsigned long flags; +u64 start; + +if (in_nmi ()) +return ; + +/* +* Make sure an interrupt handler can't upset things in a +* partially setup state. +*/ +local_irq_save (flags); +/* +* Don't halt if the lock byte is defined and is free +*/ +if (lockbyte && !ACCESS_ONCE (*lockbyte)) { +kvm_halt_stats (PV_HALT_ABORT ); + goto out; + } + start =spin_time_start (); +kvm_halt_stats (lockbyte ?PV_HALT_QHEAD :PV_HALT_QNODE ); +if (arch_irqs_disabled_flags (flags)) +halt (); +else +safe_halt (); +spin_time_accum_blocked (start); +out: +local_irq_restore (flags); +} +PV_CALLEE_SAVE_REGS_THUNK (kvm_halt_cpu); +#endif /* !CONFIG_QUEUE_SPINLOCK */ /* * Setup pv_lock_ops to exploit KVM_FEATURE_PV_UNHALT if present.
@@ -816,8 +944,16 @@ void __init kvm_spinlock_init(void)if (!kvm_para_has_feature (KVM_FEATURE_PV_UNHALT ))return ; +#ifdef CONFIG_QUEUE_SPINLOCK + pv_lock_ops.kick_cpu =PV_CALLEE_SAVE (kvm_kick_cpu); + pv_lock_ops.lockwait =PV_CALLEE_SAVE (kvm_halt_cpu); +#ifdef CONFIG_KVM_DEBUG_FS + pv_lock_ops.lockstat =PV_CALLEE_SAVE (kvm_lock_stats); +#endif +#else pv_lock_ops.lock_spinning =PV_CALLEE_SAVE (kvm_lock_spinning); pv_lock_ops.unlock_kick = kvm_unlock_kick; +#endif }static __init int kvm_spinlock_init_jump (void )
kernel/Kconfig.locks +1 -1
@@ -236,7 +236,7 @@ config ARCH_USE_QUEUE_SPINLOCK config QUEUE_SPINLOCK def_bool y if ARCH_USE_QUEUE_SPINLOCK - depends on SMP && !PARAVIRT_SPINLOCKS + depends on SMP && (!PARAVIRT_SPINLOCKS || !XEN) config ARCH_USE_QUEUE_RWLOCK bool
Signature · 1 line
1.7.1
PATCH v13 10/11 pvqspinlock, x86: Enable PV qspinlock for KVM
In reply to Waiman LongThis patch adds the necessary KVM specific code to allow KVM to support the CPU halting and kicking operations needed by the queue spinlock PV code.
Two KVM guests of 20 CPU cores (2 nodes) were created for performance testing in one of the following three configurations:
1) Only 1 VM is active
2) Both VMs are active and they share the same 20 physical CPUs
(200% overcommit)
The tests run included the disk workload of the AIM7 benchmark on both ext4 and xfs RAM disks at 3000 users on a 3.17 based kernel. The "ebizzy -m" test and futextest was was also run and its performance data were recorded. With two VMs running, the "idle=poll" kernel option was added to simulate a busy guest. If PV qspinlock is not enabled, unfairlock will be used automically in a guest.
AIM7 XFS Disk Test (no overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 2542373 7.08 98.95 5.44 PV qspinlock 2549575 7.06 98.63 5.40
unfairlock 2616279 6.91 97.05 5.42
AIM7 XFS Disk Test (200% overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 644468 27.93 415.22 6.33 PV qspinlock 645624 27.88 419.84 0.39
unfairlock 695518 25.88 377.40 4.09
AIM7 EXT4 Disk Test (no overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 1995565 9.02 103.67 5.76 PV qspinlock 2011173 8.95 102.15 5.40
unfairlock 2066590 8.71 98.13 5.46
AIM7 EXT4 Disk Test (200% overcommit)
kernel JPM Real Time Sys Time Usr Time ----- --- --------- -------- -------- PV ticketlock 478341 37.63 495.81 30.78 PV qspinlock 474058 37.97 475.74 30.95
unfairlock 560224 32.13 398.43 26.27
For the AIM7 disk workload, both PV ticketlock and qspinlock have about the same performance. The unfairlock performs slightly better than the PV lock.
EBIZZY-m Test (no overcommit)
kernel Rec/s Real Time Sys Time Usr Time ----- ----- --------- -------- -------- PV ticketlock 3255 10.00 60.65 3.62 PV qspinlock 3318 10.00 54.27 3.60
unfairlock 2833 10.00 26.66 3.09
EBIZZY-m Test (200% overcommit)
kernel Rec/s Real Time Sys Time Usr Time ----- ----- --------- -------- -------- PV ticketlock 841 10.00 71.03 2.37 PV qspinlock 834 10.00 68.27 2.39
unfairlock 865 10.00 27.08 1.51
futextest (no overcommit)
kernel kops/s ----- ------ PV ticketlock 11523 PV qspinlock 12328
unfairlock 9478
futextest (200% overcommit)
kernel kops/s
----- ------
PV ticketlock 7276
PV qspinlock 7095
unfairlock 5614
The ebizzy and futextest have much higher spinlock contention than the AIM7 disk workload. In this case, the unfairlock performs worse than both the PV ticketlock and qspinlock. The performance of the 2 PV locks are comparable.
--- arch/x86/kernel/kvm.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++- kernel/Kconfig.locks | 2 +- 2 files changed, 138 insertions(+), 2 deletions(-)
arch/x86/kernel/kvm.c +137 -1
@@ -568,7 +568,7 @@ arch_initcall(activate_jump_labels);#ifdef CONFIG_PARAVIRT_SPINLOCKS /* Kick a cpu by its apicid. Used to wake up a halted vcpu */ -static void kvm_kick_cpu (int cpu) +void kvm_kick_cpu (int cpu) {int apicid;unsigned long flags =0 ;
@@ -576,7 +576,9 @@ static void kvm_kick_cpu(int cpu) apicid =per_cpu (x86_cpu_to_apicid, cpu);kvm_hypercall2 (KVM_HC_KICK_CPU , flags, apicid); } +PV_CALLEE_SAVE_REGS_THUNK (kvm_kick_cpu); +#ifndef CONFIG_QUEUE_SPINLOCK enum kvm_contention_stat {TAKEN_SLOW , TAKEN_SLOW_PICKUP,
@@ -804,6 +806,132 @@ static void kvm_unlock_kick(struct arch_spinlock *lock, __ticket_t ticket) } } } +#else /* !CONFIG_QUEUE_SPINLOCK */ + +#ifdef CONFIG_KVM_DEBUG_FS +static struct dentry *d_spin_debug; +static struct dentry *d_kvm_debug; +static u32 kick_nohlt_stats;/* Kick but not halt count */ +static u32 halt_qhead_stats;/* Queue head halting count */ +static u32 halt_qnode_stats;/* Queue node halting count */ +static u32 halt_abort_stats;/* Halting abort count */ +static u32 wake_kick_stats;/* Wakeup by kicking count */ +static u32 wake_spur_stats;/* Spurious wakeup count */ +static u64 time_blocked;/* Total blocking time */ + +static int __init kvm_spinlock_debugfs (void ) +{ + d_kvm_debug =debugfs_create_dir ("kvm-guest" ,NULL ); +if (!d_kvm_debug) { +printk (KERN_WARNING +"Could not create 'kvm' debugfs directory\n" ); +return -ENOMEM ; + } + d_spin_debug =debugfs_create_dir ("spinlocks" , d_kvm_debug); + +debugfs_create_u32 ("kick_nohlt_stats" , +0644 , d_spin_debug, &kick_nohlt_stats); +debugfs_create_u32 ("halt_qhead_stats" , +0644 , d_spin_debug, &halt_qhead_stats); +debugfs_create_u32 ("halt_qnode_stats" , +0644 , d_spin_debug, &halt_qnode_stats); +debugfs_create_u32 ("halt_abort_stats" , +0644 , d_spin_debug, &halt_abort_stats); +debugfs_create_u32 ("wake_kick_stats" , +0644 , d_spin_debug, &wake_kick_stats); +debugfs_create_u32 ("wake_spur_stats" , +0644 , d_spin_debug, &wake_spur_stats); +debugfs_create_u64 ("time_blocked" , +0644 , d_spin_debug, &time_blocked); +return 0 ; +} + +static inline void kvm_halt_stats (enum pv_lock_stats type) +{ +if (type ==PV_HALT_QHEAD ) +add_smp (&halt_qhead_stats,1 ); +else if (type ==PV_HALT_QNODE ) +add_smp (&halt_qnode_stats,1 ); +else /* type == PV_HALT_ABORT */ +add_smp (&halt_abort_stats,1 ); +} + +void kvm_lock_stats (enum pv_lock_stats type) +{ +if (type ==PV_WAKE_KICKED ) +add_smp (&wake_kick_stats,1 ); +else if (type ==PV_WAKE_SPURIOUS ) +add_smp (&wake_spur_stats,1 ); +else /* type == PV_KICK_NOHALT */ +add_smp (&kick_nohlt_stats,1 ); +} +PV_CALLEE_SAVE_REGS_THUNK (kvm_lock_stats); + +static inline u64 spin_time_start (void ) +{ +return sched_clock (); +} + +static inline void spin_time_accum_blocked (u64 start) +{ +u64 delta; + + delta =sched_clock () - start; +add_smp (&time_blocked, delta); +} + +fs_initcall (kvm_spinlock_debugfs); + +#else /* CONFIG_KVM_DEBUG_FS */ +static inline void kvm_halt_stats (enum pv_lock_stats type) +{ +} + +static inline u64 spin_time_start (void ) +{ +return 0 ; +} + +static inline void spin_time_accum_blocked (u64 start) +{ +} +#endif /* CONFIG_KVM_DEBUG_FS */ + +/* +* Halt the current CPU & release it back to the host +*/ +void kvm_halt_cpu (u8 *lockbyte) +{ +unsigned long flags; +u64 start; + +if (in_nmi ()) +return ; + +/* +* Make sure an interrupt handler can't upset things in a +* partially setup state. +*/ +local_irq_save (flags); +/* +* Don't halt if the lock byte is defined and is free +*/ +if (lockbyte && !ACCESS_ONCE (*lockbyte)) { +kvm_halt_stats (PV_HALT_ABORT ); + goto out; + } + start =spin_time_start (); +kvm_halt_stats (lockbyte ?PV_HALT_QHEAD :PV_HALT_QNODE ); +if (arch_irqs_disabled_flags (flags)) +halt (); +else +safe_halt (); +spin_time_accum_blocked (start); +out: +local_irq_restore (flags); +} +PV_CALLEE_SAVE_REGS_THUNK (kvm_halt_cpu); +#endif /* !CONFIG_QUEUE_SPINLOCK */ /* * Setup pv_lock_ops to exploit KVM_FEATURE_PV_UNHALT if present.
@@ -816,8 +944,16 @@ void __init kvm_spinlock_init(void)if (!kvm_para_has_feature (KVM_FEATURE_PV_UNHALT ))return ; +#ifdef CONFIG_QUEUE_SPINLOCK + pv_lock_ops.kick_cpu =PV_CALLEE_SAVE (kvm_kick_cpu); + pv_lock_ops.lockwait =PV_CALLEE_SAVE (kvm_halt_cpu); +#ifdef CONFIG_KVM_DEBUG_FS + pv_lock_ops.lockstat =PV_CALLEE_SAVE (kvm_lock_stats); +#endif +#else pv_lock_ops.lock_spinning =PV_CALLEE_SAVE (kvm_lock_spinning); pv_lock_ops.unlock_kick = kvm_unlock_kick; +#endif }static __init int kvm_spinlock_init_jump (void )
kernel/Kconfig.locks +1 -1
@@ -236,7 +236,7 @@ config ARCH_USE_QUEUE_SPINLOCK config QUEUE_SPINLOCK def_bool y if ARCH_USE_QUEUE_SPINLOCK - depends on SMP && !PARAVIRT_SPINLOCKS + depends on SMP && (!PARAVIRT_SPINLOCKS || !XEN) config ARCH_USE_QUEUE_RWLOCK bool
Signature · 1 line
1.7.1
PATCH v13 11/11 pvqspinlock, x86: Enable PV qspinlock for XEN
In reply to Waiman LongThis patch adds the necessary XEN specific code to allow XEN to support the CPU halting and kicking operations needed by the queue spinlock PV code.
--- arch/x86/xen/spinlock.c | 149 +++++++++++++++++++++++++++++++++++++++++++++-- kernel/Kconfig.locks | 2 +- 2 files changed, 145 insertions(+), 6 deletions(-)
arch/x86/xen/spinlock.c +144 -5
@@ -17,6 +17,12 @@#include "xen-ops.h" #include "debugfs.h" +static DEFINE_PER_CPU(int, lock_kicker_irq) = -1; +static DEFINE_PER_CPU(char *, irq_name); +static bool xen_pvspin = true; + +#ifndef CONFIG_QUEUE_SPINLOCK +enum xen_contention_stat {TAKEN_SLOW , TAKEN_SLOW_PICKUP,
@@ -100,12 +106,9 @@ struct xen_lock_waiting {__ticket_t want; }; -static DEFINE_PER_CPU(int, lock_kicker_irq) = -1; -static DEFINE_PER_CPU(char *, irq_name); static DEFINE_PER_CPU(struct xen_lock_waiting, lock_waiting);static cpumask_t waiting_cpus; -static bool xen_pvspin = true; __visible void xen_lock_spinning(struct arch_spinlock *lock, __ticket_t want) {int irq =__this_cpu_read (lock_kicker_irq);
@@ -213,6 +216,118 @@ static void xen_unlock_kick(struct arch_spinlock *lock, __ticket_t next) } } +#else /* CONFIG_QUEUE_SPINLOCK */ + +#ifdef CONFIG_XEN_DEBUG_FS +static u32 kick_nohlt_stats;/* Kick but not halt count */ +static u32 halt_qhead_stats;/* Queue head halting count */ +static u32 halt_qnode_stats;/* Queue node halting count */ +static u32 halt_abort_stats;/* Halting abort count */ +static u32 wake_kick_stats;/* Wakeup by kicking count */ +static u32 wake_spur_stats;/* Spurious wakeup count */ +static u64 time_blocked;/* Total blocking time */ + +static inline void xen_halt_stats (enum pv_lock_stats type) +{ +if (type ==PV_HALT_QHEAD ) +add_smp (&halt_qhead_stats,1 ); +else if (type ==PV_HALT_QNODE ) +add_smp (&halt_qnode_stats,1 ); +else /* type == PV_HALT_ABORT */ +add_smp (&halt_abort_stats,1 ); +} + +void xen_lock_stats (enum pv_lock_stats type) +{ +if (type ==PV_WAKE_KICKED ) +add_smp (&wake_kick_stats,1 ); +else if (type ==PV_WAKE_SPURIOUS ) +add_smp (&wake_spur_stats,1 ); +else /* type == PV_KICK_NOHALT */ +add_smp (&kick_nohlt_stats,1 ); +} +PV_CALLEE_SAVE_REGS_THUNK (xen_lock_stats); + +static inline u64 spin_time_start (void ) +{ +return sched_clock (); +} + +static inline void spin_time_accum_blocked (u64 start) +{ +u64 delta; + + delta =sched_clock () - start; +add_smp (&time_blocked, delta); +} +#else /* CONFIG_XEN_DEBUG_FS */ +static inline void xen_halt_stats (enum pv_lock_stats type) +{ +} + +static inline u64 spin_time_start (void ) +{ +return 0 ; +} + +static inline void spin_time_accum_blocked (u64 start) +{ +} +#endif /* CONFIG_XEN_DEBUG_FS */ + +void xen_kick_cpu (int cpu) +{ +xen_send_IPI_one (cpu,XEN_SPIN_UNLOCK_VECTOR ); +} +PV_CALLEE_SAVE_REGS_THUNK (xen_kick_cpu); + +/* +* Halt the current CPU & release it back to the host +*/ +void xen_halt_cpu (u8 *lockbyte) +{ +int irq =__this_cpu_read (lock_kicker_irq); +unsigned long flags; +u64 start; + +/* If kicker interrupts not initialized yet, just spin */ +if (irq ==-1 ) +return ; + +/* +* Make sure an interrupt handler can't upset things in a +* partially setup state. +*/ +local_irq_save (flags); + start =spin_time_start (); + +xen_halt_stats (lockbyte ?PV_HALT_QHEAD :PV_HALT_QNODE ); +/* clear pending */ +xen_clear_irq_pending (irq); + +/* Allow interrupts while blocked */ +local_irq_restore (flags); +/* +* Don't halt if the lock is now available +*/ +if (lockbyte && !ACCESS_ONCE (*lockbyte)) { +xen_halt_stats (PV_HALT_ABORT ); +return ; + } +/* +* If an interrupt happens here, it will leave the wakeup irq +* pending, which will cause xen_poll_irq() to return +* immediately. +*/ + +/* Block until irq becomes pending (or perhaps a spurious wakeup) */ +xen_poll_irq (irq); +spin_time_accum_blocked (start); +} +PV_CALLEE_SAVE_REGS_THUNK (xen_halt_cpu); + +#endif /* CONFIG_QUEUE_SPINLOCK */ +static irqreturn_t dummy_handler (int irq,void *dev_id) {BUG ();
@@ -258,7 +373,6 @@ void xen_uninit_lock_cpu(int cpu)per_cpu (irq_name, cpu) =NULL ; } -/* * Our init of PV spinlocks is split in two init functions due to us * using paravirt patching and jump labels patching and having to do
@@ -275,8 +389,17 @@ void __init xen_init_spinlocks(void)return ; }printk (KERN_DEBUG "xen: PV spinlocks enabled\n" ); + +#ifdef CONFIG_QUEUE_SPINLOCK + pv_lock_ops.kick_cpu =PV_CALLEE_SAVE (xen_kick_cpu); + pv_lock_ops.lockwait =PV_CALLEE_SAVE (xen_halt_cpu); +#ifdef CONFIG_XEN_DEBUG_FS + pv_lock_ops.lockstat =PV_CALLEE_SAVE (xen_lock_stats); +#endif +#else pv_lock_ops.lock_spinning =PV_CALLEE_SAVE (xen_lock_spinning); pv_lock_ops.unlock_kick = xen_unlock_kick; +#endif }/*
@@ -321,6 +444,7 @@ static int __init xen_spinlock_debugfs(void) d_spin_debug =debugfs_create_dir ("spinlocks" , d_xen); +#ifndef CONFIG_QUEUE_SPINLOCK debugfs_create_u8 ("zero_stats" ,0644 , d_spin_debug, &zero_stats); debugfs_create_u32("taken_slow", 0444, d_spin_debug,
@@ -340,7 +464,22 @@ static int __init xen_spinlock_debugfs(void)debugfs_create_u32_array ("histo_blocked" ,0444 , d_spin_debug, spinlock_stats.histo_spin_blocked,HISTO_BUCKETS +1 ); - +#else /* CONFIG_QUEUE_SPINLOCK */ +debugfs_create_u32 ("kick_nohlt_stats" , +0644 , d_spin_debug, &kick_nohlt_stats); +debugfs_create_u32 ("halt_qhead_stats" , +0644 , d_spin_debug, &halt_qhead_stats); +debugfs_create_u32 ("halt_qnode_stats" , +0644 , d_spin_debug, &halt_qnode_stats); +debugfs_create_u32 ("halt_abort_stats" , +0644 , d_spin_debug, &halt_abort_stats); +debugfs_create_u32 ("wake_kick_stats" , +0644 , d_spin_debug, &wake_kick_stats); +debugfs_create_u32 ("wake_spur_stats" , +0644 , d_spin_debug, &wake_spur_stats); +debugfs_create_u64 ("time_blocked" , +0644 , d_spin_debug, &time_blocked); +#endif /* CONFIG_QUEUE_SPINLOCK */ return 0 ; }fs_initcall (xen_spinlock_debugfs);
kernel/Kconfig.locks +1 -1
@@ -236,7 +236,7 @@ config ARCH_USE_QUEUE_SPINLOCK config QUEUE_SPINLOCK def_bool y if ARCH_USE_QUEUE_SPINLOCK - depends on SMP && (!PARAVIRT_SPINLOCKS || !XEN) + depends on SMP config ARCH_USE_QUEUE_RWLOCK bool
Signature · 1 line
1.7.1
PATCH v13 11/11 pvqspinlock, x86: Enable PV qspinlock for XEN
In reply to Waiman LongThis patch adds the necessary XEN specific code to allow XEN to support the CPU halting and kicking operations needed by the queue spinlock PV code.
--- arch/x86/xen/spinlock.c | 149 +++++++++++++++++++++++++++++++++++++++++++++-- kernel/Kconfig.locks | 2 +- 2 files changed, 145 insertions(+), 6 deletions(-)
arch/x86/xen/spinlock.c +144 -5
@@ -17,6 +17,12 @@#include "xen-ops.h" #include "debugfs.h" +static DEFINE_PER_CPU(int, lock_kicker_irq) = -1; +static DEFINE_PER_CPU(char *, irq_name); +static bool xen_pvspin = true; + +#ifndef CONFIG_QUEUE_SPINLOCK +enum xen_contention_stat {TAKEN_SLOW , TAKEN_SLOW_PICKUP,
@@ -100,12 +106,9 @@ struct xen_lock_waiting {__ticket_t want; }; -static DEFINE_PER_CPU(int, lock_kicker_irq) = -1; -static DEFINE_PER_CPU(char *, irq_name); static DEFINE_PER_CPU(struct xen_lock_waiting, lock_waiting);static cpumask_t waiting_cpus; -static bool xen_pvspin = true; __visible void xen_lock_spinning(struct arch_spinlock *lock, __ticket_t want) {int irq =__this_cpu_read (lock_kicker_irq);
@@ -213,6 +216,118 @@ static void xen_unlock_kick(struct arch_spinlock *lock, __ticket_t next) } } +#else /* CONFIG_QUEUE_SPINLOCK */ + +#ifdef CONFIG_XEN_DEBUG_FS +static u32 kick_nohlt_stats;/* Kick but not halt count */ +static u32 halt_qhead_stats;/* Queue head halting count */ +static u32 halt_qnode_stats;/* Queue node halting count */ +static u32 halt_abort_stats;/* Halting abort count */ +static u32 wake_kick_stats;/* Wakeup by kicking count */ +static u32 wake_spur_stats;/* Spurious wakeup count */ +static u64 time_blocked;/* Total blocking time */ + +static inline void xen_halt_stats (enum pv_lock_stats type) +{ +if (type ==PV_HALT_QHEAD ) +add_smp (&halt_qhead_stats,1 ); +else if (type ==PV_HALT_QNODE ) +add_smp (&halt_qnode_stats,1 ); +else /* type == PV_HALT_ABORT */ +add_smp (&halt_abort_stats,1 ); +} + +void xen_lock_stats (enum pv_lock_stats type) +{ +if (type ==PV_WAKE_KICKED ) +add_smp (&wake_kick_stats,1 ); +else if (type ==PV_WAKE_SPURIOUS ) +add_smp (&wake_spur_stats,1 ); +else /* type == PV_KICK_NOHALT */ +add_smp (&kick_nohlt_stats,1 ); +} +PV_CALLEE_SAVE_REGS_THUNK (xen_lock_stats); + +static inline u64 spin_time_start (void ) +{ +return sched_clock (); +} + +static inline void spin_time_accum_blocked (u64 start) +{ +u64 delta; + + delta =sched_clock () - start; +add_smp (&time_blocked, delta); +} +#else /* CONFIG_XEN_DEBUG_FS */ +static inline void xen_halt_stats (enum pv_lock_stats type) +{ +} + +static inline u64 spin_time_start (void ) +{ +return 0 ; +} + +static inline void spin_time_accum_blocked (u64 start) +{ +} +#endif /* CONFIG_XEN_DEBUG_FS */ + +void xen_kick_cpu (int cpu) +{ +xen_send_IPI_one (cpu,XEN_SPIN_UNLOCK_VECTOR ); +} +PV_CALLEE_SAVE_REGS_THUNK (xen_kick_cpu); + +/* +* Halt the current CPU & release it back to the host +*/ +void xen_halt_cpu (u8 *lockbyte) +{ +int irq =__this_cpu_read (lock_kicker_irq); +unsigned long flags; +u64 start; + +/* If kicker interrupts not initialized yet, just spin */ +if (irq ==-1 ) +return ; + +/* +* Make sure an interrupt handler can't upset things in a +* partially setup state. +*/ +local_irq_save (flags); + start =spin_time_start (); + +xen_halt_stats (lockbyte ?PV_HALT_QHEAD :PV_HALT_QNODE ); +/* clear pending */ +xen_clear_irq_pending (irq); + +/* Allow interrupts while blocked */ +local_irq_restore (flags); +/* +* Don't halt if the lock is now available +*/ +if (lockbyte && !ACCESS_ONCE (*lockbyte)) { +xen_halt_stats (PV_HALT_ABORT ); +return ; + } +/* +* If an interrupt happens here, it will leave the wakeup irq +* pending, which will cause xen_poll_irq() to return +* immediately. +*/ + +/* Block until irq becomes pending (or perhaps a spurious wakeup) */ +xen_poll_irq (irq); +spin_time_accum_blocked (start); +} +PV_CALLEE_SAVE_REGS_THUNK (xen_halt_cpu); + +#endif /* CONFIG_QUEUE_SPINLOCK */ +static irqreturn_t dummy_handler (int irq,void *dev_id) {BUG ();
@@ -258,7 +373,6 @@ void xen_uninit_lock_cpu(int cpu)per_cpu (irq_name, cpu) =NULL ; } -/* * Our init of PV spinlocks is split in two init functions due to us * using paravirt patching and jump labels patching and having to do
@@ -275,8 +389,17 @@ void __init xen_init_spinlocks(void)return ; }printk (KERN_DEBUG "xen: PV spinlocks enabled\n" ); + +#ifdef CONFIG_QUEUE_SPINLOCK + pv_lock_ops.kick_cpu =PV_CALLEE_SAVE (xen_kick_cpu); + pv_lock_ops.lockwait =PV_CALLEE_SAVE (xen_halt_cpu); +#ifdef CONFIG_XEN_DEBUG_FS + pv_lock_ops.lockstat =PV_CALLEE_SAVE (xen_lock_stats); +#endif +#else pv_lock_ops.lock_spinning =PV_CALLEE_SAVE (xen_lock_spinning); pv_lock_ops.unlock_kick = xen_unlock_kick; +#endif }/*
@@ -321,6 +444,7 @@ static int __init xen_spinlock_debugfs(void) d_spin_debug =debugfs_create_dir ("spinlocks" , d_xen); +#ifndef CONFIG_QUEUE_SPINLOCK debugfs_create_u8 ("zero_stats" ,0644 , d_spin_debug, &zero_stats); debugfs_create_u32("taken_slow", 0444, d_spin_debug,
@@ -340,7 +464,22 @@ static int __init xen_spinlock_debugfs(void)debugfs_create_u32_array ("histo_blocked" ,0444 , d_spin_debug, spinlock_stats.histo_spin_blocked,HISTO_BUCKETS +1 ); - +#else /* CONFIG_QUEUE_SPINLOCK */ +debugfs_create_u32 ("kick_nohlt_stats" , +0644 , d_spin_debug, &kick_nohlt_stats); +debugfs_create_u32 ("halt_qhead_stats" , +0644 , d_spin_debug, &halt_qhead_stats); +debugfs_create_u32 ("halt_qnode_stats" , +0644 , d_spin_debug, &halt_qnode_stats); +debugfs_create_u32 ("halt_abort_stats" , +0644 , d_spin_debug, &halt_abort_stats); +debugfs_create_u32 ("wake_kick_stats" , +0644 , d_spin_debug, &wake_kick_stats); +debugfs_create_u32 ("wake_spur_stats" , +0644 , d_spin_debug, &wake_spur_stats); +debugfs_create_u64 ("time_blocked" , +0644 , d_spin_debug, &time_blocked); +#endif /* CONFIG_QUEUE_SPINLOCK */ return 0 ; }fs_initcall (xen_spinlock_debugfs);
kernel/Kconfig.locks +1 -1
@@ -236,7 +236,7 @@ config ARCH_USE_QUEUE_SPINLOCK config QUEUE_SPINLOCK def_bool y if ARCH_USE_QUEUE_SPINLOCK - depends on SMP && (!PARAVIRT_SPINLOCKS || !XEN) + depends on SMP config ARCH_USE_QUEUE_RWLOCK bool
Signature · 1 line
1.7.1