linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v7 00/11] qspinlock: a 4-byte queue spinlock with PV support
@ 2014-03-19 20:13 Waiman Long
  2014-03-19 20:13 ` [PATCH v7 01/11] qspinlock: A generic 4-byte queue spinlock implementation Waiman Long
                   ` (10 more replies)
  0 siblings, 11 replies; 27+ messages in thread
From: Waiman Long @ 2014-03-19 20:13 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Arnd Bergmann,
	Peter Zijlstra
  Cc: Jeremy Fitzhardinge, Raghavendra K T, kvm, virtualization,
	Andi Kleen, Michel Lespinasse, Alok Kataria, linux-arch,
	Gleb Natapov, x86, xen-devel, Paul E. McKenney, Rik van Riel,
	Konrad Rzeszutek Wilk, Scott J Norton, Steven Rostedt,
	Chris Wright, Oleg Nesterov, Boris Ostrovsky,
	Aswin Chandramouleeswaran, Chegu Vinod, Waiman Long, linux-kernel,
	David Vrabel, Andrew

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-4: 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) Patches 5-7: Enables the use of unfair queue spinlock in a
    para-virtualized execution environment. 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.

Patches 1-8 are fully tested and ready for production. Patches 9-10
are also tested on KVM guests. Patch 11, however, has not been tested
on XEN guest yet. Anyone who would like to test this out is welcome to
do so.

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 noticeable performance benefit probably won't
show up in machines with less than 4 sockets.

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.

Waiman Long (11):
  qspinlock: A generic 4-byte queue spinlock implementation
  qspinlock, x86: Enable x86-64 to use queue spinlock
  qspinlock: More optimized code for smaller NR_CPUS
  qspinlock: Optimized code path for 2 contending tasks
  pvqspinlock, x86: Allow unfair spinlock in a PV guest
  pvqspinlock, x86: Allow unfair queue spinlock in a KVM guest
  pvqspinlock, x86: Allow unfair queue spinlock in a XEN guest
  pvqspinlock, x86: Rename paravirt_ticketlocks_enabled
  pvqspinlock, x86: Add qspinlock para-virtualization support
  pvqspinlock, x86: Enable qspinlock PV support for KVM
  pvqspinlock, x86: Enable qspinlock PV support for XEN

 arch/x86/Kconfig                      |   12 +
 arch/x86/include/asm/paravirt.h       |   12 +-
 arch/x86/include/asm/paravirt_types.h |    5 +
 arch/x86/include/asm/pvqspinlock.h    |  249 +++++++++
 arch/x86/include/asm/qspinlock.h      |  161 ++++++
 arch/x86/include/asm/spinlock.h       |    9 +-
 arch/x86/include/asm/spinlock_types.h |    4 +
 arch/x86/kernel/Makefile              |    1 +
 arch/x86/kernel/kvm.c                 |  101 ++++-
 arch/x86/kernel/paravirt-spinlocks.c  |   16 +-
 arch/x86/xen/setup.c                  |   19 +
 arch/x86/xen/spinlock.c               |   92 +++-
 include/asm-generic/qspinlock.h       |  122 +++++
 include/asm-generic/qspinlock_types.h |   62 +++
 kernel/Kconfig.locks                  |    7 +
 kernel/locking/Makefile               |    1 +
 kernel/locking/qspinlock.c            |  938 +++++++++++++++++++++++++++++++++
 17 files changed, 1799 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

^ permalink raw reply	[flat|nested] 27+ messages in thread
* Re: [PATCH v7 07/11] pvqspinlock, x86: Allow unfair queue spinlock in a XEN guest
@ 2014-03-21 11:00 Konrad Rzeszutek Wilk
  0 siblings, 0 replies; 27+ messages in thread
From: Konrad Rzeszutek Wilk @ 2014-03-21 11:00 UTC (permalink / raw)
  To: Waiman Long
  Cc: Jeremy Fitzhardinge, Raghavendra K T, Gleb Natapov,
	Peter Zijlstra, virtualization, Andi Kleen, H. Peter Anvin,
	Michel Lespinasse, Alok Kataria, linux-arch, kvm, x86,
	Ingo Molnar, xen-devel, Paul E. McKenney, Rik van Riel,
	Arnd Bergmann, Scott J Norton, Steven Rostedt, Chris Wright,
	Boris Ostrovsky, Aswin Chandramouleeswaran, Chegu Vinod,
	Oleg Nesterov, linux-kernel


On Mar 20, 2014 11:40 PM, Waiman Long <waiman.long@hp.com> wrote:
>
> On 03/19/2014 04:28 PM, Konrad Rzeszutek Wilk wrote: 
> > On Wed, Mar 19, 2014 at 04:14:05PM -0400, Waiman Long wrote: 
> >> This patch adds a XEN init function to activate the unfair queue 
> >> spinlock in a XEN guest when the PARAVIRT_UNFAIR_LOCKS kernel config 
> >> option is selected. 
> >> 
> >> Signed-off-by: Waiman Long<Waiman.Long@hp.com> 
> >> --- 
> >>   arch/x86/xen/setup.c |   19 +++++++++++++++++++ 
> >>   1 files changed, 19 insertions(+), 0 deletions(-) 
> >> 
> >> diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c 
> >> index 0982233..66bb6f5 100644 
> >> --- a/arch/x86/xen/setup.c 
> >> +++ b/arch/x86/xen/setup.c 
> >> @@ -625,3 +625,22 @@ void __init xen_arch_setup(void) 
> >>   numa_off = 1; 
> >>   #endif 
> >>   } 
> >> + 
> >> +#ifdef CONFIG_PARAVIRT_UNFAIR_LOCKS 
> >> +/* 
> >> + * Enable unfair lock if running in a Xen guest 
> >> + */ 
> >> +static __init int xen_unfair_locks_init_jump(void) 
> >> +{ 
> >> + /* 
> >> + * Disable unfair lock if not running in a PV domain 
> >> + */ 
> >> + if (!xen_pv_domain()) 
> >> + return 0; 
> > I would just make this 'xen_domain'. Not sure why you need 
> > to have it only for PV while the PVHVM guests can also use it? 
>
> The compilation of the setup.c file should have implied xen_domain 
> already (at least HVM). The check is added to make sure that unfair lock 
> won't be enabled on bare metal. As for PVHVM, is there a way to detect 
> it is running as such which is distinct from HVM?

Xen_domain() should cover PVHVM and PV.
>
> > Would it also make sense to use the same printk statement 
> > that the KVM has? 
> > 
>
> Yes, I can add a printk statement like KVM. 
>
> -Longman 
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2014-03-21 21:41 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-19 20:13 [PATCH v7 00/11] qspinlock: a 4-byte queue spinlock with PV support Waiman Long
2014-03-19 20:13 ` [PATCH v7 01/11] qspinlock: A generic 4-byte queue spinlock implementation Waiman Long
2014-03-19 20:14 ` [PATCH v7 02/11] qspinlock, x86: Enable x86-64 to use queue spinlock Waiman Long
2014-03-19 20:24   ` Konrad Rzeszutek Wilk
2014-03-21  3:36     ` Waiman Long
2014-03-19 20:14 ` [PATCH v7 03/11] qspinlock: More optimized code for smaller NR_CPUS Waiman Long
2014-03-19 20:14 ` [PATCH v7 04/11] qspinlock: Optimized code path for 2 contending tasks Waiman Long
2014-03-19 20:14 ` [PATCH v7 05/11] pvqspinlock, x86: Allow unfair spinlock in a PV guest Waiman Long
2014-03-19 20:14 ` [PATCH v7 06/11] pvqspinlock, x86: Allow unfair queue spinlock in a KVM guest Waiman Long
2014-03-20 22:01   ` Paolo Bonzini
2014-03-20 22:01     ` Paolo Bonzini
2014-03-20 22:29     ` H. Peter Anvin
2014-03-20 22:29       ` H. Peter Anvin
2014-03-20 22:40       ` Paolo Bonzini
2014-03-20 22:40         ` Paolo Bonzini
2014-03-21 21:27     ` Waiman Long
2014-03-19 20:14 ` [PATCH v7 07/11] pvqspinlock, x86: Allow unfair queue spinlock in a XEN guest Waiman Long
2014-03-19 20:28   ` Konrad Rzeszutek Wilk
2014-03-21  3:40     ` Waiman Long
2014-03-19 20:14 ` [PATCH v7 08/11] pvqspinlock, x86: Rename paravirt_ticketlocks_enabled Waiman Long
2014-03-19 20:14 ` [PATCH v7 09/11] pvqspinlock, x86: Add qspinlock para-virtualization support Waiman Long
2014-03-19 20:14 ` [PATCH v7 10/11] pvqspinlock, x86: Enable qspinlock PV support for KVM Waiman Long
2014-03-20 22:07   ` Paolo Bonzini
2014-03-20 22:07     ` Paolo Bonzini
2014-03-21 21:41     ` Waiman Long
2014-03-19 20:14 ` [PATCH RFC v7 11/11] pvqspinlock, x86: Enable qspinlock PV support for XEN Waiman Long
  -- strict thread matches above, loose matches on Subject: below --
2014-03-21 11:00 [PATCH v7 07/11] pvqspinlock, x86: Allow unfair queue spinlock in a XEN guest Konrad Rzeszutek Wilk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).