diff options
author | Peter Zijlstra <peterz@infradead.org> | 2016-04-17 19:16:06 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2016-06-16 04:48:26 -0400 |
commit | e898eb27ffd8b0ad6f4fd0b631559bc877c85444 (patch) | |
tree | b9ee91a96640d1c139d43b3cb1cc8c226efcb938 /arch/metag | |
parent | e39d88ea3ce4a471cd0202f4f2c8f5ee0f8d7f53 (diff) |
locking/atomic, arch/metag: Implement atomic_fetch_{add,sub,and,or,xor}()
Implement FETCH-OP atomic primitives, these are very similar to the
existing OP-RETURN primitives we already have, except they return the
value of the atomic variable _before_ modification.
This is especially useful for irreversible operations -- such as
bitops (because it becomes impossible to reconstruct the state prior
to modification).
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: James Hogan <james.hogan@imgtec.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-arch@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-metag@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/metag')
-rw-r--r-- | arch/metag/include/asm/atomic.h | 2 | ||||
-rw-r--r-- | arch/metag/include/asm/atomic_lnkget.h | 36 | ||||
-rw-r--r-- | arch/metag/include/asm/atomic_lock1.h | 33 |
3 files changed, 63 insertions, 8 deletions
diff --git a/arch/metag/include/asm/atomic.h b/arch/metag/include/asm/atomic.h index 470e365f04ea..6ca210de8a7d 100644 --- a/arch/metag/include/asm/atomic.h +++ b/arch/metag/include/asm/atomic.h | |||
@@ -17,6 +17,8 @@ | |||
17 | #include <asm/atomic_lnkget.h> | 17 | #include <asm/atomic_lnkget.h> |
18 | #endif | 18 | #endif |
19 | 19 | ||
20 | #define atomic_fetch_or atomic_fetch_or | ||
21 | |||
20 | #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0) | 22 | #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0) |
21 | 23 | ||
22 | #define atomic_dec_return(v) atomic_sub_return(1, (v)) | 24 | #define atomic_dec_return(v) atomic_sub_return(1, (v)) |
diff --git a/arch/metag/include/asm/atomic_lnkget.h b/arch/metag/include/asm/atomic_lnkget.h index 88fa25fae8bd..def2c642f053 100644 --- a/arch/metag/include/asm/atomic_lnkget.h +++ b/arch/metag/include/asm/atomic_lnkget.h | |||
@@ -69,16 +69,44 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \ | |||
69 | return result; \ | 69 | return result; \ |
70 | } | 70 | } |
71 | 71 | ||
72 | #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op) | 72 | #define ATOMIC_FETCH_OP(op) \ |
73 | static inline int atomic_fetch_##op(int i, atomic_t *v) \ | ||
74 | { \ | ||
75 | int result, temp; \ | ||
76 | \ | ||
77 | smp_mb(); \ | ||
78 | \ | ||
79 | asm volatile ( \ | ||
80 | "1: LNKGETD %1, [%2]\n" \ | ||
81 | " " #op " %0, %1, %3\n" \ | ||
82 | " LNKSETD [%2], %0\n" \ | ||
83 | " DEFR %0, TXSTAT\n" \ | ||
84 | " ANDT %0, %0, #HI(0x3f000000)\n" \ | ||
85 | " CMPT %0, #HI(0x02000000)\n" \ | ||
86 | " BNZ 1b\n" \ | ||
87 | : "=&d" (temp), "=&d" (result) \ | ||
88 | : "da" (&v->counter), "bd" (i) \ | ||
89 | : "cc"); \ | ||
90 | \ | ||
91 | smp_mb(); \ | ||
92 | \ | ||
93 | return result; \ | ||
94 | } | ||
95 | |||
96 | #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op) ATOMIC_FETCH_OP(op) | ||
73 | 97 | ||
74 | ATOMIC_OPS(add) | 98 | ATOMIC_OPS(add) |
75 | ATOMIC_OPS(sub) | 99 | ATOMIC_OPS(sub) |
76 | 100 | ||
77 | ATOMIC_OP(and) | 101 | #undef ATOMIC_OPS |
78 | ATOMIC_OP(or) | 102 | #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_FETCH_OP(op) |
79 | ATOMIC_OP(xor) | 103 | |
104 | ATOMIC_OPS(and) | ||
105 | ATOMIC_OPS(or) | ||
106 | ATOMIC_OPS(xor) | ||
80 | 107 | ||
81 | #undef ATOMIC_OPS | 108 | #undef ATOMIC_OPS |
109 | #undef ATOMIC_FETCH_OP | ||
82 | #undef ATOMIC_OP_RETURN | 110 | #undef ATOMIC_OP_RETURN |
83 | #undef ATOMIC_OP | 111 | #undef ATOMIC_OP |
84 | 112 | ||
diff --git a/arch/metag/include/asm/atomic_lock1.h b/arch/metag/include/asm/atomic_lock1.h index 0295d9b8d5bf..6c1380a8a0d4 100644 --- a/arch/metag/include/asm/atomic_lock1.h +++ b/arch/metag/include/asm/atomic_lock1.h | |||
@@ -64,15 +64,40 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \ | |||
64 | return result; \ | 64 | return result; \ |
65 | } | 65 | } |
66 | 66 | ||
67 | #define ATOMIC_OPS(op, c_op) ATOMIC_OP(op, c_op) ATOMIC_OP_RETURN(op, c_op) | 67 | #define ATOMIC_FETCH_OP(op, c_op) \ |
68 | static inline int atomic_fetch_##op(int i, atomic_t *v) \ | ||
69 | { \ | ||
70 | unsigned long result; \ | ||
71 | unsigned long flags; \ | ||
72 | \ | ||
73 | __global_lock1(flags); \ | ||
74 | result = v->counter; \ | ||
75 | fence(); \ | ||
76 | v->counter c_op i; \ | ||
77 | __global_unlock1(flags); \ | ||
78 | \ | ||
79 | return result; \ | ||
80 | } | ||
81 | |||
82 | #define ATOMIC_OPS(op, c_op) \ | ||
83 | ATOMIC_OP(op, c_op) \ | ||
84 | ATOMIC_OP_RETURN(op, c_op) \ | ||
85 | ATOMIC_FETCH_OP(op, c_op) | ||
68 | 86 | ||
69 | ATOMIC_OPS(add, +=) | 87 | ATOMIC_OPS(add, +=) |
70 | ATOMIC_OPS(sub, -=) | 88 | ATOMIC_OPS(sub, -=) |
71 | ATOMIC_OP(and, &=) | ||
72 | ATOMIC_OP(or, |=) | ||
73 | ATOMIC_OP(xor, ^=) | ||
74 | 89 | ||
75 | #undef ATOMIC_OPS | 90 | #undef ATOMIC_OPS |
91 | #define ATOMIC_OPS(op, c_op) \ | ||
92 | ATOMIC_OP(op, c_op) \ | ||
93 | ATOMIC_FETCH_OP(op, c_op) | ||
94 | |||
95 | ATOMIC_OPS(and, &=) | ||
96 | ATOMIC_OPS(or, |=) | ||
97 | ATOMIC_OPS(xor, ^=) | ||
98 | |||
99 | #undef ATOMIC_OPS | ||
100 | #undef ATOMIC_FETCH_OP | ||
76 | #undef ATOMIC_OP_RETURN | 101 | #undef ATOMIC_OP_RETURN |
77 | #undef ATOMIC_OP | 102 | #undef ATOMIC_OP |
78 | 103 | ||