arch/generic/sh/x86/powerpc/ia64: add __mutex_fastpath_lock_retval_arg
Subsystems (4)
RFC PATCH 1/2 arch/generic/sh/x86/powerpc/ia64: add __mutex_fastpath_lock_retval_arg
I was hoping to convert the 'mutexes' in ttm to proper mutexes, so I extended the core mutex code slightly to add support for reservations. This requires however passing an argument to __mutex_fastpath_lock_retval, so I added this for all archs based on their existing __mutex_fastpath_lock_retval implementation.
I'm guessing this has to be split up, but I figured most of the flames would be about patch 2 anyhow..
Signed-off-by Maarten Lankhorst <[email protected]>
---
arch/ia64/include/asm/mutex.h +20 -0
@@ -44,6 +44,26 @@ __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *)) }/** +* __mutex_fastpath_lock_retval_arg - try to take the lock by moving the count +* from 1 to a 0 value +* @count: pointer of type atomic_t +* @arg: argument to pass along if fastpath fails. +* @fail_fn: function to call if the original value was not 1 +* +* Change the count from 1 to a value lower than 1, and call <fail_fn> if +* it wasn't 1 originally. This function returns 0 if the fastpath succeeds, +* or anything the slow path function returns. +*/ +static inline int __mutex_fastpath_lock_retval_arg (atomic_t *count, +void *arg,int (*fail_fn)(atomic_t *,void *)) +{ +if (unlikely (ia64_fetchadd4_acq (count,-1 ) !=1 )) +return fail_fn (count, arg); +else +return 0 ; +} + +/** * __mutex_fastpath_unlock - try to promote the count from 0 to 1 * @count: pointer of type atomic_t * @fail_fn: function to call if the original value was not 0
arch/powerpc/include/asm/mutex.h +20 -0
@@ -97,6 +97,26 @@ __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *)) }/** +* __mutex_fastpath_lock_retval_arg - try to take the lock by moving the count +* from 1 to a 0 value +* @count: pointer of type atomic_t +* @arg: argument to pass along if fastpath fails. +* @fail_fn: function to call if the original value was not 1 +* +* Change the count from 1 to a value lower than 1, and call <fail_fn> if +* it wasn't 1 originally. This function returns 0 if the fastpath succeeds, +* or anything the slow path function returns. +*/ +static inline int __mutex_fastpath_lock_retval_arg (atomic_t *count, +void *arg,int (*fail_fn)(atomic_t *,void *)) +{ +if (unlikely (__mutex_dec_return_lock (count) <0 )) +return fail_fn (count, arg); +else +return 0 ; +} + +/** * __mutex_fastpath_unlock - try to promote the count from 0 to 1 * @count: pointer of type atomic_t * @fail_fn: function to call if the original value was not 0
arch/sh/include/asm/mutex-llsc.h +20 -0
@@ -56,6 +56,26 @@ __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))return __res; } +static inline int __mutex_fastpath_lock_retval_arg (atomic_t *count, +void *arg,int (*fail_fn)(atomic_t *,void *)) +{ +int __done, __res; + + __asm__ __volatile__ ( +"movli.l @%2, %0 \n" +"add #-1, %0 \n" +"movco.l %0, @%2 \n" +"movt %1 \n" + :"=&z" (__res),"=&r" (__done) + :"r" (&(count)->counter) + :"t" ); + +if (unlikely (!__done || __res !=0 )) + __res =fail_fn (count, arg); + +return __res; +} +static inline void __mutex_fastpath_unlock (atomic_t *count,void (*fail_fn)(atomic_t *)) {
arch/x86/include/asm/mutex_32.h +20 -0
@@ -58,6 +58,26 @@ static inline int __mutex_fastpath_lock_retval(atomic_t *count, }/** +* __mutex_fastpath_lock_retval_arg - try to take the lock by moving the count +* from 1 to a 0 value +* @count: pointer of type atomic_t +* @arg: argument to pass along if fastpath fails. +* @fail_fn: function to call if the original value was not 1 +* +* Change the count from 1 to a value lower than 1, and call <fail_fn> if +* it wasn't 1 originally. This function returns 0 if the fastpath succeeds, +* or anything the slow path function returns. +*/ +static inline int __mutex_fastpath_lock_retval_arg (atomic_t *count, +void *arg,int (*fail_fn)(atomic_t *,void *)) +{ +if (unlikely (atomic_dec_return (count) <0 )) +return fail_fn (count, arg); +else +return 0 ; +} + +/** * __mutex_fastpath_unlock - try to promote the mutex from 0 to 1 * @count: pointer of type atomic_t * @fail_fn: function to call if the original value was not 0
arch/x86/include/asm/mutex_64.h +20 -0
@@ -53,6 +53,26 @@ static inline int __mutex_fastpath_lock_retval(atomic_t *count, }/** +* __mutex_fastpath_lock_retval_arg - try to take the lock by moving the count +* from 1 to a 0 value +* @count: pointer of type atomic_t +* @arg: argument to pass along if fastpath fails. +* @fail_fn: function to call if the original value was not 1 +* +* Change the count from 1 to a value lower than 1, and call <fail_fn> if +* it wasn't 1 originally. This function returns 0 if the fastpath succeeds, +* or anything the slow path function returns. +*/ +static inline int __mutex_fastpath_lock_retval_arg (atomic_t *count, +void *arg,int (*fail_fn)(atomic_t *,void *)) +{ +if (unlikely (atomic_dec_return (count) <0 )) +return fail_fn (count, arg); +else +return 0 ; +} + +/** * __mutex_fastpath_unlock - increment and call function if nonpositive * @v: pointer of type atomic_t * @fail_fn: function to call if the result is nonpositive
include/asm-generic/mutex-dec.h +20 -0
@@ -43,6 +43,26 @@ __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *)) }/** +* __mutex_fastpath_lock_retval_arg - try to take the lock by moving the count +* from 1 to a 0 value +* @count: pointer of type atomic_t +* @arg: argument to pass along if fastpath fails. +* @fail_fn: function to call if the original value was not 1 +* +* Change the count from 1 to a value lower than 1, and call <fail_fn> if +* it wasn't 1 originally. This function returns 0 if the fastpath succeeds, +* or anything the slow path function returns. +*/ +static inline int +__mutex_fastpath_lock_retval_arg (atomic_t *count,void *arg, +int (*fail_fn)(atomic_t *,void *)) +{ +if (unlikely (atomic_dec_return (count) <0 )) +return fail_fn (count, arg); +return 0 ; +} + +/** * __mutex_fastpath_unlock - try to promote the count from 0 to 1 * @count: pointer of type atomic_t * @fail_fn: function to call if the original value was not 0
include/asm-generic/mutex-null.h +1 -0
@@ -12,6 +12,7 @@#define __mutex_fastpath_lock (count, fail_fn) fail_fn(count)#define __mutex_fastpath_lock_retval (count, fail_fn) fail_fn(count) +#define __mutex_fastpath_lock_retval_arg (count, arg, fail_fn) fail_fn(count, arg)#define __mutex_fastpath_unlock (count, fail_fn) fail_fn(count)#define __mutex_fastpath_trylock (count, fail_fn) fail_fn(count)#define __mutex_slowpath_needs_to_unlock () 1
include/asm-generic/mutex-xchg.h +21 -0
@@ -55,6 +55,27 @@ __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *)) }/** +* __mutex_fastpath_lock_retval_arg - try to take the lock by moving the count +* from 1 to a 0 value +* @count: pointer of type atomic_t +* @arg: argument to pass along if fastpath fails. +* @fail_fn: function to call if the original value was not 1 +* +* Change the count from 1 to a value lower than 1, and call <fail_fn> if +* it wasn't 1 originally. This function returns 0 if the fastpath succeeds, +* or anything the slow path function returns. +*/ +static inline int +__mutex_fastpath_lock_retval_arg (atomic_t *count,void *arg, +int (*fail_fn)(atomic_t *,void *)) +{ +if (unlikely (atomic_xchg (count,0 ) !=1 )) +if (likely (atomic_xchg (count,-1 ) !=1 )) +return fail_fn (count, arg); +return 0 ; +} + +/** * __mutex_fastpath_unlock - try to promote the mutex from 0 to 1 * @count: pointer of type atomic_t * @fail_fn: function to call if the original value was not 0