Skip to content

Commit 026659b

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
locking/local_lock: Add PREEMPT_RT support
On PREEMPT_RT enabled kernels local_lock maps to a per CPU 'sleeping' spinlock which protects the critical section while staying preemptible. CPU locality is established by disabling migration. Provide the necessary types and macros to substitute the non-RT variant. Co-developed-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3155238 commit 026659b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

include/linux/local_lock_internal.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <linux/percpu-defs.h>
77
#include <linux/lockdep.h>
88

9+
#ifndef CONFIG_PREEMPT_RT
10+
911
typedef struct {
1012
#ifdef CONFIG_DEBUG_LOCK_ALLOC
1113
struct lockdep_map dep_map;
@@ -95,3 +97,45 @@ do { \
9597
local_lock_release(this_cpu_ptr(lock)); \
9698
local_irq_restore(flags); \
9799
} while (0)
100+
101+
#else /* !CONFIG_PREEMPT_RT */
102+
103+
/*
104+
* On PREEMPT_RT local_lock maps to a per CPU spinlock, which protects the
105+
* critical section while staying preemptible.
106+
*/
107+
typedef spinlock_t local_lock_t;
108+
109+
#define INIT_LOCAL_LOCK(lockname) __LOCAL_SPIN_LOCK_UNLOCKED((lockname))
110+
111+
#define __local_lock_init(l) \
112+
do { \
113+
local_spin_lock_init((l)); \
114+
} while (0)
115+
116+
#define __local_lock(__lock) \
117+
do { \
118+
migrate_disable(); \
119+
spin_lock(this_cpu_ptr((__lock))); \
120+
} while (0)
121+
122+
#define __local_lock_irq(lock) __local_lock(lock)
123+
124+
#define __local_lock_irqsave(lock, flags) \
125+
do { \
126+
typecheck(unsigned long, flags); \
127+
flags = 0; \
128+
__local_lock(lock); \
129+
} while (0)
130+
131+
#define __local_unlock(__lock) \
132+
do { \
133+
spin_unlock(this_cpu_ptr((__lock))); \
134+
migrate_enable(); \
135+
} while (0)
136+
137+
#define __local_unlock_irq(lock) __local_unlock(lock)
138+
139+
#define __local_unlock_irqrestore(lock, flags) __local_unlock(lock)
140+
141+
#endif /* CONFIG_PREEMPT_RT */

0 commit comments

Comments
 (0)