Skip to content

Commit 16badac

Browse files
Alexandre Ghitipalmer-dabbelt
authored andcommitted
riscv: Improve sbi_ecall() code generation by reordering arguments
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 <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Yunhui Cui <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 56c1c1a commit 16badac

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

arch/riscv/include/asm/sbi.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,12 @@ struct sbiret {
304304
};
305305

306306
void sbi_init(void);
307-
struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
308-
unsigned long arg1, unsigned long arg2,
309-
unsigned long arg3, unsigned long arg4,
310-
unsigned long arg5);
307+
struct sbiret __sbi_ecall(unsigned long arg0, unsigned long arg1,
308+
unsigned long arg2, unsigned long arg3,
309+
unsigned long arg4, unsigned long arg5,
310+
int fid, int ext);
311+
#define sbi_ecall(e, f, a0, a1, a2, a3, a4, a5) \
312+
__sbi_ecall(a0, a1, a2, a3, a4, a5, f, e)
311313

312314
#ifdef CONFIG_RISCV_SBI_V01
313315
void sbi_console_putchar(int ch);

arch/riscv/kernel/sbi.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ static int (*__sbi_rfence)(int fid, const struct cpumask *cpu_mask,
2727
unsigned long start, unsigned long size,
2828
unsigned long arg4, unsigned long arg5) __ro_after_init;
2929

30-
struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
31-
unsigned long arg1, unsigned long arg2,
32-
unsigned long arg3, unsigned long arg4,
33-
unsigned long arg5)
30+
struct sbiret __sbi_ecall(unsigned long arg0, unsigned long arg1,
31+
unsigned long arg2, unsigned long arg3,
32+
unsigned long arg4, unsigned long arg5,
33+
int fid, int ext)
3434
{
3535
struct sbiret ret;
3636

@@ -55,7 +55,7 @@ struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
5555

5656
return ret;
5757
}
58-
EXPORT_SYMBOL(sbi_ecall);
58+
EXPORT_SYMBOL(__sbi_ecall);
5959

6060
int sbi_err_map_linux_errno(int err)
6161
{

0 commit comments

Comments
 (0)