Skip to content

Commit 64b47e8

Browse files
joshtripletttorvalds
authored andcommitted
lglock: map to spinlock when !CONFIG_SMP
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> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Michal Marek <mmarek@suse.cz> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: David Howells <dhowells@redhat.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Nick Piggin <npiggin@kernel.dk> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 188a814 commit 64b47e8

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎include/linux/lglock.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <linux/cpu.h>
2626
#include <linux/notifier.h>
2727

28+
#ifdef CONFIG_SMP
29+
2830
#ifdef CONFIG_DEBUG_LOCK_ALLOC
2931
#define LOCKDEP_INIT_MAP lockdep_init_map
3032
#else
@@ -57,4 +59,18 @@ void lg_local_unlock_cpu(struct lglock *lg, int cpu);
5759
void lg_global_lock(struct lglock *lg);
5860
void lg_global_unlock(struct lglock *lg);
5961

62+
#else
63+
/* When !CONFIG_SMP, map lglock to spinlock */
64+
#define lglock spinlock
65+
#define DEFINE_LGLOCK(name) DEFINE_SPINLOCK(name)
66+
#define DEFINE_STATIC_LGLOCK(name) static DEFINE_SPINLOCK(name)
67+
#define lg_lock_init(lg, name) spin_lock_init(lg)
68+
#define lg_local_lock spin_lock
69+
#define lg_local_unlock spin_unlock
70+
#define lg_local_lock_cpu(lg, cpu) spin_lock(lg)
71+
#define lg_local_unlock_cpu(lg, cpu) spin_unlock(lg)
72+
#define lg_global_lock spin_lock
73+
#define lg_global_unlock spin_unlock
74+
#endif
75+
6076
#endif

‎kernel/locking/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
obj-y += mutex.o semaphore.o rwsem.o lglock.o mcs_spinlock.o
2+
obj-y += mutex.o semaphore.o rwsem.o mcs_spinlock.o
33

44
ifdef CONFIG_FUNCTION_TRACER
55
CFLAGS_REMOVE_lockdep.o = -pg
@@ -14,6 +14,7 @@ ifeq ($(CONFIG_PROC_FS),y)
1414
obj-$(CONFIG_LOCKDEP) += lockdep_proc.o
1515
endif
1616
obj-$(CONFIG_SMP) += spinlock.o
17+
obj-$(CONFIG_SMP) += lglock.o
1718
obj-$(CONFIG_PROVE_LOCKING) += spinlock.o
1819
obj-$(CONFIG_RT_MUTEXES) += rtmutex.o
1920
obj-$(CONFIG_DEBUG_RT_MUTEXES) += rtmutex-debug.o

0 commit comments

Comments
 (0)