Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 120069
b: refs/heads/master
c: 0c91223
h: refs/heads/master
i:
  120067: 09ca237
v: v3
  • Loading branch information
Michael Trimarchi authored and Paul Mundt committed Dec 22, 2008
1 parent f16a724 commit 8dbda67
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 5c72f303a2b7862dbba79f4176ddc922a440b567
refs/heads/master: 0c9122323acb0c3410dfbd219cb47f4c2e9305e3
107 changes: 107 additions & 0 deletions trunk/arch/sh/include/asm/mutex-llsc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* arch/sh/include/asm/mutex-llsc.h
*
* SH-4A optimized mutex locking primitives
*
* Please look into asm-generic/mutex-xchg.h for a formal definition.
*/
#ifndef __ASM_SH_MUTEX_LLSC_H
#define __ASM_SH_MUTEX_LLSC_H

/*
* Attempting to lock a mutex on SH4A is done like in ARMv6+ architecure.
* with a bastardized atomic decrement (it is not a reliable atomic decrement
* but it satisfies the defined semantics for our purpose, while being
* smaller and faster than a real atomic decrement or atomic swap.
* The idea is to attempt decrementing the lock value only once. If once
* decremented it isn't zero, or if its store-back fails due to a dispute
* on the exclusive store, we simply bail out immediately through the slow
* path where the lock will be reattempted until it succeeds.
*/
static inline void
__mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
{
int __res;

__asm__ __volatile__ (
"movli.l @%1, %0 \n"
"dt %0 \n"
"movco.l %0, @%1 \n"
: "=&z" (__res)
: "r" (&(count)->counter)
: "t");

if (unlikely(__res != 0))
fail_fn(count);
}

static inline int
__mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))
{
int __res;

__asm__ __volatile__ (
"movli.l @%1, %0 \n"
"dt %0 \n"
"movco.l %0, @%1 \n"
: "=&z" (__res)
: "r" (&(count)->counter)
: "t");

if (unlikely(__res != 0))
__res = fail_fn(count);

return __res;
}

static inline void
__mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *))
{
int __res;

__asm__ __volatile__ (
"1: movli.l @%1, %0 \n\t"
"add #1, %0 \n\t"
"movco.l %0, @%1 \n\t"
"bf 1b\n\t"
: "=&z" (__res)
: "r" (&(count)->counter)
: "t");

if (unlikely(__res <= 0))
fail_fn(count);
}

/*
* If the unlock was done on a contended lock, or if the unlock simply fails
* then the mutex remains locked.
*/
#define __mutex_slowpath_needs_to_unlock() 1

/*
* For __mutex_fastpath_trylock we do an atomic decrement and check the
* result and put it in the __res variable.
*/
static inline int
__mutex_fastpath_trylock(atomic_t *count, int (*fail_fn)(atomic_t *))
{
int __res, __orig;

__asm__ __volatile__ (
"1: movli.l @%2, %0 \n\t"
"dt %0 \n\t"
"movco.l %0,@%2 \n\t"
"bf 1b \n\t"
"cmp/eq #0,%0 \n\t"
"bt 2f \n\t"
"mov #0, %1 \n\t"
"bf 3f \n\t"
"2: mov #1, %1 \n\t"
"3: "
: "=&z" (__orig), "=&r" (__res)
: "r" (&count->counter)
: "t");

return __res;
}
#endif /* __ASM_SH_MUTEX_LLSC_H */
5 changes: 4 additions & 1 deletion trunk/arch/sh/include/asm/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
* implementation in place, or pick the atomic_xchg() based generic
* implementation. (see asm-generic/mutex-xchg.h for details)
*/

#if defined(CONFIG_CPU_SH4A)
#include <asm/mutex-llsc.h>
#else
#include <asm-generic/mutex-dec.h>
#endif

0 comments on commit 8dbda67

Please sign in to comment.