Skip to content

Commit d84f317

Browse files
author
Kent Overstreet
committed
locking/mutex: split out mutex_types.h
Trimming down sched.h dependencies: we don't want to include more than the base types. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Will Deacon <will@kernel.org> Cc: Waiman Long <longman@redhat.com> Cc: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 50d91c7 commit d84f317

File tree

3 files changed

+73
-52
lines changed

3 files changed

+73
-52
lines changed

include/linux/mutex.h

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/osq_lock.h>
2121
#include <linux/debug_locks.h>
2222
#include <linux/cleanup.h>
23+
#include <linux/mutex_types.h>
2324

2425
#ifdef CONFIG_DEBUG_LOCK_ALLOC
2526
# define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
@@ -33,49 +34,6 @@
3334

3435
#ifndef CONFIG_PREEMPT_RT
3536

36-
/*
37-
* Simple, straightforward mutexes with strict semantics:
38-
*
39-
* - only one task can hold the mutex at a time
40-
* - only the owner can unlock the mutex
41-
* - multiple unlocks are not permitted
42-
* - recursive locking is not permitted
43-
* - a mutex object must be initialized via the API
44-
* - a mutex object must not be initialized via memset or copying
45-
* - task may not exit with mutex held
46-
* - memory areas where held locks reside must not be freed
47-
* - held mutexes must not be reinitialized
48-
* - mutexes may not be used in hardware or software interrupt
49-
* contexts such as tasklets and timers
50-
*
51-
* These semantics are fully enforced when DEBUG_MUTEXES is
52-
* enabled. Furthermore, besides enforcing the above rules, the mutex
53-
* debugging code also implements a number of additional features
54-
* that make lock debugging easier and faster:
55-
*
56-
* - uses symbolic names of mutexes, whenever they are printed in debug output
57-
* - point-of-acquire tracking, symbolic lookup of function names
58-
* - list of all locks held in the system, printout of them
59-
* - owner tracking
60-
* - detects self-recursing locks and prints out all relevant info
61-
* - detects multi-task circular deadlocks and prints out all affected
62-
* locks and tasks (and only those tasks)
63-
*/
64-
struct mutex {
65-
atomic_long_t owner;
66-
raw_spinlock_t wait_lock;
67-
#ifdef CONFIG_MUTEX_SPIN_ON_OWNER
68-
struct optimistic_spin_queue osq; /* Spinner MCS lock */
69-
#endif
70-
struct list_head wait_list;
71-
#ifdef CONFIG_DEBUG_MUTEXES
72-
void *magic;
73-
#endif
74-
#ifdef CONFIG_DEBUG_LOCK_ALLOC
75-
struct lockdep_map dep_map;
76-
#endif
77-
};
78-
7937
#ifdef CONFIG_DEBUG_MUTEXES
8038

8139
#define __DEBUG_MUTEX_INITIALIZER(lockname) \
@@ -131,14 +89,6 @@ extern bool mutex_is_locked(struct mutex *lock);
13189
/*
13290
* Preempt-RT variant based on rtmutexes.
13391
*/
134-
#include <linux/rtmutex.h>
135-
136-
struct mutex {
137-
struct rt_mutex_base rtmutex;
138-
#ifdef CONFIG_DEBUG_LOCK_ALLOC
139-
struct lockdep_map dep_map;
140-
#endif
141-
};
14292

14393
#define __MUTEX_INITIALIZER(mutexname) \
14494
{ \

include/linux/mutex_types.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef __LINUX_MUTEX_TYPES_H
3+
#define __LINUX_MUTEX_TYPES_H
4+
5+
#include <linux/atomic.h>
6+
#include <linux/lockdep_types.h>
7+
#include <linux/osq_lock.h>
8+
#include <linux/spinlock_types.h>
9+
#include <linux/types.h>
10+
11+
#ifndef CONFIG_PREEMPT_RT
12+
13+
/*
14+
* Simple, straightforward mutexes with strict semantics:
15+
*
16+
* - only one task can hold the mutex at a time
17+
* - only the owner can unlock the mutex
18+
* - multiple unlocks are not permitted
19+
* - recursive locking is not permitted
20+
* - a mutex object must be initialized via the API
21+
* - a mutex object must not be initialized via memset or copying
22+
* - task may not exit with mutex held
23+
* - memory areas where held locks reside must not be freed
24+
* - held mutexes must not be reinitialized
25+
* - mutexes may not be used in hardware or software interrupt
26+
* contexts such as tasklets and timers
27+
*
28+
* These semantics are fully enforced when DEBUG_MUTEXES is
29+
* enabled. Furthermore, besides enforcing the above rules, the mutex
30+
* debugging code also implements a number of additional features
31+
* that make lock debugging easier and faster:
32+
*
33+
* - uses symbolic names of mutexes, whenever they are printed in debug output
34+
* - point-of-acquire tracking, symbolic lookup of function names
35+
* - list of all locks held in the system, printout of them
36+
* - owner tracking
37+
* - detects self-recursing locks and prints out all relevant info
38+
* - detects multi-task circular deadlocks and prints out all affected
39+
* locks and tasks (and only those tasks)
40+
*/
41+
struct mutex {
42+
atomic_long_t owner;
43+
raw_spinlock_t wait_lock;
44+
#ifdef CONFIG_MUTEX_SPIN_ON_OWNER
45+
struct optimistic_spin_queue osq; /* Spinner MCS lock */
46+
#endif
47+
struct list_head wait_list;
48+
#ifdef CONFIG_DEBUG_MUTEXES
49+
void *magic;
50+
#endif
51+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
52+
struct lockdep_map dep_map;
53+
#endif
54+
};
55+
56+
#else /* !CONFIG_PREEMPT_RT */
57+
/*
58+
* Preempt-RT variant based on rtmutexes.
59+
*/
60+
#include <linux/rtmutex.h>
61+
62+
struct mutex {
63+
struct rt_mutex_base rtmutex;
64+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
65+
struct lockdep_map dep_map;
66+
#endif
67+
};
68+
69+
#endif /* CONFIG_PREEMPT_RT */
70+
71+
#endif /* __LINUX_MUTEX_TYPES_H */

include/linux/sched.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <linux/sem.h>
1616
#include <linux/shm.h>
1717
#include <linux/kmsan_types.h>
18-
#include <linux/mutex.h>
18+
#include <linux/mutex_types.h>
1919
#include <linux/plist.h>
2020
#include <linux/hrtimer_types.h>
2121
#include <linux/irqflags.h>

0 commit comments

Comments
 (0)