]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
riscv: Improve sbi_ecall() code generation by reordering arguments
authorAlexandre Ghiti <alexghiti@rivosinc.com>
Fri, 22 Mar 2024 11:26:29 +0000 (12:26 +0100)
committerPalmer Dabbelt <palmer@rivosinc.com>
Wed, 10 Jul 2024 20:30:56 +0000 (13:30 -0700)
The sbi_ecall() function arguments are not in the same order as the
ecall arguments, so we end up re-ordering the registers before the
ecall which is useless and costly.

So simply reorder the arguments in the same way as expected by ecall.
Instead of reordering directly the arguments of sbi_ecall(), use a proxy
macro since the current ordering is more natural.

Before:

Dump of assembler code for function sbi_ecall:
   0xffffffff800085e0 <+0>: add sp,sp,-32
   0xffffffff800085e2 <+2>: sd s0,24(sp)
   0xffffffff800085e4 <+4>: mv t1,a0
   0xffffffff800085e6 <+6>: add s0,sp,32
   0xffffffff800085e8 <+8>: mv t3,a1
   0xffffffff800085ea <+10>: mv a0,a2
   0xffffffff800085ec <+12>: mv a1,a3
   0xffffffff800085ee <+14>: mv a2,a4
   0xffffffff800085f0 <+16>: mv a3,a5
   0xffffffff800085f2 <+18>: mv a4,a6
   0xffffffff800085f4 <+20>: mv a5,a7
   0xffffffff800085f6 <+22>: mv a6,t3
   0xffffffff800085f8 <+24>: mv a7,t1
   0xffffffff800085fa <+26>: ecall
   0xffffffff800085fe <+30>: ld s0,24(sp)
   0xffffffff80008600 <+32>: add sp,sp,32
   0xffffffff80008602 <+34>: ret

After:

Dump of assembler code for function __sbi_ecall:
   0xffffffff8000b6b2 <+0>: add sp,sp,-32
   0xffffffff8000b6b4 <+2>: sd s0,24(sp)
   0xffffffff8000b6b6 <+4>: add s0,sp,32
   0xffffffff8000b6b8 <+6>: ecall
   0xffffffff8000b6bc <+10>: ld s0,24(sp)
   0xffffffff8000b6be <+12>: add sp,sp,32
   0xffffffff8000b6c0 <+14>: ret

Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Atish Patra <atishp@rivosinc.com>
Reviewed-by: Yunhui Cui <cuiyunhui@bytedance.com>
Link: https://lore.kernel.org/r/20240322112629.68170-1-alexghiti@rivosinc.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/include/asm/sbi.h
arch/riscv/kernel/sbi.c

index 1079e214fe855e8fcabcbcc8b9e6687efd68eb1e..7cffd4ffecd0ce9be737860dc5f83a3339508b03 100644 (file)
@@ -304,10 +304,12 @@ struct sbiret {
 };
 
 void sbi_init(void);
-struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
-                       unsigned long arg1, unsigned long arg2,
-                       unsigned long arg3, unsigned long arg4,
-                       unsigned long arg5);
+struct sbiret __sbi_ecall(unsigned long arg0, unsigned long arg1,
+                         unsigned long arg2, unsigned long arg3,
+                         unsigned long arg4, unsigned long arg5,
+                         int fid, int ext);
+#define sbi_ecall(e, f, a0, a1, a2, a3, a4, a5)        \
+               __sbi_ecall(a0, a1, a2, a3, a4, a5, f, e)
 
 #ifdef CONFIG_RISCV_SBI_V01
 void sbi_console_putchar(int ch);
index a1d21d8f529365328b1b2a48f0def4710c137df3..837bdab2601bd970c3a2f946026360ff80c52257 100644 (file)
@@ -27,10 +27,10 @@ static int (*__sbi_rfence)(int fid, const struct cpumask *cpu_mask,
                           unsigned long start, unsigned long size,
                           unsigned long arg4, unsigned long arg5) __ro_after_init;
 
-struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
-                       unsigned long arg1, unsigned long arg2,
-                       unsigned long arg3, unsigned long arg4,
-                       unsigned long arg5)
+struct sbiret __sbi_ecall(unsigned long arg0, unsigned long arg1,
+                         unsigned long arg2, unsigned long arg3,
+                         unsigned long arg4, unsigned long arg5,
+                         int fid, int ext)
 {
        struct sbiret ret;
 
@@ -55,7 +55,7 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
 
        return ret;
 }
-EXPORT_SYMBOL(sbi_ecall);
+EXPORT_SYMBOL(__sbi_ecall);
 
 int sbi_err_map_linux_errno(int err)
 {