FP/VEC/VSX switching optimisations
v5 cover FP/VEC/VSX switching optimisations
Cover-letter for V1 of the series is at
https://lists.ozlabs.org/pipermail/linuxppc-dev/2015-November/136350.html
Cover-letter for V2 of the series is at
https://lists.ozlabs.org/pipermail/linuxppc-dev/2016-January/138054.html
Changes in V3:
Addressed review comments from Michael Neuling
- Made commit message in 4/9 better reflect the patch
- Removed overuse of #ifdef blocks and redundant condition in 5/9
- Split 6/8 in two to better prepare for 7,8,9
- Removed #ifdefs in 6/9
Changes in V4:
- Addressed non ABI compliant ASM macros in 1/9
- Fixed build breakage due to changing #ifdefs in V3 (6/9)
- Reordered some conditions in if statements
Changes in V5:
- Enchanced basic-asm.h to provide ABI independent macro as pointed out by Naveen Rao.
- Tested for both BE and LE builds. Had to disable -flto from the selftests/powerpc Makefile as it didn't play well with the custom ASM.
- Added some extra debugging output to the vmx_signal testcase
- Fixed comments in testing code
- Updated VSX test code to use GCC Altivec macros
Cyril Bur (9):
selftests/powerpc: Test the preservation of FPU and VMX regs across
syscall
selftests/powerpc: Test preservation of FPU and VMX regs across
preemption
selftests/powerpc: Test FPU and VMX regs in signal ucontext
powerpc: Explicitly disable math features when copying thread
powerpc: Restore FPU/VEC/VSX if previously used
powerpc: Prepare for splitting giveup_{fpu,altivec,vsx} in two
powerpc: Add the ability to save FPU without giving it up
powerpc: Add the ability to save Altivec without giving it up
powerpc: Add the ability to save VSX without giving it up
arch/powerpc/include/asm/processor.h | 2 + arch/powerpc/include/asm/reg.h | 8 + arch/powerpc/include/asm/switch_to.h | 13 +- arch/powerpc/kernel/asm-offsets.c | 2 + arch/powerpc/kernel/entry_64.S | 21 +- arch/powerpc/kernel/fpu.S | 25 +-- arch/powerpc/kernel/ppc_ksyms.c | 4 - arch/powerpc/kernel/process.c | 168 +++++++++++++-- arch/powerpc/kernel/vector.S | 45 +--- tools/testing/selftests/powerpc/Makefile | 3 +- tools/testing/selftests/powerpc/basic_asm.h | 62 ++++++ tools/testing/selftests/powerpc/math/.gitignore | 6 + tools/testing/selftests/powerpc/math/Makefile | 21 ++ tools/testing/selftests/powerpc/math/fpu_asm.S | 197 +++++++++++++++++ tools/testing/selftests/powerpc/math/fpu_preempt.c | 113 ++++++++++ tools/testing/selftests/powerpc/math/fpu_signal.c | 135 ++++++++++++ tools/testing/selftests/powerpc/math/fpu_syscall.c | 90 ++++++++ tools/testing/selftests/powerpc/math/vmx_asm.S | 234 +++++++++++++++++++++ tools/testing/selftests/powerpc/math/vmx_preempt.c | 112 ++++++++++ tools/testing/selftests/powerpc/math/vmx_signal.c | 156 ++++++++++++++ tools/testing/selftests/powerpc/math/vmx_syscall.c | 91 ++++++++ 21 files changed, 1425 insertions(+), 83 deletions(-) create mode 100644 tools/testing/selftests/powerpc/basic_asm.h create mode 100644 tools/testing/selftests/powerpc/math/.gitignore create mode 100644 tools/testing/selftests/powerpc/math/Makefile create mode 100644 tools/testing/selftests/powerpc/math/fpu_asm.S create mode 100644 tools/testing/selftests/powerpc/math/fpu_preempt.c create mode 100644 tools/testing/selftests/powerpc/math/fpu_signal.c create mode 100644 tools/testing/selftests/powerpc/math/fpu_syscall.c create mode 100644 tools/testing/selftests/powerpc/math/vmx_asm.S create mode 100644 tools/testing/selftests/powerpc/math/vmx_preempt.c create mode 100644 tools/testing/selftests/powerpc/math/vmx_signal.c create mode 100644 tools/testing/selftests/powerpc/math/vmx_syscall.c
Signature · 1 line
2.7.1
PATCH v5 1/9 selftests/powerpc: Test the preservation of FPU and VMX regs across syscall
Test that the non volatile floating point and Altivec registers get correctly preserved across the fork() syscall.
fork() works nicely for this purpose, the registers should be the same for both parent and child
--- tools/testing/selftests/powerpc/Makefile | 3 +- tools/testing/selftests/powerpc/basic_asm.h | 62 +++++++ tools/testing/selftests/powerpc/math/.gitignore | 2 + tools/testing/selftests/powerpc/math/Makefile | 16 ++ tools/testing/selftests/powerpc/math/fpu_asm.S | 161 +++++++++++++++++ tools/testing/selftests/powerpc/math/fpu_syscall.c | 90 ++++++++++ tools/testing/selftests/powerpc/math/vmx_asm.S | 195 +++++++++++++++++++++ tools/testing/selftests/powerpc/math/vmx_syscall.c | 91 ++++++++++ 8 files changed, 619 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/powerpc/basic_asm.h create mode 100644 tools/testing/selftests/powerpc/math/.gitignore create mode 100644 tools/testing/selftests/powerpc/math/Makefile create mode 100644 tools/testing/selftests/powerpc/math/fpu_asm.S create mode 100644 tools/testing/selftests/powerpc/math/fpu_syscall.c create mode 100644 tools/testing/selftests/powerpc/math/vmx_asm.S create mode 100644 tools/testing/selftests/powerpc/math/vmx_syscall.c
tools/testing/selftests/powerpc/Makefile +2 -1
@@ -22,7 +22,8 @@ SUB_DIRS = benchmarks \ switch_endian \ syscalls \ tm \ - vphn + vphn \ + math endif
tools/testing/selftests/powerpc/basic_asm.h new file +62 -0
62 lines not on this page · raw message
tools/testing/selftests/powerpc/math/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +fpu_syscall +vmx_syscall
tools/testing/selftests/powerpc/math/Makefile new file +16 -0
@@ -0,0 +1,16 @@ +TEST_PROGS := fpu_syscall vmx_syscall + +all: $(TEST_PROGS) + +#The general powerpc makefile adds -flto. This isn't interacting well with the custom ASM. +#filter-out -flto to avoid false failures. +$(TEST_PROGS): ../harness.c +$(TEST_PROGS): CFLAGS = $(filter-out -flto,$(CFLAGS) -O2 -g -pthread -m64 -maltivec) + +fpu_syscall: fpu_asm.S +vmx_syscall: vmx_asm.S + +include ../../lib.mk + +clean: + rm -f $(TEST_PROGS) *.o
tools/testing/selftests/powerpc/math/fpu_asm.S new file +161 -0
161 lines not on this page · raw message
tools/testing/selftests/powerpc/math/fpu_syscall.c new file +90 -0
90 lines not on this page · raw message
tools/testing/selftests/powerpc/math/vmx_asm.S new file +195 -0
195 lines not on this page · raw message
tools/testing/selftests/powerpc/math/vmx_syscall.c new file +91 -0
91 lines not on this page · raw message
Signature · 1 line
2.7.1
PATCH v5 3/9 selftests/powerpc: Test FPU and VMX regs in signal ucontext
In reply to Cyril BurLoad up the non volatile FPU and VMX regs and ensure that they are the expected value in a signal handler
--- tools/testing/selftests/powerpc/math/.gitignore | 2 + tools/testing/selftests/powerpc/math/Makefile | 4 +- tools/testing/selftests/powerpc/math/fpu_signal.c | 135 +++++++++++++++++++ tools/testing/selftests/powerpc/math/vmx_signal.c | 156 ++++++++++++++++++++++ 4 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/powerpc/math/fpu_signal.c create mode 100644 tools/testing/selftests/powerpc/math/vmx_signal.c
tools/testing/selftests/powerpc/math/.gitignore +2 -0
@@ -2,3 +2,5 @@ fpu_syscall vmx_syscall fpu_preempt vmx_preempt +fpu_signal +vmx_signal
tools/testing/selftests/powerpc/math/Makefile +3 -1
@@ -1,4 +1,4 @@ -TEST_PROGS := fpu_syscall fpu_preempt vmx_syscall vmx_preempt +TEST_PROGS := fpu_syscall fpu_preempt fpu_signal vmx_syscall vmx_preempt vmx_signal all: $(TEST_PROGS)
@@ -9,9 +9,11 @@ $(TEST_PROGS): CFLAGS = $(filter-out -flto,$(CFLAGS) -O2 -g -pthread -m64 -malti fpu_syscall: fpu_asm.S fpu_preempt: fpu_asm.S +fpu_signal: fpu_asm.S vmx_syscall: vmx_asm.S vmx_preempt: vmx_asm.S +vmx_signal: vmx_asm.S include ../../lib.mk
tools/testing/selftests/powerpc/math/fpu_signal.c new file +135 -0
135 lines not on this page · raw message
tools/testing/selftests/powerpc/math/vmx_signal.c new file +156 -0
156 lines not on this page · raw message
Signature · 1 line
2.7.1
PATCH v5 4/9 powerpc: Explicitly disable math features when copying thread
In reply to Cyril BurCurrently when threads get scheduled off they always giveup the FPU, Altivec (VMX) and Vector (VSX) units if they were using them. When they are scheduled back on a fault is then taken to enable each facility and load registers. As a result explicitly disabling FPU/VMX/VSX has not been necessary.
Future changes and optimisations remove this mandatory giveup and fault which could cause calls such as clone() and fork() to copy threads and run them later with FPU/VMX/VSX enabled but no registers loaded.
This patch starts the process of having MSR_{FP,VEC,VSX} mean that a threads registers are hot while not having MSR_{FP,VEC,VSX} means that the registers must be loaded. This allows for a smarter return to userspace.
--- arch/powerpc/kernel/process.c | 1 + 1 file changed, 1 insertion(+)
arch/powerpc/kernel/process.c +1 -0
@@ -1307,6 +1307,7 @@ int copy_thread(unsigned long clone_flags, unsigned long usp, f = ret_from_fork; } + childregs->msr &= ~(MSR_FP |MSR_VEC |MSR_VSX ); sp -=STACK_FRAME_OVERHEAD ;/*
Signature · 1 line
2.7.1
PATCH v5 5/9 powerpc: Restore FPU/VEC/VSX if previously used
In reply to Cyril BurCurrently the FPU, VEC and VSX facilities are lazily loaded. This is not a problem unless a process is using these facilities.
Modern versions of GCC are very good at automatically vectorising code, new and modernised workloads make use of floating point and vector facilities, even the kernel makes use of vectorised memcpy.
All this combined greatly increases the cost of a syscall since the kernel uses the facilities sometimes even in syscall fast-path making it increasingly common for a thread to take an *_unavailable exception soon after a syscall, not to mention potentially taking all three.
The obvious overcompensation to this problem is to simply always load all the facilities on every exit to userspace. Loading up all FPU, VEC and VSX registers every time can be expensive and if a workload does avoid using them, it should not be forced to incur this penalty.
An 8bit counter is used to detect if the registers have been used in the past and the registers are always loaded until the value wraps to back to zero.
Several versions of the assembly in entry_64.S. 1. Always calling C, 2. Performing a common case check and then calling C and 3. A complex check in asm. After some benchmarking it was determined that avoiding C in the common case is a performance benefit. The full check in asm greatly complicated that codepath for a negligible performance gain and the trade-off was deemed not worth it.
--- arch/powerpc/include/asm/processor.h | 2 + arch/powerpc/kernel/asm-offsets.c | 2 + arch/powerpc/kernel/entry_64.S | 21 +++++++-- arch/powerpc/kernel/fpu.S | 4 ++ arch/powerpc/kernel/process.c | 88 +++++++++++++++++++++++++++++++----- arch/powerpc/kernel/vector.S | 4 ++ 6 files changed, 107 insertions(+), 14 deletions(-)
arch/powerpc/include/asm/processor.h +2 -0
@@ -236,11 +236,13 @@ struct thread_struct {#endif struct arch_hw_breakpoint hw_brk;/* info on the hardware breakpoint */ unsigned long trap_nr;/* last trap # on this thread */ +u8 load_fp;#ifdef CONFIG_ALTIVEC struct thread_vr_state vr_state;struct thread_vr_state *vr_save_area;unsigned long vrsave;int used_vr;/* set if process has used altivec */ +u8 load_vec;#endif /* CONFIG_ALTIVEC */ #ifdef CONFIG_VSX /* VSR status */
arch/powerpc/kernel/asm-offsets.c +2 -0
@@ -95,12 +95,14 @@ int main(void)DEFINE (THREAD_FPSTATE , offsetof(struct thread_struct , fp_state));DEFINE (THREAD_FPSAVEAREA , offsetof(struct thread_struct , fp_save_area));DEFINE (FPSTATE_FPSCR , offsetof(struct thread_fp_state , fpscr)); +DEFINE (THREAD_LOAD_FP , offsetof(struct thread_struct , load_fp));#ifdef CONFIG_ALTIVEC DEFINE (THREAD_VRSTATE , offsetof(struct thread_struct , vr_state));DEFINE (THREAD_VRSAVEAREA , offsetof(struct thread_struct , vr_save_area));DEFINE (THREAD_VRSAVE , offsetof(struct thread_struct , vrsave));DEFINE (THREAD_USED_VR , offsetof(struct thread_struct , used_vr));DEFINE (VRSTATE_VSCR , offsetof(struct thread_vr_state , vscr)); +DEFINE (THREAD_LOAD_VEC , offsetof(struct thread_struct , load_vec));#endif /* CONFIG_ALTIVEC */ #ifdef CONFIG_VSX DEFINE (THREAD_USED_VSR , offsetof(struct thread_struct , used_vsr));
arch/powerpc/kernel/entry_64.S +18 -3
@@ -210,7 +210,20 @@ system_call: /* label this so stack traces look sane */ li r11,-MAX_ERRNO andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK) bne- syscall_exit_work - cmpld r3,r11 + + andi. r0,r8,MSR_FP + beq 2f +#ifdef CONFIG_ALTIVEC + andis. r0,r8,MSR_VEC@h + bne 3f +#endif +2: addi r3,r1,STACK_FRAME_OVERHEAD + bl restore_math + ld r8,_MSR(r1) + ld r3,RESULT(r1) + li r11,-MAX_ERRNO + +3: cmpld r3,r11 ld r5,_CCR(r1) bge- syscall_error .Lsyscall_error_cont:
@@ -602,8 +615,8 @@ _GLOBAL(ret_from_except_lite) /* Check current_thread_info()->flags */ andi. r0,r4,_TIF_USER_WORK_MASK -#ifdef CONFIG_PPC_BOOK3E bne 1f +#ifdef CONFIG_PPC_BOOK3E /* * Check to see if the dbcr0 register is set up to debug. * Use the internal debug mode bit to do this.
@@ -618,7 +631,9 @@ _GLOBAL(ret_from_except_lite) mtspr SPRN_DBSR,r10 b restore #else - beq restore + addi r3,r1,STACK_FRAME_OVERHEAD + bl restore_math + b restore #endif 1: andi. r0,r4,_TIF_NEED_RESCHED beq 2f
arch/powerpc/kernel/fpu.S +4 -0
@@ -130,6 +130,10 @@ END_FTR_SECTION_IFSET(CPU_FTR_VSX) or r12,r12,r4 std r12,_MSR(r1) #endif + /* Don't care if r4 overflows, this is desired behaviour */ + lbz r4,THREAD_LOAD_FP(r5) + addi r4,r4,1 + stb r4,THREAD_LOAD_FP(r5) addi r10,r5,THREAD_FPSTATE lfd fr0,FPSTATE_FPSCR(r10) MTFSF_L(fr0)
arch/powerpc/kernel/process.c +77 -11
127 lines not on this page · raw message
arch/powerpc/kernel/vector.S +4 -0
@@ -91,6 +91,10 @@ _GLOBAL(load_up_altivec) oris r12,r12,MSR_VEC@h std r12,_MSR(r1) #endif + /* Don't care if r4 overflows, this is desired behaviour */ + lbz r4,THREAD_LOAD_VEC(r5) + addi r4,r4,1 + stb r4,THREAD_LOAD_VEC(r5) addi r6,r5,THREAD_VRSTATE li r4,1 li r10,VRSTATE_VSCR
Signature · 1 line
2.7.1
PATCH v5 6/9 powerpc: Prepare for splitting giveup_{fpu, altivec, vsx} in two
In reply to Cyril BurThis prepares for the decoupling of saving {fpu,altivec,vsx} registers and marking {fpu,altivec,vsx} as being unused by a thread.
Currently giveup_{fpu,altivec,vsx}() does both however optimisations to task switching can be made if these two operations are decoupled. save_all() will permit the saving of registers to thread structs and leave threads MSR with bits enabled.
This patch introduces no functional change.
--- arch/powerpc/include/asm/reg.h | 8 ++++++++ arch/powerpc/include/asm/switch_to.h | 7 +++++++ arch/powerpc/kernel/process.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/reg.h +8 -0
@@ -75,6 +75,14 @@#define MSR_HV 0#endif +/* +* To be used in shared book E/book S, this avoids needing to worry about +* book S/book E in shared code +*/ +#ifndef MSR_SPE +#define MSR_SPE 0 +#endif +#define MSR_VEC __MASK(MSR_VEC_LG)/* Enable AltiVec */ #define MSR_VSX __MASK(MSR_VSX_LG)/* Enable VSX */ #define MSR_POW __MASK(MSR_POW_LG)/* Enable Power Management */
arch/powerpc/include/asm/switch_to.h +7 -0
@@ -34,6 +34,7 @@ static inline void disable_kernel_fp(void) msr_check_and_clear(MSR_FP); }#else +static inline void __giveup_fpu (struct task_struct *t) { }static inline void flush_fp_to_thread (struct task_struct *t) { }#endif
@@ -46,6 +47,8 @@ static inline void disable_kernel_altivec(void) {msr_check_and_clear (MSR_VEC ); } +#else +static inline void __giveup_altivec (struct task_struct *t) { }#endif #ifdef CONFIG_VSX
@@ -57,6 +60,8 @@ static inline void disable_kernel_vsx(void) {msr_check_and_clear (MSR_FP |MSR_VEC |MSR_VSX ); } +#else +static inline void __giveup_vsx (struct task_struct *t) { }#endif #ifdef CONFIG_SPE
@@ -68,6 +73,8 @@ static inline void disable_kernel_spe(void) {msr_check_and_clear (MSR_SPE ); } +#else +static inline void __giveup_spe (struct task_struct *t) { }#endif static inline void clear_task_ebb (struct task_struct *t)
arch/powerpc/kernel/process.c +30 -1
@@ -444,12 +444,41 @@ void restore_math(struct pt_regs *regs) regs->msr = msr; } +void save_all (struct task_struct *tsk) +{ +unsigned long usermsr; + +if (!tsk->thread.regs) +return ; + + usermsr = tsk->thread.regs->msr; + +if ((usermsr & msr_all_available) ==0 ) +return ; + +msr_check_and_set (msr_all_available); + +if (usermsr &MSR_FP ) +__giveup_fpu (tsk); + +if (usermsr &MSR_VEC ) +__giveup_altivec (tsk); + +if (usermsr &MSR_VSX ) +__giveup_vsx (tsk); + +if (usermsr &MSR_SPE ) +__giveup_spe (tsk); + +msr_check_and_clear (msr_all_available); +} +void flush_all_to_thread (struct task_struct *tsk) {if (tsk->thread.regs) {preempt_disable ();BUG_ON (tsk != current); -giveup_all (tsk); +save_all (tsk);#ifdef CONFIG_SPE if (tsk->thread.regs->msr &MSR_SPE )
Signature · 1 line
2.7.1
PATCH v5 7/9 powerpc: Add the ability to save FPU without giving it up
In reply to Cyril BurThis patch adds the ability to be able to save the FPU registers to the thread struct without giving up (disabling the facility) next time the process returns to userspace.
This patch optimises the thread copy path (as a result of a fork() or clone()) so that the parent thread can return to userspace with hot registers avoiding a possibly pointless reload of FPU register state.
--- arch/powerpc/include/asm/switch_to.h | 3 ++- arch/powerpc/kernel/fpu.S | 21 ++++----------------- arch/powerpc/kernel/process.c | 12 +++++++++++- 3 files changed, 17 insertions(+), 19 deletions(-)
arch/powerpc/include/asm/switch_to.h +2 -1
@@ -28,13 +28,14 @@ extern void giveup_all(struct task_struct *);extern void enable_kernel_fp (void );extern void flush_fp_to_thread (struct task_struct *);extern void giveup_fpu (struct task_struct *); -extern void __giveup_fpu (struct task_struct *); +extern void save_fpu (struct task_struct *);static inline void disable_kernel_fp (void ) {msr_check_and_clear (MSR_FP ); }#else static inline void __giveup_fpu (struct task_struct *t) { } +static inline void save_fpu (struct task_struct *t) { }static inline void flush_fp_to_thread (struct task_struct *t) { }#endif
arch/powerpc/kernel/fpu.S +4 -17
@@ -143,33 +143,20 @@ END_FTR_SECTION_IFSET(CPU_FTR_VSX) blr /* - * __giveup_fpu(tsk) - * Disable FP for the task given as the argument, - * and save the floating-point registers in its thread_struct. + * save_fpu(tsk) + * Save the floating-point registers in its thread_struct. * Enables the FPU for use in the kernel on return. */ -_GLOBAL(__giveup_fpu) +_GLOBAL(save_fpu) addi r3,r3,THREAD /* want THREAD of task */ PPC_LL r6,THREAD_FPSAVEAREA(r3) PPC_LL r5,PT_REGS(r3) PPC_LCMPI 0,r6,0 bne 2f addi r6,r3,THREAD_FPSTATE -2: PPC_LCMPI 0,r5,0 - SAVE_32FPVSRS(0, R4, R6) +2: SAVE_32FPVSRS(0, R4, R6) mffs fr0 stfd fr0,FPSTATE_FPSCR(r6) - beq 1f - PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5) - li r3,MSR_FP|MSR_FE0|MSR_FE1 -#ifdef CONFIG_VSX -BEGIN_FTR_SECTION - oris r3,r3,MSR_VSX@h -END_FTR_SECTION_IFSET(CPU_FTR_VSX) -#endif - andc r4,r4,r3 /* disable FP for previous task */ - PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5) -1: blr /*
arch/powerpc/kernel/process.c +11 -1
@@ -133,6 +133,16 @@ void __msr_check_and_clear(unsigned long bits)EXPORT_SYMBOL (__msr_check_and_clear);#ifdef CONFIG_PPC_FPU +void __giveup_fpu (struct task_struct *tsk) +{ +save_fpu (tsk); + tsk->thread.regs->msr &= ~MSR_FP ; +#ifdef CONFIG_VSX +if (cpu_has_feature (CPU_FTR_VSX )) + tsk->thread.regs->msr &= ~MSR_VSX ; +#endif +} +void giveup_fpu (struct task_struct *tsk) {check_if_tm_restore_required (tsk);
@@ -459,7 +469,7 @@ void save_all(struct task_struct *tsk)msr_check_and_set (msr_all_available);if (usermsr &MSR_FP ) -__giveup_fpu (tsk); +save_fpu (tsk);if (usermsr &MSR_VEC )__giveup_altivec (tsk);
Signature · 1 line
2.7.1
PATCH v5 8/9 powerpc: Add the ability to save Altivec without giving it up
In reply to Cyril BurThis patch adds the ability to be able to save the VEC registers to the thread struct without giving up (disabling the facility) next time the process returns to userspace.
This patch builds on a previous optimisation for the FPU registers in the thread copy path to avoid a possibly pointless reload of VEC state.
--- arch/powerpc/include/asm/switch_to.h | 3 ++- arch/powerpc/kernel/process.c | 12 +++++++++++- arch/powerpc/kernel/vector.S | 24 ++++-------------------- 3 files changed, 17 insertions(+), 22 deletions(-)
arch/powerpc/include/asm/switch_to.h +2 -1
@@ -43,12 +43,13 @@ static inline void flush_fp_to_thread(struct task_struct *t) { }extern void enable_kernel_altivec (void );extern void flush_altivec_to_thread (struct task_struct *);extern void giveup_altivec (struct task_struct *); -extern void __giveup_altivec (struct task_struct *); +extern void save_altivec (struct task_struct *);static inline void disable_kernel_altivec (void ) {msr_check_and_clear (MSR_VEC ); }#else +static inline void save_altivec (struct task_struct *t) { }static inline void __giveup_altivec (struct task_struct *t) { }#endif
arch/powerpc/kernel/process.c +11 -1
@@ -213,6 +213,16 @@ static int restore_fp(struct task_struct *tsk) { return 0; }#ifdef CONFIG_ALTIVEC #define loadvec (thr) ((thr).load_vec) +static void __giveup_altivec (struct task_struct *tsk) +{ +save_altivec (tsk); + tsk->thread.regs->msr &= ~MSR_VEC ; +#ifdef CONFIG_VSX +if (cpu_has_feature (CPU_FTR_VSX )) + tsk->thread.regs->msr &= ~MSR_VSX ; +#endif +} +void giveup_altivec (struct task_struct *tsk) {check_if_tm_restore_required (tsk);
@@ -472,7 +482,7 @@ void save_all(struct task_struct *tsk)save_fpu (tsk);if (usermsr &MSR_VEC ) -__giveup_altivec (tsk); +save_altivec (tsk);if (usermsr &MSR_VSX )__giveup_vsx (tsk);
arch/powerpc/kernel/vector.S +4 -20
@@ -106,36 +106,20 @@ _GLOBAL(load_up_altivec) blr /* - * __giveup_altivec(tsk) - * Disable VMX for the task given as the argument, - * and save the vector registers in its thread_struct. + * save_altivec(tsk) + * Save the vector registers to its thread_struct */ -_GLOBAL(__giveup_altivec) +_GLOBAL(save_altivec) addi r3,r3,THREAD /* want THREAD of task */ PPC_LL r7,THREAD_VRSAVEAREA(r3) PPC_LL r5,PT_REGS(r3) PPC_LCMPI 0,r7,0 bne 2f addi r7,r3,THREAD_VRSTATE -2: PPC_LCMPI 0,r5,0 - SAVE_32VRS(0,r4,r7) +2: SAVE_32VRS(0,r4,r7) mfvscr v0 li r4,VRSTATE_VSCR stvx v0,r4,r7 - beq 1f - PPC_LL r4,_MSR-STACK_FRAME_OVERHEAD(r5) -#ifdef CONFIG_VSX -BEGIN_FTR_SECTION - lis r3,(MSR_VEC|MSR_VSX)@h -FTR_SECTION_ELSE - lis r3,MSR_VEC@h -ALT_FTR_SECTION_END_IFSET(CPU_FTR_VSX) -#else - lis r3,MSR_VEC@h -#endif - andc r4,r4,r3 /* disable FP for previous task */ - PPC_STL r4,_MSR-STACK_FRAME_OVERHEAD(r5) -1: blr #ifdef CONFIG_VSX
Signature · 1 line
2.7.1
PATCH v5 2/9 selftests/powerpc: Test preservation of FPU and VMX regs across preemption
In reply to Cyril BurLoop in assembly checking the registers with many threads.
--- tools/testing/selftests/powerpc/math/.gitignore | 2 + tools/testing/selftests/powerpc/math/Makefile | 5 +- tools/testing/selftests/powerpc/math/fpu_asm.S | 36 +++++++ tools/testing/selftests/powerpc/math/fpu_preempt.c | 113 +++++++++++++++++++++ tools/testing/selftests/powerpc/math/vmx_asm.S | 43 +++++++- tools/testing/selftests/powerpc/math/vmx_preempt.c | 112 ++++++++++++++++++++ 6 files changed, 308 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/powerpc/math/fpu_preempt.c create mode 100644 tools/testing/selftests/powerpc/math/vmx_preempt.c
tools/testing/selftests/powerpc/math/.gitignore +2 -0
@@ -1,2 +1,4 @@ fpu_syscall vmx_syscall +fpu_preempt +vmx_preempt
tools/testing/selftests/powerpc/math/Makefile +4 -1
@@ -1,4 +1,4 @@ -TEST_PROGS := fpu_syscall vmx_syscall +TEST_PROGS := fpu_syscall fpu_preempt vmx_syscall vmx_preempt all: $(TEST_PROGS)
@@ -8,7 +8,10 @@ $(TEST_PROGS): ../harness.c $(TEST_PROGS): CFLAGS = $(filter-out -flto,$(CFLAGS) -O2 -g -pthread -m64 -maltivec) fpu_syscall: fpu_asm.S +fpu_preempt: fpu_asm.S + vmx_syscall: vmx_asm.S +vmx_preempt: vmx_asm.S include ../../lib.mk
tools/testing/selftests/powerpc/math/fpu_asm.S +36 -0
@@ -159,3 +159,39 @@ FUNC_START(test_fpu) POP_BASIC_STACK(256) blr FUNC_END(test_fpu) + +#int preempt_fpu(double *darray, int *threads_running, int *running) +#On starting will (atomically) decrement not_ready as a signal that the FPU +#has been loaded with darray. Will proceed to check the validity of the FPU +#registers while running is not zero. +FUNC_START(preempt_fpu) + PUSH_BASIC_STACK(256) + std r3,STACK_FRAME_PARAM(0)(sp) #double *darray + std r4,STACK_FRAME_PARAM(1)(sp) #int *threads_starting + std r5,STACK_FRAME_PARAM(2)(sp) #int *running + PUSH_FPU(STACK_FRAME_LOCAL(3,0)) + + bl load_fpu + nop + + #Atomic DEC + ld r3,STACK_FRAME_PARAM(1)(sp) +1: lwarx r4,0,r3 + addi r4,r4,-1 + stwcx. r4,0,r3 + bne- 1b + +2: ld r3,STACK_FRAME_PARAM(0)(sp) + bl check_fpu + nop + cmpdi r3,0 + bne 3f + ld r4,STACK_FRAME_PARAM(2)(sp) + ld r5,0(r4) + cmpwi r5,0 + bne 2b + +3: POP_FPU(STACK_FRAME_LOCAL(3,0)) + POP_BASIC_STACK(256) + blr +FUNC_END(preempt_fpu)
tools/testing/selftests/powerpc/math/fpu_preempt.c new file +113 -0
113 lines not on this page · raw message
tools/testing/selftests/powerpc/math/vmx_asm.S +41 -2
70 lines not on this page · raw message
tools/testing/selftests/powerpc/math/vmx_preempt.c new file +112 -0
112 lines not on this page · raw message
Signature · 1 line
2.7.1
PATCH v5 9/9 powerpc: Add the ability to save VSX without giving it up
In reply to Cyril BurThis patch adds the ability to be able to save the VSX registers to the thread struct without giving up (disabling the facility) next time the process returns to userspace.
This patch builds on a previous optimisation for the FPU and VEC registers in the thread copy path to avoid a possibly pointless reload of VSX state.
--- arch/powerpc/include/asm/switch_to.h | 4 ---- arch/powerpc/kernel/ppc_ksyms.c | 4 ---- arch/powerpc/kernel/process.c | 42 +++++++++++++++++++++++++----------- arch/powerpc/kernel/vector.S | 17 --------------- 4 files changed, 30 insertions(+), 37 deletions(-)
arch/powerpc/include/asm/switch_to.h +0 -4
@@ -56,14 +56,10 @@ static inline void __giveup_altivec(struct task_struct *t) { }#ifdef CONFIG_VSX extern void enable_kernel_vsx (void );extern void flush_vsx_to_thread (struct task_struct *); -extern void giveup_vsx (struct task_struct *); -extern void __giveup_vsx (struct task_struct *);static inline void disable_kernel_vsx (void ) {msr_check_and_clear (MSR_FP |MSR_VEC |MSR_VSX ); } -#else -static inline void __giveup_vsx (struct task_struct *t) { }#endif #ifdef CONFIG_SPE
arch/powerpc/kernel/ppc_ksyms.c +0 -4
@@ -28,10 +28,6 @@ EXPORT_SYMBOL(load_vr_state);EXPORT_SYMBOL (store_vr_state);#endif -#ifdef CONFIG_VSX -EXPORT_SYMBOL_GPL (__giveup_vsx); -#endif -#ifdef CONFIG_EPAPR_PARAVIRT EXPORT_SYMBOL (epapr_hypercall_start);#endif
arch/powerpc/kernel/process.c +30 -12
69 lines not on this page · raw message
arch/powerpc/kernel/vector.S +0 -17
@@ -151,23 +151,6 @@ _GLOBAL(load_up_vsx) std r12,_MSR(r1) b fast_exception_return -/* - * __giveup_vsx(tsk) - * Disable VSX for the task given as the argument. - * Does NOT save vsx registers. - */ -_GLOBAL(__giveup_vsx) - addi r3,r3,THREAD /* want THREAD of task */ - ld r5,PT_REGS(r3) - cmpdi 0,r5,0 - beq 1f - ld r4,_MSR-STACK_FRAME_OVERHEAD(r5) - lis r3,MSR_VSX@h - andc r4,r4,r3 /* disable VSX for previous task */ - std r4,_MSR-STACK_FRAME_OVERHEAD(r5) -1: - blr - #endif /* CONFIG_VSX */
Signature · 1 line
2.7.1
Re: [PATCH v5 1/9] selftests/powerpc: Test the preservation of FPU and VMX regs across syscall
In reply to Cyril BurQuoted 55 lines · Cyril Bur
Test that the non volatile floating point and Altivec registers get correctly preserved across the
fork()syscall.
fork()works nicely for this purpose, the registers should be the same for both parent and childSigned-off-by Cyril Bur <[email protected]>--- tools/testing/selftests/powerpc/Makefile | 3 +- tools/testing/selftests/powerpc/basic_asm.h | 62 +++++++ tools/testing/selftests/powerpc/math/.gitignore | 2 + tools/testing/selftests/powerpc/math/Makefile | 16 ++ tools/testing/selftests/powerpc/math/fpu_asm.S | 161 +++++++++++++++++ tools/testing/selftests/powerpc/math/fpu_syscall.c | 90 ++++++++++ tools/testing/selftests/powerpc/math/vmx_asm.S | 195 +++++++++++++++++++++ tools/testing/selftests/powerpc/math/vmx_syscall.c | 91 ++++++++++ 8 files changed, 619 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/powerpc/basic_asm.h create mode 100644 tools/testing/selftests/powerpc/math/.gitignore create mode 100644 tools/testing/selftests/powerpc/math/Makefile create mode 100644 tools/testing/selftests/powerpc/math/fpu_asm.S create mode 100644 tools/testing/selftests/powerpc/math/fpu_syscall.c create mode 100644 tools/testing/selftests/powerpc/math/vmx_asm.S create mode 100644 tools/testing/selftests/powerpc/math/vmx_syscall.ctools/testing/selftests/powerpc/Makefile +2
-1@@ -22,7 +22,8 @@ SUB_DIRS = benchmarks \ switch_endian \ syscalls \ tm \ - vphn + vphn \ + math endiftools/testing/selftests/powerpc/basic_asm.h new file +10
-0@@ -0,0 +1,62 @@ +#include <ppc-asm.h> +#include <asm/unistd.h> + +#if defined(_CALL_ELF) && _CALL_ELF ==2 +#define STACK_FRAME_MIN_SIZE 32 +#define STACK_FRAME_TOC_POS 24 +#define __STACK_FRAME_PARAM (_param) (32 + ((_param)*8)) +#define __STACK_FRAME_LOCAL (_num_params,_var_num) ((STACK_FRAME_PARAM(_num_params)) + ((_var_num)*8)) +#else +#define STACK_FRAME_MIN_SIZE 112
tools/testing/selftests/powerpc/basic_asm.h line 20
Quoted 10 lines
tools/testing/selftests/powerpc/basic_asm.h new file +10
-0+#define STACK_FRAME_TOC_POS 40 +#define __STACK_FRAME_PARAM (i) (48 + ((i)*8)) +/* +* Caveat: if a function passed more than 8 params, the caller will have +* made more space... this should be reflected by this C code. +* if (_num_params > 8) +* total = 112 + ((_num_params - 8) * 8) +* +* And substitute the '112' for 'total' in the macro. Doable in preprocessor for ASM? +*/
Per my understanding, the parameter save area is only for parameters to functions that *we* call. And since we control that, I don't think we need to worry about having more than 8 parameters.
tools/testing/selftests/powerpc/basic_asm.h line 26
Quoted 6 lines
tools/testing/selftests/powerpc/basic_asm.h new file +6
-0+#define __STACK_FRAME_LOCAL (_num_params,_var_num) (112 + ((_var_num)*8)) +#endif +/* Parameter x saved to the stack */ +#define STACK_FRAME_PARAM (var) __STACK_FRAME_PARAM(var) +/* Local variable x saved to the stack after x parameters */ +#define STACK_FRAME_LOCAL (num_params,var) __STACK_FRAME_LOCAL(num_params,var)
So this works, but I'm wondering if this is really worth the code complexity - every use needs to determine appropriate extra stack space, the number of parameters to save and so on. This is after all for selftests and so, we probably don't need to be precise in stack space usage. We can get away using a larger fixed size stack. That will simplify a lot of the code further on and future tests won't need to bother with all the details.
So, how about (not tested):
#define STACK_FRAME_PARAM_SAVE_AREA 64
#define STACK_FRAME_LOCAL_VAR 64
#define STACK_FRAME_FPU_SAVE_AREA 144
#define STACK_FRAME_GPR_SAVE_AREA 144
#define STACK_FRAME_VMX_SAVE_AREA 192
#if defined(_CALL_ELF) && _CALL_ELF == 2
#define STACK_FRAME_HEADER 32
#define STACK_FRAME_VRSAVE 0
#else
#define STACK_FRAME_HEADER 48
#define STACK_FRAME_VRSAVE 16
#endif
#define STACK_FRAME_SIZE (STACK_FRAME_HEADER + \ STACK_FRAME_VRSAVE + \ STACK_FRAME_PARAM_SAVE_AREA + \ STACK_FRAME_LOCAL_VAR + \ STACK_FRAME_FPU_SAVE_AREA + \ STACK_FRAME_GPR_SAVE_AREA + \ STACK_FRAME_VMX_SAVE_AREA)
/* Accessors */
#define STACK_FRAME_LR_POS 16
#define STACK_FRAME_CR_POS 8
#if defined(_CALL_ELF) && _CALL_ELF == 2
#define STACK_FRAME_TOC_POS 24
#else
#define STACK_FRAME_TOC_POS 40
#endif
#define STACK_FRAME_PARAM(i) (STACK_FRAME_HEADER + ((i) * 8))
#define STACK_FRAME_LOCAL(i) (STACK_FRAME_HEADER + \ STACK_FRAME_PARAM_SAVE_AREA + \ ((i) * 8))
/* The below are referenced from the previous stack pointer */
#define STACK_FRAME_FPU(i) (STACK_FRAME_SIZE - ((32 - (i)) * 8))
#define STACK_FRAME_GPR(i) (STACK_FRAME_SIZE - \ STACK_FRAME_FPU_SAVE_AREA - \ ((32 - (i)) * 8)) #define STACK_FRAME_VMX(i) (STACK_FRAME_SIZE - \ STACK_FRAME_FPU_SAVE_AREA - \ STACK_FRAME_GPR_SAVE_AREA - \ STACK_FRAME_VRSAVE - \ ((32 - (i)) * 16)
Quoted 26 lines
tools/testing/selftests/powerpc/basic_asm.h new file +26
-0+#define STACK_FRAME_LR_POS 16 +#define STACK_FRAME_CR_POS 8 + +#define LOAD_REG_IMMEDIATE (reg,expr) \ + lis reg,(expr)@highest; \ + ori reg,reg,(expr)@higher; \ + rldicr reg,reg,32,31; \ + oris reg,reg,(expr)@high; \ + ori reg,reg,(expr)@l; + +/* It is very important to note here that _extra is the extra amount of +* stack space needed. +* This space must be accessed using STACK_FRAME_PARAM() or +* STACK_FRAME_LOCAL() macros! +* +* r1 and r2 are not defined in ppc-asm.h (instead they are defined as sp +* and toc). Kernel programmers tend to prefer rX even for r1 and r2, hence +* %1 and %r2. r0 is defined in ppc-asm.h and therefore %r0 gets +* preprocessed incorrectly, hence r0. +*/ +#define PUSH_BASIC_STACK (_extra) \ + mflr r0; \ + std r0,STACK_FRAME_LR_POS(%r1); \ + stdu %r1,-(_extra + STACK_FRAME_MIN_SIZE)(%r1); \ + mfcr r0; \ + stw r0,STACK_FRAME_CR_POS(%r1); \
tools/testing/selftests/powerpc/basic_asm.h line 62
Quoted 10 lines
tools/testing/selftests/powerpc/basic_asm.h new file +10
-0+ std %r2,STACK_FRAME_TOC_POS(%r1); + +#define POP_BASIC_STACK (_extra) \ + ld %r2,STACK_FRAME_TOC_POS(%r1); \ + lwz r0,STACK_FRAME_CR_POS(%r1); \ + mtcr r0; \ + addi %r1,%r1,(_extra + STACK_FRAME_MIN_SIZE); \ + ld r0,STACK_FRAME_LR_POS(%r1); \ + mtlr r0; +
So, these become:
#define PUSH_BASIC_STACK() \ mflr r0; \ std r0,STACK_FRAME_LR_POS(%r1); \ stdu %r1,-(STACK_FRAME_SIZE)(%r1); \ mfcr r0; \ stw r0,STACK_FRAME_CR_POS(%r1); \ std %r2,STACK_FRAME_TOC_POS(%r1);
#define POP_BASIC_STACK() \ ld %r2,STACK_FRAME_TOC_POS(%r1); \ lwz r0,STACK_FRAME_CR_POS(%r1); \ mtcr r0; \ addi %r1,%r1,(STACK_FRAME_SIZE); \ ld r0,STACK_FRAME_LR_POS(%r1); \ mtlr r0;
Quoted 57 lines
tools/testing/selftests/powerpc/math/.gitignore new file +2
-0@@ -0,0 +1,2 @@ +fpu_syscall +vmx_syscalltools/testing/selftests/powerpc/math/Makefile new file +16
-0@@ -0,0 +1,16 @@ +TEST_PROGS := fpu_syscall vmx_syscall + +all: $(TEST_PROGS) + +#The general powerpc makefile adds -flto. This isn't interacting well with the custom ASM. +#filter-out -flto to avoid false failures. +$(TEST_PROGS): ../harness.c +$(TEST_PROGS): CFLAGS = $(filter-out -flto,$(CFLAGS) -O2 -g -pthread -m64 -maltivec) + +fpu_syscall: fpu_asm.S +vmx_syscall: vmx_asm.S + +include ../../lib.mk + +clean: + rm -f $(TEST_PROGS) *.otools/testing/selftests/powerpc/math/fpu_asm.S new file +21
-0@@ -0,0 +1,161 @@ +/* + * Copyright 2015, Cyril Bur, IBM Corp. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + +#include "../basic_asm.h" + +#define PUSH_FPU(pos) \ + stfd f14,pos(sp); \ + stfd f15,pos+8(sp); \ + stfd f16,pos+16(sp); \ + stfd f17,pos+24(sp); \ + stfd f18,pos+32(sp); \ + stfd f19,pos+40(sp); \ + stfd f20,pos+48(sp); \ + stfd f21,pos+56(sp); \ + stfd f22,pos+64(sp); \
tools/testing/selftests/powerpc/math/fpu_asm.S line 31
Quoted 10 lines
tools/testing/selftests/powerpc/math/fpu_asm.S new file +10
-0+ stfd f23,pos+72(sp); \ + stfd f24,pos+80(sp); \ + stfd f25,pos+88(sp); \ + stfd f26,pos+96(sp); \ + stfd f27,pos+104(sp); \ + stfd f28,pos+112(sp); \ + stfd f29,pos+120(sp); \ + stfd f30,pos+128(sp); \ + stfd f31,pos+136(sp); +
#define PUSH_FPU() \ stfd f14,STACK_FRAME_FPU(14)(sp); \ stfd f15,STACK_FRAME_FPU(15)(sp); \ stfd f16,STACK_FRAME_FPU(16)(sp); \ stfd f17,STACK_FRAME_FPU(17)(sp); \
... and so on without need for a parameter.
Quoted 6 lines
tools/testing/selftests/powerpc/math/fpu_asm.S new file +6
-0+#define POP_FPU(pos) \ + lfd f14,pos(sp); \ + lfd f15,pos+8(sp); \ + lfd f16,pos+16(sp); \ + lfd f17,pos+24(sp); \ + lfd f18,pos+32(sp); \
<snip>
tools/testing/selftests/powerpc/math/fpu_asm.S line 143
Quoted 9 lines
tools/testing/selftests/powerpc/math/fpu_asm.S new file +9
-0+ +FUNC_START(test_fpu) + #r3 holds pointer to where to put the result of fork + #r4 holds pointer to the pid + #f14-f31 are non volatiles + PUSH_BASIC_STACK(256) + std r3,STACK_FRAME_PARAM(0)(sp) #Address of darray + std r4,STACK_FRAME_PARAM(1)(sp) #Address of pid + PUSH_FPU(STACK_FRAME_LOCAL(2,0))
The above now becomes:FUNC_START(test_fpu)
#r3 holds pointer to where to put the result of fork #r4 holds pointer to the pid
#f14-f31 are non volatiles PUSH_BASIC_STACK()
std r3,STACK_FRAME_PARAM(0)(sp) #Address of darray
std r4,STACK_FRAME_PARAM(1)(sp) #Address of pid
PUSH_FPU()
Also note that as per the ABI, the floating point registers save area is just below the previous stack pointer.
Quoted 6 lines
tools/testing/selftests/powerpc/math/fpu_asm.S new file +6
-0+ + bl load_fpu + nop + li r0,__NR_fork + sc +
tools/testing/selftests/powerpc/math/fpu_asm.S line 159
Quoted 10 lines
tools/testing/selftests/powerpc/math/fpu_asm.S new file +10
-0+ #pass the result of the fork to the caller + ld r9,STACK_FRAME_PARAM(1)(sp) + std r3,0(r9) + + ld r3,STACK_FRAME_PARAM(0)(sp) + bl check_fpu + nop + + POP_FPU(STACK_FRAME_LOCAL(2,0)) + POP_BASIC_STACK(256)
And, just:
POP_FPU() POP_BASIC_STACK()
In my opinion, that's much simpler.
- Naveen
Re: [PATCH v5 1/9] selftests/powerpc: Test the preservation of FPU and VMX regs across syscall
Quoted 62 lines · On Wed, 24 Feb 2016 19:57:38 +0530 "Naveen N. Rao"…
Quoted 61 lines · Cyril Bur
Test that the non volatile floating point and Altivec registers get correctly preserved across the
fork()syscall.
fork()works nicely for this purpose, the registers should be the same for both parent and childSigned-off-by Cyril Bur <[email protected]>--- tools/testing/selftests/powerpc/Makefile | 3 +- tools/testing/selftests/powerpc/basic_asm.h | 62 +++++++ tools/testing/selftests/powerpc/math/.gitignore | 2 + tools/testing/selftests/powerpc/math/Makefile | 16 ++ tools/testing/selftests/powerpc/math/fpu_asm.S | 161 +++++++++++++++++ tools/testing/selftests/powerpc/math/fpu_syscall.c | 90 ++++++++++ tools/testing/selftests/powerpc/math/vmx_asm.S | 195 +++++++++++++++++++++ tools/testing/selftests/powerpc/math/vmx_syscall.c | 91 ++++++++++ 8 files changed, 619 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/powerpc/basic_asm.h create mode 100644 tools/testing/selftests/powerpc/math/.gitignore create mode 100644 tools/testing/selftests/powerpc/math/Makefile create mode 100644 tools/testing/selftests/powerpc/math/fpu_asm.S create mode 100644 tools/testing/selftests/powerpc/math/fpu_syscall.c create mode 100644 tools/testing/selftests/powerpc/math/vmx_asm.S create mode 100644 tools/testing/selftests/powerpc/math/vmx_syscall.ctools/testing/selftests/powerpc/Makefile +2
-1@@ -22,7 +22,8 @@ SUB_DIRS = benchmarks \ switch_endian \ syscalls \ tm \ - vphn + vphn \ + math endiftools/testing/selftests/powerpc/basic_asm.h new file +16
-0@@ -0,0 +1,62 @@ +#include <ppc-asm.h> +#include <asm/unistd.h> + +#if defined(_CALL_ELF) && _CALL_ELF ==2 +#define STACK_FRAME_MIN_SIZE 32 +#define STACK_FRAME_TOC_POS 24 +#define __STACK_FRAME_PARAM (_param) (32 + ((_param)*8)) +#define __STACK_FRAME_LOCAL (_num_params,_var_num) ((STACK_FRAME_PARAM(_num_params)) + ((_var_num)*8)) +#else +#define STACK_FRAME_MIN_SIZE 112 +#define STACK_FRAME_TOC_POS 40 +#define __STACK_FRAME_PARAM (i) (48 + ((i)*8)) +/* +* Caveat: if a function passed more than 8 params, the caller will have +* made more space... this should be reflected by this C code. +* if (_num_params > 8)
Quoted 9 lines
tools/testing/selftests/powerpc/basic_asm.h line 20
Quoted 4 lines
tools/testing/selftests/powerpc/basic_asm.h new file +4
-0+* total = 112 + ((_num_params - 8) * 8) +* +* And substitute the '112' for 'total' in the macro. Doable in preprocessor for ASM? +*/ Per my understanding, the parameter save area is only for parameters to functions that *we* call. And since we control that, I don't think we need to worry about having more than 8 parameters.
Yes, I just thought I'd put that there to prevent anyone blindly reusing this macro somewhere and getting stung. But you're correct, we don't need to worry about this caveat for this code.
Quoted 7 lines
tools/testing/selftests/powerpc/basic_asm.h line 26
Quoted 6 lines
tools/testing/selftests/powerpc/basic_asm.h new file +6
-0+#define __STACK_FRAME_LOCAL (_num_params,_var_num) (112 + ((_var_num)*8)) +#endif +/* Parameter x saved to the stack */ +#define STACK_FRAME_PARAM (var) __STACK_FRAME_PARAM(var) +/* Local variable x saved to the stack after x parameters */ +#define STACK_FRAME_LOCAL (num_params,var) __STACK_FRAME_LOCAL(num_params,var)
Quoted 8 lines
So this works, but I'm wondering if this is really worth the code complexity - every use needs to determine appropriate extra stack space, the number of parameters to save and so on. This is after all for selftests and so, we probably don't need to be precise in stack space usage. We can get away using a larger fixed size stack. That will simplify a lot of the code further on and future tests won't need to bother with all the details.
So I agree that we don't need to be precise about stack space at all (I'm sure you noticed all my stack pushes and pops are very overestimated in size).
I should probably go back to basics and explain how these macros started. In writing all this I got fed up of typing the PUSH_BASIC_STACK and POP_BASIC_STACK macro out at the start of each function. I wasn't trying to macro out the entire calling convention and honestly I don't think it is a good idea. The more easy to use/abstracted the macros get the less flexible they become. These being selftests, I expect that people might want to do funky/questionable/hacky things, flexibility in the macros might help with that.
I feel like if we want to go down the route of fully abstracting out everything then perhaps we should be considering C...
Quoted 239 lines
So, how about (not tested):
#define
STACK_FRAME_PARAM_SAVE_AREA64
#defineSTACK_FRAME_LOCAL_VAR64
#defineSTACK_FRAME_FPU_SAVE_AREA144
#defineSTACK_FRAME_GPR_SAVE_AREA144
#defineSTACK_FRAME_VMX_SAVE_AREA192#if
defined(_CALL_ELF)&&_CALL_ELF== 2
#defineSTACK_FRAME_HEADER32
#defineSTACK_FRAME_VRSAVE0
#else
#defineSTACK_FRAME_HEADER48
#defineSTACK_FRAME_VRSAVE16
#endif#define STACK_FRAME_SIZE (STACK_FRAME_HEADER + \ STACK_FRAME_VRSAVE + \ STACK_FRAME_PARAM_SAVE_AREA + \ STACK_FRAME_LOCAL_VAR + \ STACK_FRAME_FPU_SAVE_AREA + \ STACK_FRAME_GPR_SAVE_AREA + \ STACK_FRAME_VMX_SAVE_AREA)/* Accessors */
#defineSTACK_FRAME_LR_POS16
#defineSTACK_FRAME_CR_POS8
#ifdefined(_CALL_ELF)&&_CALL_ELF== 2
#defineSTACK_FRAME_TOC_POS24
#else
#defineSTACK_FRAME_TOC_POS40
#endif#define
STACK_FRAME_PARAM(i)(STACK_FRAME_HEADER+ ((i) * 8))#define STACK_FRAME_LOCAL(i) (STACK_FRAME_HEADER + \ STACK_FRAME_PARAM_SAVE_AREA + \ ((i) * 8))/* The below are referenced from the previous stack pointer */
#defineSTACK_FRAME_FPU(i)(STACK_FRAME_SIZE- ((32 - (i)) * 8))#define STACK_FRAME_GPR(i) (STACK_FRAME_SIZE - \ STACK_FRAME_FPU_SAVE_AREA - \ ((32 - (i)) * 8)) #define STACK_FRAME_VMX(i) (STACK_FRAME_SIZE - \ STACK_FRAME_FPU_SAVE_AREA - \ STACK_FRAME_GPR_SAVE_AREA - \ STACK_FRAME_VRSAVE - \ ((32 - (i)) * 16)Quoted 26 lines
tools/testing/selftests/powerpc/basic_asm.h new file +26
-0+#define STACK_FRAME_LR_POS 16 +#define STACK_FRAME_CR_POS 8 + +#define LOAD_REG_IMMEDIATE (reg,expr) \ + lis reg,(expr)@highest; \ + ori reg,reg,(expr)@higher; \ + rldicr reg,reg,32,31; \ + oris reg,reg,(expr)@high; \ + ori reg,reg,(expr)@l; + +/* It is very important to note here that _extra is the extra amount of +* stack space needed. +* This space must be accessed using STACK_FRAME_PARAM() or +* STACK_FRAME_LOCAL() macros! +* +* r1 and r2 are not defined in ppc-asm.h (instead they are defined as sp +* and toc). Kernel programmers tend to prefer rX even for r1 and r2, hence +* %1 and %r2. r0 is defined in ppc-asm.h and therefore %r0 gets +* preprocessed incorrectly, hence r0. +*/ +#define PUSH_BASIC_STACK (_extra) \ + mflr r0; \ + std r0,STACK_FRAME_LR_POS(%r1); \ + stdu %r1,-(_extra + STACK_FRAME_MIN_SIZE)(%r1); \ + mfcr r0; \ + stw r0,STACK_FRAME_CR_POS(%r1); \tools/testing/selftests/powerpc/basic_asm.h line 62
Quoted 10 lines
tools/testing/selftests/powerpc/basic_asm.h new file +10
-0+ std %r2,STACK_FRAME_TOC_POS(%r1); + +#define POP_BASIC_STACK (_extra) \ + ld %r2,STACK_FRAME_TOC_POS(%r1); \ + lwz r0,STACK_FRAME_CR_POS(%r1); \ + mtcr r0; \ + addi %r1,%r1,(_extra + STACK_FRAME_MIN_SIZE); \ + ld r0,STACK_FRAME_LR_POS(%r1); \ + mtlr r0; +So, these become:
#define PUSH_BASIC_STACK() \ mflr r0; \ std r0,STACK_FRAME_LR_POS(%r1); \ stdu %r1,-(STACK_FRAME_SIZE)(%r1); \ mfcr r0; \ stw r0,STACK_FRAME_CR_POS(%r1); \ std %r2,STACK_FRAME_TOC_POS(%r1);#define POP_BASIC_STACK() \ ld %r2,STACK_FRAME_TOC_POS(%r1); \ lwz r0,STACK_FRAME_CR_POS(%r1); \ mtcr r0; \ addi %r1,%r1,(STACK_FRAME_SIZE); \ ld r0,STACK_FRAME_LR_POS(%r1); \ mtlr r0;Quoted 57 lines
tools/testing/selftests/powerpc/math/.gitignore new file +2
-0@@ -0,0 +1,2 @@ +fpu_syscall +vmx_syscalltools/testing/selftests/powerpc/math/Makefile new file +16
-0@@ -0,0 +1,16 @@ +TEST_PROGS := fpu_syscall vmx_syscall + +all: $(TEST_PROGS) + +#The general powerpc makefile adds -flto. This isn't interacting well with the custom ASM. +#filter-out -flto to avoid false failures. +$(TEST_PROGS): ../harness.c +$(TEST_PROGS): CFLAGS = $(filter-out -flto,$(CFLAGS) -O2 -g -pthread -m64 -maltivec) + +fpu_syscall: fpu_asm.S +vmx_syscall: vmx_asm.S + +include ../../lib.mk + +clean: + rm -f $(TEST_PROGS) *.otools/testing/selftests/powerpc/math/fpu_asm.S new file +21
-0@@ -0,0 +1,161 @@ +/* + * Copyright 2015, Cyril Bur, IBM Corp. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + +#include "../basic_asm.h" + +#define PUSH_FPU(pos) \ + stfd f14,pos(sp); \ + stfd f15,pos+8(sp); \ + stfd f16,pos+16(sp); \ + stfd f17,pos+24(sp); \ + stfd f18,pos+32(sp); \ + stfd f19,pos+40(sp); \ + stfd f20,pos+48(sp); \ + stfd f21,pos+56(sp); \ + stfd f22,pos+64(sp); \tools/testing/selftests/powerpc/math/fpu_asm.S line 31
Quoted 10 lines
tools/testing/selftests/powerpc/math/fpu_asm.S new file +10
-0+ stfd f23,pos+72(sp); \ + stfd f24,pos+80(sp); \ + stfd f25,pos+88(sp); \ + stfd f26,pos+96(sp); \ + stfd f27,pos+104(sp); \ + stfd f28,pos+112(sp); \ + stfd f29,pos+120(sp); \ + stfd f30,pos+128(sp); \ + stfd f31,pos+136(sp); +#define PUSH_FPU() \ stfd f14,STACK_FRAME_FPU(14)(sp); \ stfd f15,STACK_FRAME_FPU(15)(sp); \ stfd f16,STACK_FRAME_FPU(16)(sp); \ stfd f17,STACK_FRAME_FPU(17)(sp); \... and so on without need for a parameter.
Quoted 6 lines
tools/testing/selftests/powerpc/math/fpu_asm.S new file +6
-0+#define POP_FPU(pos) \ + lfd f14,pos(sp); \ + lfd f15,pos+8(sp); \ + lfd f16,pos+16(sp); \ + lfd f17,pos+24(sp); \ + lfd f18,pos+32(sp); \<snip>
tools/testing/selftests/powerpc/math/fpu_asm.S line 143
Quoted 9 lines
tools/testing/selftests/powerpc/math/fpu_asm.S new file +9
-0+ +FUNC_START(test_fpu) + #r3 holds pointer to where to put the result of fork + #r4 holds pointer to the pid + #f14-f31 are non volatiles + PUSH_BASIC_STACK(256) + std r3,STACK_FRAME_PARAM(0)(sp) #Address of darray + std r4,STACK_FRAME_PARAM(1)(sp) #Address of pid + PUSH_FPU(STACK_FRAME_LOCAL(2,0))The above now becomes:
FUNC_START(test_fpu)
#r3 holds pointer to where to put the result of fork #r4 holds pointer to the pid
#f14-f31 are non volatilesPUSH_BASIC_STACK()
std r3,STACK_FRAME_PARAM(0)(sp) #Address of darray
std r4,STACK_FRAME_PARAM(1)(sp) #Address of pid
PUSH_FPU()Also note that as per the ABI, the floating point registers save area is just below the previous stack pointer.
Quoted 6 lines
tools/testing/selftests/powerpc/math/fpu_asm.S new file +6
-0+ + bl load_fpu + nop + li r0,__NR_fork + sc +tools/testing/selftests/powerpc/math/fpu_asm.S line 159
Quoted 10 lines
tools/testing/selftests/powerpc/math/fpu_asm.S new file +10
-0+ #pass the result of the fork to the caller + ld r9,STACK_FRAME_PARAM(1)(sp) + std r3,0(r9) + + ld r3,STACK_FRAME_PARAM(0)(sp) + bl check_fpu + nop + + POP_FPU(STACK_FRAME_LOCAL(2,0)) + POP_BASIC_STACK(256)And, just:
POP_FPU() POP_BASIC_STACK()In my opinion, that's much simpler.
- Naveen
Re: [PATCH v5 1/9] selftests/powerpc: Test the preservation of FPU and VMX regs across syscall
In reply to Cyril BurQuoted 25 lines · On Tue, 23 Feb 2016 14:38:14 +1100 Cyril Bur <[email protected]> wrote:
Test that the non volatile floating point and Altivec registers get correctly preserved across the
fork()syscall.
fork()works nicely for this purpose, the registers should be the same for both parent and childSigned-off-by Cyril Bur <[email protected]>--- tools/testing/selftests/powerpc/Makefile | 3 +- tools/testing/selftests/powerpc/basic_asm.h | 62 +++++++ tools/testing/selftests/powerpc/math/.gitignore | 2 + tools/testing/selftests/powerpc/math/Makefile | 16 ++ tools/testing/selftests/powerpc/math/fpu_asm.S | 161 +++++++++++++++++ tools/testing/selftests/powerpc/math/fpu_syscall.c | 90 ++++++++++ tools/testing/selftests/powerpc/math/vmx_asm.S | 195 +++++++++++++++++++++ tools/testing/selftests/powerpc/math/vmx_syscall.c | 91 ++++++++++ 8 files changed, 619 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/powerpc/basic_asm.h create mode 100644 tools/testing/selftests/powerpc/math/.gitignore create mode 100644 tools/testing/selftests/powerpc/math/Makefile create mode 100644 tools/testing/selftests/powerpc/math/fpu_asm.S create mode 100644 tools/testing/selftests/powerpc/math/fpu_syscall.c create mode 100644 tools/testing/selftests/powerpc/math/vmx_asm.S create mode 100644 tools/testing/selftests/powerpc/math/vmx_syscall.c
[snip]
Quoted 14 lines
tools/testing/selftests/powerpc/math/.gitignore new file +2
-0@@ -0,0 +1,2 @@ +fpu_syscall +vmx_syscalltools/testing/selftests/powerpc/math/Makefile new file +0
-0
tools/testing/selftests/powerpc/math/Makefile line 8
Quoted 8 lines
tools/testing/selftests/powerpc/math/Makefile new file +8
-0@@ -0,0 +1,16 @@ +TEST_PROGS := fpu_syscall vmx_syscall + +all: $(TEST_PROGS) + +#The general powerpc makefile adds -flto. This isn't interacting well with the custom ASM. +#filter-out -flto to avoid false failures. +$(TEST_PROGS): ../harness.c +$(TEST_PROGS): CFLAGS = $(filter-out -flto,$(CFLAGS) -O2 -g -pthread -m64 -maltivec)
Hi Michael, sorry, there should be a ':' before the '=' to avoid recursive variable problems
-$(TEST_PROGS): CFLAGS = $(filter-out -flto,$(CFLAGS) -O2 -g -pthread -m64 -maltivec) +$(TEST_PROGS): CFLAGS := $(filter-out -flto,$(CFLAGS) -O2 -g -pthread -m64 -maltivec)
Are you ok to fix it up here?
Thanks
Quoted 24 lines
tools/testing/selftests/powerpc/math/Makefile new file +8
-0+ +fpu_syscall: fpu_asm.S +vmx_syscall: vmx_asm.S + +include ../../lib.mk + +clean: + rm -f $(TEST_PROGS) *.otools/testing/selftests/powerpc/math/fpu_asm.S new file +10
-0@@ -0,0 +1,161 @@ +/* + * Copyright 2015, Cyril Bur, IBM Corp. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + +#include "../basic_asm.h"
[snip]
Re: [PATCH v5 1/9] selftests/powerpc: Test the preservation of FPU and VMX regs across syscall
In reply to Cyril BurQuoted 12 lines · Cyril Bur
Quoted 9 lines · On Wed, 24 Feb 2016 19:57:38 +0530 "Naveen N. Rao"…
Quoted 8 lines · Cyril Bur
Test that the non volatile floating point and Altivec registers get correctly preserved across the
fork()syscall.
fork()works nicely for this purpose, the registers should be the same for both parent and childSigned-off-by Cyril Bur <[email protected]>---
<snip>
Quoted 33 lines
Quoted 23 lines
Quoted 23 lines
tools/testing/selftests/powerpc/basic_asm.h new file +16
-0@@ -0,0 +1,62 @@ +#include <ppc-asm.h> +#include <asm/unistd.h> + +#if defined(_CALL_ELF) && _CALL_ELF ==2 +#define STACK_FRAME_MIN_SIZE 32 +#define STACK_FRAME_TOC_POS 24 +#define __STACK_FRAME_PARAM (_param) (32 + ((_param)*8)) +#define __STACK_FRAME_LOCAL (_num_params,_var_num) ((STACK_FRAME_PARAM(_num_params)) + ((_var_num)*8)) +#else +#define STACK_FRAME_MIN_SIZE 112 +#define STACK_FRAME_TOC_POS 40 +#define __STACK_FRAME_PARAM (i) (48 + ((i)*8)) +/* +* Caveat: if a function passed more than 8 params, the caller will have +* made more space... this should be reflected by this C code. +* if (_num_params > 8) Quoted 9 lines
tools/testing/selftests/powerpc/basic_asm.h line 20
Quoted 4 lines
tools/testing/selftests/powerpc/basic_asm.h new file +4
-0+* total = 112 + ((_num_params - 8) * 8) +* +* And substitute the '112' for 'total' in the macro. Doable in preprocessor for ASM? +*/ Per my understanding, the parameter save area is only for parameters to functions that *we* call. And since we control that, I don't think we need to worry about having more than 8 parameters.
Quoted 3 lines
Yes, I just thought I'd put that there to prevent anyone blindly reusing this macro somewhere and getting stung. But you're correct, we don't need to worry about this caveat for this code.
Agreed, so probably a simpler warning will suffice. Also, it is worth noting that this is not necessarily 8 parameters, but 8 doublewords - we may have less number of parameters, but may still need more than 8 doublewords.
Quoted 17 lines
Quoted 16 lines
tools/testing/selftests/powerpc/basic_asm.h line 26
Quoted 7 lines
tools/testing/selftests/powerpc/basic_asm.h new file +6
-0+#define __STACK_FRAME_LOCAL (_num_params,_var_num) (112 + ((_var_num)*8)) +#endif +/* Parameter x saved to the stack */ +#define STACK_FRAME_PARAM (var) __STACK_FRAME_PARAM(var) +/* Local variable x saved to the stack after x parameters */ +#define STACK_FRAME_LOCAL (num_params,var) __STACK_FRAME_LOCAL(num_params,var)So this works, but I'm wondering if this is really worth the code complexity - every use needs to determine appropriate extra stack space, the number of parameters to save and so on. This is after all for selftests and so, we probably don't need to be precise in stack space usage. We can get away using a larger fixed size stack. That will simplify a lot of the code further on and future tests won't need to bother with all the details.
Quoted 8 lines
So I agree that we don't need to be precise about stack space at all (I'm sure you noticed all my stack pushes and pops are very overestimated in size).
I should probably go back to basics and explain how these macros started. In writing all this I got fed up of typing the
PUSH_BASIC_STACKandPOP_BASIC_STACKmacro out at the start of each function. I wasn't trying to macro out the entire calling convention and honestly I don't think it is a good idea. The more easy to use/abstracted the macros get the less flexible they
The simplification here is largely in terms of the stack size and the fpu/gpr/vmx save areas. I don't think most tests would need more control there. For the few tests that may need it, they can always hand code or introduce different macros.
Quoted 2 lines
become. These being selftests, I expect that people might want to do funky/questionable/hacky things, flexibility in the macros might help with that.
Sure, but having every test deal with the intricacies of the stack is not good. It's better to have simple macros that work for the common generic case and consider introducing more specific macros/hard coding where more control is desired.
Quoted 3 lines
I feel like if we want to go down the route of fully abstracting out everything then perhaps we should be considering C...
If that works for your tests, sure, I think that is not a bad idea.
- Naveen
Re: [PATCH v5 1/9] selftests/powerpc: Test the preservation of FPU and VMX regs across syscall
Quoted 49 lines · On Thu, 25 Feb 2016 11:52:05 +0530 "Naveen N. Rao"…
Quoted 12 lines · Cyril Bur
Quoted 9 lines · On Wed, 24 Feb 2016 19:57:38 +0530 "Naveen N. Rao"…
Quoted 8 lines · Cyril Bur
Test that the non volatile floating point and Altivec registers get correctly preserved across the
fork()syscall.
fork()works nicely for this purpose, the registers should be the same for both parent and childSigned-off-by Cyril Bur <[email protected]>---
<snip>
Quoted 33 lines
Quoted 32 lines
Quoted 17 lines
tools/testing/selftests/powerpc/basic_asm.h new file +10
-0@@ -0,0 +1,62 @@ +#include <ppc-asm.h> +#include <asm/unistd.h> + +#if defined(_CALL_ELF) && _CALL_ELF ==2 +#define STACK_FRAME_MIN_SIZE 32 +#define STACK_FRAME_TOC_POS 24 +#define __STACK_FRAME_PARAM (_param) (32 + ((_param)*8)) +#define __STACK_FRAME_LOCAL (_num_params,_var_num) ((STACK_FRAME_PARAM(_num_params)) + ((_var_num)*8)) +#else +#define STACK_FRAME_MIN_SIZE 112tools/testing/selftests/powerpc/basic_asm.h line 20
Quoted 10 lines
tools/testing/selftests/powerpc/basic_asm.h new file +10
-0+#define STACK_FRAME_TOC_POS 40 +#define __STACK_FRAME_PARAM (i) (48 + ((i)*8)) +/* +* Caveat: if a function passed more than 8 params, the caller will have +* made more space... this should be reflected by this C code. +* if (_num_params > 8) +* total = 112 + ((_num_params - 8) * 8) +* +* And substitute the '112' for 'total' in the macro. Doable in preprocessor for ASM? +*/ Per my understanding, the parameter save area is only for parameters to functions that *we* call. And since we control that, I don't think we need to worry about having more than 8 parameters.
Quoted 9 lines
Quoted 3 lines
Yes, I just thought I'd put that there to prevent anyone blindly reusing this macro somewhere and getting stung. But you're correct, we don't need to worry about this caveat for this code.
Agreed, so probably a simpler warning will suffice. Also, it is worth noting that this is not necessarily 8 parameters, but 8 doublewords - we may have less number of parameters, but may still need more than 8 doublewords.
True, happy to send s/params/doublewords/ if it's that important.
Quoted 26 lines
Quoted 17 lines
Quoted 16 lines
tools/testing/selftests/powerpc/basic_asm.h line 26
Quoted 7 lines
tools/testing/selftests/powerpc/basic_asm.h new file +6
-0+#define __STACK_FRAME_LOCAL (_num_params,_var_num) (112 + ((_var_num)*8)) +#endif +/* Parameter x saved to the stack */ +#define STACK_FRAME_PARAM (var) __STACK_FRAME_PARAM(var) +/* Local variable x saved to the stack after x parameters */ +#define STACK_FRAME_LOCAL (num_params,var) __STACK_FRAME_LOCAL(num_params,var)So this works, but I'm wondering if this is really worth the code complexity - every use needs to determine appropriate extra stack space, the number of parameters to save and so on. This is after all for selftests and so, we probably don't need to be precise in stack space usage. We can get away using a larger fixed size stack. That will simplify a lot of the code further on and future tests won't need to bother with all the details.
Quoted 8 lines
So I agree that we don't need to be precise about stack space at all (I'm sure you noticed all my stack pushes and pops are very overestimated in size).
I should probably go back to basics and explain how these macros started. In writing all this I got fed up of typing the
PUSH_BASIC_STACKandPOP_BASIC_STACKmacro out at the start of each function. I wasn't trying to macro out the entire calling convention and honestly I don't think it is a good idea. The more easy to use/abstracted the macros get the less flexible they
Quoted 5 lines
The simplification here is largely in terms of the stack size and the fpu/gpr/vmx save areas. I don't think most tests would need more control there. For the few tests that may need it, they can always hand code or introduce different macros.
It seems like your goal here is to make it so easy to write asm with these macros that the programmer shouldn't need to open the abi because it's all done for them. Lets just stick to the avoiding pointless repetition/avoiding silly mistakes feature of macros.
If these macros all of a sudden take off and every selftest programmer complains they aren't simple enough, perhaps we can revisit.
Quoted 8 lines
Quoted 2 lines
become. These being selftests, I expect that people might want to do funky/questionable/hacky things, flexibility in the macros might help with that.
Sure, but having every test deal with the intricacies of the stack is not good. It's better to have simple macros that work for the common generic case and consider introducing more specific macros/hard coding where more control is desired.
But what is the common general case? Isn't the common general case writing in C and if you've devolved into .S files its likely you're doing something not common or general?
Quoted 9 lines
Quoted 3 lines
I feel like if we want to go down the route of fully abstracting out everything then perhaps we should be considering C...
If that works for your tests, sure, I think that is not a bad idea.
- Naveen
Re: [PATCH v5 1/9] selftests/powerpc: Test the preservation of FPU and VMX regs across syscall
Quoted 56 lines · Cyril Bur
Quoted 53 lines · On Thu, 25 Feb 2016 11:52:05 +0530 "Naveen N. Rao"…
Quoted 12 lines · Cyril Bur
Quoted 9 lines · On Wed, 24 Feb 2016 19:57:38 +0530 "Naveen N. Rao"…
Quoted 8 lines · Cyril Bur
Test that the non volatile floating point and Altivec registers get correctly preserved across the
fork()syscall.
fork()works nicely for this purpose, the registers should be the same for both parent and childSigned-off-by Cyril Bur <[email protected]>---
<snip>
Quoted 36 lines
Quoted 23 lines
Quoted 23 lines
tools/testing/selftests/powerpc/basic_asm.h new file +16
-0@@ -0,0 +1,62 @@ +#include <ppc-asm.h> +#include <asm/unistd.h> + +#if defined(_CALL_ELF) && _CALL_ELF ==2 +#define STACK_FRAME_MIN_SIZE 32 +#define STACK_FRAME_TOC_POS 24 +#define __STACK_FRAME_PARAM (_param) (32 + ((_param)*8)) +#define __STACK_FRAME_LOCAL (_num_params,_var_num) ((STACK_FRAME_PARAM(_num_params)) + ((_var_num)*8)) +#else +#define STACK_FRAME_MIN_SIZE 112 +#define STACK_FRAME_TOC_POS 40 +#define __STACK_FRAME_PARAM (i) (48 + ((i)*8)) +/* +* Caveat: if a function passed more than 8 params, the caller will have +* made more space... this should be reflected by this C code. +* if (_num_params > 8) Quoted 9 lines
tools/testing/selftests/powerpc/basic_asm.h line 20
Quoted 4 lines
tools/testing/selftests/powerpc/basic_asm.h new file +4
-0+* total = 112 + ((_num_params - 8) * 8) +* +* And substitute the '112' for 'total' in the macro. Doable in preprocessor for ASM? +*/ Per my understanding, the parameter save area is only for parameters to functions that *we* call. And since we control that, I don't think we need to worry about having more than 8 parameters.
Yes, I just thought I'd put that there to prevent anyone blindly reusing this macro somewhere and getting stung. But you're correct, we don't need to worry about this caveat for this code.
Quoted 7 lines
Quoted 5 lines
Agreed, so probably a simpler warning will suffice. Also, it is worth noting that this is not necessarily 8 parameters, but 8 doublewords - we may have less number of parameters, but may still need more than 8 doublewords.
True, happy to send s/params/doublewords/ if it's that important.
It is, 8 parameters vs 8 doublewords mean different things.
Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 17 lines
tools/testing/selftests/powerpc/basic_asm.h line 26
Quoted 8 lines
tools/testing/selftests/powerpc/basic_asm.h new file +6
-0+#define __STACK_FRAME_LOCAL (_num_params,_var_num) (112 + ((_var_num)*8)) +#endif +/* Parameter x saved to the stack */ +#define STACK_FRAME_PARAM (var) __STACK_FRAME_PARAM(var) +/* Local variable x saved to the stack after x parameters */ +#define STACK_FRAME_LOCAL (num_params,var) __STACK_FRAME_LOCAL(num_params,var)So this works, but I'm wondering if this is really worth the code complexity - every use needs to determine appropriate extra stack space, the number of parameters to save and so on. This is after all for selftests and so, we probably don't need to be precise in stack space usage. We can get away using a larger fixed size stack. That will simplify a lot of the code further on and future tests won't need to bother with all the details.
So I agree that we don't need to be precise about stack space at all (I'm sure you noticed all my stack pushes and pops are very overestimated in size).
I should probably go back to basics and explain how these macros started. In writing all this I got fed up of typing the
PUSH_BASIC_STACKandPOP_BASIC_STACKmacro out at the start of each function. I wasn't trying to macro out the entire calling convention and honestly I don't think it is a good idea. The more easy to use/abstracted the macros get the less flexible they
Quoted 8 lines
Quoted 5 lines
The simplification here is largely in terms of the stack size and the fpu/gpr/vmx save areas. I don't think most tests would need more control there. For the few tests that may need it, they can always hand code or introduce different macros.
It seems like your goal here is to make it so easy to write asm with these macros that the programmer shouldn't need to open the abi because it's all done
I'm sorry, but I don't know how you got that impression. Let me clarify:
this is only for selftests where there are no specific requirements on how the stack frame is set up (which I expect to be the common case including all the selftests you've written).
Quoted 5 lines
for them. Lets just stick to the avoiding pointless repetition/avoiding silly mistakes feature of macros.
If these macros all of a sudden take off and every selftest programmer complains they aren't simple enough, perhaps we can revisit.
Right, though it's just about how the stack is handled.
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines
become. These being selftests, I expect that people might want to do funky/questionable/hacky things, flexibility in the macros might help with that.
Sure, but having every test deal with the intricacies of the stack is not good. It's better to have simple macros that work for the common generic case and consider introducing more specific macros/hard coding where more control is desired.
Quoted 3 lines
But what is the common general case? Isn't the common general case writing in C and if you've devolved into .S files its likely you're doing something not common or general?
Like I said earlier, what I'm proposing is only about how the stack gets handled. If that's the only thing your code is doing differently in asm (which doesn't seem to be the case), then sure, the generic macros may not work. That's for you to take a call on.
But, I don't quite understand why you think that specific control over stack frame setup is a *must* for all asm code? Surely there is more to asm than that...
- Naveen