Reworking forge FPU switching
Hi,
after testing a few ideas to avoid useless fpu save/restore, I came to the changes in the following patches. I tried to split the changes in many patches to simplify review. The ARM changes are not included, they are not finished yet, and the critics to the changes in the generic parts may entail some changes for ARM.
Regards.
Signature · 1 line
Gilles.
PATCH 1/7 cobalt/fpu: remove xnarch_init_fpu, it is no longer used
--- kernel/cobalt/arch/arm/thread.c | 30 ------------------------------ kernel/cobalt/arch/powerpc/thread.c | 9 --------- kernel/cobalt/arch/sh/thread.c | 14 -------------- 3 files changed, 53 deletions(-)
kernel/cobalt/arch/arm/thread.c +0 -30
@@ -33,20 +33,6 @@ asmlinkage void __asm_thread_trampoline(void);#ifdef CONFIG_XENO_HW_FPU -static inline void do_init_fpu (struct arm_fpustate *fpuenv) -{ -fp_init (&fpuenv->fpstate); -#if defined(CONFIG_VFP ) -/* vfpstate has already been zeroed by xnarch_init_fpu */ - fpuenv->vfpstate.hard.fpexc =FPEXC_EN ; - fpuenv->vfpstate.hard.fpscr =FPSCR_ROUND_NEAREST ; -#if (LINUX_VERSION_CODE >=KERNEL_VERSION (3 ,2 ,0 ) \ - || defined(CONFIG_VFP_3_2_BACKPORT )) && defined(CONFIG_SMP ) - fpuenv->vfpstate.hard.cpu =NR_CPUS ; -#endif /* linux >= 3.2.0 */ -#endif -} -#define task_fpenv (task) \ ((struct arm_fpustate *) &task_thread_info(task)->used_cp[0])
@@ -341,22 +327,6 @@ void xnarch_enable_fpu(struct xnarchtcb *tcb)#endif /* CONFIG_XENO_HW_FPU */ } -void xnarch_init_fpu (struct xnarchtcb *tcb) -{ -/* -* This must run on behalf of the thread we initialize the FPU -* for. -*/ -#ifdef CONFIG_XENO_HW_FPU -memset (&tcb->fpuenv,0 ,sizeof (tcb->fpuenv)); -do_init_fpu (&tcb->fpuenv); -#ifdef CONFIG_VFP -do_enable_fpu (); -do_restore_fpu (&tcb->fpuenv); -#endif /* CONFIG_VFP */ -#endif /* CONFIG_XENO_HW_FPU */ -} -void xnarch_save_fpu (struct xnarchtcb *tcb) {#ifdef CONFIG_XENO_HW_FPU
kernel/cobalt/arch/powerpc/thread.c +0 -9
@@ -115,15 +115,6 @@ asmlinkage void __asm_restore_fpu(struct thread_struct *ts); })#endif /* CONFIG_PPC64 */ -void xnarch_init_fpu (struct xnarchtcb *tcb) -{ -/* -* This must run on behalf of the thread we initialize the FPU -* for. All FPU regs are guaranteed zero. -*/ -__asm_init_fpu (&tcb->core.ts); -} -void xnarch_enable_fpu (struct xnarchtcb *tcb) {struct task_struct *task = tcb->core.host_task;
kernel/cobalt/arch/sh/thread.c +0 -14
@@ -226,20 +226,6 @@ static inline void do_restore_fpu(struct thread_struct *ts) :"memory"); } -static inline void do_init_fpu (struct thread_struct *ts) -{ -do_restore_fpu (ts); -} - -void xnarch_init_fpu (struct xnarchtcb *tcb) -{ -/* -* This must run on behalf of the thread we initialize the FPU -* for. All FPU regs are guaranteed zero. -*/ -do_init_fpu (&tcb->core.ts); -} -inline void xnarch_enable_fpu (struct xnarchtcb *tcb) {struct task_struct *task = tcb->core.host_task;
Signature · 1 line
1.7.10.4
PATCH 2/7 cobalt/fpu: pass xnthread structures to arch/*/thread.c
in order to prepare for next changes
--- include/cobalt/kernel/thread.h | 6 ++++- .../cobalt/arch/arm/include/asm/xenomai/thread.h | 26 +++++++++++--------- kernel/cobalt/arch/arm/mayday.c | 2 +- kernel/cobalt/arch/arm/thread.c | 15 +++++++---- .../arch/blackfin/include/asm/xenomai/thread.h | 18 +++++++------- kernel/cobalt/arch/blackfin/mayday.c | 2 +- kernel/cobalt/arch/blackfin/thread.c | 3 ++- .../cobalt/arch/nios2/include/asm/xenomai/thread.h | 18 +++++++------- kernel/cobalt/arch/nios2/mayday.c | 2 +- kernel/cobalt/arch/nios2/thread.c | 3 ++- .../arch/powerpc/include/asm/xenomai/thread.h | 24 +++++++++--------- kernel/cobalt/arch/powerpc/mayday.c | 2 +- kernel/cobalt/arch/powerpc/thread.c | 17 ++++++++----- kernel/cobalt/arch/sh/include/asm/xenomai/thread.h | 18 ++++++++------ kernel/cobalt/arch/sh/mayday.c | 2 +- kernel/cobalt/arch/sh/thread.c | 15 +++++++---- .../cobalt/arch/x86/include/asm/xenomai/thread.h | 26 ++++++++++---------- kernel/cobalt/arch/x86/mayday.c | 2 +- kernel/cobalt/arch/x86/thread.c | 25 ++++++++++++------- kernel/cobalt/include/asm-generic/xenomai/thread.h | 5 ++++ kernel/cobalt/sched.c | 6 ++--- kernel/cobalt/shadow.c | 6 ++--- kernel/cobalt/thread.c | 16 ++++++------ 23 files changed, 146 insertions(+), 113 deletions(-)
include/cobalt/kernel/thread.h +5 -1
@@ -208,6 +208,11 @@ static inline void xnthread_clear_info(struct xnthread *thread, int bits) thread->info &= ~bits; } +static inline struct xnarchtcb *xnthread_archtcb (struct xnthread *thread) +{ +return &thread->tcb; +} +#define xnthread_lock_count (thread) ((thread)->schedlck)#define xnthread_init_schedparam (thread) ((thread)->init_schedparam)#define xnthread_base_priority (thread) ((thread)->bprio)
@@ -216,7 +221,6 @@ static inline void xnthread_clear_info(struct xnthread *thread, int bits)#define xnthread_base_class (thread) ((thread)->base_class)#define xnthread_sched_class (thread) ((thread)->sched_class)#define xnthread_time_slice (thread) ((thread)->rrperiod) -#define xnthread_archtcb (thread) (&((thread)->tcb))#define xnthread_timeout (thread) xntimer_get_timeout(&(thread)->rtimer)#define xnthread_handle (thread) ((thread)->registry.handle)#define xnthread_host_task (thread) (xnthread_archtcb(thread)->core.host_task)
kernel/cobalt/arch/arm/include/asm/xenomai/thread.h +14 -12
@@ -81,28 +81,30 @@ struct xnarchtcb {#define xnarch_fault_notify (d) (!xnarch_fault_bp_p(d)) -void xnarch_enable_fpu (struct xnarchtcb *current_tcb); +void xnarch_enable_fpu (struct xnthread *current_thread); -void xnarch_save_fpu (struct xnarchtcb *tcb); +void xnarch_save_fpu (struct xnthread *thread); -void xnarch_restore_fpu (struct xnarchtcb *tcb); +void xnarch_restore_fpu (struct xnthread *thread); -void xnarch_switch_to (struct xnarchtcb *out_tcb,struct xnarchtcb *in_tcb); +void xnarch_switch_to (struct xnthread *out,struct xnthread *in); -static inline void xnarch_enter_root (struct xnarchtcb *rootcb) { } +static inline void xnarch_enter_root (struct xnthread *root) { }int xnarch_escalate (void );#ifdef CONFIG_XENO_HW_FPU -static inline void xnarch_init_root_tcb (struct xnarchtcb *tcb) +static inline void xnarch_init_root_tcb (struct xnthread *thread) { +struct xnarchtcb *tcb =xnthread_archtcb (thread); tcb->is_root =1 ; tcb->fpup =NULL ; } -static inline void xnarch_init_shadow_tcb (struct xnarchtcb *tcb) +static inline void xnarch_init_shadow_tcb (struct xnthread *thread) { +struct xnarchtcb *tcb =xnthread_archtcb (thread); tcb->is_root =0 ; tcb->fpup = (struct arm_fpustate *) &task_thread_info (tcb->core.host_task)->used_cp[0 ];
@@ -110,12 +112,12 @@ static inline void xnarch_init_shadow_tcb(struct xnarchtcb *tcb)int xnarch_fault_fpu_p (struct ipipe_trap_data *d); -void xnarch_leave_root (struct xnarchtcb *rootcb); +void xnarch_leave_root (struct xnthread *root);#else /* !CONFIG_XENO_HW_FPU */ -static inline void xnarch_init_root_tcb (struct xnarchtcb *tcb) { } -static inline void xnarch_init_shadow_tcb (struct xnarchtcb *tcb) { } +static inline void xnarch_init_root_tcb (struct xnthread *thread) { } +static inline void xnarch_init_shadow_tcb (struct xnthread *thread) { }/* * Userland may raise FPU faults with FPU-enabled kernels, regardless
@@ -127,11 +129,11 @@ static inline int xnarch_fault_fpu_p(struct ipipe_trap_data *d) return 0; } -static inline void xnarch_leave_root (struct xnarchtcb *rootcb) { } +static inline void xnarch_leave_root (struct xnthread *root) { }#endif /* !CONFIG_XENO_HW_FPU */ -static inline int xnarch_handle_fpu_fault (struct xnarchtcb *tcb) +static inline int xnarch_handle_fpu_fault (struct xnthread *thread) {return 0 ; }
kernel/cobalt/arch/arm/mayday.c +1 -1
@@ -18,10 +18,10 @@*/ #include <linux/types.h> #include <linux/ipipe.h> +#include <cobalt/kernel/thread.h> #include <asm/cacheflush.h> #include <asm/ptrace.h> #include <asm/xenomai/syscall.h> -#include <asm/xenomai/thread.h> void xnarch_setup_mayday_page (void *page) {
kernel/cobalt/arch/arm/thread.c +10 -5
@@ -235,8 +235,9 @@ int xnarch_fault_fpu_p(struct ipipe_trap_data *d)return exc !=IPIPE_TRAP_UNDEFINSTR ; } -void xnarch_leave_root (struct xnarchtcb *rootcb) +void xnarch_leave_root (struct xnthread *root) { +struct xnarchtcb *rootcb =xnthread_archtcb (root);#ifdef CONFIG_VFP rootcb->fpup =get_fpu_owner ();#else /* !CONFIG_VFP */
@@ -249,8 +250,9 @@ void xnarch_leave_root(struct xnarchtcb *rootcb)#endif /* CONFIG_XENO_HW_FPU */ -void xnarch_switch_to (struct xnarchtcb *out_tcb,struct xnarchtcb *in_tcb) +void xnarch_switch_to (struct xnthread *out,struct xnthread *in) { +struct xnarchtcb *out_tcb = &out->tcb, *in_tcb = &in->tcb;struct mm_struct *prev_mm, *next_mm;struct task_struct *next;
@@ -282,8 +284,9 @@ void xnarch_switch_to(struct xnarchtcb *out_tcb, struct xnarchtcb *in_tcb)#endif } -void xnarch_enable_fpu (struct xnarchtcb *tcb) +void xnarch_enable_fpu (struct xnthread *thread) { +struct xnarchtcb *tcb = &thread->tcb;#ifdef CONFIG_XENO_HW_FPU #ifdef CONFIG_VFP /* If we are restoring the Linux current thread which does not own the
@@ -327,8 +330,9 @@ void xnarch_enable_fpu(struct xnarchtcb *tcb)#endif /* CONFIG_XENO_HW_FPU */ } -void xnarch_save_fpu (struct xnarchtcb *tcb) +void xnarch_save_fpu (struct xnthread *thread) { +struct xnarchtcb *tcb = &thread->tcb;#ifdef CONFIG_XENO_HW_FPU #ifdef CONFIG_VFP if (tcb->fpup)
@@ -346,8 +350,9 @@ void xnarch_save_fpu(struct xnarchtcb *tcb)#endif /* CONFIG_XENO_HW_FPU */ } -void xnarch_restore_fpu (struct xnarchtcb *tcb) +void xnarch_restore_fpu (struct xnthread *thread) { +struct xnarchtcb *tcb = &thread->tcb; #ifdef CONFIG_XENO_HW_FPU #ifdef CONFIG_VFP if (likely(!tcb->is_root)) {
kernel/cobalt/arch/blackfin/include/asm/xenomai/thread.h +9 -9
@@ -50,19 +50,19 @@ struct xnarchtcb {#define xnarch_fault_notify (d) (!xnarch_fault_bp_p(d)) -void xnarch_switch_to (struct xnarchtcb *out_tcb,struct xnarchtcb *in_tcb); +void xnarch_switch_to (struct xnthread *out,struct xnthread *in);int xnarch_escalate (void ); -static inline void xnarch_init_root_tcb (struct xnarchtcb *tcb) { } -static inline void xnarch_init_shadow_tcb (struct xnarchtcb *tcb) { } -static inline void xnarch_enter_root (struct xnarchtcb *rootcb) { } -static inline void xnarch_leave_root (struct xnarchtcb *rootcb) { } -static inline void xnarch_enable_fpu (struct xnarchtcb *current_tcb) { } -static inline void xnarch_save_fpu (struct xnarchtcb *tcb) { } -static inline void xnarch_restore_fpu (struct xnarchtcb *tcb) { } +static inline void xnarch_init_root_tcb (struct xnthread *thread) { } +static inline void xnarch_init_shadow_tcb (struct xnthread *thread) { } +static inline void xnarch_enter_root (struct xnthread *root) { } +static inline void xnarch_leave_root (struct xnthread *root) { } +static inline void xnarch_enable_fpu (struct xnthread *current_thread) { } +static inline void xnarch_save_fpu (struct xnthread *thread) { } +static inline void xnarch_restore_fpu (struct xnthread *thread) { } -static inline int xnarch_handle_fpu_fault (struct xnarchtcb *tcb) +static inline int xnarch_handle_fpu_fault (struct xnthread *thread) {return 0 ; }
kernel/cobalt/arch/blackfin/mayday.c +1 -1
@@ -18,11 +18,11 @@*/ #include <linux/types.h> #include <linux/ipipe.h> +#include <cobalt/kernel/thread.h> #include <asm/cacheflush.h> #include <asm/ptrace.h> #include <asm/bug.h> #include <asm/xenomai/syscall.h> -#include <asm/xenomai/thread.h> void xnarch_setup_mayday_page (void *page) {
kernel/cobalt/arch/blackfin/thread.c +2 -1
@@ -56,8 +56,9 @@ void mpu_switch(struct xnarchtcb *out_tcb, struct xnarchtcb *in_tcb)#endif /* CONFIG_MPU */ -void xnarch_switch_to (struct xnarchtcb *out_tcb,struct xnarchtcb *in_tcb) +void xnarch_switch_to (struct xnthread *out,struct xnthread *in) { +struct xnarchtcb *out_tcb = &out->tcb, *in_tcb = &in->tcb;mpu_switch (out_tcb, in_tcb);__asm_switch_context (out_tcb->core.tsp, in_tcb->core.tsp); }
kernel/cobalt/arch/nios2/include/asm/xenomai/thread.h +9 -9
@@ -49,20 +49,20 @@ struct xnarchtcb {#define xnarch_fault_notify (d) (xnarch_fault_bp_p(d) == 0) -static inline void xnarch_init_root_tcb (struct xnarchtcb *tcb) { } -static inline void xnarch_init_shadow_tcb (struct xnarchtcb *tcb) { } -static inline void xnarch_enter_root (struct xnarchtcb *rootcb) { } -static inline void xnarch_leave_root (struct xnarchtcb *rootcb) { } -static inline void xnarch_enable_fpu (struct xnarchtcb *current_tcb) { } -static inline void xnarch_save_fpu (struct xnarchtcb *tcb) { } -static inline void xnarch_restore_fpu (struct xnarchtcb *tcb) { } +static inline void xnarch_init_root_tcb (struct xnthread *thread) { } +static inline void xnarch_init_shadow_tcb (struct xnthread *thread) { } +static inline void xnarch_enter_root (struct xnthread *root) { } +static inline void xnarch_leave_root (struct xnthread *thread) { } +static inline void xnarch_enable_fpu (struct xnthread *thread) { } +static inline void xnarch_save_fpu (struct xnthread *thread) { } +static inline void xnarch_restore_fpu (struct xnthread *thread) { } -static inline int xnarch_handle_fpu_fault (struct xnarchtcb *tcb) +static inline int xnarch_handle_fpu_fault (struct xnthread *thread) {return 0 ; } -void xnarch_switch_to (struct xnarchtcb *out_tcb,struct xnarchtcb *in_tcb); +void xnarch_switch_to (struct xnthread *out,struct xnthread *in);int xnarch_escalate (void );
kernel/cobalt/arch/nios2/mayday.c +1 -1
@@ -19,9 +19,9 @@#include <linux/types.h> #include <linux/ipipe.h> +#include <cobalt/kernel/thread.h> #include <asm/cacheflush.h> #include <asm/ptrace.h> -#include <asm/xenomai/thread.h> void xnarch_setup_mayday_page (void *page) {
kernel/cobalt/arch/nios2/thread.c +2 -1
@@ -27,8 +27,9 @@ asmlinkage void __asm_thread_switch(struct thread_struct *prev, struct thread_struct *next); -void xnarch_switch_to (struct xnarchtcb *out_tcb,struct xnarchtcb *in_tcb) +void xnarch_switch_to (struct xnthread *out,struct xnthread *in) { +struct xnarchtcb *out_tcb = &out->tcb, *in_tcb = &in->tcb;struct mm_struct *prev_mm, *next_mm;struct task_struct *next;
kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h +13 -11
@@ -52,42 +52,44 @@ struct xnarchtcb { (d)->exception == IPIPE_TRAP_DEBUG))#define xnarch_fault_notify (d) (xnarch_fault_bp_p(d) == 0) -static inline void xnarch_enter_root (struct xnarchtcb *rootcb) { } +static inline void xnarch_enter_root (struct xnthread *root) { }#ifdef CONFIG_XENO_HW_FPU -static inline void xnarch_init_root_tcb (struct xnarchtcb *tcb) +static inline void xnarch_init_root_tcb (struct xnthread *thread) { +struct xnarchtcb *tcb =xnthread_archtcb (thread); tcb->fpup =NULL ; } -static inline void xnarch_init_shadow_tcb (struct xnarchtcb *tcb) +static inline void xnarch_init_shadow_tcb (struct xnthread *thread) { +struct xnarchtcb *tcb =xnthread_archtcb (thread); tcb->fpup = &tcb->core.host_task->thread; } -void xnarch_leave_root (struct xnarchtcb *rootcb); +void xnarch_leave_root (struct xnthread *root);#else /* !CONFIG_XENO_HW_FPU */ -static inline void xnarch_init_root_tcb (struct xnarchtcb *tcb) { } -static inline void xnarch_init_shadow_tcb (struct xnarchtcb *tcb) { } +static inline void xnarch_init_root_tcb (struct xnthread *thread) { } +static inline void xnarch_init_shadow_tcb (struct xnthread *thread) { }#endif /* !CONFIG_XENO_HW_FPU */ -static inline int xnarch_handle_fpu_fault (struct xnarchtcb *tcb) +static inline int xnarch_handle_fpu_fault (struct xnthread *thread) {return 0 ; } -void xnarch_switch_to (struct xnarchtcb *out_tcb,struct xnarchtcb *in_tcb); +void xnarch_switch_to (struct xnthread *out,struct xnthread *in);int xnarch_escalate (void ); -void xnarch_enable_fpu (struct xnarchtcb *current_tcb); +void xnarch_enable_fpu (struct xnthread *current_thread); -void xnarch_save_fpu (struct xnarchtcb *tcb); +void xnarch_save_fpu (struct xnthread *thread); -void xnarch_restore_fpu (struct xnarchtcb *tcb); +void xnarch_restore_fpu (struct xnthread *thread);#endif /* !_COBALT_POWERPC_ASM_THREAD_H */
kernel/cobalt/arch/powerpc/mayday.c +1 -1
@@ -19,9 +19,9 @@#include <linux/types.h> #include <linux/ipipe.h> +#include <cobalt/kernel/thread.h> #include <asm/cacheflush.h> #include <asm/ptrace.h> -#include <asm/xenomai/thread.h> #include <asm/xenomai/syscall.h> void xnarch_setup_mayday_page (void *page)
kernel/cobalt/arch/powerpc/thread.c +11 -6
@@ -30,9 +30,9 @@ asmlinkage struct task_struct * __asm_thread_switch(struct thread_struct *prev, struct thread_struct *next); -void xnarch_switch_to (struct xnarchtcb *out_tcb, -struct xnarchtcb *in_tcb) +void xnarch_switch_to (struct xnthread *out,struct xnthread *in) { +struct xnarchtcb *out_tcb = &out->tcb, *in_tcb = &in->tcb;struct mm_struct *prev_mm, *next_mm;struct task_struct *next;
@@ -115,8 +115,9 @@ asmlinkage void __asm_restore_fpu(struct thread_struct *ts); })#endif /* CONFIG_PPC64 */ -void xnarch_enable_fpu (struct xnarchtcb *tcb) +void xnarch_enable_fpu (struct xnthread *thread) { +struct xnarchtcb *tcb =xnthread_archtcb (thread);struct task_struct *task = tcb->core.host_task;if (task && task != tcb->core.user_fpu_owner)
@@ -125,8 +126,10 @@ void xnarch_enable_fpu(struct xnarchtcb *tcb)do_enable_fpu (); } -void xnarch_save_fpu (struct xnarchtcb *tcb) +void xnarch_save_fpu (struct xnthread *thread) { +struct xnarchtcb *tcb =xnthread_archtcb (thread); +if (tcb->fpup) {__asm_save_fpu (tcb->fpup);
@@ -136,8 +139,9 @@ void xnarch_save_fpu(struct xnarchtcb *tcb) } } -void xnarch_restore_fpu (struct xnarchtcb *tcb) +void xnarch_restore_fpu (struct xnthread *thread) { +struct xnarchtcb *tcb =xnthread_archtcb (thread);struct thread_struct *ts;struct pt_regs *regs;
@@ -164,8 +168,9 @@ void xnarch_restore_fpu(struct xnarchtcb *tcb)do_disable_fpu (); } -void xnarch_leave_root (struct xnarchtcb *rootcb) +void xnarch_leave_root (struct xnthread *root) { +struct xnarchtcb *rootcb =xnthread_archtcb (root); rootcb->core.user_fpu_owner =get_fpu_owner (rootcb->core.host_task);/* So that xnarch_save_fpu() will operate on the right FPU area. */ rootcb->fpup = rootcb->core.user_fpu_owner ?
kernel/cobalt/arch/sh/include/asm/xenomai/thread.h +10 -8
@@ -48,31 +48,33 @@ struct xnarchtcb { (d)->exception == IPIPE_TRAP_BP)#define xnarch_fault_notify (d) (xnarch_fault_bp_p(d) == 0) -static inline void xnarch_enter_root (struct xnarchtcb *rootcb) { } +static inline void xnarch_enter_root (struct xnthread *root) { }#ifdef CONFIG_XENO_HW_FPU -void xnarch_leave_root (struct xnarchtcb *rootcb); +void xnarch_leave_root (struct xnthread *root); -static inline void xnarch_init_root_tcb (struct xnarchtcb *tcb) +static inline void xnarch_init_root_tcb (struct xnthread *thread) { +struct xnarchtcb *tcb =xnthread_archtcb (thread); tcb->fpup =NULL ; } -static inline void xnarch_init_shadow_tcb (struct xnarchtcb *tcb) +static inline void xnarch_init_shadow_tcb (struct xnthread *thread) { +struct xnarchtcb *tcb =xnthread_archtcb (thread); tcb->fpup = &tcb->core.host_task->thread; }#else /* !CONFIG_XENO_HW_FPU */ -static inline void xnarch_leave_root (struct xnarchtcb *rootcb) { } -static inline void xnarch_init_root_tcb (struct xnarchtcb *tcb) { } -static inline void xnarch_init_shadow_tcb (struct xnarchtcb *tcb) { } +static inline void xnarch_leave_root (struct xnthread *root) { } +static inline void xnarch_init_root_tcb (struct xnthread *thread) { } +static inline void xnarch_init_shadow_tcb (struct xnthread *thread) { }#endif /* !CONFIG_XENO_HW_FPU */ -static inline int xnarch_handle_fpu_fault (struct xnarchtcb *tcb) +static inline int xnarch_handle_fpu_fault (struct xnthread *thread) {return 0 ; }
kernel/cobalt/arch/sh/mayday.c +1 -1
@@ -20,9 +20,9 @@#include <linux/types.h> #include <linux/ipipe.h> #include <linux/mm.h> +#include <cobalt/kernel/thread.h> #include <asm/cacheflush.h> #include <asm/ptrace.h> -#include <asm/xenomai/thread.h> void xnarch_setup_mayday_page (void *page) {
kernel/cobalt/arch/sh/thread.c +10 -5
@@ -90,8 +90,9 @@ __last; \ }) -void xnarch_switch_to (struct xnarchtcb *out_tcb,struct xnarchtcb *in_tcb) +void xnarch_switch_to (struct xnthread *out,struct xnthread *in) { +struct xnarchtcb *out_tcb = &out->tcb, *in_tcb = &in->tcb;struct mm_struct *prev_mm, *next_mm;struct task_struct *next;
@@ -226,8 +227,9 @@ static inline void do_restore_fpu(struct thread_struct *ts) :"memory"); } -inline void xnarch_enable_fpu (struct xnarchtcb *tcb) +inline void xnarch_enable_fpu (struct xnthread *thread) { +struct xnarchtcb *tcb =xnthread_archtcb (thread);struct task_struct *task = tcb->core.host_task;if (task != tcb->core.user_fpu_owner)
@@ -236,8 +238,9 @@ inline void xnarch_enable_fpu(struct xnarchtcb *tcb)enable_fpu (); } -void xnarch_save_fpu (struct xnarchtcb *tcb) +void xnarch_save_fpu (struct xnthread *thread) { +struct xnarchtcb *tcb =xnthread_archtcb (thread);struct pt_regs *regs;if (tcb->fpup) {
@@ -249,8 +252,9 @@ void xnarch_save_fpu(struct xnarchtcb *tcb) } } -void xnarch_restore_fpu (struct xnarchtcb *tcb) +void xnarch_restore_fpu (struct xnthread *thread) { +struct xnarchtcb *tcb =xnthread_archtcb (thread);struct pt_regs *regs;if (tcb->fpup) {
@@ -269,8 +273,9 @@ void xnarch_restore_fpu(struct xnarchtcb *tcb)disable_fpu (); } -void xnarch_leave_root (struct xnarchtcb *rootcb) +void xnarch_leave_root (struct xnthread *root) { +struct xnarchtcb *rootcb =xnthread_archtcb (root); rootcb->core.user_fpu_owner =get_fpu_owner (rootcb->core.host_task); rootcb->fpup = rootcb->core.user_fpu_owner ? &rootcb->core.user_fpu_owner->thread :NULL ;
kernel/cobalt/arch/x86/include/asm/xenomai/thread.h +13 -13
@@ -67,33 +67,33 @@ static inline int xnarch_shadow_p(struct xnarchtcb *tcb, struct task_struct *tas#ifdef CONFIG_XENO_HW_FPU -void xnarch_save_fpu (struct xnarchtcb *tcb); -void xnarch_restore_fpu (struct xnarchtcb *tcb); -void xnarch_enable_fpu (struct xnarchtcb *tcb); -int xnarch_handle_fpu_fault (struct xnarchtcb *tcb); +void xnarch_save_fpu (struct xnthread *thread); +void xnarch_restore_fpu (struct xnthread *thread); +void xnarch_enable_fpu (struct xnthread *thread); +int xnarch_handle_fpu_fault (struct xnthread *thread);#else /* !CONFIG_XENO_HW_FPU */ -static inline void xnarch_save_fpu (struct xnarchtcb *tcb) { } -static inline void xnarch_restore_fpu (struct xnarchtcb *tcb) { } -static inline void xnarch_enable_fpu (struct xnarchtcb *tcb) { } +static inline void xnarch_save_fpu (struct xnthread *thread) { } +static inline void xnarch_restore_fpu (struct xnthread *thread) { } +static inline void xnarch_enable_fpu (struct xnthread *thread) { } -static inline int xnarch_handle_fpu_fault (struct xnarchtcb *tcb) +static inline int xnarch_handle_fpu_fault (struct xnthread *thread) {return 0 ; }#endif /* !CONFIG_XENO_HW_FPU */ -void xnarch_init_root_tcb (struct xnarchtcb *tcb); +void xnarch_init_root_tcb (struct xnthread *thread); -void xnarch_init_shadow_tcb (struct xnarchtcb *tcb); +void xnarch_init_shadow_tcb (struct xnthread *thread); -void xnarch_switch_to (struct xnarchtcb *out_tcb,struct xnarchtcb *in_tcb); +void xnarch_switch_to (struct xnthread *out,struct xnthread *in); -static inline void xnarch_enter_root (struct xnarchtcb *tcb) { } +static inline void xnarch_enter_root (struct xnthread *root) { } -void xnarch_leave_root (struct xnarchtcb *rootcb); +void xnarch_leave_root (struct xnthread *root);int xnarch_escalate (void );
kernel/cobalt/arch/x86/mayday.c +1 -1
@@ -19,8 +19,8 @@#include <linux/types.h> #include <linux/ipipe.h> +#include <cobalt/kernel/thread.h> #include <asm/ptrace.h> -#include <asm/xenomai/thread.h> #include <asm/xenomai/syscall.h> #ifdef CONFIG_X86_32
kernel/cobalt/arch/x86/thread.c +16 -9
@@ -83,8 +83,9 @@ static inline void do_switch_threads(struct xnarchtcb *out_tcb,#endif /* CONFIG_X86_64 */ -void xnarch_switch_to (struct xnarchtcb *out_tcb,struct xnarchtcb *in_tcb) +void xnarch_switch_to (struct xnthread *out,struct xnthread *in) { +struct xnarchtcb *out_tcb = &out->tcb, *in_tcb = &in->tcb;unsigned long __maybe_unused fs, gs;struct mm_struct *prev_mm, *next_mm;struct task_struct *prev, *next;
@@ -218,8 +219,9 @@ static inline void __do_restore_i387(x86_fpustate *fpup)#endif /* CONFIG_X86_64 */ } -int xnarch_handle_fpu_fault (struct xnarchtcb *tcb) +int xnarch_handle_fpu_fault (struct xnthread *thread) { +struct xnarchtcb *tcb =xnthread_archtcb (to);struct task_struct *p = tcb->core.host_task;if (tsk_used_math (p))
@@ -244,8 +246,9 @@ int xnarch_handle_fpu_fault(struct xnarchtcb *tcb)return 1 ; } -void xnarch_leave_root (struct xnarchtcb *rootcb) +void xnarch_leave_root (struct xnthread *root) { +struct xnarchtcb *rootcb =xnthread_archtcb (root);struct task_struct *p = current;#ifdef CONFIG_X86_64
@@ -263,8 +266,9 @@ void xnarch_leave_root(struct xnarchtcb *rootcb) } } -void xnarch_save_fpu (struct xnarchtcb *tcb) +void xnarch_save_fpu (struct xnthread *thread) { +struct xnarchtcb *tcb =xnthread_archtcb (thread);struct task_struct *p = tcb->core.host_task;if (wrap_test_fpu_used (p) ==0 )
@@ -278,8 +282,9 @@ void xnarch_save_fpu(struct xnarchtcb *tcb)wrap_clear_fpu_used (p); } -void xnarch_restore_fpu (struct xnarchtcb *tcb) +void xnarch_restore_fpu (struct xnthread *thread) { +struct xnarchtcb *tcb =xnthread_archtcb (thread);struct task_struct *p = tcb->core.host_task;if (tcb->root_kfpu ==0 && (tsk_used_math (p) ==0 || tcb->is_root))
@@ -302,15 +307,16 @@ void xnarch_restore_fpu(struct xnarchtcb *tcb) wrap_set_fpu_used(p); } -void xnarch_enable_fpu (struct xnarchtcb *tcb) +void xnarch_enable_fpu (struct xnthread *thread) { -xnarch_restore_fpu (tcb); +xnarch_restore_fpu (thread); }#endif /* CONFIG_XENO_HW_FPU */ -void xnarch_init_root_tcb (struct xnarchtcb *tcb) +void xnarch_init_root_tcb (struct xnthread *thread) { +struct xnarchtcb *tcb =xnthread_archtcb (thread); tcb->sp =0 ; tcb->spp = &tcb->sp; tcb->ipp = &tcb->ip;
@@ -319,9 +325,10 @@ void xnarch_init_root_tcb(struct xnarchtcb *tcb) tcb->root_kfpu =0 ; } -void xnarch_init_shadow_tcb (struct xnarchtcb *tcb) +void xnarch_init_shadow_tcb (struct xnthread *thread) {struct task_struct *p = tcb->core.host_task; +struct xnarchtcb *tcb =xnthread_archtcb (thread); tcb->sp =0 ; tcb->spp = &p->thread.sp;
kernel/cobalt/include/asm-generic/xenomai/thread.h +5 -0
@@ -28,6 +28,9 @@struct task_struct ; +struct xnthread ; +struct xnarchtcb ; +struct xntcb {struct task_struct *host_task;struct thread_struct *tsp;
@@ -43,4 +46,6 @@ struct xntcb { #endif }; +static inline struct xnarchtcb *xnthread_archtcb (struct xnthread *thread); +#endif /* !_COBALT_ASM_GENERIC_THREAD_H */
kernel/cobalt/sched.c +2 -4
@@ -25,7 +25,6 @@#include <cobalt/kernel/heap.h> #include <cobalt/kernel/shadow.h> #include <cobalt/kernel/arith.h> -#include <asm/xenomai/thread.h> DEFINE_PER_CPU(struct xnsched, nksched);EXPORT_PER_CPU_SYMBOL_GPL (nksched);
@@ -646,8 +645,7 @@ static inline void switch_context(struct xnsched *sched,xnlock_clear_irqon (&nklock);#endif /* !CONFIG_XENO_HW_UNLOCKED_SWITCH */ -xnarch_switch_to (xnthread_archtcb (prev), -xnthread_archtcb (next)); +xnarch_switch_to (prev, next); }/**
@@ -746,7 +744,7 @@ static inline void leave_root(struct xnthread *root)#ifdef CONFIG_XENO_HW_UNLOCKED_SWITCH rootcb->core.tip =task_thread_info (p);#endif -xnarch_leave_root (rootcb); +xnarch_leave_root (root); }void __xnsched_run_handler (void )/* hw interrupts off. */
kernel/cobalt/shadow.c +2 -4
@@ -57,9 +57,9 @@#include <cobalt/kernel/stat.h> #include <cobalt/kernel/ppd.h> #include <cobalt/kernel/vdso.h> +#include <cobalt/kernel/thread.h> #include <asm/xenomai/features.h> #include <asm/xenomai/syscall.h> -#include <asm/xenomai/thread.h> #include <asm-generic/xenomai/mayday.h> #include "debug.h"
@@ -2592,7 +2592,6 @@ int ipipe_kevent_hook(int kevent, void *data)static inline int handle_exception (struct ipipe_trap_data *d) {struct xnthread *thread; -struct xnarchtcb *tcb;if (xnsched_root_p ())return 0 ;
@@ -2608,8 +2607,7 @@ static inline int handle_exception(struct ipipe_trap_data *d)if (xnarch_fault_fpu_p (d)) {if (!xnthread_test_state (thread,XNROOT )) {/* FPU exception received in primary mode. */ - tcb =xnthread_archtcb (thread); -if (xnarch_handle_fpu_fault (tcb)) +if (xnarch_handle_fpu_fault (thread))return 1 ; } print_symbol("invalid use of FPU in Xenomai context at %s\n",
kernel/cobalt/thread.c +7 -9
@@ -36,7 +36,6 @@#include <cobalt/kernel/shadow.h> #include <cobalt/kernel/lock.h> #include <cobalt/kernel/thread.h> -#include <asm/xenomai/thread.h> /** * @ingroup nucleus
@@ -225,7 +224,7 @@ void xnthread_init_shadow_tcb(struct xnthread *thread, struct task_struct *task)#ifdef CONFIG_XENO_HW_FPU tcb->core.user_fpu_owner = task;#endif /* CONFIG_XENO_HW_FPU */ -xnarch_init_shadow_tcb (tcb); +xnarch_init_shadow_tcb (thread); }void xnthread_init_root_tcb (struct xnthread *thread)
@@ -239,7 +238,7 @@ void xnthread_init_root_tcb(struct xnthread *thread)#ifdef CONFIG_XENO_HW_UNLOCKED_SWITCH tcb->core.tip = &tcb->core.ti;#endif -xnarch_init_root_tcb (tcb); +xnarch_init_root_tcb (thread); }void xnthread_deregister (struct xnthread *thread)
@@ -380,7 +379,7 @@ static inline void release_fpu(struct xnthread *thread)* area of the migrated thread. */ if (xnthread_test_state (thread,XNFPU )) { -xnarch_save_fpu (xnthread_archtcb (thread)); +xnarch_save_fpu (thread); thread->sched->fpuholder =NULL ; } }
@@ -397,16 +396,15 @@ void xnthread_switch_fpu(struct xnsched *sched) xnarch_fpu_ptr(xnthread_archtcb(sched->fpuholder)) != xnarch_fpu_ptr(xnthread_archtcb(curr))) {if (sched->fpuholder) -xnarch_save_fpu (xnthread_archtcb - (sched->fpuholder)); +xnarch_save_fpu (sched->fpuholder); -xnarch_restore_fpu (xnthread_archtcb (curr)); +xnarch_restore_fpu (curr); } else -xnarch_enable_fpu (xnthread_archtcb (curr )); +xnarch_enable_fpu (curr ); sched->fpuholder = curr; }else -xnarch_enable_fpu (xnthread_archtcb (curr)); +xnarch_enable_fpu (curr); }#else /* !CONFIG_XENO_HW_FPU */
Signature · 1 line
1.7.10.4
PATCH 3/7 cobalt/fpu: replace the is_root member with XNROOT tests
In reply to Gilles Chanteperdrix--- kernel/cobalt/arch/arm/include/asm/xenomai/thread.h | 4 ---- kernel/cobalt/arch/arm/thread.c | 4 ++-- kernel/cobalt/arch/x86/include/asm/xenomai/thread.h | 1 - kernel/cobalt/arch/x86/thread.c | 6 +++--- 4 files changed, 5 insertions(+), 10 deletions(-)
kernel/cobalt/arch/arm/include/asm/xenomai/thread.h +0 -4
@@ -51,9 +51,7 @@ struct arm_fpustate {struct xnarchtcb {struct xntcb core;#ifdef CONFIG_XENO_HW_FPU -struct arm_fpustate fpuenv;struct arm_fpustate *fpup; -unsigned int is_root;#define xnarch_fpu_ptr (tcb) ((tcb)->fpup)#else #define xnarch_fpu_ptr (tcb) NULL
@@ -98,14 +96,12 @@ int xnarch_escalate(void);static inline void xnarch_init_root_tcb (struct xnthread *thread) {struct xnarchtcb *tcb =xnthread_archtcb (thread); - tcb->is_root =1 ; tcb->fpup =NULL ; }static inline void xnarch_init_shadow_tcb (struct xnthread *thread) {struct xnarchtcb *tcb =xnthread_archtcb (thread); - tcb->is_root =0 ; tcb->fpup = (struct arm_fpustate *) &task_thread_info (tcb->core.host_task)->used_cp[0 ]; }
kernel/cobalt/arch/arm/thread.c +2 -2
@@ -294,7 +294,7 @@ void xnarch_enable_fpu(struct xnthread *thread)newly switched thread uses the FPU, to allow the kernel handler to pick the correct FPU context. */ -if (likely (!tcb->is_root)) { +if (likely (!xnthread_test_state (thread,XNROOT ))) {do_enable_fpu ();/* No exception should be pending, since it should have caused a trap earlier.
@@ -355,7 +355,7 @@ void xnarch_restore_fpu(struct xnthread *thread)struct xnarchtcb *tcb = &thread->tcb; #ifdef CONFIG_XENO_HW_FPU #ifdef CONFIG_VFP - if (likely(!tcb->is_root)) { + if (likely(!xnthread_test_state(thread, XNROOT))) { do_enable_fpu(); do_restore_fpu(tcb->fpup); } else {
kernel/cobalt/arch/x86/include/asm/xenomai/thread.h +0 -1
@@ -35,7 +35,6 @@ struct xnarchtcb {unsigned long ip;unsigned long *ipp;x86_fpustate *fpup; - unsigned int is_root: 1; unsigned int root_kfpu: 1; unsigned int root_used_math: 1;struct {
kernel/cobalt/arch/x86/thread.c +3 -3
@@ -287,7 +287,8 @@ void xnarch_restore_fpu(struct xnthread *thread)struct xnarchtcb *tcb =xnthread_archtcb (thread);struct task_struct *p = tcb->core.host_task; -if (tcb->root_kfpu ==0 && (tsk_used_math (p) ==0 || tcb->is_root)) +if (tcb->root_kfpu ==0 && + (tsk_used_math (p) ==0 ||xnthread_test_state (thread,XNROOT )))/* Restore lazy mode */ return ;
@@ -320,15 +321,14 @@ void xnarch_init_root_tcb(struct xnthread *thread) tcb->sp =0 ; tcb->spp = &tcb->sp; tcb->ipp = &tcb->ip; - tcb->is_root =1 ; tcb->fpup =NULL ; tcb->root_kfpu =0 ; }void xnarch_init_shadow_tcb (struct xnthread *thread) { -struct task_struct *p = tcb->core.host_task;struct xnarchtcb *tcb =xnthread_archtcb (thread); +struct task_struct *p = tcb->core.host_task; tcb->sp =0 ; tcb->spp = &p->thread.sp;
Signature · 1 line
1.7.10.4
PATCH 4/7 cobalt/fpu: dynamic XNFPU
In reply to Gilles ChanteperdrixInstead of systematically creating user-space tasks with XNFPU enabled, let the architectures decide when they want to enable it. In case they arm it upon FPU fault, set sched->fpuholder if the fault is handled in primary mode.
--- kernel/cobalt/arch/arm/include/asm/xenomai/thread.h | 7 +------ kernel/cobalt/arch/arm/thread.c | 10 ++++++++++ kernel/cobalt/arch/sh/include/asm/xenomai/thread.h | 6 +----- kernel/cobalt/arch/sh/thread.c | 10 ++++++++++ kernel/cobalt/arch/x86/thread.c | 3 +++ kernel/cobalt/posix/thread.c | 2 +- kernel/cobalt/shadow.c | 18 +++++++++--------- 7 files changed, 35 insertions(+), 21 deletions(-)
kernel/cobalt/arch/arm/include/asm/xenomai/thread.h +1 -6
@@ -99,12 +99,7 @@ static inline void xnarch_init_root_tcb(struct xnthread *thread) tcb->fpup =NULL ; } -static inline void xnarch_init_shadow_tcb (struct xnthread *thread) -{ -struct xnarchtcb *tcb =xnthread_archtcb (thread); - tcb->fpup = (struct arm_fpustate *) - &task_thread_info (tcb->core.host_task)->used_cp[0 ]; -} +void xnarch_init_shadow_tcb (struct xnthread *thread);int xnarch_fault_fpu_p (struct ipipe_trap_data *d);
kernel/cobalt/arch/arm/thread.c +10 -0
@@ -402,3 +402,13 @@ int xnarch_escalate(void)return 0 ; } + +void xnarch_init_shadow_tcb (struct xnthread *thread) +{ +struct xnarchtcb *tcb =xnthread_archtcb (thread); + tcb->fpup = (struct arm_fpustate *) + &task_thread_info (tcb->core.host_task)->used_cp[0 ]; + +if (xnthread_test_state (thread,XNUSER )) +xnthread_set_state (thread,XNFPU ); +}
kernel/cobalt/arch/sh/include/asm/xenomai/thread.h +1 -5
@@ -60,11 +60,7 @@ static inline void xnarch_init_root_tcb(struct xnthread *thread) tcb->fpup = NULL; } -static inline void xnarch_init_shadow_tcb (struct xnthread *thread) -{ -struct xnarchtcb *tcb =xnthread_archtcb (thread); - tcb->fpup = &tcb->core.host_task->thread; -} +void xnarch_init_shadow_tcb (struct xnthread *thread);#else /* !CONFIG_XENO_HW_FPU */
kernel/cobalt/arch/sh/thread.c +10 -0
@@ -292,3 +292,13 @@ int xnarch_escalate(void)return 0 ; } + +void xnarch_init_shadow_tcb (struct xnthread *thread) +{ +struct xnarchtcb *tcb =xnthread_archtcb (thread); + tcb->fpup = &tcb->core.host_task->thread; + +if (xnthread_test_state (thread,XNUSER )) +xnthread_set_state (thread,XNFPU ); +} +
kernel/cobalt/arch/x86/thread.c +3 -0
@@ -339,6 +339,9 @@ void xnarch_init_shadow_tcb(struct xnthread *thread)#endif tcb->fpup =x86_fpustate_ptr (&p->thread); tcb->root_kfpu =0 ; + +if (xnthread_test_state (thread,XNUSER )) +xnthread_set_state (thread,XNFPU ); }int xnarch_escalate (void )
kernel/cobalt/posix/thread.c +1 -1
@@ -437,7 +437,7 @@ static inline int pthread_create(struct cobalt_thread **thread_p, } iattr.name = thread->attr.name; - iattr.flags =XNUSER |XNFPU ; + iattr.flags =XNUSER ; iattr.personality = &cobalt_personality; iattr.affinity =CPU_MASK_ALL ;
kernel/cobalt/shadow.c +9 -9
@@ -2591,12 +2591,14 @@ int ipipe_kevent_hook(int kevent, void *data)static inline int handle_exception (struct ipipe_trap_data *d) { +struct xnsched *sched;struct xnthread *thread; -if (xnsched_root_p ()) -return 0 ; + sched =xnsched_current (); + thread = sched->curr; - thread =xnsched_current_thread (); +if (xnthread_test_state (thread,XNROOT )) +return 0 ; trace_mark(xn_nucleus, thread_fault, "thread %p thread_name %s ip %p type 0x%x",
@@ -2605,17 +2607,15 @@ static inline int handle_exception(struct ipipe_trap_data *d) xnarch_fault_trap(d));if (xnarch_fault_fpu_p (d)) { -if (!xnthread_test_state (thread,XNROOT )) { -/* FPU exception received in primary mode. */ -if (xnarch_handle_fpu_fault (thread)) -return 1 ; +/* FPU exception received in primary mode. */ +if (xnarch_handle_fpu_fault (thread)) { + sched->fpuholder = thread; +return 1 ; }print_symbol ("invalid use of FPU in Xenomai context at %s\n" ,xnarch_fault_pc (d)); } -if (xnthread_test_state (thread,XNROOT )) -return 0 ;/* * If we experienced a trap on behalf of a shadow thread * running in primary mode, move it to the Linux domain,
Signature · 1 line
1.7.10.4
PATCH 5/7 cobalt/fpu: change xnarch_handle_fpu_fault interface
In reply to Gilles ChanteperdrixPass the current FPU holder to allow enabling XNFPU dynamically. Also pass the faults information for architectures which need to fiddle with the PC register to restart the faulting instruction.
--- kernel/cobalt/arch/arm/include/asm/xenomai/thread.h | 4 +++- kernel/cobalt/arch/blackfin/include/asm/xenomai/thread.h | 4 +++- kernel/cobalt/arch/nios2/include/asm/xenomai/thread.h | 4 +++- kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h | 4 +++- kernel/cobalt/arch/sh/include/asm/xenomai/thread.h | 4 +++- kernel/cobalt/arch/x86/include/asm/xenomai/thread.h | 7 +++++-- kernel/cobalt/arch/x86/thread.c | 3 ++- kernel/cobalt/shadow.c | 2 +- 8 files changed, 23 insertions(+), 9 deletions(-)
kernel/cobalt/arch/arm/include/asm/xenomai/thread.h +3 -1
@@ -124,7 +124,9 @@ static inline void xnarch_leave_root(struct xnthread *root) { }#endif /* !CONFIG_XENO_HW_FPU */ -static inline int xnarch_handle_fpu_fault (struct xnthread *thread) +static inline int +xnarch_handle_fpu_fault (struct xnthread *from, +struct xnthread *to,struct ipipe_trap_data *d) {return 0 ; }
kernel/cobalt/arch/blackfin/include/asm/xenomai/thread.h +3 -1
@@ -62,7 +62,9 @@ static inline void xnarch_enable_fpu(struct xnthread *current_thread) { }static inline void xnarch_save_fpu (struct xnthread *thread) { }static inline void xnarch_restore_fpu (struct xnthread *thread) { } -static inline int xnarch_handle_fpu_fault (struct xnthread *thread) +static inline int +xnarch_handle_fpu_fault (struct xnthread *from, +struct xnthread *to,struct ipipe_trap_data *d) {return 0 ; }
kernel/cobalt/arch/nios2/include/asm/xenomai/thread.h +3 -1
@@ -57,7 +57,9 @@ static inline void xnarch_enable_fpu(struct xnthread *thread) { }static inline void xnarch_save_fpu (struct xnthread *thread) { }static inline void xnarch_restore_fpu (struct xnthread *thread) { } -static inline int xnarch_handle_fpu_fault (struct xnthread *thread) +static inline int +xnarch_handle_fpu_fault (struct xnthread *from, +struct xnthread *to,struct ipipe_trap_data *d) {return 0 ; }
kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h +3 -1
@@ -77,7 +77,9 @@ static inline void xnarch_init_shadow_tcb(struct xnthread *thread) { }#endif /* !CONFIG_XENO_HW_FPU */ -static inline int xnarch_handle_fpu_fault (struct xnthread *thread) +static inline int +xnarch_handle_fpu_fault (struct xnthread *from, +struct xnthread *to,struct ipipe_trap_data *d) {return 0 ; }
kernel/cobalt/arch/sh/include/asm/xenomai/thread.h +3 -1
@@ -70,7 +70,9 @@ static inline void xnarch_init_shadow_tcb(struct xnthread *thread) { }#endif /* !CONFIG_XENO_HW_FPU */ -static inline int xnarch_handle_fpu_fault (struct xnthread *thread) +static inline int +xnarch_handle_fpu_fault (struct xnthread *from, +struct xnthread *to,struct ipipe_trap_data *d) {return 0 ; }
kernel/cobalt/arch/x86/include/asm/xenomai/thread.h +5 -2
@@ -69,7 +69,8 @@ static inline int xnarch_shadow_p(struct xnarchtcb *tcb, struct task_struct *tasvoid xnarch_save_fpu (struct xnthread *thread);void xnarch_restore_fpu (struct xnthread *thread);void xnarch_enable_fpu (struct xnthread *thread); -int xnarch_handle_fpu_fault (struct xnthread *thread); +int xnarch_handle_fpu_fault (struct xnthread *from, +struct xnthread *to,struct ipipe_trap_data *d);#else /* !CONFIG_XENO_HW_FPU */
@@ -77,7 +78,9 @@ static inline void xnarch_save_fpu(struct xnthread *thread) { }static inline void xnarch_restore_fpu (struct xnthread *thread) { }static inline void xnarch_enable_fpu (struct xnthread *thread) { } -static inline int xnarch_handle_fpu_fault (struct xnthread *thread) +static inline int +xnarch_handle_fpu_fault (struct xnthread *from, +struct xnthread *to,struct ipipe_trap_data *d) {return 0 ; }
kernel/cobalt/arch/x86/thread.c +2 -1
@@ -219,7 +219,8 @@ static inline void __do_restore_i387(x86_fpustate *fpup)#endif /* CONFIG_X86_64 */ } -int xnarch_handle_fpu_fault (struct xnthread *thread) +int xnarch_handle_fpu_fault (struct xnthread *from, +struct xnthread *to,struct ipipe_trap_data *d) {struct xnarchtcb *tcb =xnthread_archtcb (to);struct task_struct *p = tcb->core.host_task;
kernel/cobalt/shadow.c +1 -1
@@ -2608,7 +2608,7 @@ static inline int handle_exception(struct ipipe_trap_data *d)if (xnarch_fault_fpu_p (d)) {/* FPU exception received in primary mode. */ -if (xnarch_handle_fpu_fault (thread)) { +if (xnarch_handle_fpu_fault (sched->fpuholder, thread, d)) { sched->fpuholder = thread;return 1 ; }
Signature · 1 line
1.7.10.4
PATCH 6/7 cobalt/fpu: change fpu handling interface
In reply to Gilles ChanteperdrixFor different reasons on x86 and ARM, implementing FPU switching in terms of xnarch_enable_fpu/xnarch_save_fpu/xnarch_restore_fpu no longer really makes sense. So, keep xnarch_save_fpu for migration, but replace xnarch_enable_fpu and xnarch_restore_fpu with xnarch_switch_fpu(from, to).
A default implementation for xnarch_switch_fpu is provided which switches fpu in terms of xnarch_save_fpu/xnarch_restore_fpu/xnarch_enable_fpu on architectures where it still makes sense.
--- .../cobalt/arch/arm/include/asm/xenomai/thread.h | 4 +--- kernel/cobalt/arch/arm/thread.c | 16 ++++++++++++++++ .../arch/blackfin/include/asm/xenomai/thread.h | 7 +++++-- .../cobalt/arch/nios2/include/asm/xenomai/thread.h | 7 +++++-- .../arch/powerpc/include/asm/xenomai/thread.h | 4 +--- kernel/cobalt/arch/powerpc/thread.c | 20 ++++++++++++++++++-- kernel/cobalt/arch/sh/thread.c | 20 ++++++++++++++++++-- .../cobalt/arch/x86/include/asm/xenomai/thread.h | 10 ++++++---- kernel/cobalt/arch/x86/thread.c | 9 +++------ kernel/cobalt/thread.c | 14 +------------- 10 files changed, 74 insertions(+), 37 deletions(-)
kernel/cobalt/arch/arm/include/asm/xenomai/thread.h +1 -3
@@ -79,11 +79,9 @@ struct xnarchtcb {#define xnarch_fault_notify (d) (!xnarch_fault_bp_p(d)) -void xnarch_enable_fpu (struct xnthread *current_thread); -void xnarch_save_fpu (struct xnthread *thread); -void xnarch_restore_fpu (struct xnthread *thread); +int xnarch_switch_fpu (struct xnthread *from,struct xnthread *thread);void xnarch_switch_to (struct xnthread *out,struct xnthread *in);
kernel/cobalt/arch/arm/thread.c +16 -0
@@ -393,6 +393,22 @@ void xnarch_restore_fpu(struct xnthread *thread)#endif /* CONFIG_XENO_HW_FPU */ } +int xnarch_switch_fpu (struct xnthread *from,struct xnthread *to) +{ +if (from == to || +xnarch_fpu_ptr (xnthread_archtcb (from)) == +xnarch_fpu_ptr (xnthread_archtcb (to))) { +xnarch_enable_fpu (to); +return 1 ; + } + +if (from) +xnarch_save_fpu (from); + +xnarch_restore_fpu (to); +return 1 ; +} +int xnarch_escalate (void ) {if (ipipe_root_p) {
kernel/cobalt/arch/blackfin/include/asm/xenomai/thread.h +5 -2
@@ -58,9 +58,12 @@ static inline void xnarch_init_root_tcb(struct xnthread *thread) { }static inline void xnarch_init_shadow_tcb (struct xnthread *thread) { }static inline void xnarch_enter_root (struct xnthread *root) { }static inline void xnarch_leave_root (struct xnthread *root) { } -static inline void xnarch_enable_fpu (struct xnthread *current_thread) { }static inline void xnarch_save_fpu (struct xnthread *thread) { } -static inline void xnarch_restore_fpu (struct xnthread *thread) { } +static inline int +xnarch_switch_fpu (struct xnthread *from,struct xnthread *thread) +{ +return 0 ; +} static inline int xnarch_handle_fpu_fault(struct xnthread *from,
kernel/cobalt/arch/nios2/include/asm/xenomai/thread.h +5 -2
@@ -53,9 +53,12 @@ static inline void xnarch_init_root_tcb(struct xnthread *thread) { }static inline void xnarch_init_shadow_tcb (struct xnthread *thread) { }static inline void xnarch_enter_root (struct xnthread *root) { }static inline void xnarch_leave_root (struct xnthread *thread) { } -static inline void xnarch_enable_fpu (struct xnthread *thread) { }static inline void xnarch_save_fpu (struct xnthread *thread) { } -static inline void xnarch_restore_fpu (struct xnthread *thread) { } +static inline int +xnarch_switch_fpu (struct xnthread *from,struct xnthread *to) +{ +return 0 ; +} static inline int xnarch_handle_fpu_fault(struct xnthread *from,
kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h +1 -3
@@ -88,10 +88,8 @@ void xnarch_switch_to(struct xnthread *out, struct xnthread *in);int xnarch_escalate (void ); -void xnarch_enable_fpu (struct xnthread *current_thread); -void xnarch_save_fpu (struct xnthread *thread); -void xnarch_restore_fpu (struct xnthread *thread); +int xnarch_switch_fpu (struct xnthread *from,struct xnthread *thread);#endif /* !_COBALT_POWERPC_ASM_THREAD_H */
kernel/cobalt/arch/powerpc/thread.c +18 -2
@@ -115,7 +115,7 @@ asmlinkage void __asm_restore_fpu(struct thread_struct *ts); })#endif /* CONFIG_PPC64 */ -void xnarch_enable_fpu (struct xnthread *thread) +static void xnarch_enable_fpu (struct xnthread *thread) {struct xnarchtcb *tcb =xnthread_archtcb (thread);struct task_struct *task = tcb->core.host_task;
@@ -139,7 +139,7 @@ void xnarch_save_fpu(struct xnthread *thread) } } -void xnarch_restore_fpu (struct xnthread *thread) +static void xnarch_restore_fpu (struct xnthread *thread) {struct xnarchtcb *tcb =xnthread_archtcb (thread);struct thread_struct *ts;
@@ -168,6 +168,22 @@ void xnarch_restore_fpu(struct xnthread *thread)do_disable_fpu (); } +int xnarch_switch_fpu (struct xnthread *from,struct xnthread *to) +{ +if (from == to || +xnarch_fpu_ptr (xnthread_archtcb (from)) == +xnarch_fpu_ptr (xnthread_archtcb (to))) { +xnarch_enable_fpu (to); +return 1 ; + } + +if (from) +xnarch_save_fpu (from); + +xnarch_restore_fpu (to); +return 1 ; +} +void xnarch_leave_root (struct xnthread *root) {struct xnarchtcb *rootcb =xnthread_archtcb (root);
kernel/cobalt/arch/sh/thread.c +18 -2
@@ -227,7 +227,7 @@ static inline void do_restore_fpu(struct thread_struct *ts) :"memory"); } -inline void xnarch_enable_fpu (struct xnthread *thread) +static inline void xnarch_enable_fpu (struct xnthread *thread) {struct xnarchtcb *tcb =xnthread_archtcb (thread);struct task_struct *task = tcb->core.host_task;
@@ -252,7 +252,7 @@ void xnarch_save_fpu(struct xnthread *thread) } } -void xnarch_restore_fpu (struct xnthread *thread) +static void xnarch_restore_fpu (struct xnthread *thread) {struct xnarchtcb *tcb =xnthread_archtcb (thread);struct pt_regs *regs;
@@ -273,6 +273,22 @@ void xnarch_restore_fpu(struct xnthread *thread)disable_fpu (); } +int xnarch_switch_fpu (struct xnthread *from,struct xnthread *to) +{ +if (from == to || +xnarch_fpu_ptr (xnthread_archtcb (from)) == +xnarch_fpu_ptr (xnthread_archtcb (to))) { +xnarch_enable_fpu (to); +return 1 ; + } + +if (from) +xnarch_save_fpu (from); + +xnarch_restore_fpu (to); +return 1 ; +} +void xnarch_leave_root (struct xnthread *root) {struct xnarchtcb *rootcb =xnthread_archtcb (root);
kernel/cobalt/arch/x86/include/asm/xenomai/thread.h +6 -4
@@ -67,16 +67,18 @@ static inline int xnarch_shadow_p(struct xnarchtcb *tcb, struct task_struct *tas#ifdef CONFIG_XENO_HW_FPU void xnarch_save_fpu (struct xnthread *thread); -void xnarch_restore_fpu (struct xnthread *thread); -void xnarch_enable_fpu (struct xnthread *thread); +int xnarch_switch_fpu (struct xnthread *from,struct xnthread *to);int xnarch_handle_fpu_fault (struct xnthread *from,struct xnthread *to,struct ipipe_trap_data *d);#else /* !CONFIG_XENO_HW_FPU */ static inline void xnarch_save_fpu (struct xnthread *thread) { } -static inline void xnarch_restore_fpu (struct xnthread *thread) { } -static inline void xnarch_enable_fpu (struct xnthread *thread) { } +static inline int +xnarch_switch_fpu (struct xnthread *from,struct xnthread *thread) +{ +return 0 ; +} static inline int xnarch_handle_fpu_fault(struct xnthread *from,
kernel/cobalt/arch/x86/thread.c +3 -6
@@ -283,7 +283,7 @@ void xnarch_save_fpu(struct xnthread *thread)wrap_clear_fpu_used (p); } -void xnarch_restore_fpu (struct xnthread *thread) +int xnarch_switch_fpu (struct xnthread *from,struct xnthread *thread) {struct xnarchtcb *tcb =xnthread_archtcb (thread);struct task_struct *p = tcb->core.host_task;
@@ -291,7 +291,7 @@ void xnarch_restore_fpu(struct xnthread *thread)if (tcb->root_kfpu ==0 && (tsk_used_math (p) ==0 ||xnthread_test_state (thread,XNROOT )))/* Restore lazy mode */ -return ; +return xnthread_test_state (thread,XNROOT );/* * Restore the FPU hardware with valid fp registers from a
@@ -307,11 +307,8 @@ void xnarch_restore_fpu(struct xnthread *thread) clear_stopped_child_used_math(p); }else wrap_set_fpu_used (p); -} -void xnarch_enable_fpu (struct xnthread *thread) -{ -xnarch_restore_fpu (thread); +return 1 ; }#endif /* CONFIG_XENO_HW_FPU */
kernel/cobalt/thread.c +1 -13
@@ -391,20 +391,8 @@ void xnthread_switch_fpu(struct xnsched *sched)if (!xnthread_test_state (curr,XNFPU ))return ; -if (sched->fpuholder != curr) { -if (sched->fpuholder ==NULL || -xnarch_fpu_ptr (xnthread_archtcb (sched->fpuholder)) != -xnarch_fpu_ptr (xnthread_archtcb (curr))) { -if (sched->fpuholder) -xnarch_save_fpu (sched->fpuholder); - -xnarch_restore_fpu (curr); - }else -xnarch_enable_fpu (curr); - +if (xnarch_switch_fpu (sched->fpuholder, curr)) sched->fpuholder = curr; - }else - xnarch_enable_fpu(curr); }#else /* !CONFIG_XENO_HW_FPU */
Signature · 1 line
1.7.10.4
PATCH 7/7 cobalt/x86: lazy FPU switching
In reply to Gilles ChanteperdrixOnly enable XNFPU on first FPU use in kernel-space. Skip context restore with fxsr when context allows it.
--- kernel/cobalt/arch/x86/thread.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-)
kernel/cobalt/arch/x86/thread.c +24 -9
@@ -225,7 +225,7 @@ int xnarch_handle_fpu_fault(struct xnthread *from,struct xnarchtcb *tcb =xnthread_archtcb (to);struct task_struct *p = tcb->core.host_task; -if (tsk_used_math (p)) +if (wrap_test_fpu_used (p))return 0 ;/*
@@ -243,6 +243,7 @@ int xnarch_handle_fpu_fault(struct xnthread *from,set_stopped_child_used_math (p);wrap_set_fpu_used (p); +xnthread_set_state (to,XNFPU );return 1 ; }
@@ -273,7 +274,7 @@ void xnarch_save_fpu(struct xnthread *thread)struct task_struct *p = tcb->core.host_task;if (wrap_test_fpu_used (p) ==0 ) -/* Common case: already saved by __switch_to */ +/* Saved by last __switch_to */ return ;/* Exceptional case: a migrating thread */
@@ -287,11 +288,28 @@ int xnarch_switch_fpu(struct xnthread *from, struct xnthread *thread) {struct xnarchtcb *tcb =xnthread_archtcb (thread);struct task_struct *p = tcb->core.host_task; +const unsigned root_kfpu = tcb->root_kfpu; -if (tcb->root_kfpu ==0 && - (tsk_used_math (p) ==0 ||xnthread_test_state (thread,XNROOT ))) +if (root_kfpu ==0 ) {/* Restore lazy mode */ -return xnthread_test_state (thread,XNROOT ); +if (tsk_used_math (p) ==0 ) +return 0 ; +if (xnthread_test_state (thread,XNROOT )) +return 1 ; + +/* +* If we never switched fpu, and the cpu has fxsr, the +* last context switch saved fpu but did not +* reinitialize it, so we can simply reenable fpu +*/ +if (cpu_has_fxsr && + (from == thread || + (from && from->tcb.fpup == thread->tcb.fpup))) { +clts (); +wrap_set_fpu_used (p); +return thread != from; + } + }/* * Restore the FPU hardware with valid fp registers from a
@@ -300,7 +318,7 @@ int xnarch_switch_fpu(struct xnthread *from, struct xnthread *thread)clts ();__do_restore_i387 (x86_fpustate_ptr (&p->thread)); -if (tcb->root_kfpu) { +if (root_kfpu) {x86_fpustate_ptr (&p->thread) = tcb->fpup;wrap_clear_fpu_used (p);if (tcb->root_used_math ==0 )
@@ -337,9 +355,6 @@ void xnarch_init_shadow_tcb(struct xnthread *thread)#endif tcb->fpup =x86_fpustate_ptr (&p->thread); tcb->root_kfpu =0 ; - -if (xnthread_test_state (thread,XNUSER )) -xnthread_set_state (thread,XNFPU ); }int xnarch_escalate (void )
Signature · 1 line
1.7.10.4