Skip to content

Commit b3c8064

Browse files
ericchancfpalmer-dabbelt
authored andcommitted
riscv/barrier: Define RISCV_FULL_BARRIER
Introduce RISCV_FULL_BARRIER and use in arch_atomic* function. like RISCV_ACQUIRE_BARRIER and RISCV_RELEASE_BARRIER, the fence instruction can be eliminated When SMP is not enabled. Signed-off-by: Eric Chan <ericchancf@google.com> Reviewed-by: Andrea Parri <parri.andrea@gmail.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com> Link: https://lore.kernel.org/r/20240217131302.3668481-1-ericchancf@google.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 89f4fd7 commit b3c8064

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

arch/riscv/include/asm/atomic.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static __always_inline int arch_atomic_fetch_add_unless(atomic_t *v, int a, int
207207
" add %[rc], %[p], %[a]\n"
208208
" sc.w.rl %[rc], %[rc], %[c]\n"
209209
" bnez %[rc], 0b\n"
210-
" fence rw, rw\n"
210+
RISCV_FULL_BARRIER
211211
"1:\n"
212212
: [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter)
213213
: [a]"r" (a), [u]"r" (u)
@@ -228,7 +228,7 @@ static __always_inline s64 arch_atomic64_fetch_add_unless(atomic64_t *v, s64 a,
228228
" add %[rc], %[p], %[a]\n"
229229
" sc.d.rl %[rc], %[rc], %[c]\n"
230230
" bnez %[rc], 0b\n"
231-
" fence rw, rw\n"
231+
RISCV_FULL_BARRIER
232232
"1:\n"
233233
: [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter)
234234
: [a]"r" (a), [u]"r" (u)
@@ -248,7 +248,7 @@ static __always_inline bool arch_atomic_inc_unless_negative(atomic_t *v)
248248
" addi %[rc], %[p], 1\n"
249249
" sc.w.rl %[rc], %[rc], %[c]\n"
250250
" bnez %[rc], 0b\n"
251-
" fence rw, rw\n"
251+
RISCV_FULL_BARRIER
252252
"1:\n"
253253
: [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter)
254254
:
@@ -268,7 +268,7 @@ static __always_inline bool arch_atomic_dec_unless_positive(atomic_t *v)
268268
" addi %[rc], %[p], -1\n"
269269
" sc.w.rl %[rc], %[rc], %[c]\n"
270270
" bnez %[rc], 0b\n"
271-
" fence rw, rw\n"
271+
RISCV_FULL_BARRIER
272272
"1:\n"
273273
: [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter)
274274
:
@@ -288,7 +288,7 @@ static __always_inline int arch_atomic_dec_if_positive(atomic_t *v)
288288
" bltz %[rc], 1f\n"
289289
" sc.w.rl %[rc], %[rc], %[c]\n"
290290
" bnez %[rc], 0b\n"
291-
" fence rw, rw\n"
291+
RISCV_FULL_BARRIER
292292
"1:\n"
293293
: [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter)
294294
:
@@ -310,7 +310,7 @@ static __always_inline bool arch_atomic64_inc_unless_negative(atomic64_t *v)
310310
" addi %[rc], %[p], 1\n"
311311
" sc.d.rl %[rc], %[rc], %[c]\n"
312312
" bnez %[rc], 0b\n"
313-
" fence rw, rw\n"
313+
RISCV_FULL_BARRIER
314314
"1:\n"
315315
: [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter)
316316
:
@@ -331,7 +331,7 @@ static __always_inline bool arch_atomic64_dec_unless_positive(atomic64_t *v)
331331
" addi %[rc], %[p], -1\n"
332332
" sc.d.rl %[rc], %[rc], %[c]\n"
333333
" bnez %[rc], 0b\n"
334-
" fence rw, rw\n"
334+
RISCV_FULL_BARRIER
335335
"1:\n"
336336
: [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter)
337337
:
@@ -352,7 +352,7 @@ static __always_inline s64 arch_atomic64_dec_if_positive(atomic64_t *v)
352352
" bltz %[rc], 1f\n"
353353
" sc.d.rl %[rc], %[rc], %[c]\n"
354354
" bnez %[rc], 0b\n"
355-
" fence rw, rw\n"
355+
RISCV_FULL_BARRIER
356356
"1:\n"
357357
: [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter)
358358
:

arch/riscv/include/asm/cmpxchg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@
313313
" bne %0, %z3, 1f\n" \
314314
" sc.w.rl %1, %z4, %2\n" \
315315
" bnez %1, 0b\n" \
316-
" fence rw, rw\n" \
316+
RISCV_FULL_BARRIER \
317317
"1:\n" \
318318
: "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \
319319
: "rJ" ((long)__old), "rJ" (__new) \
@@ -325,7 +325,7 @@
325325
" bne %0, %z3, 1f\n" \
326326
" sc.d.rl %1, %z4, %2\n" \
327327
" bnez %1, 0b\n" \
328-
" fence rw, rw\n" \
328+
RISCV_FULL_BARRIER \
329329
"1:\n" \
330330
: "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \
331331
: "rJ" (__old), "rJ" (__new) \

arch/riscv/include/asm/fence.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
#ifdef CONFIG_SMP
55
#define RISCV_ACQUIRE_BARRIER "\tfence r , rw\n"
66
#define RISCV_RELEASE_BARRIER "\tfence rw, w\n"
7+
#define RISCV_FULL_BARRIER "\tfence rw, rw\n"
78
#else
89
#define RISCV_ACQUIRE_BARRIER
910
#define RISCV_RELEASE_BARRIER
11+
#define RISCV_FULL_BARRIER
1012
#endif
1113

1214
#endif /* _ASM_RISCV_FENCE_H */

0 commit comments

Comments
 (0)