Skip to content

Commit 3155238

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
locking/spinlock/rt: Prepare for RT local_lock
Add the static and runtime initializer mechanics to support the RT variant of local_lock, which requires the lock type in the lockdep map to be set to LD_LOCK_PERCPU. 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 992caf7 commit 3155238

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

include/linux/spinlock_rt.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,28 @@
88

99
#ifdef CONFIG_DEBUG_LOCK_ALLOC
1010
extern void __rt_spin_lock_init(spinlock_t *lock, const char *name,
11-
struct lock_class_key *key);
11+
struct lock_class_key *key, bool percpu);
1212
#else
1313
static inline void __rt_spin_lock_init(spinlock_t *lock, const char *name,
14-
struct lock_class_key *key)
14+
struct lock_class_key *key, bool percpu)
1515
{
1616
}
1717
#endif
1818

19-
#define spin_lock_init(slock) \
20-
do { \
21-
static struct lock_class_key __key; \
22-
\
23-
rt_mutex_base_init(&(slock)->lock); \
24-
__rt_spin_lock_init(slock, #slock, &__key); \
19+
#define spin_lock_init(slock) \
20+
do { \
21+
static struct lock_class_key __key; \
22+
\
23+
rt_mutex_base_init(&(slock)->lock); \
24+
__rt_spin_lock_init(slock, #slock, &__key, false); \
25+
} while (0)
26+
27+
#define local_spin_lock_init(slock) \
28+
do { \
29+
static struct lock_class_key __key; \
30+
\
31+
rt_mutex_base_init(&(slock)->lock); \
32+
__rt_spin_lock_init(slock, #slock, &__key, true); \
2533
} while (0)
2634

2735
extern void rt_spin_lock(spinlock_t *lock);

include/linux/spinlock_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ typedef struct spinlock {
6060
SPIN_DEP_MAP_INIT(name) \
6161
}
6262

63+
#define __LOCAL_SPIN_LOCK_UNLOCKED(name) \
64+
{ \
65+
.lock = __RT_MUTEX_BASE_INITIALIZER(name.lock), \
66+
LOCAL_SPIN_DEP_MAP_INIT(name) \
67+
}
68+
6369
#define DEFINE_SPINLOCK(name) \
6470
spinlock_t name = __SPIN_LOCK_UNLOCKED(name)
6571

include/linux/spinlock_types_raw.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,17 @@ typedef struct raw_spinlock {
3737
.name = #lockname, \
3838
.wait_type_inner = LD_WAIT_CONFIG, \
3939
}
40+
41+
# define LOCAL_SPIN_DEP_MAP_INIT(lockname) \
42+
.dep_map = { \
43+
.name = #lockname, \
44+
.wait_type_inner = LD_WAIT_CONFIG, \
45+
.lock_type = LD_LOCK_PERCPU, \
46+
}
4047
#else
4148
# define RAW_SPIN_DEP_MAP_INIT(lockname)
4249
# define SPIN_DEP_MAP_INIT(lockname)
50+
# define LOCAL_SPIN_DEP_MAP_INIT(lockname)
4351
#endif
4452

4553
#ifdef CONFIG_DEBUG_SPINLOCK

kernel/locking/spinlock_rt.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,13 @@ EXPORT_SYMBOL(rt_spin_trylock_bh);
120120

121121
#ifdef CONFIG_DEBUG_LOCK_ALLOC
122122
void __rt_spin_lock_init(spinlock_t *lock, const char *name,
123-
struct lock_class_key *key)
123+
struct lock_class_key *key, bool percpu)
124124
{
125+
u8 type = percpu ? LD_LOCK_PERCPU : LD_LOCK_NORMAL;
126+
125127
debug_check_no_locks_freed((void *)lock, sizeof(*lock));
126-
lockdep_init_map_wait(&lock->dep_map, name, key, 0, LD_WAIT_CONFIG);
128+
lockdep_init_map_type(&lock->dep_map, name, key, 0, LD_WAIT_CONFIG,
129+
LD_WAIT_INV, type);
127130
}
128131
EXPORT_SYMBOL(__rt_spin_lock_init);
129132
#endif

0 commit comments

Comments
 (0)