diff mbox series

[2/4] RISC-V: reduce mcount save space on RV32

Message ID 20221027172435.2687118-3-jamie@jamieiles.com (mailing list archive)
State Superseded
Headers show
Series RISC-V: Dynamic ftrace support for RV32I | expand

Checks

Context Check Description
conchuod/cover_letter success Series has a cover letter
conchuod/tree_selection success Guessed tree name to be for-next
conchuod/patch_count success Link
conchuod/fixes_present success Fixes tag not required for -next series
conchuod/verify_signedoff success Signed-off-by tag matches author and committer
conchuod/header_inline success No static functions without inline keyword in header files
conchuod/verify_fixes success No Fixes tag
conchuod/checkpatch success total: 0 errors, 0 warnings, 0 checks, 65 lines checked
conchuod/kdoc success Errors and warnings before: 0 this patch: 0
conchuod/source_inline success Was 0 now: 0
conchuod/cc_maintainers warning 5 maintainers not CCed: ajones@ventanamicro.com palmer@dabbelt.com conor.dooley@microchip.com paul.walmsley@sifive.com aou@eecs.berkeley.edu
conchuod/build_warn_rv64 fail Errors and warnings before: 0 this patch: 0
conchuod/module_param success Was 0 now: 0

Commit Message

Jamie Iles Oct. 27, 2022, 5:24 p.m. UTC
For RV32 we can reduce the size of the ABI save+restore state by using
SZREG so that register stores are packed rather than on an 8 byte
boundary.

Signed-off-by: Jamie Iles <jamie@jamieiles.com>
---
 arch/riscv/kernel/mcount.S | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

Comments

Andrew Jones Oct. 28, 2022, 2:49 p.m. UTC | #1
On Thu, Oct 27, 2022 at 06:24:33PM +0100, Jamie Iles wrote:
> For RV32 we can reduce the size of the ABI save+restore state by using
> SZREG so that register stores are packed rather than on an 8 byte
> boundary.
> 
> Signed-off-by: Jamie Iles <jamie@jamieiles.com>
> ---
>  arch/riscv/kernel/mcount.S | 32 ++++++++++++++++----------------
>  1 file changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/arch/riscv/kernel/mcount.S b/arch/riscv/kernel/mcount.S
> index 9cf0904afd6d..4166909ce7b3 100644
> --- a/arch/riscv/kernel/mcount.S
> +++ b/arch/riscv/kernel/mcount.S
> @@ -15,8 +15,8 @@
>  
>  	.macro SAVE_ABI_STATE
>  	addi	sp, sp, -16
> -	REG_S	s0, 0(sp)
> -	REG_S	ra, 8(sp)
> +	REG_S	s0, 0*SZREG(sp)
> +	REG_S	ra, 1*SZREG(sp)
>  	addi	s0, sp, 16
>  	.endm

Shouldn't we only be adjusting sp by 2*SZREG?. Indeed RESTORE_ABI_STATE
below is getting modified that way.

>  
> @@ -25,24 +25,24 @@
>  	 * register if a0 was not saved.
>  	 */
>  	.macro SAVE_RET_ABI_STATE
> -	addi	sp, sp, -32
> -	REG_S	s0, 16(sp)
> -	REG_S	ra, 24(sp)
> -	REG_S	a0, 8(sp)
> +	addi	sp, sp, -4*SZREG
> +	REG_S	s0, 2*SZREG(sp)
> +	REG_S	ra, 3*SZREG(sp)
> +	REG_S	a0, 1*SZREG(sp)
>  	addi	s0, sp, 32

This should be 'addi s0, sp, -4*SZREG'

>  	.endm
>  
>  	.macro RESTORE_ABI_STATE
> -	REG_L	ra, 8(sp)
> -	REG_L	s0, 0(sp)
> -	addi	sp, sp, 16
> +	REG_L	ra, 1*SZREG(sp)
> +	REG_L	s0, 0*SZREG(sp)
> +	addi	sp, sp, 2*SZREG
>  	.endm
>  
>  	.macro RESTORE_RET_ABI_STATE
> -	REG_L	ra, 24(sp)
> -	REG_L	s0, 16(sp)
> -	REG_L	a0, 8(sp)
> -	addi	sp, sp, 32
> +	REG_L	ra, 3*SZREG(sp)
> +	REG_L	s0, 2*SZREG(sp)
> +	REG_L	a0, 1*SZREG(sp)
> +	addi	sp, sp, 4*SZREG
>  	.endm
>  
>  ENTRY(ftrace_stub)
> @@ -101,10 +101,10 @@ ENTRY(MCOUNT_NAME)
>   * prepare_to_return(&ra_to_caller_of_caller, ra_to_caller)
>   */
>  do_ftrace_graph_caller:
> -	addi	a0, s0, -8
> +	addi	a0, s0, -SZREG
>  	mv	a1, ra
>  #ifdef HAVE_FUNCTION_GRAPH_FP_TEST
> -	REG_L	a2, -16(s0)
> +	REG_L	a2, -2*SZREG(s0)
>  #endif
>  	SAVE_ABI_STATE
>  	call	prepare_ftrace_return
> @@ -117,7 +117,7 @@ do_ftrace_graph_caller:
>   * (*ftrace_trace_function)(ra_to_caller, ra_to_caller_of_caller)
>   */
>  do_trace:
> -	REG_L	a1, -8(s0)
> +	REG_L	a1, -SZREG(s0)
>  	mv	a0, ra
>  
>  	SAVE_ABI_STATE
> -- 
> 2.34.1
>

Thanks,
drew
Andrew Jones Oct. 28, 2022, 3:56 p.m. UTC | #2
On Fri, Oct 28, 2022 at 04:49:25PM +0200, Andrew Jones wrote:
> On Thu, Oct 27, 2022 at 06:24:33PM +0100, Jamie Iles wrote:
> > For RV32 we can reduce the size of the ABI save+restore state by using
> > SZREG so that register stores are packed rather than on an 8 byte
> > boundary.
> > 
> > Signed-off-by: Jamie Iles <jamie@jamieiles.com>
> > ---
> >  arch/riscv/kernel/mcount.S | 32 ++++++++++++++++----------------
> >  1 file changed, 16 insertions(+), 16 deletions(-)
> > 
> > diff --git a/arch/riscv/kernel/mcount.S b/arch/riscv/kernel/mcount.S
> > index 9cf0904afd6d..4166909ce7b3 100644
> > --- a/arch/riscv/kernel/mcount.S
> > +++ b/arch/riscv/kernel/mcount.S
> > @@ -15,8 +15,8 @@
> >  
> >  	.macro SAVE_ABI_STATE
> >  	addi	sp, sp, -16
> > -	REG_S	s0, 0(sp)
> > -	REG_S	ra, 8(sp)
> > +	REG_S	s0, 0*SZREG(sp)
> > +	REG_S	ra, 1*SZREG(sp)
> >  	addi	s0, sp, 16
> >  	.endm
> 
> Shouldn't we only be adjusting sp by 2*SZREG?. Indeed RESTORE_ABI_STATE
> below is getting modified that way.

It just occurred to me that leaving this adjustment as 16 is correct,
since we need to maintain 16-byte alignment, so the issue is below
in RESTORE_ABI_STATE where it isn't adding back 16.

> 
> >  
> > @@ -25,24 +25,24 @@
> >  	 * register if a0 was not saved.
> >  	 */
> >  	.macro SAVE_RET_ABI_STATE
> > -	addi	sp, sp, -32
> > -	REG_S	s0, 16(sp)
> > -	REG_S	ra, 24(sp)
> > -	REG_S	a0, 8(sp)
> > +	addi	sp, sp, -4*SZREG
> > +	REG_S	s0, 2*SZREG(sp)
> > +	REG_S	ra, 3*SZREG(sp)
> > +	REG_S	a0, 1*SZREG(sp)
> >  	addi	s0, sp, 32
> 
> This should be 'addi s0, sp, -4*SZREG'

And here I made copy+paste mistake, it should of course be 4*SZREG.

Thanks,
drew

> 
> >  	.endm
> >  
> >  	.macro RESTORE_ABI_STATE
> > -	REG_L	ra, 8(sp)
> > -	REG_L	s0, 0(sp)
> > -	addi	sp, sp, 16
> > +	REG_L	ra, 1*SZREG(sp)
> > +	REG_L	s0, 0*SZREG(sp)
> > +	addi	sp, sp, 2*SZREG
> >  	.endm
> >  
> >  	.macro RESTORE_RET_ABI_STATE
> > -	REG_L	ra, 24(sp)
> > -	REG_L	s0, 16(sp)
> > -	REG_L	a0, 8(sp)
> > -	addi	sp, sp, 32
> > +	REG_L	ra, 3*SZREG(sp)
> > +	REG_L	s0, 2*SZREG(sp)
> > +	REG_L	a0, 1*SZREG(sp)
> > +	addi	sp, sp, 4*SZREG
> >  	.endm
> >  
> >  ENTRY(ftrace_stub)
> > @@ -101,10 +101,10 @@ ENTRY(MCOUNT_NAME)
> >   * prepare_to_return(&ra_to_caller_of_caller, ra_to_caller)
> >   */
> >  do_ftrace_graph_caller:
> > -	addi	a0, s0, -8
> > +	addi	a0, s0, -SZREG
> >  	mv	a1, ra
> >  #ifdef HAVE_FUNCTION_GRAPH_FP_TEST
> > -	REG_L	a2, -16(s0)
> > +	REG_L	a2, -2*SZREG(s0)
> >  #endif
> >  	SAVE_ABI_STATE
> >  	call	prepare_ftrace_return
> > @@ -117,7 +117,7 @@ do_ftrace_graph_caller:
> >   * (*ftrace_trace_function)(ra_to_caller, ra_to_caller_of_caller)
> >   */
> >  do_trace:
> > -	REG_L	a1, -8(s0)
> > +	REG_L	a1, -SZREG(s0)
> >  	mv	a0, ra
> >  
> >  	SAVE_ABI_STATE
> > -- 
> > 2.34.1
> >
> 
> Thanks,
> drew
diff mbox series

Patch

diff --git a/arch/riscv/kernel/mcount.S b/arch/riscv/kernel/mcount.S
index 9cf0904afd6d..4166909ce7b3 100644
--- a/arch/riscv/kernel/mcount.S
+++ b/arch/riscv/kernel/mcount.S
@@ -15,8 +15,8 @@ 
 
 	.macro SAVE_ABI_STATE
 	addi	sp, sp, -16
-	REG_S	s0, 0(sp)
-	REG_S	ra, 8(sp)
+	REG_S	s0, 0*SZREG(sp)
+	REG_S	ra, 1*SZREG(sp)
 	addi	s0, sp, 16
 	.endm
 
@@ -25,24 +25,24 @@ 
 	 * register if a0 was not saved.
 	 */
 	.macro SAVE_RET_ABI_STATE
-	addi	sp, sp, -32
-	REG_S	s0, 16(sp)
-	REG_S	ra, 24(sp)
-	REG_S	a0, 8(sp)
+	addi	sp, sp, -4*SZREG
+	REG_S	s0, 2*SZREG(sp)
+	REG_S	ra, 3*SZREG(sp)
+	REG_S	a0, 1*SZREG(sp)
 	addi	s0, sp, 32
 	.endm
 
 	.macro RESTORE_ABI_STATE
-	REG_L	ra, 8(sp)
-	REG_L	s0, 0(sp)
-	addi	sp, sp, 16
+	REG_L	ra, 1*SZREG(sp)
+	REG_L	s0, 0*SZREG(sp)
+	addi	sp, sp, 2*SZREG
 	.endm
 
 	.macro RESTORE_RET_ABI_STATE
-	REG_L	ra, 24(sp)
-	REG_L	s0, 16(sp)
-	REG_L	a0, 8(sp)
-	addi	sp, sp, 32
+	REG_L	ra, 3*SZREG(sp)
+	REG_L	s0, 2*SZREG(sp)
+	REG_L	a0, 1*SZREG(sp)
+	addi	sp, sp, 4*SZREG
 	.endm
 
 ENTRY(ftrace_stub)
@@ -101,10 +101,10 @@  ENTRY(MCOUNT_NAME)
  * prepare_to_return(&ra_to_caller_of_caller, ra_to_caller)
  */
 do_ftrace_graph_caller:
-	addi	a0, s0, -8
+	addi	a0, s0, -SZREG
 	mv	a1, ra
 #ifdef HAVE_FUNCTION_GRAPH_FP_TEST
-	REG_L	a2, -16(s0)
+	REG_L	a2, -2*SZREG(s0)
 #endif
 	SAVE_ABI_STATE
 	call	prepare_ftrace_return
@@ -117,7 +117,7 @@  do_ftrace_graph_caller:
  * (*ftrace_trace_function)(ra_to_caller, ra_to_caller_of_caller)
  */
 do_trace:
-	REG_L	a1, -8(s0)
+	REG_L	a1, -SZREG(s0)
 	mv	a0, ra
 
 	SAVE_ABI_STATE