Skip to content

Commit 3a9320e

Browse files
jlelliPeter Zijlstra
authored andcommitted
locking/mutex: Expose __mutex_owner()
Implementing proxy execution requires that scheduler code be able to identify the current owner of a mutex. Expose __mutex_owner() for this purpose (alone!). Includes a null mutex check, so that users of the function can be simplified. [Removed the EXPORT_SYMBOL] [jstultz: Reworked per Peter's suggestions] Signed-off-by: Juri Lelli <[email protected]> Signed-off-by: Valentin Schneider <[email protected]> Signed-off-by: Connor O'Brien <[email protected]> Signed-off-by: John Stultz <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Metin Kaya <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Tested-by: K Prateek Nayak <[email protected]> Tested-by: Metin Kaya <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5ec5852 commit 3a9320e

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

kernel/locking/mutex.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,6 @@ __mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key)
5656
}
5757
EXPORT_SYMBOL(__mutex_init);
5858

59-
/*
60-
* @owner: contains: 'struct task_struct *' to the current lock owner,
61-
* NULL means not owned. Since task_struct pointers are aligned at
62-
* at least L1_CACHE_BYTES, we have low bits to store extra state.
63-
*
64-
* Bit0 indicates a non-empty waiter list; unlock must issue a wakeup.
65-
* Bit1 indicates unlock needs to hand the lock to the top-waiter
66-
* Bit2 indicates handoff has been done and we're waiting for pickup.
67-
*/
68-
#define MUTEX_FLAG_WAITERS 0x01
69-
#define MUTEX_FLAG_HANDOFF 0x02
70-
#define MUTEX_FLAG_PICKUP 0x04
71-
72-
#define MUTEX_FLAGS 0x07
73-
74-
/*
75-
* Internal helper function; C doesn't allow us to hide it :/
76-
*
77-
* DO NOT USE (outside of mutex code).
78-
*/
79-
static inline struct task_struct *__mutex_owner(struct mutex *lock)
80-
{
81-
return (struct task_struct *)(atomic_long_read(&lock->owner) & ~MUTEX_FLAGS);
82-
}
83-
8459
static inline struct task_struct *__owner_task(unsigned long owner)
8560
{
8661
return (struct task_struct *)(owner & ~MUTEX_FLAGS);

kernel/locking/mutex.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,33 @@ struct mutex_waiter {
2020
#endif
2121
};
2222

23+
/*
24+
* @owner: contains: 'struct task_struct *' to the current lock owner,
25+
* NULL means not owned. Since task_struct pointers are aligned at
26+
* at least L1_CACHE_BYTES, we have low bits to store extra state.
27+
*
28+
* Bit0 indicates a non-empty waiter list; unlock must issue a wakeup.
29+
* Bit1 indicates unlock needs to hand the lock to the top-waiter
30+
* Bit2 indicates handoff has been done and we're waiting for pickup.
31+
*/
32+
#define MUTEX_FLAG_WAITERS 0x01
33+
#define MUTEX_FLAG_HANDOFF 0x02
34+
#define MUTEX_FLAG_PICKUP 0x04
35+
36+
#define MUTEX_FLAGS 0x07
37+
38+
/*
39+
* Internal helper function; C doesn't allow us to hide it :/
40+
*
41+
* DO NOT USE (outside of mutex & scheduler code).
42+
*/
43+
static inline struct task_struct *__mutex_owner(struct mutex *lock)
44+
{
45+
if (!lock)
46+
return NULL;
47+
return (struct task_struct *)(atomic_long_read(&lock->owner) & ~MUTEX_FLAGS);
48+
}
49+
2350
#ifdef CONFIG_DEBUG_MUTEXES
2451
extern void debug_mutex_lock_common(struct mutex *lock,
2552
struct mutex_waiter *waiter);

0 commit comments

Comments
 (0)