riscv: Implement smp_cond_load8/16() with Zawrs
PATCH 1/1 riscv: Implement smp_cond_load8/16() with Zawrs
From: Guo Ren <[email protected]>
RISC-V code uses the queued spinlock implementation, which calls the macros smp_cond_load_acquire for one byte. So, complement the implementation of byte and halfword versions.
--- arch/riscv/include/asm/cmpxchg.h | 38 +++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-)
arch/riscv/include/asm/cmpxchg.h +35 -3
@@ -365,16 +365,48 @@ static __always_inline void __cmpwait(volatile void *ptr, {unsigned long tmp; +u32 *__ptr32b; +ulong __s, __val, __mask; + asm goto(ALTERNATIVE("j %l[no_zawrs]", "nop", 0, RISCV_ISA_EXT_ZAWRS, 1) : : : : no_zawrs);switch (size) {case 1 : - fallthrough; + __ptr32b = (u32 *)((ulong)(ptr) & ~0x3 ); + __s = ((ulong)(ptr) &0x3 ) *BITS_PER_BYTE ; + __val = val << __s; + __mask =0xf << __s; + + asmvolatile ( +" lr.w %0, %1\n" +" and %0, %0, %3\n" +" xor %0, %0, %2\n" +" bnez %0, 1f\n" +ZAWRS_WRS_NTO "\n" +"1:" + :"=&r" (tmp),"+A" (*(__ptr32b)) + :"r" (__val),"r" (__mask) + :"memory" ); +break ;case 2 : -/* RISC-V doesn't have lr instructions on byte and half-word. */ - goto no_zawrs; + __ptr32b = (u32 *)((ulong)(ptr) & ~0x3 ); + __s = ((ulong)(ptr) &0x2 ) *BITS_PER_BYTE ; + __val = val << __s; + __mask =0xff << __s; + + asmvolatile ( +" lr.w %0, %1\n" +" and %0, %0, %3\n" +" xor %0, %0, %2\n" +" bnez %0, 1f\n" +ZAWRS_WRS_NTO "\n" +"1:" + :"=&r" (tmp),"+A" (*(__ptr32b)) + :"r" (__val),"r" (__mask) + :"memory" ); +break ;case 4 : asmvolatile ( " lr.w %0, %1\n"
Signature · 1 line
2.40.1
Quoted 24 lines · On Sun, Dec 15, 2024 at 10:22:53PM -0500, [email protected] wrote:
From: Guo Ren <[email protected]>
RISC-V code uses the queued spinlock implementation, which calls the macros
smp_cond_load_acquirefor one byte. So, complement the implementation of byte and halfword versions.Signed-off-by Guo Ren <[email protected]>Signed-off-by Guo Ren <[email protected]>--- arch/riscv/include/asm/cmpxchg.h | 38 +++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-)arch/riscv/include/asm/cmpxchg.h +3
-0@@ -365,16 +365,48 @@ static __always_inline void __cmpwait(volatile void *ptr, {unsigned long tmp; +u32 *__ptr32b; +ulong __s, __val, __mask; + asm goto(ALTERNATIVE("j %l[no_zawrs]", "nop",
arch/riscv/include/asm/cmpxchg.h static __always_inline void __cmpwait(volatile void *ptr, · line 380
Quoted 10 lines
arch/riscv/include/asm/cmpxchg.h +4
-10, RISCV_ISA_EXT_ZAWRS, 1) : : : : no_zawrs);switch (size) {case 1 : - fallthrough; + __ptr32b = (u32 *)((ulong)(ptr) & ~0x3 ); + __s = ((ulong)(ptr) &0x3 ) *BITS_PER_BYTE ; + __val = val << __s; + __mask =0xf << __s;
This mask should be 0xff and the mask below should be 0xffff.
Quoted 37 lines
arch/riscv/include/asm/cmpxchg.h +28
-2+ + asmvolatile ( +" lr.w %0, %1\n" +" and %0, %0, %3\n" +" xor %0, %0, %2\n" +" bnez %0, 1f\n" +ZAWRS_WRS_NTO "\n" +"1:" + :"=&r" (tmp),"+A" (*(__ptr32b)) + :"r" (__val),"r" (__mask) + :"memory" ); +break ;case 2 : -/* RISC-V doesn't have lr instructions on byte and half-word. */ - goto no_zawrs; + __ptr32b = (u32 *)((ulong)(ptr) & ~0x3 ); + __s = ((ulong)(ptr) &0x2 ) *BITS_PER_BYTE ; + __val = val << __s; + __mask =0xff << __s; + + asmvolatile ( +" lr.w %0, %1\n" +" and %0, %0, %3\n" +" xor %0, %0, %2\n" +" bnez %0, 1f\n" +ZAWRS_WRS_NTO "\n" +"1:" + :"=&r" (tmp),"+A" (*(__ptr32b)) + :"r" (__val),"r" (__mask) + :"memory" ); +break ;case 4 : asmvolatile ( " lr.w %0, %1\n"Signature · 1 line
2.40.1
Thanks,
drew
Quoted 29 lines · Andrew Jones
Quoted 27 lines · On Sun, Dec 15, 2024 at 10:22:53PM -0500, [email protected] wrote:
From: Guo Ren <[email protected]>
RISC-V code uses the queued spinlock implementation, which calls the macros
smp_cond_load_acquirefor one byte. So, complement the implementation of byte and halfword versions.Signed-off-by Guo Ren <[email protected]>Signed-off-by Guo Ren <[email protected]>--- arch/riscv/include/asm/cmpxchg.h | 38 +++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-)arch/riscv/include/asm/cmpxchg.h +3
-0@@ -365,16 +365,48 @@ static __always_inline void __cmpwait(volatile void *ptr, {unsigned long tmp; +u32 *__ptr32b; +ulong __s, __val, __mask; + asm goto(ALTERNATIVE("j %l[no_zawrs]", "nop", 0, RISCV_ISA_EXT_ZAWRS, 1) : : : : no_zawrs);
Quoted 9 lines
arch/riscv/include/asm/cmpxchg.h static __always_inline void __cmpwait(volatile void *ptr, · line 380
Quoted 7 lines
arch/riscv/include/asm/cmpxchg.h +4
-1switch (size) {case 1 : - fallthrough; + __ptr32b = (u32 *)((ulong)(ptr) & ~0x3 ); + __s = ((ulong)(ptr) &0x3 ) *BITS_PER_BYTE ; + __val = val << __s; + __mask =0xf << __s;This mask should be
0xffand the mask below should be0xffff.
Thx for catching it; it's hard to test it out. I will correct it in the next version.
Quoted 41 lines
Quoted 36 lines
arch/riscv/include/asm/cmpxchg.h +28
-3+ + asmvolatile ( +" lr.w %0, %1\n" +" and %0, %0, %3\n" +" xor %0, %0, %2\n" +" bnez %0, 1f\n" +ZAWRS_WRS_NTO "\n" +"1:" + :"=&r" (tmp),"+A" (*(__ptr32b)) + :"r" (__val),"r" (__mask) + :"memory" ); +break ;case 2 : -/* RISC-V doesn't have lr instructions on byte and half-word. */ - goto no_zawrs; + __ptr32b = (u32 *)((ulong)(ptr) & ~0x3 ); + __s = ((ulong)(ptr) &0x2 ) *BITS_PER_BYTE ; + __val = val << __s; + __mask =0xff << __s; + + asmvolatile ( +" lr.w %0, %1\n" +" and %0, %0, %3\n" +" xor %0, %0, %2\n" +" bnez %0, 1f\n" +ZAWRS_WRS_NTO "\n" +"1:" + :"=&r" (tmp),"+A" (*(__ptr32b)) + :"r" (__val),"r" (__mask) + :"memory" ); +break ;case 4 : asmvolatile ( " lr.w %0, %1\n" --Quoted 2 lines
2.40.1
Thanks,
drew
Signature · 2 lines
Best Regards Guo Ren