History

locking/rwsem: Make owner available even if !CONFIG_RWSEM_SPIN_ON_OWNER

The owner field in the rw_semaphore structure is used primarily for optimistic spinning. However, identifying the rwsem owner can also be helpful in debugging as well as tracing locking related issues when analyzing crash dump. The owner field may also store state information that can be important to the operation of the rwsem. So the owner field is now made a permanent member of the rw_semaphore structure irrespective of CONFIG_RWSEM_SPIN_ON_OWNER.

Waiman Long committed 7 years ago

Commit c71fd891 parent 69d927b4 files · +10 −32Browse files

Unified · Split

4 files
  1. include/linux/rwsem.h +5 −4
  2. kernel/locking/rwsem-xadd.c +1 −1
  3. kernel/locking/rwsem.h +0 −23
  4. lib/Kconfig.debug +4 −4
include/linux/rwsem.h+5−4
@@ -34,12 +34,12 @@ · 33 unmodified lines
3434 */
3535 struct rw_semaphore {
3636 atomic_long_t count;
37−#ifdef CONFIG_RWSEM_SPIN_ON_OWNER
3837 /*
39− * Write owner. Used as a speculative check to see
40− * if the owner is running on the cpu.
38+ * Write owner or one of the read owners. Can be used as a
39+ * speculative check to see if the owner is running on the cpu.
4140 */
4241 struct task_struct *owner;
42+#ifdef CONFIG_RWSEM_SPIN_ON_OWNER
4343 struct optimistic_spin_queue osq; /* spinner MCS lock */
4444 #endif
4545 raw_spinlock_t wait_lock;
@@ -73,13 +73,14 @@ static inline int rwsem_is_locked(struct rw_semaphore *sem) · 27 unmodified lines
7373 #endif
7474
7575 #ifdef CONFIG_RWSEM_SPIN_ON_OWNER
76−#define __RWSEM_OPT_INIT(lockname) , .osq = OSQ_LOCK_UNLOCKED, .owner = NULL
76+#define __RWSEM_OPT_INIT(lockname) , .osq = OSQ_LOCK_UNLOCKED
7777 #else
7878 #define __RWSEM_OPT_INIT(lockname)
7979 #endif
8080
8181 #define __RWSEM_INITIALIZER(name) \
8282 { __RWSEM_INIT_COUNT(name), \
83+ .owner = NULL, \
8384 .wait_list = LIST_HEAD_INIT((name).wait_list), \
8485 .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock) \
8586 __RWSEM_OPT_INIT(name) \
kernel/locking/rwsem-xadd.c+1−1
@@ -86,8 +86,8 @@ void __init_rwsem(struct rw_semaphore *sem, const char *name, · 85 unmodified lines
8686 atomic_long_set(&sem->count, RWSEM_UNLOCKED_VALUE);
8787 raw_spin_lock_init(&sem->wait_lock);
8888 INIT_LIST_HEAD(&sem->wait_list);
89−#ifdef CONFIG_RWSEM_SPIN_ON_OWNER
9089 sem->owner = NULL;
90+#ifdef CONFIG_RWSEM_SPIN_ON_OWNER
9191 osq_lock_init(&sem->osq);
9292 #endif
9393 }
kernel/locking/rwsem.h+0−23
@@ -61,7 +61,6 @@ · 60 unmodified lines
6161 #define RWSEM_ACTIVE_READ_BIAS RWSEM_ACTIVE_BIAS
6262 #define RWSEM_ACTIVE_WRITE_BIAS (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS)
6363
64−#ifdef CONFIG_RWSEM_SPIN_ON_OWNER
6564 /*
6665 * All writes to owner are protected by WRITE_ONCE() to make sure that
6766 * store tearing can't happen as optimistic spinners may read and use
@@ -126,7 +125,6 @@ static inline bool rwsem_has_anonymous_owner(struct task_struct *owner) · 58 unmodified lines
126125 * real owner or one of the real owners. The only exception is when the
127126 * unlock is done by up_read_non_owner().
128127 */
129−#define rwsem_clear_reader_owned rwsem_clear_reader_owned
130128 static inline void rwsem_clear_reader_owned(struct rw_semaphore *sem)
131129 {
132130 unsigned long val = (unsigned long)current | RWSEM_READER_OWNED
@@ -135,28 +133,7 @@ static inline void rwsem_clear_reader_owned(struct rw_semaphore *sem) · 2 unmodified lines
135133 cmpxchg_relaxed((unsigned long *)&sem->owner, val,
136134 RWSEM_READER_OWNED | RWSEM_ANONYMOUSLY_OWNED);
137135 }
138−#endif
139−
140136 #else
141−static inline void rwsem_set_owner(struct rw_semaphore *sem)
142−{
143−}
144−
145−static inline void rwsem_clear_owner(struct rw_semaphore *sem)
146−{
147−}
148−
149−static inline void __rwsem_set_reader_owned(struct rw_semaphore *sem,
150− struct task_struct *owner)
151−{
152−}
153−
154−static inline void rwsem_set_reader_owned(struct rw_semaphore *sem)
155−{
156−}
157−#endif
158−
159−#ifndef rwsem_clear_reader_owned
160137 static inline void rwsem_clear_reader_owned(struct rw_semaphore *sem)
161138 {
162139 }
lib/Kconfig.debug+4−4
@@ -1095,7 +1095,7 @@ config PROVE_LOCKING · 1094 unmodified lines
10951095 select DEBUG_SPINLOCK
10961096 select DEBUG_MUTEXES
10971097 select DEBUG_RT_MUTEXES if RT_MUTEXES
1098− select DEBUG_RWSEMS if RWSEM_SPIN_ON_OWNER
1098+ select DEBUG_RWSEMS
10991099 select DEBUG_WW_MUTEX_SLOWPATH
11001100 select DEBUG_LOCK_ALLOC
11011101 select TRACE_IRQFLAGS
@@ -1199,10 +1199,10 @@ config DEBUG_WW_MUTEX_SLOWPATH · 97 unmodified lines
11991199
12001200 config DEBUG_RWSEMS
12011201 bool "RW Semaphore debugging: basic checks"
1202− depends on DEBUG_KERNEL && RWSEM_SPIN_ON_OWNER
1202+ depends on DEBUG_KERNEL
12031203 help
1204− This debugging feature allows mismatched rw semaphore locks and unlocks
1205− to be detected and reported.
1204+ This debugging feature allows mismatched rw semaphore locks
1205+ and unlocks to be detected and reported.
12061206
12071207 config DEBUG_LOCK_ALLOC
12081208 bool "Lock debugging: detect incorrect freeing of live locks"