Eager FPU switching for ipipe-4.9.y
cover Eager FPU switching for ipipe-4.9.y
After applying this one patch, one can merge in a newer minor release of 4.9. v4.9.109 switched to eager-only and blocked us from moving beyond this release.
A tree that contains the patch and a sample-merge can be found here:
https://github.com/henning-schild-work/linux-ipipe/tree/henning/fpu/4.9
Henning Schild (1):
x86: make fpu switching eager
arch/x86/include/asm/fpu/internal.h | 30 ++++++++---------------------- arch/x86/include/asm/fpu/types.h | 12 ------------ arch/x86/kernel/fpu/core.c | 23 +++++++++-------------- arch/x86/kernel/fpu/init.c | 5 +---- 4 files changed, 18 insertions(+), 52 deletions(-)
Signature · 1 line
2.16.4
PATCH 1/1 x86: make fpu switching eager
Linux 4.14 dropped support for lazy fpu switching and in the 4.4 and 4.9 series similar changes where backported.
So we can assume that fpu switching is purely eager for those Linux kernel versions. That simplifies things a lot and we can drop several changes from the IPIPE patch.
On the Xenomai side the only thing we still have to care about is the kernel fpu state when we interrupt an in kernel fpu user. But we do that explicit and can drop the indirection active_(fp)state.
--- arch/x86/include/asm/fpu/internal.h | 30 ++++++++---------------------- arch/x86/include/asm/fpu/types.h | 12 ------------ arch/x86/kernel/fpu/core.c | 23 +++++++++-------------- arch/x86/kernel/fpu/init.c | 5 +---- 4 files changed, 18 insertions(+), 52 deletions(-)
arch/x86/include/asm/fpu/internal.h +8 -22
@@ -13,7 +13,6 @@#include <linux/compat.h> #include <linux/sched.h> #include <linux/slab.h> -#include <linux/kconfig.h> #include <linux/ipipe.h> #include <asm/user.h>
@@ -190,24 +189,12 @@ static inline int copy_user_to_fregs(struct fregs_state __user *fx) return user_insn(frstor %[fx], "=m" (*fx), [fx] "m" (*fx)); } -#ifdef CONFIG_IPIPE -static inline union fpregs_state *active_fpstate (struct fpu *fpu) -{ -return fpu->active_state; -} -#else -static inline union fpregs_state *active_fpstate (struct fpu *fpu) -{ -return &fpu->state; -} -#endif -static inline void copy_fxregs_to_kernel (struct fpu *fpu) {if (IS_ENABLED (CONFIG_X86_32 )) - asmvolatile ("fxsave %[fx]" : [fx]"=m" (active_fpstate (fpu)->fxsave)); + asmvolatile ("fxsave %[fx]" : [fx]"=m" (fpu->state.fxsave));else if (IS_ENABLED (CONFIG_AS_FXSAVEQ )) - asmvolatile ("fxsaveq %[fx]" : [fx]"=m" (active_fpstate (fpu)->fxsave)); + asmvolatile ("fxsaveq %[fx]" : [fx]"=m" (fpu->state.fxsave));else {/* Using "rex64; fxsave %0" is broken because, if the memory * operand uses any extended registers for addressing, a second
@@ -231,8 +218,8 @@ static inline void copy_fxregs_to_kernel(struct fpu *fpu)* registers. */ asmvolatile ("rex64/fxsave (%[fx])" - :"=m" (active_fpstate (fpu)->fxsave) - : [fx]"R" (&active_fpstate (fpu)->fxsave)); + :"=m" (fpu->state.fxsave) + : [fx]"R" (&fpu->state.fxsave)); } }
@@ -441,7 +428,7 @@ static inline int copy_user_to_xregs(struct xregs_state __user *buf, u64 mask)static inline int copy_fpregs_to_fpstate (struct fpu *fpu) {if (likely (use_xsave ())) { -copy_xregs_to_kernel (&active_fpstate (fpu)->xsave); +copy_xregs_to_kernel (&fpu->state.xsave);return 1 ; }
@@ -454,7 +441,7 @@ static inline int copy_fpregs_to_fpstate(struct fpu *fpu)* Legacy FPU register saving, FNSAVE always clears FPU registers, * so we have to mark them inactive: */ - asmvolatile ("fnsave %[fp]; fwait" : [fp]"=m" (active_fpstate (fpu)->fsave)); + asmvolatile ("fnsave %[fp]; fwait" : [fp]"=m" (fpu->state.fsave));return 0 ; }
@@ -609,8 +596,7 @@ switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu)* If the task has used the math, pre-load the FPU on xsave processors * or if the past 5 consecutive context-switches used math. */ - fpu.preload = !IS_ENABLED (CONFIG_IPIPE ) && -static_cpu_has (X86_FEATURE_FPU ) && + fpu.preload =static_cpu_has (X86_FEATURE_FPU ) && new_fpu->fpstate_active && (use_eager_fpu () || new_fpu->counter >5 );
@@ -660,7 +646,7 @@ switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu)*/ static inline void switch_fpu_finish (struct fpu *new_fpu,fpu_switch_t fpu_switch) { -if (!IS_ENABLED (CONFIG_IPIPE ) && fpu_switch.preload) +if (fpu_switch.preload)copy_kernel_to_fpregs (&new_fpu->state); }
arch/x86/include/asm/fpu/types.h +0 -12
@@ -332,18 +332,6 @@ struct fpu {* deal with bursty apps that only use the FPU for a short time: */ unsigned char counter; - -#ifdef CONFIG_IPIPE -/* -* @active_state -* -* An indirection pointer to reach the active state context -* for the task. This is used by co-kernels for dealing with -* preemption of kernel fpu contexts by their own tasks. -*/ -union fpregs_state *active_state; -#endif -/* * @state: *
arch/x86/kernel/fpu/core.c +9 -14
@@ -124,7 +124,7 @@ void __kernel_fpu_end(void) flags =hard_cond_local_irq_save ();if (fpu->fpregs_active) -copy_kernel_to_fpregs (active_fpstate (fpu)); +copy_kernel_to_fpregs (&fpu->state);else __fpregs_deactivate_hw ();
@@ -184,7 +184,7 @@ EXPORT_SYMBOL_GPL(irq_ts_restore);void fpu__save (struct fpu *fpu) {unsigned long flags; - +WARN_ON_FPU (fpu != ¤t->thread.fpu); flags =hard_preempt_disable ();
@@ -192,7 +192,7 @@ void fpu__save(struct fpu *fpu)if (fpu->fpregs_active) {if (!copy_fpregs_to_fpstate (fpu)) {if (use_eager_fpu ()) -copy_kernel_to_fpregs (active_fpstate (fpu)); +copy_kernel_to_fpregs (&fpu->state);else fpregs_deactivate (fpu); }
@@ -244,13 +244,8 @@ int fpu__copy(struct fpu *dst_fpu, struct fpu *src_fpu) dst_fpu->counter =0 ; dst_fpu->fpregs_active =0 ; dst_fpu->last_cpu =-1 ; -#ifdef CONFIG_IPIPE -/* Must be set before FPU context is copied. */ - dst_fpu->active_state = &dst_fpu->state; -#endif -if (!IS_ENABLED (CONFIG_IPIPE ) && - (!src_fpu->fpstate_active || !static_cpu_has (X86_FEATURE_FPU ))) +if (!src_fpu->fpstate_active || !static_cpu_has (X86_FEATURE_FPU ))return 0 ;WARN_ON_FPU (src_fpu != ¤t->thread.fpu);
@@ -283,7 +278,7 @@ int fpu__copy(struct fpu *dst_fpu, struct fpu *src_fpu) fpu_kernel_xstate_size);if (use_eager_fpu ()) -copy_kernel_to_fpregs (active_fpstate (src_fpu)); +copy_kernel_to_fpregs (&src_fpu->state);else fpregs_deactivate (src_fpu); }
@@ -430,7 +425,7 @@ void fpu__current_fpstate_write_end(void)* an XRSTOR if they are active. */ if (fpregs_active ()) -copy_kernel_to_fpregs (active_fpstate (fpu)); +copy_kernel_to_fpregs (&fpu->state);/* * Our update is done and the fpregs/fpstate are in sync
@@ -460,7 +455,7 @@ void fpu__restore(struct fpu *fpu)kernel_fpu_disable ();trace_x86_fpu_before_restore (fpu);fpregs_activate (fpu); -copy_kernel_to_fpregs (active_fpstate (fpu)); +copy_kernel_to_fpregs (&fpu->state); fpu->counter++;trace_x86_fpu_after_restore (fpu);kernel_fpu_enable ();
@@ -489,7 +484,7 @@ EXPORT_SYMBOL_GPL(fpu__restore);void fpu__drop (struct fpu *fpu) {unsigned long flags; - + flags =hard_preempt_disable (); fpu->counter =0 ;
@@ -536,7 +531,7 @@ static inline void copy_init_fpstate_to_fpregs(void)void fpu__clear (struct fpu *fpu) {unsigned long flags; - +WARN_ON_FPU (fpu != ¤t->thread.fpu);/* Almost certainly an anomaly */ fpu__drop (fpu);
arch/x86/kernel/fpu/init.c +1 -4
@@ -42,9 +42,6 @@ static void fpu__init_cpu_generic(void) cr0 |=X86_CR0_EM ;write_cr0 (cr0); -#ifdef CONFIG_IPIPE - current->thread.fpu.active_state = ¤t->thread.fpu.state; -#endif /* Flush out any pending x87 state: */ #ifdef CONFIG_MATH_EMULATION if (!boot_cpu_has (X86_FEATURE_FPU ))
@@ -329,7 +326,7 @@ static void __init fpu__init_system_ctx_switch(void) eagerfpu =ENABLE ;if (IS_ENABLED (CONFIG_IPIPE )) - eagerfpu =DISABLE ; + eagerfpu =ENABLE ;if (eagerfpu ==ENABLE )setup_force_cpu_cap (X86_FEATURE_EAGER_FPU );
Signature · 1 line
2.16.4
Re: [Xenomai] [PATCH 1/1] x86: make fpu switching eager
Quoted 3 lines · Henning Schild
Linux 4.14 dropped support for lazy fpu switching and in the 4.4 and 4.9 series similar changes where backported.
So we can assume that fpu switching is purely eager for those Linux
My reading of this patch is that we do not "assume" them to be eager, we enforce that for now - until the changes from the related stable merge do that.
Quoted 6 lines
kernel versions. That simplifies things a lot and we can drop several changes from the IPIPE patch.
On the Xenomai side the only thing we still have to care about is the kernel fpu state when we interrupt an in kernel fpu user. But we do that explicit and can drop the indirection active_(fp)state.
That patch resolving a mechanical merge conflict ahead of the merge, right? Does it break the build?
Quoted 132 lines
Signed-off-by Henning Schild <[email protected]>--- arch/x86/include/asm/fpu/internal.h | 30 ++++++++---------------------- arch/x86/include/asm/fpu/types.h | 12 ------------ arch/x86/kernel/fpu/core.c | 23 +++++++++-------------- arch/x86/kernel/fpu/init.c | 5 +---- 4 files changed, 18 insertions(+), 52 deletions(-)arch/x86/include/asm/fpu/internal.h +8
-22@@ -13,7 +13,6 @@#include <linux/compat.h> #include <linux/sched.h> #include <linux/slab.h> -#include <linux/kconfig.h> #include <linux/ipipe.h> #include <asm/user.h> @@ -190,24 +189,12 @@ static inline int copy_user_to_fregs(struct fregs_state __user *fx) return user_insn(frstor %[fx], "=m" (*fx), [fx] "m" (*fx)); } -#ifdef CONFIG_IPIPE -static inline union fpregs_state *active_fpstate (struct fpu *fpu) -{ -return fpu->active_state; -} -#else -static inline union fpregs_state *active_fpstate (struct fpu *fpu) -{ -return &fpu->state; -} -#endif -static inline void copy_fxregs_to_kernel (struct fpu *fpu) {if (IS_ENABLED (CONFIG_X86_32 )) - asmvolatile ("fxsave %[fx]" : [fx]"=m" (active_fpstate (fpu)->fxsave)); + asmvolatile ("fxsave %[fx]" : [fx]"=m" (fpu->state.fxsave));else if (IS_ENABLED (CONFIG_AS_FXSAVEQ )) - asmvolatile ("fxsaveq %[fx]" : [fx]"=m" (active_fpstate (fpu)->fxsave)); + asmvolatile ("fxsaveq %[fx]" : [fx]"=m" (fpu->state.fxsave));else {/* Using "rex64; fxsave %0" is broken because, if the memory * operand uses any extended registers for addressing, a second @@ -231,8 +218,8 @@ static inline void copy_fxregs_to_kernel(struct fpu *fpu)* registers. */ asmvolatile ("rex64/fxsave (%[fx])" - :"=m" (active_fpstate (fpu)->fxsave) - : [fx]"R" (&active_fpstate (fpu)->fxsave)); + :"=m" (fpu->state.fxsave) + : [fx]"R" (&fpu->state.fxsave)); } }@@ -441,7 +428,7 @@ static inline int copy_user_to_xregs(struct xregs_state __user *buf, u64 mask)static inline int copy_fpregs_to_fpstate (struct fpu *fpu) {if (likely (use_xsave ())) { -copy_xregs_to_kernel (&active_fpstate (fpu)->xsave); +copy_xregs_to_kernel (&fpu->state.xsave);return 1 ; }@@ -454,7 +441,7 @@ static inline int copy_fpregs_to_fpstate(struct fpu *fpu)* Legacy FPU register saving, FNSAVE always clears FPU registers, * so we have to mark them inactive: */ - asmvolatile ("fnsave %[fp]; fwait" : [fp]"=m" (active_fpstate (fpu)->fsave)); + asmvolatile ("fnsave %[fp]; fwait" : [fp]"=m" (fpu->state.fsave));return 0 ; }@@ -609,8 +596,7 @@ switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu)* If the task has used the math, pre-load the FPU on xsave processors * or if the past 5 consecutive context-switches used math. */ - fpu.preload = !IS_ENABLED (CONFIG_IPIPE ) && -static_cpu_has (X86_FEATURE_FPU ) && + fpu.preload =static_cpu_has (X86_FEATURE_FPU ) && new_fpu->fpstate_active && (use_eager_fpu () || new_fpu->counter >5 );@@ -660,7 +646,7 @@ switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu)*/ static inline void switch_fpu_finish (struct fpu *new_fpu,fpu_switch_t fpu_switch) { -if (!IS_ENABLED (CONFIG_IPIPE ) && fpu_switch.preload) +if (fpu_switch.preload)copy_kernel_to_fpregs (&new_fpu->state); }arch/x86/include/asm/fpu/types.h +0
-12@@ -332,18 +332,6 @@ struct fpu {* deal with bursty apps that only use the FPU for a short time: */ unsigned char counter; - -#ifdef CONFIG_IPIPE -/* -* @active_state -* -* An indirection pointer to reach the active state context -* for the task. This is used by co-kernels for dealing with -* preemption of kernel fpu contexts by their own tasks. -*/ -union fpregs_state *active_state; -#endif -/* * @state: * arch/x86/kernel/fpu/core.c +1
-1@@ -124,7 +124,7 @@ void __kernel_fpu_end(void) flags =hard_cond_local_irq_save ();if (fpu->fpregs_active) -copy_kernel_to_fpregs (active_fpstate (fpu)); +copy_kernel_to_fpregs (&fpu->state);else __fpregs_deactivate_hw ();
arch/x86/kernel/fpu/core.c EXPORT_SYMBOL_GPL(irq_ts_restore); · line 187
Quoted 5 lines
arch/x86/kernel/fpu/core.c +1
-1@@ -184,7 +184,7 @@ EXPORT_SYMBOL_GPL(irq_ts_restore);void fpu__save (struct fpu *fpu) {unsigned long flags; - +
That's removing a whitespace deviation to upstream or adding one?
Quoted 64 lines
arch/x86/kernel/fpu/core.c +6
-11WARN_ON_FPU (fpu != ¤t->thread.fpu); flags =hard_preempt_disable ();@@ -192,7 +192,7 @@ void fpu__save(struct fpu *fpu)if (fpu->fpregs_active) {if (!copy_fpregs_to_fpstate (fpu)) {if (use_eager_fpu ()) -copy_kernel_to_fpregs (active_fpstate (fpu)); +copy_kernel_to_fpregs (&fpu->state);else fpregs_deactivate (fpu); }@@ -244,13 +244,8 @@ int fpu__copy(struct fpu *dst_fpu, struct fpu *src_fpu) dst_fpu->counter =0 ; dst_fpu->fpregs_active =0 ; dst_fpu->last_cpu =-1 ; -#ifdef CONFIG_IPIPE -/* Must be set before FPU context is copied. */ - dst_fpu->active_state = &dst_fpu->state; -#endif -if (!IS_ENABLED (CONFIG_IPIPE ) && - (!src_fpu->fpstate_active || !static_cpu_has (X86_FEATURE_FPU ))) +if (!src_fpu->fpstate_active || !static_cpu_has (X86_FEATURE_FPU ))return 0 ;WARN_ON_FPU (src_fpu != ¤t->thread.fpu);@@ -283,7 +278,7 @@ int fpu__copy(struct fpu *dst_fpu, struct fpu *src_fpu) fpu_kernel_xstate_size);if (use_eager_fpu ()) -copy_kernel_to_fpregs (active_fpstate (src_fpu)); +copy_kernel_to_fpregs (&src_fpu->state);else fpregs_deactivate (src_fpu); }@@ -430,7 +425,7 @@ void fpu__current_fpstate_write_end(void)* an XRSTOR if they are active. */ if (fpregs_active ()) -copy_kernel_to_fpregs (active_fpstate (fpu)); +copy_kernel_to_fpregs (&fpu->state);/* * Our update is done and the fpregs/fpstate are in sync @@ -460,7 +455,7 @@ void fpu__restore(struct fpu *fpu)kernel_fpu_disable ();trace_x86_fpu_before_restore (fpu);fpregs_activate (fpu); -copy_kernel_to_fpregs (active_fpstate (fpu)); +copy_kernel_to_fpregs (&fpu->state); fpu->counter++;trace_x86_fpu_after_restore (fpu);kernel_fpu_enable ();@@ -489,7 +484,7 @@ EXPORT_SYMBOL_GPL(fpu__restore);void fpu__drop (struct fpu *fpu) {unsigned long flags; - + flags =hard_preempt_disable (); fpu->counter =0 ;
arch/x86/kernel/fpu/core.c static inline void copy_init_fpstate_to_fpregs(void) · line 534
Quoted 5 lines
arch/x86/kernel/fpu/core.c +1
-1@@ -536,7 +531,7 @@ static inline void copy_init_fpstate_to_fpregs(void)void fpu__clear (struct fpu *fpu) {unsigned long flags; - +
Same question applies to these to hunks as well.
Quoted 18 lines
arch/x86/kernel/fpu/core.c +0
-0WARN_ON_FPU (fpu != ¤t->thread.fpu);/* Almost certainly an anomaly */ fpu__drop (fpu);arch/x86/kernel/fpu/init.c +0
-3@@ -42,9 +42,6 @@ static void fpu__init_cpu_generic(void) cr0 |=X86_CR0_EM ;write_cr0 (cr0); -#ifdef CONFIG_IPIPE - current->thread.fpu.active_state = ¤t->thread.fpu.state; -#endif /* Flush out any pending x87 state: */ #ifdef CONFIG_MATH_EMULATION if (!boot_cpu_has (X86_FEATURE_FPU ))
arch/x86/kernel/fpu/init.c static void __init fpu__init_system_ctx_switch(void) · line 329
Quoted 5 lines
arch/x86/kernel/fpu/init.c +1
-1@@ -329,7 +326,7 @@ static void __init fpu__init_system_ctx_switch(void) eagerfpu =ENABLE ;if (IS_ENABLED (CONFIG_IPIPE )) - eagerfpu =DISABLE ; + eagerfpu =ENABLE ;
Won't that be obsolete when we merge 4.9.109+?
arch/x86/kernel/fpu/init.c static void __init fpu__init_system_ctx_switch(void)
Quoted 4 lines
arch/x86/kernel/fpu/init.c +0
-0if (eagerfpu ==ENABLE )setup_force_cpu_cap (X86_FEATURE_EAGER_FPU );
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE Corporate Competence Center Embedded Linux
Re: [Xenomai] [PATCH 1/1] x86: make fpu switching eager
Am Mon, 27 Aug 2018 18:36:49 +0200
schrieb Jan Kiszka <[email protected]>:
Quoted 9 lines · Henning Schild
Quoted 4 lines
Linux 4.14 dropped support for lazy fpu switching and in the 4.4 and 4.9 series similar changes where backported.
So we can assume that fpu switching is purely eager for those LinuxMy reading of this patch is that we do not "assume" them to be eager, we enforce that for now - until the changes from the related stable merge do that.
Yes, that is the way it was developed.
Quoted 9 lines
Quoted 6 lines
kernel versions. That simplifies things a lot and we can drop several changes from the IPIPE patch.
On the Xenomai side the only thing we still have to care about is the kernel fpu state when we interrupt an in kernel fpu user. But we do that explicit and can drop the indirection active_(fp)state.That patch resolving a mechanical merge conflict ahead of the merge, right? Does it break the build?
this 108+ would not build/work indeed, the following 109 would work and build
I guess i can split that into a fully working/compiling series. But i am honestly not sure the pain is worth the gain. At the moment we are looking at code for the "final" state, intermediate steps would introduce more ifdefs just to remove them later.
So i would suggest to introduce the patch with a double-merge where the second one becomes one bisectable-commit on ipipe-4.9.y while the magic stays visible as a single commit on a side-branch.
Henning
Quoted 258 lines
Quoted 143 lines
Signed-off-by Henning Schild <[email protected]>--- arch/x86/include/asm/fpu/internal.h | 30 ++++++++---------------------- arch/x86/include/asm/fpu/types.h | 12 ------------ arch/x86/kernel/fpu/core.c | 23 +++++++++-------------- arch/x86/kernel/fpu/init.c | 5 +---- 4 files changed, 18 insertions(+), 52 deletions(-)(quoted diff) +0
-0
b/arch/x86/include/asm/fpu/internal.hindex35ca184e83e1..6bdceba90f17100644 ---a/arch/x86/include/asm/fpu/internal.h+++b/arch/x86/include/asm/fpu/internal.h@@ -13,7 +13,6 @@
#include <linux/compat.h>
#include <linux/sched.h>
#include <linux/slab.h>arch/x86/include/asm/fpu/internal.h +2
-15-#include <linux/kconfig.h> #include <linux/ipipe.h> #include <asm/user.h> @@ -190,24 +189,12 @@ static inline int copy_user_to_fregs(struct fregs_state __user *fx) return user_insn(frstor %[fx], "=m" (*fx), [fx] "m" (*fx)); } -#ifdef CONFIG_IPIPE -static inline union fpregs_state *active_fpstate (struct fpu *fpu) -{ -return fpu->active_state; -} -#else -static inline union fpregs_state *active_fpstate (struct fpu *fpu) -{ -return &fpu->state; -} -#endif - static inline void copy_fxregs_to_kernel(struct fpu *fpu) { if (IS_ENABLED(CONFIG_X86_32)) - asmvolatile ("fxsave %[fx]" : [fx] "=m" (active_fpstate(fpu)->fxsave)); + asm volatile( "fxsave %[fx]" : [fx] "=m" (fpu->state.fxsave)); else if (IS_ENABLED(CONFIG_AS_FXSAVEQ)) - asmvolatile ("fxsaveq %[fx]" : [fx] "=m" (active_fpstate(fpu)->fxsave)); + asm volatile("fxsaveq %[fx]" : [fx] "=m" (fpu->state.fxsave)); else {/* Using "rex64; fxsave %0" is broken because, if
the memory
* operand uses any extended registers for
addressing, a second @@ -231,8 +218,8 @@ static inline voidcopy_fxregs_to_kernel(struct fpu *fpu)
* registers.
*/
asm volatile( "rex64/fxsave (%[fx])"(quoted diff) +0
-2- : "=m" (active_fpstate(fpu)->fxsave) - : [fx]"R" (&active_fpstate(fpu)->fxsave));
arch/x86/include/asm/fpu/internal.h +2
-0+ : "=m" (fpu->state.fxsave) + : [fx] "R" (&fpu->state.fxsave)); } }@@ -441,7 +428,7 @@ static inline int copy_user_to_xregs(struct
xregs_state__user*buf, u64 mask) static inline intcopy_fpregs_to_fpstate(struct fpu *fpu){
if (likely(use_xsave())) {arch/x86/include/asm/fpu/internal.h +2
-2-copy_xregs_to_kernel (&active_fpstate (fpu)->xsave); +copy_xregs_to_kernel (&fpu->state.xsave);return 1 ; }@@ -454,7 +441,7 @@ static inline int copy_fpregs_to_fpstate(structfpu *fpu) * Legacy FPU register saving, FNSAVE always clears FPU registers, * so we have to mark them inactive: */ - asmvolatile ("fnsave %[fp]; fwait" : [fp] "=m" (active_fpstate(fpu)->fsave)); + asm volatile("fnsave %[fp]; fwait" : [fp]"=m" (
fpu->state.fsave));
return 0;
}(quoted diff) +0
-0@@ -609,8 +596,7 @@ switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu) * If the task has used the math, pre-load the FPU onxsave processors
* or if the past 5 consecutive context-switches used
math. */arch/x86/include/asm/fpu/internal.h +1
-2- fpu.preload = !IS_ENABLED (CONFIG_IPIPE ) && -static_cpu_has (X86_FEATURE_FPU ) && + fpu.preload =static_cpu_has (X86_FEATURE_FPU ) && new_fpu->fpstate_active && (use_eager_fpu () || new_fpu->counter >5 );@@ -660,7 +646,7 @@ switch_fpu_prepare(struct fpu *old_fpu, structfpu
*new_fpu, int cpu) */
static inline void switch_fpu_finish(struct fpu*new_fpu,fpu_switch_tfpu_switch) {arch/x86/include/asm/fpu/internal.h +1
-1-if (!IS_ENABLED (CONFIG_IPIPE ) && fpu_switch.preload) +if (fpu_switch.preload)copy_kernel_to_fpregs (&new_fpu->state); }(quoted diff) +0
-0
b/arch/x86/include/asm/fpu/types.hindex497c551469ec..48df486b02f9100644 ---a/arch/x86/include/asm/fpu/types.h
+++b/arch/x86/include/asm/fpu/types.h(quoted diff) +0
-0@@ -332,18 +332,6 @@ struct fpu { * deal with bursty apps that only use the FPU for ashort time: */
unsigned char counter;arch/x86/include/asm/fpu/types.h +0
-7- -#ifdef CONFIG_IPIPE -/* -* @active_state -* -* An indirection pointer to reach the active state context -* for the task. This is used by co-kernels for dealing with
arch/x86/include/asm/fpu/types.h +0
-5-* preemption of kernel fpu contexts by their own tasks. -*/ -union fpregs_state *active_state; -#endif -/* * @state: * arch/x86/kernel/fpu/core.c +1
-1@@ -124,7 +124,7 @@ void __kernel_fpu_end(void) flags =hard_cond_local_irq_save ();if (fpu->fpregs_active) -copy_kernel_to_fpregs (active_fpstate (fpu)); +copy_kernel_to_fpregs (&fpu->state);else __fpregs_deactivate_hw ();arch/x86/kernel/fpu/core.c EXPORT_SYMBOL_GPL(irq_ts_restore); · line 187
Quoted 5 lines
arch/x86/kernel/fpu/core.c +1
-1@@ -184,7 +184,7 @@ EXPORT_SYMBOL_GPL(irq_ts_restore);void fpu__save (struct fpu *fpu) {unsigned long flags; - +That's removing a whitespace deviation to upstream or adding one?
Quoted 67 lines
arch/x86/kernel/fpu/core.c +1
-1WARN_ON_FPU (fpu != ¤t->thread.fpu); flags =hard_preempt_disable ();@@ -192,7 +192,7 @@ void fpu__save(struct fpu *fpu)if (fpu->fpregs_active) {if (!copy_fpregs_to_fpstate (fpu)) {if (use_eager_fpu ()) -copy_kernel_to_fpregs (active_fpstate (fpu)); +copy_kernel_to_fpregs (&fpu->state); elsefpregs_deactivate (fpu );}arch/x86/kernel/fpu/core.c +1
-6@@ -244,13 +244,8 @@ int fpu__copy(struct fpu *dst_fpu, struct fpu *src_fpu) dst_fpu->counter = 0; dst_fpu->fpregs_active =0 ; dst_fpu->last_cpu =-1 ; -#ifdef CONFIG_IPIPE -/* Must be set before FPU context is copied. */ - dst_fpu->active_state = &dst_fpu->state; -#endif -if (!IS_ENABLED (CONFIG_IPIPE ) && - (!src_fpu->fpstate_active || !static_cpu_has(X86_FEATURE_FPU))) +if (!src_fpu->fpstate_active || !static_cpu_has (X86_FEATURE_FPU ))return 0 ;WARN_ON_FPU(src_fpu != ¤t->thread.fpu);arch/x86/kernel/fpu/core.c +1
-1@@ -283,7 +278,7 @@ int fpu__copy(struct fpu *dst_fpu, struct fpu *src_fpu) fpu_kernel_xstate_size);if (use_eager_fpu ()) -copy_kernel_to_fpregs (active_fpstate (src_fpu)); +copy_kernel_to_fpregs (&src_fpu->state); elsefpregs_deactivate (src_fpu );}arch/x86/kernel/fpu/core.c +3
-3@@ -430,7 +425,7 @@ void fpu__current_fpstate_write_end(void)* an XRSTOR if they are active. */ if (fpregs_active ()) -copy_kernel_to_fpregs (active_fpstate (fpu)); +copy_kernel_to_fpregs (&fpu->state);/* * Our update is done and the fpregs/fpstate are in sync @@ -460,7 +455,7 @@ void fpu__restore(struct fpu *fpu)kernel_fpu_disable ();trace_x86_fpu_before_restore (fpu);fpregs_activate (fpu); -copy_kernel_to_fpregs (active_fpstate (fpu)); +copy_kernel_to_fpregs (&fpu->state); fpu->counter++;trace_x86_fpu_after_restore (fpu);kernel_fpu_enable ();@@ -489,7 +484,7 @@ EXPORT_SYMBOL_GPL(fpu__restore);void fpu__drop (struct fpu *fpu) {unsigned long flags; - + flags =hard_preempt_disable (); fpu->counter =0 ;arch/x86/kernel/fpu/core.c static inline void · line 534
Quoted 5 lines
arch/x86/kernel/fpu/core.c +1
-1@@ -536,7 +531,7 @@ static inline void copy_init_fpstate_to_fpregs(void) void fpu__clear(struct fpu *fpu) {unsigned long flags; - +Same question applies to these to hunks as well.
Quoted 18 lines
arch/x86/kernel/fpu/core.c +0
-0WARN_ON_FPU (fpu != ¤t->thread.fpu);/* Almost certainly an anomaly */
fpu__drop(fpu);arch/x86/kernel/fpu/init.c +0
-2@@ -42,9 +42,6 @@ static void fpu__init_cpu_generic(void) cr0 |=X86_CR0_EM ;write_cr0 (cr0); -#ifdef CONFIG_IPIPE - current->thread.fpu.active_state =
¤t->thread.fpu.state; -#endif
/* Flush out any pending x87 state: */
#ifdefCONFIG_MATH_EMULATION
if (!boot_cpu_has(X86_FEATURE_FPU))arch/x86/kernel/fpu/init.c static void __init · line 329
Quoted 5 lines
arch/x86/kernel/fpu/init.c +1
-1@@ -329,7 +326,7 @@ static void __initfpu__init_system_ctx_switch (void ) eagerfpu =ENABLE ;if (IS_ENABLED (CONFIG_IPIPE )) - eagerfpu =DISABLE ; + eagerfpu =ENABLE ;Won't that be obsolete when we merge 4.9.109+?
arch/x86/kernel/fpu/init.c static void __init fpu__init_system_ctx_switch(void)
Quoted 4 lines
arch/x86/kernel/fpu/init.c +0
-0if (eagerfpu ==ENABLE )setup_force_cpu_cap (X86_FEATURE_EAGER_FPU );Jan
Re: [Xenomai] [PATCH 1/1] x86: make fpu switching eager
In reply to Jan KiszkaAm Mon, 27 Aug 2018 18:36:49 +0200
schrieb Jan Kiszka <[email protected]>:
Quoted 266 lines · Henning Schild
Quoted 4 lines
Linux 4.14 dropped support for lazy fpu switching and in the 4.4 and 4.9 series similar changes where backported.
So we can assume that fpu switching is purely eager for those LinuxMy reading of this patch is that we do not "assume" them to be eager, we enforce that for now - until the changes from the related stable merge do that.
Quoted 6 lines
kernel versions. That simplifies things a lot and we can drop several changes from the IPIPE patch.
On the Xenomai side the only thing we still have to care about is the kernel fpu state when we interrupt an in kernel fpu user. But we do that explicit and can drop the indirection active_(fp)state.That patch resolving a mechanical merge conflict ahead of the merge, right? Does it break the build?
Quoted 143 lines
Signed-off-by Henning Schild <[email protected]>--- arch/x86/include/asm/fpu/internal.h | 30 ++++++++---------------------- arch/x86/include/asm/fpu/types.h | 12 ------------ arch/x86/kernel/fpu/core.c | 23 +++++++++-------------- arch/x86/kernel/fpu/init.c | 5 +---- 4 files changed, 18 insertions(+), 52 deletions(-)(quoted diff) +0
-0
b/arch/x86/include/asm/fpu/internal.hindex35ca184e83e1..6bdceba90f17100644 ---a/arch/x86/include/asm/fpu/internal.h+++b/arch/x86/include/asm/fpu/internal.h@@ -13,7 +13,6 @@
#include <linux/compat.h>
#include <linux/sched.h>
#include <linux/slab.h>arch/x86/include/asm/fpu/internal.h +2
-15-#include <linux/kconfig.h> #include <linux/ipipe.h> #include <asm/user.h> @@ -190,24 +189,12 @@ static inline int copy_user_to_fregs(struct fregs_state __user *fx) return user_insn(frstor %[fx], "=m" (*fx), [fx] "m" (*fx)); } -#ifdef CONFIG_IPIPE -static inline union fpregs_state *active_fpstate (struct fpu *fpu) -{ -return fpu->active_state; -} -#else -static inline union fpregs_state *active_fpstate (struct fpu *fpu) -{ -return &fpu->state; -} -#endif - static inline void copy_fxregs_to_kernel(struct fpu *fpu) { if (IS_ENABLED(CONFIG_X86_32)) - asmvolatile ("fxsave %[fx]" : [fx] "=m" (active_fpstate(fpu)->fxsave)); + asm volatile( "fxsave %[fx]" : [fx] "=m" (fpu->state.fxsave)); else if (IS_ENABLED(CONFIG_AS_FXSAVEQ)) - asmvolatile ("fxsaveq %[fx]" : [fx] "=m" (active_fpstate(fpu)->fxsave)); + asm volatile("fxsaveq %[fx]" : [fx] "=m" (fpu->state.fxsave)); else {/* Using "rex64; fxsave %0" is broken because, if
the memory
* operand uses any extended registers for
addressing, a second @@ -231,8 +218,8 @@ static inline voidcopy_fxregs_to_kernel(struct fpu *fpu)
* registers.
*/
asm volatile( "rex64/fxsave (%[fx])"(quoted diff) +0
-2- : "=m" (active_fpstate(fpu)->fxsave) - : [fx]"R" (&active_fpstate(fpu)->fxsave));
arch/x86/include/asm/fpu/internal.h +2
-0+ : "=m" (fpu->state.fxsave) + : [fx] "R" (&fpu->state.fxsave)); } }@@ -441,7 +428,7 @@ static inline int copy_user_to_xregs(struct
xregs_state__user*buf, u64 mask) static inline intcopy_fpregs_to_fpstate(struct fpu *fpu){
if (likely(use_xsave())) {arch/x86/include/asm/fpu/internal.h +2
-2-copy_xregs_to_kernel (&active_fpstate (fpu)->xsave); +copy_xregs_to_kernel (&fpu->state.xsave);return 1 ; }@@ -454,7 +441,7 @@ static inline int copy_fpregs_to_fpstate(structfpu *fpu) * Legacy FPU register saving, FNSAVE always clears FPU registers, * so we have to mark them inactive: */ - asmvolatile ("fnsave %[fp]; fwait" : [fp] "=m" (active_fpstate(fpu)->fsave)); + asm volatile("fnsave %[fp]; fwait" : [fp]"=m" (
fpu->state.fsave));
return 0;
}(quoted diff) +0
-0@@ -609,8 +596,7 @@ switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu) * If the task has used the math, pre-load the FPU onxsave processors
* or if the past 5 consecutive context-switches used
math. */arch/x86/include/asm/fpu/internal.h +1
-2- fpu.preload = !IS_ENABLED (CONFIG_IPIPE ) && -static_cpu_has (X86_FEATURE_FPU ) && + fpu.preload =static_cpu_has (X86_FEATURE_FPU ) && new_fpu->fpstate_active && (use_eager_fpu () || new_fpu->counter >5 );@@ -660,7 +646,7 @@ switch_fpu_prepare(struct fpu *old_fpu, structfpu
*new_fpu, int cpu) */
static inline void switch_fpu_finish(struct fpu*new_fpu,fpu_switch_tfpu_switch) {arch/x86/include/asm/fpu/internal.h +1
-1-if (!IS_ENABLED (CONFIG_IPIPE ) && fpu_switch.preload) +if (fpu_switch.preload)copy_kernel_to_fpregs (&new_fpu->state); }(quoted diff) +0
-0
b/arch/x86/include/asm/fpu/types.hindex497c551469ec..48df486b02f9100644 ---a/arch/x86/include/asm/fpu/types.h
+++b/arch/x86/include/asm/fpu/types.h(quoted diff) +0
-0@@ -332,18 +332,6 @@ struct fpu { * deal with bursty apps that only use the FPU for ashort time: */
unsigned char counter;arch/x86/include/asm/fpu/types.h +0
-7- -#ifdef CONFIG_IPIPE -/* -* @active_state -* -* An indirection pointer to reach the active state context -* for the task. This is used by co-kernels for dealing with
arch/x86/include/asm/fpu/types.h +0
-5-* preemption of kernel fpu contexts by their own tasks. -*/ -union fpregs_state *active_state; -#endif -/* * @state: * arch/x86/kernel/fpu/core.c +1
-1@@ -124,7 +124,7 @@ void __kernel_fpu_end(void) flags =hard_cond_local_irq_save ();if (fpu->fpregs_active) -copy_kernel_to_fpregs (active_fpstate (fpu)); +copy_kernel_to_fpregs (&fpu->state);else __fpregs_deactivate_hw ();arch/x86/kernel/fpu/core.c EXPORT_SYMBOL_GPL(irq_ts_restore); · line 187
Quoted 5 lines
arch/x86/kernel/fpu/core.c +1
-1@@ -184,7 +184,7 @@ EXPORT_SYMBOL_GPL(irq_ts_restore);void fpu__save (struct fpu *fpu) {unsigned long flags; - +That's removing a whitespace deviation to upstream or adding one?
Quoted 67 lines
arch/x86/kernel/fpu/core.c +1
-1WARN_ON_FPU (fpu != ¤t->thread.fpu); flags =hard_preempt_disable ();@@ -192,7 +192,7 @@ void fpu__save(struct fpu *fpu)if (fpu->fpregs_active) {if (!copy_fpregs_to_fpstate (fpu)) {if (use_eager_fpu ()) -copy_kernel_to_fpregs (active_fpstate (fpu)); +copy_kernel_to_fpregs (&fpu->state); elsefpregs_deactivate (fpu );}arch/x86/kernel/fpu/core.c +1
-6@@ -244,13 +244,8 @@ int fpu__copy(struct fpu *dst_fpu, struct fpu *src_fpu) dst_fpu->counter = 0; dst_fpu->fpregs_active =0 ; dst_fpu->last_cpu =-1 ; -#ifdef CONFIG_IPIPE -/* Must be set before FPU context is copied. */ - dst_fpu->active_state = &dst_fpu->state; -#endif -if (!IS_ENABLED (CONFIG_IPIPE ) && - (!src_fpu->fpstate_active || !static_cpu_has(X86_FEATURE_FPU))) +if (!src_fpu->fpstate_active || !static_cpu_has (X86_FEATURE_FPU ))return 0 ;WARN_ON_FPU(src_fpu != ¤t->thread.fpu);arch/x86/kernel/fpu/core.c +1
-1@@ -283,7 +278,7 @@ int fpu__copy(struct fpu *dst_fpu, struct fpu *src_fpu) fpu_kernel_xstate_size);if (use_eager_fpu ()) -copy_kernel_to_fpregs (active_fpstate (src_fpu)); +copy_kernel_to_fpregs (&src_fpu->state); elsefpregs_deactivate (src_fpu );}arch/x86/kernel/fpu/core.c +3
-3@@ -430,7 +425,7 @@ void fpu__current_fpstate_write_end(void)* an XRSTOR if they are active. */ if (fpregs_active ()) -copy_kernel_to_fpregs (active_fpstate (fpu)); +copy_kernel_to_fpregs (&fpu->state);/* * Our update is done and the fpregs/fpstate are in sync @@ -460,7 +455,7 @@ void fpu__restore(struct fpu *fpu)kernel_fpu_disable ();trace_x86_fpu_before_restore (fpu);fpregs_activate (fpu); -copy_kernel_to_fpregs (active_fpstate (fpu)); +copy_kernel_to_fpregs (&fpu->state); fpu->counter++;trace_x86_fpu_after_restore (fpu);kernel_fpu_enable ();@@ -489,7 +484,7 @@ EXPORT_SYMBOL_GPL(fpu__restore);void fpu__drop (struct fpu *fpu) {unsigned long flags; - + flags =hard_preempt_disable (); fpu->counter =0 ;arch/x86/kernel/fpu/core.c static inline void · line 534
Quoted 5 lines
arch/x86/kernel/fpu/core.c +1
-1@@ -536,7 +531,7 @@ static inline void copy_init_fpstate_to_fpregs(void) void fpu__clear(struct fpu *fpu) {unsigned long flags; - +Same question applies to these to hunks as well.
Quoted 20 lines
arch/x86/kernel/fpu/core.c +0
-0WARN_ON_FPU (fpu != ¤t->thread.fpu);/* Almost certainly an anomaly */
fpu__drop(fpu);arch/x86/kernel/fpu/init.c +0
-2@@ -42,9 +42,6 @@ static void fpu__init_cpu_generic(void) cr0 |=X86_CR0_EM ;write_cr0 (cr0); -#ifdef CONFIG_IPIPE - current->thread.fpu.active_state =
¤t->thread.fpu.state; -#endif
/* Flush out any pending x87 state: */
#ifdefCONFIG_MATH_EMULATION
if (!boot_cpu_has(X86_FEATURE_FPU))arch/x86/kernel/fpu/init.c +0
-0@@ -329,7 +326,7 @@ static void __initfpu__init_system_ctx_switch (void ) eagerfpu =ENABLE ;
Quoted 5 lines
arch/x86/kernel/fpu/init.c static void __init fpu__init_system_ctx_switch(void) · line 329
Quoted 3 lines
arch/x86/kernel/fpu/init.c +1
-1if (IS_ENABLED (CONFIG_IPIPE )) - eagerfpu =DISABLE ; + eagerfpu =ENABLE ;Won't that be obsolete when we merge 4.9.109+?
Yes, the whole block will be dropped. It is still usefull if you enforce eager fpu in cobalt, independant of the ipipe version. Something only developers would do ...
Henning
Quoted 6 lines
arch/x86/kernel/fpu/init.c static void __init fpu__init_system_ctx_switch(void)
Quoted 4 lines
arch/x86/kernel/fpu/init.c +0
-0if (eagerfpu ==ENABLE )setup_force_cpu_cap (X86_FEATURE_EAGER_FPU );Jan
I have similar patches for 4.4 and 4.14. At the moment 4.14 can not be tested yet since we still have interrupt issues in there. The proposal for 4.9 is because i expect the patch to enter ipipe in ipipe-4.9.y and be backported into 4.4.y. And naturally become part of 4.14, wich will be released later.
Henning
Am Mon, 27 Aug 2018 15:33:46 +0200
schrieb Henning Schild <[email protected]>:
Quoted 15 lines
After applying this one patch, one can merge in a newer minor release of 4.9. v4.9.109 switched to eager-only and blocked us from moving beyond this release.
A tree that contains the patch and a sample-merge can be found here:
https://github.com/henning-schild-work/linux-ipipe/tree/henning/fpu/4.9Henning Schild (1):
x86: make fpu switching eagerarch/x86/include/asm/fpu/internal.h | 30 ++++++++---------------------- arch/x86/include/asm/fpu/types.h | 12 ------------ arch/x86/kernel/fpu/core.c | 23 +++++++++-------------- arch/x86/kernel/fpu/init.c | 5 +---- 4 files changed, 18 insertions(+), 52 deletions(-)