mirror of
https://github.com/torvalds/linux.git
synced 2025-11-30 23:16:01 +07:00
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>
This commit is contained in:
committed by
Vlastimil Babka
parent
4ec1a08d20
commit
4957089a23
@@ -66,6 +66,8 @@
|
|||||||
*/
|
*/
|
||||||
#define local_trylock(lock) __local_trylock(this_cpu_ptr(lock))
|
#define local_trylock(lock) __local_trylock(this_cpu_ptr(lock))
|
||||||
|
|
||||||
|
#define local_lock_is_locked(lock) __local_lock_is_locked(lock)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* local_trylock_irqsave - Try to acquire a per CPU local lock, save and disable
|
* local_trylock_irqsave - Try to acquire a per CPU local lock, save and disable
|
||||||
* interrupts if acquired
|
* interrupts if acquired
|
||||||
|
|||||||
@@ -165,6 +165,9 @@ do { \
|
|||||||
!!tl; \
|
!!tl; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/* preemption or migration must be disabled before calling __local_lock_is_locked */
|
||||||
|
#define __local_lock_is_locked(lock) READ_ONCE(this_cpu_ptr(lock)->acquired)
|
||||||
|
|
||||||
#define __local_lock_release(lock) \
|
#define __local_lock_release(lock) \
|
||||||
do { \
|
do { \
|
||||||
local_trylock_t *tl; \
|
local_trylock_t *tl; \
|
||||||
@@ -285,4 +288,8 @@ do { \
|
|||||||
__local_trylock(lock); \
|
__local_trylock(lock); \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/* migration must be disabled before calling __local_lock_is_locked */
|
||||||
|
#define __local_lock_is_locked(__lock) \
|
||||||
|
(rt_mutex_owner(&this_cpu_ptr(__lock)->lock) == current)
|
||||||
|
|
||||||
#endif /* CONFIG_PREEMPT_RT */
|
#endif /* CONFIG_PREEMPT_RT */
|
||||||
|
|||||||
@@ -44,6 +44,16 @@ static inline bool rt_mutex_base_is_locked(struct rt_mutex_base *lock)
|
|||||||
return READ_ONCE(lock->owner) != NULL;
|
return READ_ONCE(lock->owner) != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_RT_MUTEXES
|
||||||
|
#define RT_MUTEX_HAS_WAITERS 1UL
|
||||||
|
|
||||||
|
static inline struct task_struct *rt_mutex_owner(struct rt_mutex_base *lock)
|
||||||
|
{
|
||||||
|
unsigned long owner = (unsigned long) READ_ONCE(lock->owner);
|
||||||
|
|
||||||
|
return (struct task_struct *) (owner & ~RT_MUTEX_HAS_WAITERS);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
extern void rt_mutex_base_init(struct rt_mutex_base *rtb);
|
extern void rt_mutex_base_init(struct rt_mutex_base *rtb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -153,15 +153,6 @@ static inline struct rt_mutex_waiter *task_top_pi_waiter(struct task_struct *p)
|
|||||||
pi_tree.entry);
|
pi_tree.entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define RT_MUTEX_HAS_WAITERS 1UL
|
|
||||||
|
|
||||||
static inline struct task_struct *rt_mutex_owner(struct rt_mutex_base *lock)
|
|
||||||
{
|
|
||||||
unsigned long owner = (unsigned long) READ_ONCE(lock->owner);
|
|
||||||
|
|
||||||
return (struct task_struct *) (owner & ~RT_MUTEX_HAS_WAITERS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constants for rt mutex functions which have a selectable deadlock
|
* Constants for rt mutex functions which have a selectable deadlock
|
||||||
* detection.
|
* detection.
|
||||||
|
|||||||
Reference in New Issue
Block a user