Skip to content

Commit f252ffd

Browse files
David Daneyralfbaechle
authored andcommitted
MIPS: New macro smp_mb__before_llsc.
Replace some instances of smp_llsc_mb() with a new macro smp_mb__before_llsc(). It is used before ll/sc sequences that are documented as needing write barrier semantics. The default implementation of smp_mb__before_llsc() is just smp_llsc_mb(), so there are no changes in semantics. Also simplify definition of smp_mb(), smp_rmb(), and smp_wmb() to be just barrier() in the non-SMP case. Signed-off-by: David Daney <ddaney@caviumnetworks.com> To: linux-mips@linux-mips.org Patchwork: http://patchwork.linux-mips.org/patch/851/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent ec5380c commit f252ffd

6 files changed

Lines changed: 32 additions & 25 deletions

File tree

‎arch/mips/include/asm/atomic.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
137137
{
138138
int result;
139139

140-
smp_llsc_mb();
140+
smp_mb__before_llsc();
141141

142142
if (kernel_uses_llsc && R10000_LLSC_WAR) {
143143
int temp;
@@ -189,7 +189,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
189189
{
190190
int result;
191191

192-
smp_llsc_mb();
192+
smp_mb__before_llsc();
193193

194194
if (kernel_uses_llsc && R10000_LLSC_WAR) {
195195
int temp;
@@ -249,7 +249,7 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
249249
{
250250
int result;
251251

252-
smp_llsc_mb();
252+
smp_mb__before_llsc();
253253

254254
if (kernel_uses_llsc && R10000_LLSC_WAR) {
255255
int temp;
@@ -516,7 +516,7 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
516516
{
517517
long result;
518518

519-
smp_llsc_mb();
519+
smp_mb__before_llsc();
520520

521521
if (kernel_uses_llsc && R10000_LLSC_WAR) {
522522
long temp;
@@ -568,7 +568,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
568568
{
569569
long result;
570570

571-
smp_llsc_mb();
571+
smp_mb__before_llsc();
572572

573573
if (kernel_uses_llsc && R10000_LLSC_WAR) {
574574
long temp;
@@ -628,7 +628,7 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
628628
{
629629
long result;
630630

631-
smp_llsc_mb();
631+
smp_mb__before_llsc();
632632

633633
if (kernel_uses_llsc && R10000_LLSC_WAR) {
634634
long temp;
@@ -788,9 +788,9 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
788788
* atomic*_return operations are serializing but not the non-*_return
789789
* versions.
790790
*/
791-
#define smp_mb__before_atomic_dec() smp_llsc_mb()
791+
#define smp_mb__before_atomic_dec() smp_mb__before_llsc()
792792
#define smp_mb__after_atomic_dec() smp_llsc_mb()
793-
#define smp_mb__before_atomic_inc() smp_llsc_mb()
793+
#define smp_mb__before_atomic_inc() smp_mb__before_llsc()
794794
#define smp_mb__after_atomic_inc() smp_llsc_mb()
795795

796796
#include <asm-generic/atomic-long.h>

‎arch/mips/include/asm/barrier.h‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,26 @@
131131
#endif /* !CONFIG_CPU_HAS_WB */
132132

133133
#if defined(CONFIG_WEAK_ORDERING) && defined(CONFIG_SMP)
134-
#define __WEAK_ORDERING_MB " sync \n"
134+
#define smp_mb() __asm__ __volatile__("sync" : : :"memory")
135+
#define smp_rmb() __asm__ __volatile__("sync" : : :"memory")
136+
#define smp_wmb() __asm__ __volatile__("sync" : : :"memory")
135137
#else
136-
#define __WEAK_ORDERING_MB " \n"
138+
#define smp_mb() barrier()
139+
#define smp_rmb() barrier()
140+
#define smp_wmb() barrier()
137141
#endif
142+
138143
#if defined(CONFIG_WEAK_REORDERING_BEYOND_LLSC) && defined(CONFIG_SMP)
139144
#define __WEAK_LLSC_MB " sync \n"
140145
#else
141146
#define __WEAK_LLSC_MB " \n"
142147
#endif
143148

144-
#define smp_mb() __asm__ __volatile__(__WEAK_ORDERING_MB : : :"memory")
145-
#define smp_rmb() __asm__ __volatile__(__WEAK_ORDERING_MB : : :"memory")
146-
#define smp_wmb() __asm__ __volatile__(__WEAK_ORDERING_MB : : :"memory")
147-
148149
#define set_mb(var, value) \
149150
do { var = value; smp_mb(); } while (0)
150151

151152
#define smp_llsc_mb() __asm__ __volatile__(__WEAK_LLSC_MB : : :"memory")
152153

154+
#define smp_mb__before_llsc() smp_llsc_mb()
155+
153156
#endif /* __ASM_BARRIER_H */

‎arch/mips/include/asm/bitops.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
/*
4343
* clear_bit() doesn't provide any barrier for the compiler.
4444
*/
45-
#define smp_mb__before_clear_bit() smp_llsc_mb()
45+
#define smp_mb__before_clear_bit() smp_mb__before_llsc()
4646
#define smp_mb__after_clear_bit() smp_llsc_mb()
4747

4848
/*
@@ -258,7 +258,7 @@ static inline int test_and_set_bit(unsigned long nr,
258258
unsigned short bit = nr & SZLONG_MASK;
259259
unsigned long res;
260260

261-
smp_llsc_mb();
261+
smp_mb__before_llsc();
262262

263263
if (kernel_uses_llsc && R10000_LLSC_WAR) {
264264
unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
@@ -395,7 +395,7 @@ static inline int test_and_clear_bit(unsigned long nr,
395395
unsigned short bit = nr & SZLONG_MASK;
396396
unsigned long res;
397397

398-
smp_llsc_mb();
398+
smp_mb__before_llsc();
399399

400400
if (kernel_uses_llsc && R10000_LLSC_WAR) {
401401
unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);
@@ -485,7 +485,7 @@ static inline int test_and_change_bit(unsigned long nr,
485485
unsigned short bit = nr & SZLONG_MASK;
486486
unsigned long res;
487487

488-
smp_llsc_mb();
488+
smp_mb__before_llsc();
489489

490490
if (kernel_uses_llsc && R10000_LLSC_WAR) {
491491
unsigned long *m = ((unsigned long *) addr) + (nr >> SZLONG_LOG);

‎arch/mips/include/asm/cmpxchg.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@
7272
*/
7373
extern void __cmpxchg_called_with_bad_pointer(void);
7474

75-
#define __cmpxchg(ptr, old, new, barrier) \
75+
#define __cmpxchg(ptr, old, new, pre_barrier, post_barrier) \
7676
({ \
7777
__typeof__(ptr) __ptr = (ptr); \
7878
__typeof__(*(ptr)) __old = (old); \
7979
__typeof__(*(ptr)) __new = (new); \
8080
__typeof__(*(ptr)) __res = 0; \
8181
\
82-
barrier; \
82+
pre_barrier; \
8383
\
8484
switch (sizeof(*(__ptr))) { \
8585
case 4: \
@@ -96,13 +96,13 @@ extern void __cmpxchg_called_with_bad_pointer(void);
9696
break; \
9797
} \
9898
\
99-
barrier; \
99+
post_barrier; \
100100
\
101101
__res; \
102102
})
103103

104-
#define cmpxchg(ptr, old, new) __cmpxchg(ptr, old, new, smp_llsc_mb())
105-
#define cmpxchg_local(ptr, old, new) __cmpxchg(ptr, old, new, )
104+
#define cmpxchg(ptr, old, new) __cmpxchg(ptr, old, new, smp_mb__before_llsc(), smp_llsc_mb())
105+
#define cmpxchg_local(ptr, old, new) __cmpxchg(ptr, old, new, , )
106106

107107
#define cmpxchg64(ptr, o, n) \
108108
({ \

‎arch/mips/include/asm/spinlock.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static inline void arch_spin_unlock(arch_spinlock_t *lock)
138138
{
139139
int tmp;
140140

141-
smp_llsc_mb();
141+
smp_mb__before_llsc();
142142

143143
if (R10000_LLSC_WAR) {
144144
__asm__ __volatile__ (
@@ -305,7 +305,7 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
305305
{
306306
unsigned int tmp;
307307

308-
smp_llsc_mb();
308+
smp_mb__before_llsc();
309309

310310
if (R10000_LLSC_WAR) {
311311
__asm__ __volatile__(

‎arch/mips/include/asm/system.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ static inline unsigned long __xchg_u32(volatile int * m, unsigned int val)
9595
{
9696
__u32 retval;
9797

98+
smp_mb__before_llsc();
99+
98100
if (kernel_uses_llsc && R10000_LLSC_WAR) {
99101
unsigned long dummy;
100102

@@ -147,6 +149,8 @@ static inline __u64 __xchg_u64(volatile __u64 * m, __u64 val)
147149
{
148150
__u64 retval;
149151

152+
smp_mb__before_llsc();
153+
150154
if (kernel_uses_llsc && R10000_LLSC_WAR) {
151155
unsigned long dummy;
152156

0 commit comments

Comments
 (0)