Skip to content

Commit 4957089

Browse files
Alexei Starovoitovtehcaster
authored andcommitted
locking/local_lock: Introduce local_lock_is_locked().
Introduce local_lock_is_locked() that returns true when given local_lock is locked by current cpu (in !PREEMPT_RT) or by current task (in PREEMPT_RT). The goal is to detect a deadlock by the caller. Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
1 parent 4ec1a08 commit 4957089

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

include/linux/local_lock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
*/
6767
#define local_trylock(lock) __local_trylock(this_cpu_ptr(lock))
6868

69+
#define local_lock_is_locked(lock) __local_lock_is_locked(lock)
70+
6971
/**
7072
* local_trylock_irqsave - Try to acquire a per CPU local lock, save and disable
7173
* interrupts if acquired

include/linux/local_lock_internal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ do { \
165165
!!tl; \
166166
})
167167

168+
/* preemption or migration must be disabled before calling __local_lock_is_locked */
169+
#define __local_lock_is_locked(lock) READ_ONCE(this_cpu_ptr(lock)->acquired)
170+
168171
#define __local_lock_release(lock) \
169172
do { \
170173
local_trylock_t *tl; \
@@ -285,4 +288,8 @@ do { \
285288
__local_trylock(lock); \
286289
})
287290

291+
/* migration must be disabled before calling __local_lock_is_locked */
292+
#define __local_lock_is_locked(__lock) \
293+
(rt_mutex_owner(&this_cpu_ptr(__lock)->lock) == current)
294+
288295
#endif /* CONFIG_PREEMPT_RT */

include/linux/rtmutex.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ static inline bool rt_mutex_base_is_locked(struct rt_mutex_base *lock)
4444
return READ_ONCE(lock->owner) != NULL;
4545
}
4646

47+
#ifdef CONFIG_RT_MUTEXES
48+
#define RT_MUTEX_HAS_WAITERS 1UL
49+
50+
static inline struct task_struct *rt_mutex_owner(struct rt_mutex_base *lock)
51+
{
52+
unsigned long owner = (unsigned long) READ_ONCE(lock->owner);
53+
54+
return (struct task_struct *) (owner & ~RT_MUTEX_HAS_WAITERS);
55+
}
56+
#endif
4757
extern void rt_mutex_base_init(struct rt_mutex_base *rtb);
4858

4959
/**

kernel/locking/rtmutex_common.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,6 @@ static inline struct rt_mutex_waiter *task_top_pi_waiter(struct task_struct *p)
153153
pi_tree.entry);
154154
}
155155

156-
#define RT_MUTEX_HAS_WAITERS 1UL
157-
158-
static inline struct task_struct *rt_mutex_owner(struct rt_mutex_base *lock)
159-
{
160-
unsigned long owner = (unsigned long) READ_ONCE(lock->owner);
161-
162-
return (struct task_struct *) (owner & ~RT_MUTEX_HAS_WAITERS);
163-
}
164-
165156
/*
166157
* Constants for rt mutex functions which have a selectable deadlock
167158
* detection.

0 commit comments

Comments
 (0)