arm64/sve: Trivial optimisation for 128 bit SVE vectors
v2 cover arm64/sve: Trivial optimisation for 128 bit SVE vectors
This series is a combination of factoring out some duplicated code and a very minor optimisation to the performance of handling converting FPSIMD state to SVE in the live registers for 128 bit SVE vectors.
v2:
- Combine P and FFR flushing into a single macro.
Mark Brown (3):
arm64/sve: Split _sve_flush macro into separate Z and predicate
flushes
arm64/sve: Use the sve_flush macros in sve_load_from_fpsimd_state() arm64/sve: Skip flushing Z registers with 128 bit vectors
arch/arm64/include/asm/fpsimd.h | 2 +- arch/arm64/include/asm/fpsimdmacros.h | 4 +++- arch/arm64/kernel/entry-fpsimd.S | 19 ++++++++++++------- arch/arm64/kernel/fpsimd.c | 6 ++++-- 4 files changed, 20 insertions(+), 11 deletions(-)
base-commit: 6efb943b8616ec53a5e444193dccf1af9ad627b5
Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 1/3 arm64/sve: Split _sve_flush macro into separate Z and predicate flushes
Trivial refactoring to support further work, no change to generated code.
--- arch/arm64/include/asm/fpsimdmacros.h | 4 +++- arch/arm64/kernel/entry-fpsimd.S | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-)
arch/arm64/include/asm/fpsimdmacros.h +3 -1
@@ -213,8 +213,10 @@ mov v\nz\().16b, v\nz\().16b .endm -.macro sve_flush +.macro sve_flush_z _for n, 0, 31, _sve_flush_z \n +.endm +.macro sve_flush_p_ffr _for n, 0, 15, _sve_pfalse \n _sve_wrffr 0 .endm
arch/arm64/kernel/entry-fpsimd.S +2 -1
@@ -72,7 +72,8 @@ SYM_FUNC_END(sve_load_from_fpsimd_state) /* Zero all SVE registers but the first 128-bits of each vector */ SYM_FUNC_START(sve_flush_live) - sve_flush + sve_flush_z + sve_flush_p_ffr ret SYM_FUNC_END(sve_flush_live)
Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v2 1/3] arm64/sve: Split _sve_flush macro into separate Z and predicate flushes
Quoted 3 lines · Mark Brown
Trivial refactoring to support further work, no change to generated code.
Signed-off-by Mark Brown <[email protected]>
Quoted 43 lines
--- arch/arm64/include/asm/fpsimdmacros.h | 4 +++- arch/arm64/kernel/entry-fpsimd.S | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-)arch/arm64/include/asm/fpsimdmacros.h +3
-1@@ -213,8 +213,10 @@ mov v\nz\().16b, v\nz\().16b .endm -.macro sve_flush +.macro sve_flush_z _for n, 0, 31, _sve_flush_z \n +.endm +.macro sve_flush_p_ffr _for n, 0, 15, _sve_pfalse \n _sve_wrffr 0 .endmarch/arm64/kernel/entry-fpsimd.S +2
-1@@ -72,7 +72,8 @@ SYM_FUNC_END(sve_load_from_fpsimd_state) /* Zero all SVE registers but the first 128-bits of each vector */ SYM_FUNC_START(sve_flush_live) - sve_flush + sve_flush_z + sve_flush_p_ffr ret SYM_FUNC_END(sve_flush_live)Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 2/3 arm64/sve: Use the sve_flush macros in sve_load_from_fpsimd_state()
In reply to Mark BrownThis makes the code a bit clearer and as a result we can also make the indentation more normal, there is no change to the generated code.
--- arch/arm64/kernel/entry-fpsimd.S | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
arch/arm64/kernel/entry-fpsimd.S +4 -5
@@ -63,11 +63,10 @@ SYM_FUNC_END(sve_set_vq) * and the rest zeroed. All the other SVE registers will be zeroed. */ SYM_FUNC_START(sve_load_from_fpsimd_state) - sve_load_vq x1, x2, x3 - fpsimd_restore x0, 8 - _for n, 0, 15, _sve_pfalse \n - _sve_wrffr 0 - ret + sve_load_vq x1, x2, x3 + fpsimd_restore x0, 8 + sve_flush_p_ffr + ret SYM_FUNC_END(sve_load_from_fpsimd_state) /* Zero all SVE registers but the first 128-bits of each vector */
Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v2 2/3] arm64/sve: Use the sve_flush macros in sve_load_from_fpsimd_state()
Quoted 4 lines · Mark Brown
This makes the code a bit clearer and as a result we can also make the indentation more normal, there is no change to the generated code.
Signed-off-by Mark Brown <[email protected]>
Quoted 32 lines
--- arch/arm64/kernel/entry-fpsimd.S | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)arch/arm64/kernel/entry-fpsimd.S +4
-5@@ -63,11 +63,10 @@ SYM_FUNC_END(sve_set_vq) * and the rest zeroed. All the other SVE registers will be zeroed. */ SYM_FUNC_START(sve_load_from_fpsimd_state) - sve_load_vq x1, x2, x3 - fpsimd_restore x0, 8 - _for n, 0, 15, _sve_pfalse \n - _sve_wrffr 0 - ret + sve_load_vq x1, x2, x3 + fpsimd_restore x0, 8 + sve_flush_p_ffr + ret SYM_FUNC_END(sve_load_from_fpsimd_state) /* Zero all SVE registers but the first 128-bits of each vector */Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 3/3 arm64/sve: Skip flushing Z registers with 128 bit vectors
In reply to Mark BrownWhen the SVE vector length is 128 bits then there are no bits in the Z registers which are not shared with the V registers so we can skip them when zeroing state not shared with FPSIMD, this results in a minor performance improvement.
--- arch/arm64/include/asm/fpsimd.h | 2 +- arch/arm64/kernel/entry-fpsimd.S | 9 +++++++-- arch/arm64/kernel/fpsimd.c | 6 ++++-- 3 files changed, 12 insertions(+), 5 deletions(-)
arch/arm64/include/asm/fpsimd.h +1 -1
@@ -69,7 +69,7 @@ static inline void *sve_pffr(struct thread_struct *thread)extern void sve_save_state (void *state,u32 *pfpsr);extern void sve_load_state (void const *state,u32 const *pfpsr,unsigned long vq_minus_1); -extern void sve_flush_live (void ); +extern void sve_flush_live (unsigned long vq_minus_1);extern void sve_load_from_fpsimd_state (struct user_fpsimd_state const *state,unsigned long vq_minus_1);extern unsigned int sve_get_vl (void );
arch/arm64/kernel/entry-fpsimd.S +7 -2
@@ -69,10 +69,15 @@ SYM_FUNC_START(sve_load_from_fpsimd_state) ret SYM_FUNC_END(sve_load_from_fpsimd_state) -/* Zero all SVE registers but the first 128-bits of each vector */ +/* + * Zero all SVE registers but the first 128-bits of each vector + * + * x0 = VQ - 1 + */ SYM_FUNC_START(sve_flush_live) + cbz x0, 1f // A VQ-1 of 0 is 128 bits so no extra Z state sve_flush_z - sve_flush_p_ffr +1: sve_flush_p_ffr ret SYM_FUNC_END(sve_flush_live)
arch/arm64/kernel/fpsimd.c +4 -2
@@ -957,8 +957,10 @@ void do_sve_acc(unsigned int esr, struct pt_regs *regs)* disabling the trap, otherwise update our in-memory copy. */ if (!test_thread_flag (TIF_FOREIGN_FPSTATE )) { -sve_set_vq (sve_vq_from_vl (current->thread.sve_vl) -1 ); -sve_flush_live (); +unsigned long vq_minus_one = +sve_vq_from_vl (current->thread.sve_vl) -1 ; +sve_set_vq (vq_minus_one); +sve_flush_live (vq_minus_one);fpsimd_bind_task_to_cpu (); }else {fpsimd_to_sve (current);
Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v2 3/3] arm64/sve: Skip flushing Z registers with 128 bit vectors
Quoted 30 lines · Mark Brown
When the SVE vector length is 128 bits then there are no bits in the Z registers which are not shared with the V registers so we can skip them when zeroing state not shared with FPSIMD, this results in a minor performance improvement.
Signed-off-by Mark Brown <[email protected]>--- arch/arm64/include/asm/fpsimd.h | 2 +- arch/arm64/kernel/entry-fpsimd.S | 9 +++++++-- arch/arm64/kernel/fpsimd.c | 6 ++++-- 3 files changed, 12 insertions(+), 5 deletions(-)arch/arm64/include/asm/fpsimd.h +1
-1@@ -69,7 +69,7 @@ static inline void *sve_pffr(struct thread_struct *thread)extern void sve_save_state (void *state,u32 *pfpsr);extern void sve_load_state (void const *state,u32 const *pfpsr,unsigned long vq_minus_1); -extern void sve_flush_live (void ); +extern void sve_flush_live (unsigned long vq_minus_1);extern void sve_load_from_fpsimd_state (struct user_fpsimd_state const *state,unsigned long vq_minus_1);extern unsigned int sve_get_vl (void );arch/arm64/kernel/entry-fpsimd.S +0
-0
arch/arm64/kernel/entry-fpsimd.S SYM_FUNC_START(sve_load_from_fpsimd_state) · line 75
Quoted 8 lines
arch/arm64/kernel/entry-fpsimd.S +4
-1@@ -69,10 +69,15 @@ SYM_FUNC_START(sve_load_from_fpsimd_state) ret SYM_FUNC_END(sve_load_from_fpsimd_state) -/* Zero all SVE registers but the first 128-bits of each vector */ +/* + * Zero all SVE registers but the first 128-bits of each vector + * + * x0 = VQ - 1
This does require that ZCR_EL1.LEN has already been set to match x0, and is not changed again before entering userspace.
It would be a good idea to at least describe this in a comment so that this doesn't get forgotten later on, but there's a limit to how foolproof this low-level backend code needs to be...
Quoted 28 lines
arch/arm64/kernel/entry-fpsimd.S +3
-1+ */ SYM_FUNC_START(sve_flush_live) + cbz x0, 1f // A VQ-1 of 0 is 128 bits so no extra Z state sve_flush_z - sve_flush_p_ffr +1: sve_flush_p_ffr ret SYM_FUNC_END(sve_flush_live)arch/arm64/kernel/fpsimd.c +4
-2@@ -957,8 +957,10 @@ void do_sve_acc(unsigned int esr, struct pt_regs *regs)* disabling the trap, otherwise update our in-memory copy. */ if (!test_thread_flag (TIF_FOREIGN_FPSTATE )) { -sve_set_vq (sve_vq_from_vl (current->thread.sve_vl) -1 ); -sve_flush_live (); +unsigned long vq_minus_one = +sve_vq_from_vl (current->thread.sve_vl) -1 ; +sve_set_vq (vq_minus_one); +sve_flush_live (vq_minus_one);fpsimd_bind_task_to_cpu (); }else {fpsimd_to_sve (current);Signature · 1 line
2.20.1
With a comment added as outlined above,
Cheers
---Dave
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v2 3/3] arm64/sve: Skip flushing Z registers with 128 bit vectors
Quoted 7 lines · Dave Martin
Quoted 4 lines · Mark Brown
+/*
+ * Zero all SVE registers but the first 128-bits of each vector
+ *
+ * x0 = VQ - 1
Quoted 6 lines
This does require that ZCR_EL1.LEN has already been set to match x0, and is not changed again before entering userspace.
It would be a good idea to at least describe this in a comment so that this doesn't get forgotten later on, but there's a limit to how foolproof this low-level backend code needs to be...
Similar concerns exist for huge chunks of the existing SVE code (eg, the no further changes on vector length constraint is pretty much universal and is I'd say largely more of a "make sure you handle the register contents" thing on anything that changes the vector length).
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 4 lines · Mark Brown
This series is a combination of factoring out some duplicated code and a very minor optimisation to the performance of handling converting FPSIMD state to SVE in the live registers for 128 bit SVE vectors.
Quoted 8 lines
v2:
- Combine P and FFR flushing into a single macro.Mark Brown (3):
arm64/sve: Split_sve_flushmacro into separate Z and predicate
flushes
arm64/sve: Use thesve_flushmacros insve_load_from_fpsimd_state()arm64/sve: Skip flushing Z registers with 128 bit vectors
The series makes sense to me:
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel