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

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>

+73 -52
+1 -51
include/linux/mutex.h
··· 20 20 #include <linux/osq_lock.h> 21 21 #include <linux/debug_locks.h> 22 22 #include <linux/cleanup.h> 23 + #include <linux/mutex_types.h> 23 24 24 25 #ifdef CONFIG_DEBUG_LOCK_ALLOC 25 26 # define __DEP_MAP_MUTEX_INITIALIZER(lockname) \ ··· 33 32 #endif 34 33 35 34 #ifndef CONFIG_PREEMPT_RT 36 - 37 - /* 38 - * Simple, straightforward mutexes with strict semantics: 39 - * 40 - * - only one task can hold the mutex at a time 41 - * - only the owner can unlock the mutex 42 - * - multiple unlocks are not permitted 43 - * - recursive locking is not permitted 44 - * - a mutex object must be initialized via the API 45 - * - a mutex object must not be initialized via memset or copying 46 - * - task may not exit with mutex held 47 - * - memory areas where held locks reside must not be freed 48 - * - held mutexes must not be reinitialized 49 - * - mutexes may not be used in hardware or software interrupt 50 - * contexts such as tasklets and timers 51 - * 52 - * These semantics are fully enforced when DEBUG_MUTEXES is 53 - * enabled. Furthermore, besides enforcing the above rules, the mutex 54 - * debugging code also implements a number of additional features 55 - * that make lock debugging easier and faster: 56 - * 57 - * - uses symbolic names of mutexes, whenever they are printed in debug output 58 - * - point-of-acquire tracking, symbolic lookup of function names 59 - * - list of all locks held in the system, printout of them 60 - * - owner tracking 61 - * - detects self-recursing locks and prints out all relevant info 62 - * - detects multi-task circular deadlocks and prints out all affected 63 - * locks and tasks (and only those tasks) 64 - */ 65 - struct mutex { 66 - atomic_long_t owner; 67 - raw_spinlock_t wait_lock; 68 - #ifdef CONFIG_MUTEX_SPIN_ON_OWNER 69 - struct optimistic_spin_queue osq; /* Spinner MCS lock */ 70 - #endif 71 - struct list_head wait_list; 72 - #ifdef CONFIG_DEBUG_MUTEXES 73 - void *magic; 74 - #endif 75 - #ifdef CONFIG_DEBUG_LOCK_ALLOC 76 - struct lockdep_map dep_map; 77 - #endif 78 - }; 79 35 80 36 #ifdef CONFIG_DEBUG_MUTEXES 81 37 ··· 89 131 /* 90 132 * Preempt-RT variant based on rtmutexes. 91 133 */ 92 - #include <linux/rtmutex.h> 93 - 94 - struct mutex { 95 - struct rt_mutex_base rtmutex; 96 - #ifdef CONFIG_DEBUG_LOCK_ALLOC 97 - struct lockdep_map dep_map; 98 - #endif 99 - }; 100 134 101 135 #define __MUTEX_INITIALIZER(mutexname) \ 102 136 { \
+71
include/linux/mutex_types.h
··· 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 */
+1 -1
include/linux/sched.h
··· 15 15 #include <linux/sem.h> 16 16 #include <linux/shm.h> 17 17 #include <linux/kmsan_types.h> 18 - #include <linux/mutex.h> 18 + #include <linux/mutex_types.h> 19 19 #include <linux/plist.h> 20 20 #include <linux/hrtimer_types.h> 21 21 #include <linux/irqflags.h>