Commit 64b47e8fdb40a0d46e8cf458dd3e24f8afa073f6
Committed by
Linus Torvalds
1 parent
188a81409f
Exists in
master
and in
13 other branches
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>
Showing 2 changed files with 18 additions and 1 deletions Side-by-side Diff
include/linux/lglock.h
... | ... | @@ -25,6 +25,8 @@ |
25 | 25 | #include <linux/cpu.h> |
26 | 26 | #include <linux/notifier.h> |
27 | 27 | |
28 | +#ifdef CONFIG_SMP | |
29 | + | |
28 | 30 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
29 | 31 | #define LOCKDEP_INIT_MAP lockdep_init_map |
30 | 32 | #else |
... | ... | @@ -56,6 +58,20 @@ |
56 | 58 | void lg_local_unlock_cpu(struct lglock *lg, int cpu); |
57 | 59 | void lg_global_lock(struct lglock *lg); |
58 | 60 | void lg_global_unlock(struct lglock *lg); |
61 | + | |
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 | |
59 | 75 | |
60 | 76 | #endif |
kernel/locking/Makefile
1 | 1 | |
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 | |
3 | 3 | |
4 | 4 | ifdef CONFIG_FUNCTION_TRACER |
5 | 5 | CFLAGS_REMOVE_lockdep.o = -pg |
... | ... | @@ -14,6 +14,7 @@ |
14 | 14 | obj-$(CONFIG_LOCKDEP) += lockdep_proc.o |
15 | 15 | endif |
16 | 16 | obj-$(CONFIG_SMP) += spinlock.o |
17 | +obj-$(CONFIG_SMP) += lglock.o | |
17 | 18 | obj-$(CONFIG_PROVE_LOCKING) += spinlock.o |
18 | 19 | obj-$(CONFIG_RT_MUTEXES) += rtmutex.o |
19 | 20 | obj-$(CONFIG_DEBUG_RT_MUTEXES) += rtmutex-debug.o |