Module: xenomai-gch Branch: for-forge Commit: 0b9db0ef2e640d1f23ce55e1b6444c776202f317 URL: http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=0b9db0ef2e640d1f23ce55e1b6444c776202f317
Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org> Date: Fri Oct 25 20:42:48 2013 +0200 cobalt/fpu: change fpu handling interface For 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. --- kernel/cobalt/arch/arm/include/asm/xenomai/thread.h | 4 +--- kernel/cobalt/arch/arm/thread.c | 15 +++++++++++++++ .../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 | 19 +++++++++++++++++-- kernel/cobalt/arch/sh/thread.c | 19 +++++++++++++++++-- kernel/cobalt/arch/x86/include/asm/xenomai/thread.h | 10 ++++++---- kernel/cobalt/arch/x86/thread.c | 7 +------ kernel/cobalt/thread.c | 16 ++-------------- 10 files changed, 70 insertions(+), 38 deletions(-) diff --git a/kernel/cobalt/arch/arm/include/asm/xenomai/thread.h b/kernel/cobalt/arch/arm/include/asm/xenomai/thread.h index 8c42775..dd582d7 100644 --- a/kernel/cobalt/arch/arm/include/asm/xenomai/thread.h +++ b/kernel/cobalt/arch/arm/include/asm/xenomai/thread.h @@ -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); +void xnarch_switch_fpu(struct xnthread *from, struct xnthread *thread); void xnarch_switch_to(struct xnthread *out, struct xnthread *in); diff --git a/kernel/cobalt/arch/arm/thread.c b/kernel/cobalt/arch/arm/thread.c index 4915d75..d8cc813 100644 --- a/kernel/cobalt/arch/arm/thread.c +++ b/kernel/cobalt/arch/arm/thread.c @@ -388,6 +388,21 @@ void xnarch_restore_fpu(struct xnthread *thread) #endif /* CONFIG_XENO_HW_FPU */ } +void 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; + } + + if (from) + xnarch_save_fpu(from); + + xnarch_restore_fpu(to); +} + int xnarch_escalate(void) { if (ipipe_root_p) { diff --git a/kernel/cobalt/arch/blackfin/include/asm/xenomai/thread.h b/kernel/cobalt/arch/blackfin/include/asm/xenomai/thread.h index 6c630e7..0ecb0ea 100644 --- a/kernel/cobalt/arch/blackfin/include/asm/xenomai/thread.h +++ b/kernel/cobalt/arch/blackfin/include/asm/xenomai/thread.h @@ -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 void +xnarch_switch_fpu(struct xnthread *from, struct xnthread *thread) +{ + return 0; +} static inline int xnarch_handle_fpu_fault(struct xnthread *from, diff --git a/kernel/cobalt/arch/nios2/include/asm/xenomai/thread.h b/kernel/cobalt/arch/nios2/include/asm/xenomai/thread.h index 05de3c2..87f5e17 100644 --- a/kernel/cobalt/arch/nios2/include/asm/xenomai/thread.h +++ b/kernel/cobalt/arch/nios2/include/asm/xenomai/thread.h @@ -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 void +xnarch_switch_fpu(struct xnthread *from, struct xnthread *to) +{ + return 0; +} static inline int xnarch_handle_fpu_fault(struct xnthread *from, diff --git a/kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h b/kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h index 7504fba..d93147d 100644 --- a/kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h +++ b/kernel/cobalt/arch/powerpc/include/asm/xenomai/thread.h @@ -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); +void xnarch_switch_fpu(struct xnthread *from, struct xnthread *thread); #endif /* !_COBALT_POWERPC_ASM_THREAD_H */ diff --git a/kernel/cobalt/arch/powerpc/thread.c b/kernel/cobalt/arch/powerpc/thread.c index 70aad0e..53bbcf7 100644 --- a/kernel/cobalt/arch/powerpc/thread.c +++ b/kernel/cobalt/arch/powerpc/thread.c @@ -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,21 @@ void xnarch_restore_fpu(struct xnthread *thread) do_disable_fpu(); } +void 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; + } + + if (from) + xnarch_save_fpu(from); + + xnarch_restore_fpu(to); +} + void xnarch_leave_root(struct xnthread *root) { struct xnarchtcb *rootcb = xnthread_archtcb(root); diff --git a/kernel/cobalt/arch/sh/thread.c b/kernel/cobalt/arch/sh/thread.c index 78feb97..7dbf386 100644 --- a/kernel/cobalt/arch/sh/thread.c +++ b/kernel/cobalt/arch/sh/thread.c @@ -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,21 @@ void xnarch_restore_fpu(struct xnthread *thread) disable_fpu(); } +void 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; + } + + if (from) + xnarch_save_fpu(from); + + xnarch_restore_fpu(to); +} + void xnarch_leave_root(struct xnthread *root) { struct xnarchtcb *rootcb = xnthread_archtcb(root); diff --git a/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h b/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h index 938b25d..750fd41 100644 --- a/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h @@ -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); +void 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 void +xnarch_switch_fpu(struct xnthread *from, struct xnthread *thread) +{ + return 0; +} static inline int xnarch_handle_fpu_fault(struct xnthread *from, diff --git a/kernel/cobalt/arch/x86/thread.c b/kernel/cobalt/arch/x86/thread.c index f262ebf..d5da297 100644 --- a/kernel/cobalt/arch/x86/thread.c +++ b/kernel/cobalt/arch/x86/thread.c @@ -283,7 +283,7 @@ void xnarch_save_fpu(struct xnthread *thread) wrap_clear_fpu_used(p); } -void xnarch_restore_fpu(struct xnthread *thread) +void xnarch_switch_fpu(struct xnthread *from, struct xnthread *thread) { struct xnarchtcb *tcb = xnthread_archtcb(thread); struct task_struct *p = tcb->core.host_task; @@ -309,11 +309,6 @@ void xnarch_restore_fpu(struct xnthread *thread) wrap_set_fpu_used(p); } -void xnarch_enable_fpu(struct xnthread *thread) -{ - xnarch_restore_fpu(thread); -} - #endif /* CONFIG_XENO_HW_FPU */ void xnarch_init_root_tcb(struct xnthread *thread) diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c index 11fee30..00d6c41 100644 --- a/kernel/cobalt/thread.c +++ b/kernel/cobalt/thread.c @@ -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); - - sched->fpuholder = curr; - } else - xnarch_enable_fpu(curr); + xnarch_switch_fpu(sched->fpuholder, curr); + sched->fpuholder = curr; } #else /* !CONFIG_XENO_HW_FPU */ _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git