linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lglock: Map to spinlock when !CONFIG_SMP
@ 2013-10-25 15:19 Josh Triplett
  2013-10-28  2:59 ` Rusty Russell
  0 siblings, 1 reply; 2+ messages in thread
From: Josh Triplett @ 2013-10-25 15:19 UTC (permalink / raw)
  To: Rusty Russell, Andrew Morton, Michal Marek, Thomas Gleixner,
	David Howells, H. Peter Anvin, linux-kernel

When the system has only one CPU, lglock is effectively a spinlock; map
it directly to spinlock to eliminate the indirection and duplicate code.

In addition to removing overhead, this drops 1.6k of code with a defconfig
modified to have !CONFIG_SMP, and 1.1k with a minimal config.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
---
 include/linux/lglock.h | 16 ++++++++++++++++
 kernel/Makefile        |  4 ++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/include/linux/lglock.h b/include/linux/lglock.h
index 0d24e93..6561b1c 100644
--- a/include/linux/lglock.h
+++ b/include/linux/lglock.h
@@ -35,6 +35,8 @@
 #define DEFINE_BRLOCK(name)		DEFINE_LGLOCK(name)
 #define DEFINE_STATIC_BRLOCK(name)	DEFINE_STATIC_LGLOCK(name)
 
+#ifdef CONFIG_SMP
+
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 #define LOCKDEP_INIT_MAP lockdep_init_map
 #else
@@ -67,4 +69,18 @@ void lg_local_unlock_cpu(struct lglock *lg, int cpu);
 void lg_global_lock(struct lglock *lg);
 void lg_global_unlock(struct lglock *lg);
 
+#else
+/* When !CONFIG_SMP, map lglock to spinlock */
+#define lglock spinlock
+#define DEFINE_LGLOCK(name) DEFINE_SPINLOCK(name)
+#define DEFINE_STATIC_LGLOCK(name) static DEFINE_SPINLOCK(name)
+#define lg_lock_init(lg, name) spin_lock_init(lg)
+#define lg_local_lock spin_lock
+#define lg_local_unlock spin_unlock
+#define lg_local_lock_cpu(lg, cpu) spin_lock(lg)
+#define lg_local_unlock_cpu(lg, cpu) spin_unlock(lg)
+#define lg_global_lock spin_lock
+#define lg_global_unlock spin_unlock
+#endif
+
 #endif
diff --git a/kernel/Makefile b/kernel/Makefile
index 1ce4755..84a89f7 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -10,7 +10,7 @@ obj-y     = fork.o exec_domain.o panic.o \
 	    kthread.o wait.o sys_ni.o posix-cpu-timers.o mutex.o \
 	    hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
 	    notifier.o ksysfs.o cred.o reboot.o \
-	    async.o range.o groups.o lglock.o smpboot.o
+	    async.o range.o groups.o smpboot.o
 
 ifdef CONFIG_FUNCTION_TRACER
 # Do not trace debug files and internal ftrace files
@@ -50,7 +50,7 @@ obj-$(CONFIG_SMP) += smp.o
 ifneq ($(CONFIG_SMP),y)
 obj-y += up.o
 endif
-obj-$(CONFIG_SMP) += spinlock.o
+obj-$(CONFIG_SMP) += lglock.o spinlock.o
 obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o
 obj-$(CONFIG_PROVE_LOCKING) += spinlock.o
 obj-$(CONFIG_UID16) += uid16.o
-- 
1.8.4.rc3


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

* Re: [PATCH] lglock: Map to spinlock when !CONFIG_SMP
  2013-10-25 15:19 [PATCH] lglock: Map to spinlock when !CONFIG_SMP Josh Triplett
@ 2013-10-28  2:59 ` Rusty Russell
  0 siblings, 0 replies; 2+ messages in thread
From: Rusty Russell @ 2013-10-28  2:59 UTC (permalink / raw)
  To: Josh Triplett, Andrew Morton, Michal Marek, Thomas Gleixner,
	David Howells, H. Peter Anvin, linux-kernel

Josh Triplett <josh@joshtriplett.org> writes:
> When the system has only one CPU, lglock is effectively a spinlock; map
> it directly to spinlock to eliminate the indirection and duplicate code.
>
> In addition to removing overhead, this drops 1.6k of code with a defconfig
> modified to have !CONFIG_SMP, and 1.1k with a minimal config.
>
> Signed-off-by: Josh Triplett <josh@joshtriplett.org>

Nice.  Looks like a patch for Andrew Morton though.

Cheers,
Rusty.

> ---
>  include/linux/lglock.h | 16 ++++++++++++++++
>  kernel/Makefile        |  4 ++--
>  2 files changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/lglock.h b/include/linux/lglock.h
> index 0d24e93..6561b1c 100644
> --- a/include/linux/lglock.h
> +++ b/include/linux/lglock.h
> @@ -35,6 +35,8 @@
>  #define DEFINE_BRLOCK(name)		DEFINE_LGLOCK(name)
>  #define DEFINE_STATIC_BRLOCK(name)	DEFINE_STATIC_LGLOCK(name)
>  
> +#ifdef CONFIG_SMP
> +
>  #ifdef CONFIG_DEBUG_LOCK_ALLOC
>  #define LOCKDEP_INIT_MAP lockdep_init_map
>  #else
> @@ -67,4 +69,18 @@ void lg_local_unlock_cpu(struct lglock *lg, int cpu);
>  void lg_global_lock(struct lglock *lg);
>  void lg_global_unlock(struct lglock *lg);
>  
> +#else
> +/* When !CONFIG_SMP, map lglock to spinlock */
> +#define lglock spinlock
> +#define DEFINE_LGLOCK(name) DEFINE_SPINLOCK(name)
> +#define DEFINE_STATIC_LGLOCK(name) static DEFINE_SPINLOCK(name)
> +#define lg_lock_init(lg, name) spin_lock_init(lg)
> +#define lg_local_lock spin_lock
> +#define lg_local_unlock spin_unlock
> +#define lg_local_lock_cpu(lg, cpu) spin_lock(lg)
> +#define lg_local_unlock_cpu(lg, cpu) spin_unlock(lg)
> +#define lg_global_lock spin_lock
> +#define lg_global_unlock spin_unlock
> +#endif
> +
>  #endif
> diff --git a/kernel/Makefile b/kernel/Makefile
> index 1ce4755..84a89f7 100644
> --- a/kernel/Makefile
> +++ b/kernel/Makefile
> @@ -10,7 +10,7 @@ obj-y     = fork.o exec_domain.o panic.o \
>  	    kthread.o wait.o sys_ni.o posix-cpu-timers.o mutex.o \
>  	    hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
>  	    notifier.o ksysfs.o cred.o reboot.o \
> -	    async.o range.o groups.o lglock.o smpboot.o
> +	    async.o range.o groups.o smpboot.o
>  
>  ifdef CONFIG_FUNCTION_TRACER
>  # Do not trace debug files and internal ftrace files
> @@ -50,7 +50,7 @@ obj-$(CONFIG_SMP) += smp.o
>  ifneq ($(CONFIG_SMP),y)
>  obj-y += up.o
>  endif
> -obj-$(CONFIG_SMP) += spinlock.o
> +obj-$(CONFIG_SMP) += lglock.o spinlock.o
>  obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o
>  obj-$(CONFIG_PROVE_LOCKING) += spinlock.o
>  obj-$(CONFIG_UID16) += uid16.o
> -- 
> 1.8.4.rc3

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

end of thread, other threads:[~2013-10-28  3:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-25 15:19 [PATCH] lglock: Map to spinlock when !CONFIG_SMP Josh Triplett
2013-10-28  2:59 ` Rusty Russell

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).