diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2008-12-29 16:32:35 -0500 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2008-12-29 16:32:35 -0500 |
commit | 33edcf133ba93ecba2e4b6472e97b689895d805c (patch) | |
tree | 327d7a20acef64005e7c5ccbfa1265be28aeb6ac /arch/sh/include/asm/mutex-llsc.h | |
parent | be4d638c1597580ed2294d899d9f1a2cd10e462c (diff) | |
parent | 3c92ec8ae91ecf59d88c798301833d7cf83f2179 (diff) |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'arch/sh/include/asm/mutex-llsc.h')
-rw-r--r-- | arch/sh/include/asm/mutex-llsc.h | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/arch/sh/include/asm/mutex-llsc.h b/arch/sh/include/asm/mutex-llsc.h new file mode 100644 index 000000000000..ee839ee58ac8 --- /dev/null +++ b/arch/sh/include/asm/mutex-llsc.h | |||
@@ -0,0 +1,112 @@ | |||
1 | /* | ||
2 | * arch/sh/include/asm/mutex-llsc.h | ||
3 | * | ||
4 | * SH-4A optimized mutex locking primitives | ||
5 | * | ||
6 | * Please look into asm-generic/mutex-xchg.h for a formal definition. | ||
7 | */ | ||
8 | #ifndef __ASM_SH_MUTEX_LLSC_H | ||
9 | #define __ASM_SH_MUTEX_LLSC_H | ||
10 | |||
11 | /* | ||
12 | * Attempting to lock a mutex on SH4A is done like in ARMv6+ architecure. | ||
13 | * with a bastardized atomic decrement (it is not a reliable atomic decrement | ||
14 | * but it satisfies the defined semantics for our purpose, while being | ||
15 | * smaller and faster than a real atomic decrement or atomic swap. | ||
16 | * The idea is to attempt decrementing the lock value only once. If once | ||
17 | * decremented it isn't zero, or if its store-back fails due to a dispute | ||
18 | * on the exclusive store, we simply bail out immediately through the slow | ||
19 | * path where the lock will be reattempted until it succeeds. | ||
20 | */ | ||
21 | static inline void | ||
22 | __mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *)) | ||
23 | { | ||
24 | int __ex_flag, __res; | ||
25 | |||
26 | __asm__ __volatile__ ( | ||
27 | "movli.l @%2, %0 \n" | ||
28 | "add #-1, %0 \n" | ||
29 | "movco.l %0, @%2 \n" | ||
30 | "movt %1 \n" | ||
31 | : "=&z" (__res), "=&r" (__ex_flag) | ||
32 | : "r" (&(count)->counter) | ||
33 | : "t"); | ||
34 | |||
35 | __res |= !__ex_flag; | ||
36 | if (unlikely(__res != 0)) | ||
37 | fail_fn(count); | ||
38 | } | ||
39 | |||
40 | static inline int | ||
41 | __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *)) | ||
42 | { | ||
43 | int __ex_flag, __res; | ||
44 | |||
45 | __asm__ __volatile__ ( | ||
46 | "movli.l @%2, %0 \n" | ||
47 | "add #-1, %0 \n" | ||
48 | "movco.l %0, @%2 \n" | ||
49 | "movt %1 \n" | ||
50 | : "=&z" (__res), "=&r" (__ex_flag) | ||
51 | : "r" (&(count)->counter) | ||
52 | : "t"); | ||
53 | |||
54 | __res |= !__ex_flag; | ||
55 | if (unlikely(__res != 0)) | ||
56 | __res = fail_fn(count); | ||
57 | |||
58 | return __res; | ||
59 | } | ||
60 | |||
61 | static inline void | ||
62 | __mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *)) | ||
63 | { | ||
64 | int __ex_flag, __res; | ||
65 | |||
66 | __asm__ __volatile__ ( | ||
67 | "movli.l @%2, %0 \n\t" | ||
68 | "add #1, %0 \n\t" | ||
69 | "movco.l %0, @%2 \n\t" | ||
70 | "movt %1 \n\t" | ||
71 | : "=&z" (__res), "=&r" (__ex_flag) | ||
72 | : "r" (&(count)->counter) | ||
73 | : "t"); | ||
74 | |||
75 | __res |= !__ex_flag; | ||
76 | if (unlikely(__res <= 0)) | ||
77 | fail_fn(count); | ||
78 | } | ||
79 | |||
80 | /* | ||
81 | * If the unlock was done on a contended lock, or if the unlock simply fails | ||
82 | * then the mutex remains locked. | ||
83 | */ | ||
84 | #define __mutex_slowpath_needs_to_unlock() 1 | ||
85 | |||
86 | /* | ||
87 | * For __mutex_fastpath_trylock we do an atomic decrement and check the | ||
88 | * result and put it in the __res variable. | ||
89 | */ | ||
90 | static inline int | ||
91 | __mutex_fastpath_trylock(atomic_t *count, int (*fail_fn)(atomic_t *)) | ||
92 | { | ||
93 | int __res, __orig; | ||
94 | |||
95 | __asm__ __volatile__ ( | ||
96 | "1: movli.l @%2, %0 \n\t" | ||
97 | "dt %0 \n\t" | ||
98 | "movco.l %0,@%2 \n\t" | ||
99 | "bf 1b \n\t" | ||
100 | "cmp/eq #0,%0 \n\t" | ||
101 | "bt 2f \n\t" | ||
102 | "mov #0, %1 \n\t" | ||
103 | "bf 3f \n\t" | ||
104 | "2: mov #1, %1 \n\t" | ||
105 | "3: " | ||
106 | : "=&z" (__orig), "=&r" (__res) | ||
107 | : "r" (&count->counter) | ||
108 | : "t"); | ||
109 | |||
110 | return __res; | ||
111 | } | ||
112 | #endif /* __ASM_SH_MUTEX_LLSC_H */ | ||