Skip to content

Commit e4564f7

Browse files
author
Peter Zijlstra
committed
lockdep: fixup mutex annotations
The fancy mutex_lock fastpath has too many indirections to track the caller hence all contentions are perceived to come from mutex_lock(). Avoid this by explicitly not using the fastpath code (it was disabled already anyway). Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 3aa416b commit e4564f7

2 files changed

Lines changed: 26 additions & 18 deletions

File tree

‎include/linux/mutex.h‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,17 @@ static inline int fastcall mutex_is_locked(struct mutex *lock)
120120
* See kernel/mutex.c for detailed documentation of these APIs.
121121
* Also see Documentation/mutex-design.txt.
122122
*/
123-
extern void fastcall mutex_lock(struct mutex *lock);
124-
extern int __must_check fastcall mutex_lock_interruptible(struct mutex *lock);
125-
126123
#ifdef CONFIG_DEBUG_LOCK_ALLOC
127124
extern void mutex_lock_nested(struct mutex *lock, unsigned int subclass);
128125
extern int __must_check mutex_lock_interruptible_nested(struct mutex *lock,
129126
unsigned int subclass);
127+
128+
#define mutex_lock(lock) mutex_lock_nested(lock, 0)
129+
#define mutex_lock_interruptible(lock) mutex_lock_interruptible_nested(lock, 0)
130130
#else
131+
extern void fastcall mutex_lock(struct mutex *lock);
132+
extern int __must_check fastcall mutex_lock_interruptible(struct mutex *lock);
133+
131134
# define mutex_lock_nested(lock, subclass) mutex_lock(lock)
132135
# define mutex_lock_interruptible_nested(lock, subclass) mutex_lock_interruptible(lock)
133136
#endif

‎kernel/mutex.c‎

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ __mutex_init(struct mutex *lock, const char *name, struct lock_class_key *key)
5151

5252
EXPORT_SYMBOL(__mutex_init);
5353

54+
#ifndef CONFIG_DEBUG_LOCK_ALLOC
5455
/*
5556
* We split the mutex lock/unlock logic into separate fastpath and
5657
* slowpath functions, to reduce the register pressure on the fastpath.
@@ -92,6 +93,7 @@ void inline fastcall __sched mutex_lock(struct mutex *lock)
9293
}
9394

9495
EXPORT_SYMBOL(mutex_lock);
96+
#endif
9597

9698
static void fastcall noinline __sched
9799
__mutex_unlock_slowpath(atomic_t *lock_count);
@@ -122,7 +124,8 @@ EXPORT_SYMBOL(mutex_unlock);
122124
* Lock a mutex (possibly interruptible), slowpath:
123125
*/
124126
static inline int __sched
125-
__mutex_lock_common(struct mutex *lock, long state, unsigned int subclass)
127+
__mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
128+
unsigned long ip)
126129
{
127130
struct task_struct *task = current;
128131
struct mutex_waiter waiter;
@@ -132,7 +135,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass)
132135
spin_lock_mutex(&lock->wait_lock, flags);
133136

134137
debug_mutex_lock_common(lock, &waiter);
135-
mutex_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
138+
mutex_acquire(&lock->dep_map, subclass, 0, ip);
136139
debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
137140

138141
/* add waiting tasks to the end of the waitqueue (FIFO): */
@@ -143,7 +146,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass)
143146
if (old_val == 1)
144147
goto done;
145148

146-
lock_contended(&lock->dep_map, _RET_IP_);
149+
lock_contended(&lock->dep_map, ip);
147150

148151
for (;;) {
149152
/*
@@ -166,7 +169,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass)
166169
if (unlikely(state == TASK_INTERRUPTIBLE &&
167170
signal_pending(task))) {
168171
mutex_remove_waiter(lock, &waiter, task_thread_info(task));
169-
mutex_release(&lock->dep_map, 1, _RET_IP_);
172+
mutex_release(&lock->dep_map, 1, ip);
170173
spin_unlock_mutex(&lock->wait_lock, flags);
171174

172175
debug_mutex_free_waiter(&waiter);
@@ -197,20 +200,12 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass)
197200
return 0;
198201
}
199202

200-
static void fastcall noinline __sched
201-
__mutex_lock_slowpath(atomic_t *lock_count)
202-
{
203-
struct mutex *lock = container_of(lock_count, struct mutex, count);
204-
205-
__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0);
206-
}
207-
208203
#ifdef CONFIG_DEBUG_LOCK_ALLOC
209204
void __sched
210205
mutex_lock_nested(struct mutex *lock, unsigned int subclass)
211206
{
212207
might_sleep();
213-
__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, subclass);
208+
__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, subclass, _RET_IP_);
214209
}
215210

216211
EXPORT_SYMBOL_GPL(mutex_lock_nested);
@@ -219,7 +214,7 @@ int __sched
219214
mutex_lock_interruptible_nested(struct mutex *lock, unsigned int subclass)
220215
{
221216
might_sleep();
222-
return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, subclass);
217+
return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, subclass, _RET_IP_);
223218
}
224219

225220
EXPORT_SYMBOL_GPL(mutex_lock_interruptible_nested);
@@ -271,6 +266,7 @@ __mutex_unlock_slowpath(atomic_t *lock_count)
271266
__mutex_unlock_common_slowpath(lock_count, 1);
272267
}
273268

269+
#ifndef CONFIG_DEBUG_LOCK_ALLOC
274270
/*
275271
* Here come the less common (and hence less performance-critical) APIs:
276272
* mutex_lock_interruptible() and mutex_trylock().
@@ -298,13 +294,22 @@ int fastcall __sched mutex_lock_interruptible(struct mutex *lock)
298294

299295
EXPORT_SYMBOL(mutex_lock_interruptible);
300296

297+
static void fastcall noinline __sched
298+
__mutex_lock_slowpath(atomic_t *lock_count)
299+
{
300+
struct mutex *lock = container_of(lock_count, struct mutex, count);
301+
302+
__mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0, _RET_IP_);
303+
}
304+
301305
static int fastcall noinline __sched
302306
__mutex_lock_interruptible_slowpath(atomic_t *lock_count)
303307
{
304308
struct mutex *lock = container_of(lock_count, struct mutex, count);
305309

306-
return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, 0);
310+
return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, 0, _RET_IP_);
307311
}
312+
#endif
308313

309314
/*
310315
* Spinlock based trylock, we take the spinlock and check whether we

0 commit comments

Comments
 (0)