From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756787Ab3KFVll (ORCPT ); Wed, 6 Nov 2013 16:41:41 -0500 Received: from mga09.intel.com ([134.134.136.24]:21401 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756243Ab3KFVlh (ORCPT ); Wed, 6 Nov 2013 16:41:37 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.93,535,1378882800"; d="scan'208";a="404699060" Subject: Re: [PATCH v3 4/5] MCS Lock: Make mcs_spinlock.h includable in other files From: Tim Chen To: Ingo Molnar Cc: Andrew Morton , Thomas Gleixner , linux-kernel@vger.kernel.org, linux-mm , linux-arch@vger.kernel.org, Linus Torvalds , Waiman Long , Andrea Arcangeli , Alex Shi , Andi Kleen , Michel Lespinasse , Davidlohr Bueso , Matthew R Wilcox , Dave Hansen , Peter Zijlstra , Rik van Riel , Peter Hurley , "Paul E.McKenney" , Raghavendra K T , George Spelvin , "H. Peter Anvin" , Arnd Bergmann , Aswin Chandramouleeswaran , Scott J Norton , Will Deacon , "Figo.zhang" In-Reply-To: <1383773832.11046.356.camel@schen9-DESK> References: <1383773832.11046.356.camel@schen9-DESK> Content-Type: text/plain; charset="UTF-8" Date: Wed, 06 Nov 2013 13:41:33 -0800 Message-ID: <1383774093.11046.358.camel@schen9-DESK> Mime-Version: 1.0 X-Mailer: Evolution 2.32.3 (2.32.3-1.fc14) Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2013-11-06 at 13:37 -0800, Tim Chen wrote: > The following changes are made to enable mcs_spinlock.h file to be > widely included in other files without causing problem: > > 1) Include a number of prerequisite header files and define > arch_mutex_cpu_relax(), if not previously defined. > 2) Make mcs_spin_unlock() an inlined function and > rename mcs_spin_lock() to _raw_mcs_spin_lock() which is also an > inlined function. > 3) Create a new mcs_spinlock.c file to contain the non-inlined > mcs_spin_lock() function. > > Signed-off-by: Waiman Long > Signed-off-by: Tim Chen Should be Acked-by: Tim Chen > --- > include/linux/mcs_spinlock.h | 27 ++++++++++++++++++++++----- > kernel/Makefile | 6 +++--- > kernel/mcs_spinlock.c | 21 +++++++++++++++++++++ > 3 files changed, 46 insertions(+), 8 deletions(-) > create mode 100644 kernel/mcs_spinlock.c > > diff --git a/include/linux/mcs_spinlock.h b/include/linux/mcs_spinlock.h > index 93d445d..f2c71e8 100644 > --- a/include/linux/mcs_spinlock.h > +++ b/include/linux/mcs_spinlock.h > @@ -12,11 +12,27 @@ > #ifndef __LINUX_MCS_SPINLOCK_H > #define __LINUX_MCS_SPINLOCK_H > > +/* > + * asm/processor.h may define arch_mutex_cpu_relax(). > + * If it is not defined, cpu_relax() will be used. > + */ > +#include > +#include > +#include > +#include > + > +#ifndef arch_mutex_cpu_relax > +# define arch_mutex_cpu_relax() cpu_relax() > +#endif > + > struct mcs_spinlock { > struct mcs_spinlock *next; > int locked; /* 1 if lock acquired */ > }; > > +extern > +void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node); > + > /* > * In order to acquire the lock, the caller should declare a local node and > * pass a reference of the node to this function in addition to the lock. > @@ -24,11 +40,11 @@ struct mcs_spinlock { > * on this node->locked until the previous lock holder sets the node->locked > * in mcs_spin_unlock(). > * > - * We don't inline mcs_spin_lock() so that perf can correctly account for the > - * time spent in this lock function. > + * The _raw_mcs_spin_lock() function should not be called directly. Instead, > + * users should call mcs_spin_lock(). > */ > -static noinline > -void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node) > +static inline > +void _raw_mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node) > { > struct mcs_spinlock *prev; > > @@ -55,7 +71,8 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node) > * Releases the lock. The caller should pass in the corresponding node that > * was used to acquire the lock. > */ > -static void mcs_spin_unlock(struct mcs_spinlock **lock, struct mcs_spinlock *node) > +static inline > +void mcs_spin_unlock(struct mcs_spinlock **lock, struct mcs_spinlock *node) > { > struct mcs_spinlock *next = ACCESS_ONCE(node->next); > > diff --git a/kernel/Makefile b/kernel/Makefile > index 1ce4755..2ad8454 100644 > --- a/kernel/Makefile > +++ b/kernel/Makefile > @@ -50,9 +50,9 @@ obj-$(CONFIG_SMP) += smp.o > ifneq ($(CONFIG_SMP),y) > obj-y += up.o > endif > -obj-$(CONFIG_SMP) += spinlock.o > -obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o > -obj-$(CONFIG_PROVE_LOCKING) += spinlock.o > +obj-$(CONFIG_SMP) += spinlock.o mcs_spinlock.o > +obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o mcs_spinlock.o > +obj-$(CONFIG_PROVE_LOCKING) += spinlock.o mcs_spinlock.o > obj-$(CONFIG_UID16) += uid16.o > obj-$(CONFIG_MODULES) += module.o > obj-$(CONFIG_MODULE_SIG) += module_signing.o modsign_pubkey.o modsign_certificate.o > diff --git a/kernel/mcs_spinlock.c b/kernel/mcs_spinlock.c > new file mode 100644 > index 0000000..3c55626 > --- /dev/null > +++ b/kernel/mcs_spinlock.c > @@ -0,0 +1,21 @@ > +/* > + * MCS lock > + * > + * The MCS lock (proposed by Mellor-Crummey and Scott) is a simple spin-lock > + * with the desirable properties of being fair, and with each cpu trying > + * to acquire the lock spinning on a local variable. > + * It avoids expensive cache bouncings that common test-and-set spin-lock > + * implementations incur. > + */ > +#include > +#include > + > +/* > + * We don't inline mcs_spin_lock() so that perf can correctly account for the > + * time spent in this lock function. > + */ > +void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node) > +{ > + _raw_mcs_spin_lock(lock, node); > +} > +EXPORT_SYMBOL_GPL(mcs_spin_lock);