Skip to content

Commit

Permalink
locking/spinlock: Provide RT specific spinlock_t
Browse files Browse the repository at this point in the history
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 <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20210815211303.654230709@linutronix.de
  • Loading branch information
Thomas Gleixner authored and Ingo Molnar committed Aug 17, 2021
1 parent e4e17af commit 051790e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions include/linux/spinlock_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

#include <linux/spinlock_types_raw.h>

#ifndef CONFIG_PREEMPT_RT

/* Non PREEMPT_RT kernels map spinlock to raw_spinlock */
typedef struct spinlock {
union {
struct raw_spinlock rlock;
Expand Down Expand Up @@ -39,6 +42,29 @@ typedef struct spinlock {

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

#else /* !CONFIG_PREEMPT_RT */

/* PREEMPT_RT kernels map spinlock to rt_mutex */
#include <linux/rtmutex.h>

typedef struct spinlock {
struct rt_mutex_base lock;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lockdep_map dep_map;
#endif
} spinlock_t;

#define __SPIN_LOCK_UNLOCKED(name) \
{ \
.lock = __RT_MUTEX_BASE_INITIALIZER(name.lock), \
SPIN_DEP_MAP_INIT(name) \
}

#define DEFINE_SPINLOCK(name) \
spinlock_t name = __SPIN_LOCK_UNLOCKED(name)

#endif /* CONFIG_PREEMPT_RT */

#include <linux/rwlock_types.h>

#endif /* __LINUX_SPINLOCK_TYPES_H */

0 comments on commit 051790e

Please sign in to comment.