Skip to content

Commit 051790e

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
locking/spinlock: Provide RT specific spinlock_t
RT replaces spinlocks with a simple wrapper around an rtmutex, which turns spinlocks on RT into 'sleeping' spinlocks. The actual implementation of the spinlock API differs from a regular rtmutex, as it does neither handle timeouts nor signals and it is state preserving across the lock operation. 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 e4e17af commit 051790e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

include/linux/spinlock_types.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
#include <linux/spinlock_types_raw.h>
1313

14+
#ifndef CONFIG_PREEMPT_RT
15+
16+
/* Non PREEMPT_RT kernels map spinlock to raw_spinlock */
1417
typedef struct spinlock {
1518
union {
1619
struct raw_spinlock rlock;
@@ -39,6 +42,29 @@ typedef struct spinlock {
3942

4043
#define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)
4144

45+
#else /* !CONFIG_PREEMPT_RT */
46+
47+
/* PREEMPT_RT kernels map spinlock to rt_mutex */
48+
#include <linux/rtmutex.h>
49+
50+
typedef struct spinlock {
51+
struct rt_mutex_base lock;
52+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
53+
struct lockdep_map dep_map;
54+
#endif
55+
} spinlock_t;
56+
57+
#define __SPIN_LOCK_UNLOCKED(name) \
58+
{ \
59+
.lock = __RT_MUTEX_BASE_INITIALIZER(name.lock), \
60+
SPIN_DEP_MAP_INIT(name) \
61+
}
62+
63+
#define DEFINE_SPINLOCK(name) \
64+
spinlock_t name = __SPIN_LOCK_UNLOCKED(name)
65+
66+
#endif /* CONFIG_PREEMPT_RT */
67+
4268
#include <linux/rwlock_types.h>
4369

4470
#endif /* __LINUX_SPINLOCK_TYPES_H */

0 commit comments

Comments
 (0)