Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Alexei Starovoitov and committed by
Vlastimil Babka
4957089a 4ec1a08d

+19 -9
+2
include/linux/local_lock.h
··· 66 66 */ 67 67 #define local_trylock(lock) __local_trylock(this_cpu_ptr(lock)) 68 68 69 + #define local_lock_is_locked(lock) __local_lock_is_locked(lock) 70 + 69 71 /** 70 72 * local_trylock_irqsave - Try to acquire a per CPU local lock, save and disable 71 73 * interrupts if acquired
+7
include/linux/local_lock_internal.h
··· 165 165 !!tl; \ 166 166 }) 167 167 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 + 168 171 #define __local_lock_release(lock) \ 169 172 do { \ 170 173 local_trylock_t *tl; \ ··· 287 284 flags = 0; \ 288 285 __local_trylock(lock); \ 289 286 }) 287 + 288 + /* migration must be disabled before calling __local_lock_is_locked */ 289 + #define __local_lock_is_locked(__lock) \ 290 + (rt_mutex_owner(&this_cpu_ptr(__lock)->lock) == current) 290 291 291 292 #endif /* CONFIG_PREEMPT_RT */
+10
include/linux/rtmutex.h
··· 44 44 return READ_ONCE(lock->owner) != NULL; 45 45 } 46 46 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 47 57 extern void rt_mutex_base_init(struct rt_mutex_base *rtb); 48 58 49 59 /**
-9
kernel/locking/rtmutex_common.h
··· 153 153 pi_tree.entry); 154 154 } 155 155 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 - 165 156 /* 166 157 * Constants for rt mutex functions which have a selectable deadlock 167 158 * detection.