Skip to content

Commit

Permalink
sh: Fix up the SH-4A mutex fastpath semantics.
Browse files Browse the repository at this point in the history
This fixes up the __mutex_fastpath_xxx() routines to match the semantics
noted in the comment. Previously these were looping rather than doing a
single-pass, which is counter-intuitive, as the slow path takes care of
the looping for us in the event of contention.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
  • Loading branch information
Paul Mundt committed Dec 22, 2008
1 parent c6f17cb commit 77ba93a
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions arch/sh/include/asm/mutex-llsc.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,37 @@
static inline void
__mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
{
int __res;
int __ex_flag, __res;

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

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

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

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

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

Expand All @@ -57,18 +61,19 @@ __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))
static inline void
__mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *))
{
int __res;
int __ex_flag, __res;

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

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

Expand Down

0 comments on commit 77ba93a

Please sign in to comment.