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

Showing the changes to kernel (2 of 4 files). Show all

Unified · Split

2 files
  1. kernel/locking/rwsem-xadd.c +1 −1
  2. kernel/locking/rwsem.h +0 −23
kernel/locking/rwsem-xadd.c+1−1
@@ -86,8 +86,8 @@ void __init_rwsem(struct rw_semaphore *sem, const char *name, · 85 unmodified lines
86 atomic_long_set(&sem->count, RWSEM_UNLOCKED_VALUE);86 atomic_long_set(&sem->count, RWSEM_UNLOCKED_VALUE);
87 raw_spin_lock_init(&sem->wait_lock);87 raw_spin_lock_init(&sem->wait_lock);
88 INIT_LIST_HEAD(&sem->wait_list);88 INIT_LIST_HEAD(&sem->wait_list);
89#ifdef CONFIG_RWSEM_SPIN_ON_OWNER
90 sem->owner = NULL;89 sem->owner = NULL;
90#ifdef CONFIG_RWSEM_SPIN_ON_OWNER
91 osq_lock_init(&sem->osq);91 osq_lock_init(&sem->osq);
92#endif92#endif
93}93}
kernel/locking/rwsem.h+0−23
@@ -61,7 +61,6 @@ · 60 unmodified lines
61#define RWSEM_ACTIVE_READ_BIAS RWSEM_ACTIVE_BIAS61#define RWSEM_ACTIVE_READ_BIAS RWSEM_ACTIVE_BIAS
62#define RWSEM_ACTIVE_WRITE_BIAS (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS)62#define RWSEM_ACTIVE_WRITE_BIAS (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS)
63 63
64#ifdef CONFIG_RWSEM_SPIN_ON_OWNER
65/*64/*
66 * All writes to owner are protected by WRITE_ONCE() to make sure that65 * All writes to owner are protected by WRITE_ONCE() to make sure that
67 * store tearing can't happen as optimistic spinners may read and use66 * 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
126 * real owner or one of the real owners. The only exception is when the125 * real owner or one of the real owners. The only exception is when the
127 * unlock is done by up_read_non_owner().126 * unlock is done by up_read_non_owner().
128 */127 */
129#define rwsem_clear_reader_owned rwsem_clear_reader_owned
130static inline void rwsem_clear_reader_owned(struct rw_semaphore *sem)128static inline void rwsem_clear_reader_owned(struct rw_semaphore *sem)
131{129{
132 unsigned long val = (unsigned long)current | RWSEM_READER_OWNED130 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
135 cmpxchg_relaxed((unsigned long *)&sem->owner, val,133 cmpxchg_relaxed((unsigned long *)&sem->owner, val,
136 RWSEM_READER_OWNED | RWSEM_ANONYMOUSLY_OWNED);134 RWSEM_READER_OWNED | RWSEM_ANONYMOUSLY_OWNED);
137}135}
138#endif
139
140#else136#else
141static inline void rwsem_set_owner(struct rw_semaphore *sem)
142{
143}
144
145static inline void rwsem_clear_owner(struct rw_semaphore *sem)
146{
147}
148
149static inline void __rwsem_set_reader_owned(struct rw_semaphore *sem,
150 struct task_struct *owner)
151{
152}
153
154static inline void rwsem_set_reader_owned(struct rw_semaphore *sem)
155{
156}
157#endif
158
159#ifndef rwsem_clear_reader_owned
160static inline void rwsem_clear_reader_owned(struct rw_semaphore *sem)137static inline void rwsem_clear_reader_owned(struct rw_semaphore *sem)
161{138{
162}139}