Skip to content

Commit a41b56e

Browse files
Maarten Lankhorstingomolnar
authored andcommitted
arch: Make __mutex_fastpath_lock_retval return whether fastpath succeeded or not
This will allow me to call functions that have multiple arguments if fastpath fails. This is required to support ticket mutexes, because they need to be able to pass an extra argument to the fail function. Originally I duplicated the functions, by adding __mutex_fastpath_lock_retval_arg. This ended up being just a duplication of the existing function, so a way to test if fastpath was called ended up being better. This also cleaned up the reservation mutex patch some by being able to call an atomic_set instead of atomic_xchg, and making it easier to detect if the wrong unlock function was previously used. Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: dri-devel@lists.freedesktop.org Cc: linaro-mm-sig@lists.linaro.org Cc: robclark@gmail.com Cc: rostedt@goodmis.org Cc: daniel@ffwll.ch Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/20130620113105.4001.83929.stgit@patser Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 1e876e3 commit a41b56e

9 files changed

Lines changed: 41 additions & 59 deletions

File tree

‎arch/ia64/include/asm/mutex.h‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,15 @@ __mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
2929
* __mutex_fastpath_lock_retval - try to take the lock by moving the count
3030
* from 1 to a 0 value
3131
* @count: pointer of type atomic_t
32-
* @fail_fn: function to call if the original value was not 1
3332
*
34-
* Change the count from 1 to a value lower than 1, and call <fail_fn> if
35-
* it wasn't 1 originally. This function returns 0 if the fastpath succeeds,
36-
* or anything the slow path function returns.
33+
* Change the count from 1 to a value lower than 1. This function returns 0
34+
* if the fastpath succeeds, or -1 otherwise.
3735
*/
3836
static inline int
39-
__mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))
37+
__mutex_fastpath_lock_retval(atomic_t *count)
4038
{
4139
if (unlikely(ia64_fetchadd4_acq(count, -1) != 1))
42-
return fail_fn(count);
40+
return -1;
4341
return 0;
4442
}
4543

‎arch/powerpc/include/asm/mutex.h‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,15 @@ __mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
8282
* __mutex_fastpath_lock_retval - try to take the lock by moving the count
8383
* from 1 to a 0 value
8484
* @count: pointer of type atomic_t
85-
* @fail_fn: function to call if the original value was not 1
8685
*
87-
* Change the count from 1 to a value lower than 1, and call <fail_fn> if
88-
* it wasn't 1 originally. This function returns 0 if the fastpath succeeds,
89-
* or anything the slow path function returns.
86+
* Change the count from 1 to a value lower than 1. This function returns 0
87+
* if the fastpath succeeds, or -1 otherwise.
9088
*/
9189
static inline int
92-
__mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))
90+
__mutex_fastpath_lock_retval(atomic_t *count)
9391
{
9492
if (unlikely(__mutex_dec_return_lock(count) < 0))
95-
return fail_fn(count);
93+
return -1;
9694
return 0;
9795
}
9896

‎arch/sh/include/asm/mutex-llsc.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ __mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
3737
}
3838

3939
static inline int
40-
__mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))
40+
__mutex_fastpath_lock_retval(atomic_t *count)
4141
{
4242
int __done, __res;
4343

@@ -51,7 +51,7 @@ __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))
5151
: "t");
5252

5353
if (unlikely(!__done || __res != 0))
54-
__res = fail_fn(count);
54+
__res = -1;
5555

5656
return __res;
5757
}

‎arch/x86/include/asm/mutex_32.h‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,14 @@ do { \
4242
* __mutex_fastpath_lock_retval - try to take the lock by moving the count
4343
* from 1 to a 0 value
4444
* @count: pointer of type atomic_t
45-
* @fail_fn: function to call if the original value was not 1
4645
*
47-
* Change the count from 1 to a value lower than 1, and call <fail_fn> if it
48-
* wasn't 1 originally. This function returns 0 if the fastpath succeeds,
49-
* or anything the slow path function returns
46+
* Change the count from 1 to a value lower than 1. This function returns 0
47+
* if the fastpath succeeds, or -1 otherwise.
5048
*/
51-
static inline int __mutex_fastpath_lock_retval(atomic_t *count,
52-
int (*fail_fn)(atomic_t *))
49+
static inline int __mutex_fastpath_lock_retval(atomic_t *count)
5350
{
5451
if (unlikely(atomic_dec_return(count) < 0))
55-
return fail_fn(count);
52+
return -1;
5653
else
5754
return 0;
5855
}

‎arch/x86/include/asm/mutex_64.h‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,14 @@ do { \
3737
* __mutex_fastpath_lock_retval - try to take the lock by moving the count
3838
* from 1 to a 0 value
3939
* @count: pointer of type atomic_t
40-
* @fail_fn: function to call if the original value was not 1
4140
*
42-
* Change the count from 1 to a value lower than 1, and call <fail_fn> if
43-
* it wasn't 1 originally. This function returns 0 if the fastpath succeeds,
44-
* or anything the slow path function returns
41+
* Change the count from 1 to a value lower than 1. This function returns 0
42+
* if the fastpath succeeds, or -1 otherwise.
4543
*/
46-
static inline int __mutex_fastpath_lock_retval(atomic_t *count,
47-
int (*fail_fn)(atomic_t *))
44+
static inline int __mutex_fastpath_lock_retval(atomic_t *count)
4845
{
4946
if (unlikely(atomic_dec_return(count) < 0))
50-
return fail_fn(count);
47+
return -1;
5148
else
5249
return 0;
5350
}

‎include/asm-generic/mutex-dec.h‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,15 @@ __mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
2828
* __mutex_fastpath_lock_retval - try to take the lock by moving the count
2929
* from 1 to a 0 value
3030
* @count: pointer of type atomic_t
31-
* @fail_fn: function to call if the original value was not 1
3231
*
33-
* Change the count from 1 to a value lower than 1, and call <fail_fn> if
34-
* it wasn't 1 originally. This function returns 0 if the fastpath succeeds,
35-
* or anything the slow path function returns.
32+
* Change the count from 1 to a value lower than 1. This function returns 0
33+
* if the fastpath succeeds, or -1 otherwise.
3634
*/
3735
static inline int
38-
__mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))
36+
__mutex_fastpath_lock_retval(atomic_t *count)
3937
{
4038
if (unlikely(atomic_dec_return(count) < 0))
41-
return fail_fn(count);
39+
return -1;
4240
return 0;
4341
}
4442

‎include/asm-generic/mutex-null.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define _ASM_GENERIC_MUTEX_NULL_H
1212

1313
#define __mutex_fastpath_lock(count, fail_fn) fail_fn(count)
14-
#define __mutex_fastpath_lock_retval(count, fail_fn) fail_fn(count)
14+
#define __mutex_fastpath_lock_retval(count) (-1)
1515
#define __mutex_fastpath_unlock(count, fail_fn) fail_fn(count)
1616
#define __mutex_fastpath_trylock(count, fail_fn) fail_fn(count)
1717
#define __mutex_slowpath_needs_to_unlock() 1

‎include/asm-generic/mutex-xchg.h‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,16 @@ __mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
3939
* __mutex_fastpath_lock_retval - try to take the lock by moving the count
4040
* from 1 to a 0 value
4141
* @count: pointer of type atomic_t
42-
* @fail_fn: function to call if the original value was not 1
4342
*
44-
* Change the count from 1 to a value lower than 1, and call <fail_fn> if it
45-
* wasn't 1 originally. This function returns 0 if the fastpath succeeds,
46-
* or anything the slow path function returns
43+
* Change the count from 1 to a value lower than 1. This function returns 0
44+
* if the fastpath succeeds, or -1 otherwise.
4745
*/
4846
static inline int
49-
__mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))
47+
__mutex_fastpath_lock_retval(atomic_t *count)
5048
{
5149
if (unlikely(atomic_xchg(count, 0) != 1))
5250
if (likely(atomic_xchg(count, -1) != 1))
53-
return fail_fn(count);
51+
return -1;
5452
return 0;
5553
}
5654

‎kernel/mutex.c‎

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,10 @@ __mutex_unlock_slowpath(atomic_t *lock_count)
494494
* mutex_lock_interruptible() and mutex_trylock().
495495
*/
496496
static noinline int __sched
497-
__mutex_lock_killable_slowpath(atomic_t *lock_count);
497+
__mutex_lock_killable_slowpath(struct mutex *lock);
498498

499499
static noinline int __sched
500-
__mutex_lock_interruptible_slowpath(atomic_t *lock_count);
500+
__mutex_lock_interruptible_slowpath(struct mutex *lock);
501501

502502
/**
503503
* mutex_lock_interruptible - acquire the mutex, interruptible
@@ -515,12 +515,12 @@ int __sched mutex_lock_interruptible(struct mutex *lock)
515515
int ret;
516516

517517
might_sleep();
518-
ret = __mutex_fastpath_lock_retval
519-
(&lock->count, __mutex_lock_interruptible_slowpath);
520-
if (!ret)
518+
ret = __mutex_fastpath_lock_retval(&lock->count);
519+
if (likely(!ret)) {
521520
mutex_set_owner(lock);
522-
523-
return ret;
521+
return 0;
522+
} else
523+
return __mutex_lock_interruptible_slowpath(lock);
524524
}
525525

526526
EXPORT_SYMBOL(mutex_lock_interruptible);
@@ -530,12 +530,12 @@ int __sched mutex_lock_killable(struct mutex *lock)
530530
int ret;
531531

532532
might_sleep();
533-
ret = __mutex_fastpath_lock_retval
534-
(&lock->count, __mutex_lock_killable_slowpath);
535-
if (!ret)
533+
ret = __mutex_fastpath_lock_retval(&lock->count);
534+
if (likely(!ret)) {
536535
mutex_set_owner(lock);
537-
538-
return ret;
536+
return 0;
537+
} else
538+
return __mutex_lock_killable_slowpath(lock);
539539
}
540540
EXPORT_SYMBOL(mutex_lock_killable);
541541

@@ -548,18 +548,14 @@ __mutex_lock_slowpath(atomic_t *lock_count)
548548
}
549549

550550
static noinline int __sched
551-
__mutex_lock_killable_slowpath(atomic_t *lock_count)
551+
__mutex_lock_killable_slowpath(struct mutex *lock)
552552
{
553-
struct mutex *lock = container_of(lock_count, struct mutex, count);
554-
555553
return __mutex_lock_common(lock, TASK_KILLABLE, 0, NULL, _RET_IP_);
556554
}
557555

558556
static noinline int __sched
559-
__mutex_lock_interruptible_slowpath(atomic_t *lock_count)
557+
__mutex_lock_interruptible_slowpath(struct mutex *lock)
560558
{
561-
struct mutex *lock = container_of(lock_count, struct mutex, count);
562-
563559
return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, 0, NULL, _RET_IP_);
564560
}
565561
#endif

0 commit comments

Comments
 (0)