Skip to contentSkip to conversation

cobalt/x86: add support for eager fpu handling

PATCH Applied Henning Schild 2 participants 12 messages Sep 14, 2018 – Sep 27, 2018 x86

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 cobalt/x86: add support for eager fpu handling

Upstream 4.14 switched to purely eager fpu switching. That was backported to 4.4 and 4.9. This commit makes cobalt able to deal whith the changed kernel behaviour.
This commit takes care of 4.9 to begin with.

Introduce IPIPE_X86_FPU_EAGER to switch between the new and the old implementations. The new implementation is much simpler than the old one. We basically only deal with the odd case where Xenomai preempts Linux in a kernel-fpu context.
In a regular Linux that can never happen and if it happens we need to make sure to get things into a consistent state. We have to make "current" as not owning the fpu anymore and allow others to use in-kernel fpu (kernel_fpu_enable). __switch_to from Linux will do the rest.

---
 .../arch/x86/include/asm/xenomai/thread.h     |  8 ++-
 .../arch/x86/include/asm/xenomai/wrappers.h   |  5 ++
 kernel/cobalt/arch/x86/thread.c               | 69 ++++++++++++++++++-
 3 files changed, 79 insertions(+), 3 deletions(-)
kernel/cobalt/arch/x86/include/asm/xenomai/thread.h +7 -1
index f174a82c0..0c5c4da9c 100644
@@ -24,6 +24,7 @@
 #include <asm/xenomai/wrappers.h>
 #include <asm/traps.h>
 
+#ifndef IPIPE_X86_FPU_EAGER
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,4,0)
 typedef union thread_xstate x86_fpustate;
 #define x86_fpustate_ptr(t) ((t)->fpu.state)
@@ -31,6 +32,7 @@ typedef union thread_xstate x86_fpustate;
 typedef union fpregs_state x86_fpustate;
 #define x86_fpustate_ptr(t) ((t)->fpu.active_state)
 #endif
+#endif
 
 struct xnarchtcb {
 	struct xntcb core;
@@ -40,10 +42,14 @@ struct xnarchtcb {
 	unsigned long ip;
 	unsigned long *ipp;
 #endif  
+#ifdef IPIPE_X86_FPU_EAGER
+	struct fpu *kfpu;
+#else
 	x86_fpustate *fpup;
-	unsigned int root_kfpu: 1;
 	unsigned int root_used_math: 1;
 	x86_fpustate *kfpu_state;
+#endif
+	unsigned int root_kfpu: 1;
 	struct {
 		unsigned long ip;
 		unsigned long ax;
kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +5 -0
index 5f9cff3c9..00f0aaae5 100644
@@ -24,6 +24,11 @@
 #define __get_user_inatomic __get_user
 #define __put_user_inatomic __put_user
 
+#if LINUX_VERSION_CODE > KERNEL_VERSION(4,9,108) && \
+    LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0)
+#define IPIPE_X86_FPU_EAGER
+#endif
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
 #include <asm/i387.h>
 #include <asm/fpu-internal.h>
kernel/cobalt/arch/x86/thread.c +67 -2

143 lines not on this page · raw message

Signature · 1 line
2.19.0
#1 lore raw

PATCH v2 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 fpu is eager for those 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.

This patch basically drops most of the fpu specifics from the ipipe patch.

This patch applies on ipipe-4.9.y and it has to be followed by a merge with

Quoted 1 line

= 4.9.109. Cobalt will not compile if you are already eager and still

4.9.108

---
 arch/x86/include/asm/fpu/internal.h | 30 ++++++++---------------------
 arch/x86/include/asm/fpu/types.h    | 12 ------------
 arch/x86/kernel/fpu/core.c          | 17 ++++++----------
 arch/x86/kernel/fpu/init.c          |  5 +----
 4 files changed, 15 insertions(+), 49 deletions(-)
arch/x86/include/asm/fpu/internal.h +8 -22
index 35ca184e83e1..6bdceba90f17 100644
@@ -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))
-		asm volatile( "fxsave %[fx]" : [fx] "=m" (active_fpstate(fpu)->fxsave));
+		asm volatile( "fxsave %[fx]" : [fx] "=m" (fpu->state.fxsave));
 	else if (IS_ENABLED(CONFIG_AS_FXSAVEQ))
-		asm volatile("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 void copy_fxregs_to_kernel(struct fpu *fpu)
 		 * registers.
 		 */
 		asm volatile( "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:
 	 */
-	asm volatile("fnsave %[fp]; fwait" : [fp] "=m" (active_fpstate(fpu)->fsave));
+	asm volatile("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
index 497c551469ec..48df486b02f9 100644
@@ -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 +6 -11
index d31a73b2ab76..7dd8518272ca 100644
@@ -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();
 
@@ -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 != &current->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();
arch/x86/kernel/fpu/init.c +1 -4
index 3eee35d3d6f8..a1fc061d03e1 100644
@@ -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 = &current->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.19.0
#2 lore raw

Re: [Xenomai] [IPIPE] [PATCHv2] x86: make fpu switching eager

Change to v1:
removed whitespace changes and changed commit message

Am Fri, 14 Sep 2018 17:10:15 +0200
schrieb Henning Schild <[email protected]>:

Quoted 235 lines

Linux 4.14 dropped support for lazy fpu switching and in the 4.4 and 4.9 series similar changes where backported.
So fpu is eager for those 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.

This patch basically drops most of the fpu specifics from the ipipe patch.

This patch applies on ipipe-4.9.y and it has to be followed by a merge with

Quoted 2 lines

= 4.9.109. Cobalt will not compile if you are already eager and still

4.9.108

---
 arch/x86/include/asm/fpu/internal.h | 30
++++++++--------------------- arch/x86/include/asm/fpu/types.h    |
12 ------------ arch/x86/kernel/fpu/core.c          | 17
++++++---------- arch/x86/kernel/fpu/init.c          |  5 +----
 4 files changed, 15 insertions(+), 49 deletions(-)
(quoted diff) +0 -0

b/arch/x86/include/asm/fpu/internal.h index 35ca184e83e1..6bdceba90f17 100644 --- 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))
-		asm volatile( "fxsave %[fx]" : [fx]
 "=m" (active_fpstate(fpu)->fxsave));
+		asm volatile( "fxsave %[fx]" : [fx]
 "=m" (fpu->state.fxsave)); else if (IS_ENABLED(CONFIG_AS_FXSAVEQ))
-		asm volatile("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 void copy_fxregs_to_kernel(struct fpu *fpu)

arch/x86/include/asm/fpu/internal.h +0 -2
 		 * registers.
 		 */
 		asm volatile( "rex64/fxsave (%[fx])"
-			      : "=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 int copy_fpregs_to_fpstate(struct fpu *fpu) {

arch/x86/include/asm/fpu/internal.h +2 -2
 	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:
 	 */
-	asm volatile("fnsave %[fp]; fwait" : [fp]
 "=m" (active_fpstate(fpu)->fsave));
+	asm volatile("fnsave %[fp]; fwait" : [fp]

"=m" (fpu->state.fsave));

arch/x86/include/asm/fpu/internal.h +0 -0
 	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

arch/x86/include/asm/fpu/internal.h +1 -2
 	 * 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) {

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.h index 497c551469ec..48df486b02f9 100644 --- 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 a short

time: */

arch/x86/include/asm/fpu/types.h +0 -12
 	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 +2 -2
index d31a73b2ab76..7dd8518272ca 100644
@@ -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();
 
@@ -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);
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;
 
arch/x86/kernel/fpu/core.c +1 -1
 	WARN_ON_FPU(src_fpu != &current->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);
arch/x86/kernel/fpu/core.c +2 -2
 	}
@@ -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();
arch/x86/kernel/fpu/init.c +0 -2
index 3eee35d3d6f8..a1fc061d03e1 100644
@@ -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 =

&current->thread.fpu.state; -#endif

arch/x86/kernel/fpu/init.c +1 -1
 	/* 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 · 7 lines
Siemens AG
Corporate Technology
CT RDA IOT SES-DE
Otto-Hahn-Ring 6
81739 Muenchen, Germany
Mobile: +49 172 8378927
mailto: [email protected]
#3 lore raw

PATCH v2 2/4 cobalt/x86: add ipipe-4.4 eager fpu support

In reply to Henning Schild

Linux 4.4.138 switched to eager fpu, set IPIPE_X86_FPU_EAGER accordingly.

---
 kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h | 4 ++++
 1 file changed, 4 insertions(+)
kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +4 -0
index 00f0aaae5..a47730106 100644
@@ -28,6 +28,10 @@
     LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0)
 #define IPIPE_X86_FPU_EAGER
 #endif
+#if LINUX_VERSION_CODE > KERNEL_VERSION(4,4,137) && \
+    LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
+#define IPIPE_X86_FPU_EAGER
+#endif
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
 #include <asm/i387.h>
Signature · 1 line
2.19.0
#4 lore raw

PATCH v2 3/4 cobalt: fixup for kernel 4.14+

In reply to Henning Schild
---
 kernel/cobalt/include/asm-generic/xenomai/syscall.h | 5 +++++
 1 file changed, 5 insertions(+)
kernel/cobalt/include/asm-generic/xenomai/syscall.h +5 -0
index f11ade8e7..3873fa634 100644
@@ -20,7 +20,12 @@
 #define _COBALT_ASM_GENERIC_SYSCALL_H
 
 #include <linux/types.h>
+#include <linux/version.h>
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
 #include <asm/uaccess.h>
+#else
+#include <linux/uaccess.h>
+#endif
 #include <asm/xenomai/features.h>
 #include <asm/xenomai/wrappers.h>
 #include <asm/xenomai/machine.h>
Signature · 1 line
2.19.0
#5 lore raw

PATCH v2 4/4 cobalt/x86: add ipipe-4.14 eager fpu support

In reply to Henning Schild

4.14 is always eager, unfortunately we will need a few ifdefs inside the eager fpu support as well.

---
 .../arch/x86/include/asm/xenomai/wrappers.h   |  4 ++++
 kernel/cobalt/arch/x86/thread.c               | 21 ++++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)
kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +4 -0
index a47730106..a4cc368a5 100644
@@ -32,6 +32,10 @@
     LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
 #define IPIPE_X86_FPU_EAGER
 #endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)
+#define IPIPE_X86_FPU_EAGER
+#endif
+
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
 #include <asm/i387.h>
kernel/cobalt/arch/x86/thread.c +20 -1
index 18cf636e5..2668ce274 100644
@@ -42,6 +42,7 @@ static struct kmem_cache *xstate_cache;
 #define cpu_has_xsave boot_cpu_has(X86_FEATURE_XSAVE)
 #endif
 
+#ifndef IPIPE_X86_FPU_EAGER
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
 #include <asm/i387.h>
 #include <asm/fpu-internal.h>
@@ -72,6 +73,9 @@ static inline void x86_fpregs_activate(struct task_struct *t)
 #define x86_xstate_alignment		__alignof__(union fpregs_state)
 
 #endif
+#else /* IPIPE_X86_FPU_EAGER */
+#define x86_xstate_alignment		__alignof__(union fpregs_state)
+#endif /* ! IPIPE_X86_FPU_EAGER */
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,8,0)
 /*
@@ -465,9 +469,15 @@ void xnarch_leave_root(struct xnthread *root)
 	// save fpregs from in-kernel use
 	copy_fpregs_to_fpstate(rootcb->kfpu);
 	kernel_fpu_enable();
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)
+	// restore current's fpregs
+	__cpu_invalidate_fpregs_state();
+	switch_fpu_finish(&current->thread.fpu, smp_processor_id());
+#else
 	// mark current thread as not owning the FPU anymore
 	if (&current->thread.fpu.fpstate_active)
 		fpregs_deactivate(&current->thread.fpu);
+#endif
 }
 
 void xnarch_switch_fpu(struct xnthread *from, struct xnthread *to)
@@ -528,7 +538,11 @@ void xnarch_init_shadow_tcb(struct xnthread *thread)
 #else /* IPIPE_X86_FPU_EAGER */
 	/* XNFPU is always set */
 	xnthread_set_state(thread, XNFPU);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
 	fpu__activate_fpstate_read(&p->thread.fpu);
+#else
+	fpu__initialize(&p->thread.fpu);
+#endif
 #endif /* ! IPIPE_X86_FPU_EAGER */
 }
 
@@ -537,7 +551,12 @@ int mach_x86_thread_init(void)
 	xstate_cache = kmem_cache_create("cobalt_x86_xstate",
 					 fpu_kernel_xstate_size,
 					 x86_xstate_alignment,
-					 SLAB_NOTRACK, NULL);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
+					 SLAB_NOTRACK,
+#else
+					 0,
+#endif
+					 NULL);
 	if (xstate_cache == NULL)
 		return -ENOMEM;
 
Signature · 1 line
2.19.0
#6 lore raw

Re: [Xenomai] [PATCHv2 4/4] cobalt/x86: add ipipe-4.14 eager fpu support

All three kernels are tested now. I addressed comments from the first review. Unfortunately i did not find a nice split to reduce the ifdef hell we are in here.

I guess once we drop lazy fpu, most of it will go away.

Henning

Am Fri, 14 Sep 2018 17:10:18 +0200
schrieb Henning Schild <[email protected]>:

Quoted 88 lines

4.14 is always eager, unfortunately we will need a few ifdefs inside the eager fpu support as well.

---
 .../arch/x86/include/asm/xenomai/wrappers.h   |  4 ++++
 kernel/cobalt/arch/x86/thread.c               | 21

++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)

(quoted diff) +0 -0

b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h index a47730106..a4cc368a5 100644 --- a/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h @@ -32,6 +32,10 @@ LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
#define IPIPE_X86_FPU_EAGER
#endif

kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +4 -0
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)
+#define IPIPE_X86_FPU_EAGER
+#endif
+
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
 #include <asm/i387.h>
(quoted diff) +0 -0

b/kernel/cobalt/arch/x86/thread.c index 18cf636e5..2668ce274 100644

kernel/cobalt/arch/x86/thread.c +1 -0
@@ -42,6 +42,7 @@ static struct kmem_cache *xstate_cache;
 #define cpu_has_xsave boot_cpu_has(X86_FEATURE_XSAVE)
 #endif
 
+#ifndef IPIPE_X86_FPU_EAGER
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
 #include <asm/i387.h>
 #include <asm/fpu-internal.h>
@@ -72,6 +73,9 @@ static inline void x86_fpregs_activate(struct

task_struct *t) #define x86_xstate_alignment
__alignof__(union fpregs_state)
#endif

kernel/cobalt/arch/x86/thread.c +2 -0
+#else /* IPIPE_X86_FPU_EAGER */
+#define x86_xstate_alignment		__alignof__(union

fpregs_state) +#endif /* ! IPIPE_X86_FPU_EAGER */

#if LINUX_VERSION_CODE < KERNEL_VERSION(4,8,0)
/*

kernel/cobalt/arch/x86/thread.c +16 -1
@@ -465,9 +469,15 @@ void xnarch_leave_root(struct xnthread *root)
 	// save fpregs from in-kernel use
 	copy_fpregs_to_fpstate(rootcb->kfpu);
 	kernel_fpu_enable();
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)
+	// restore current's fpregs
+	__cpu_invalidate_fpregs_state();
+	switch_fpu_finish(&current->thread.fpu, smp_processor_id());
+#else
 	// mark current thread as not owning the FPU anymore
 	if (&current->thread.fpu.fpstate_active)
 		fpregs_deactivate(&current->thread.fpu);
+#endif
 }
 
 void xnarch_switch_fpu(struct xnthread *from, struct xnthread *to)
@@ -528,7 +538,11 @@ void xnarch_init_shadow_tcb(struct xnthread
 *thread) #else /* IPIPE_X86_FPU_EAGER */
 	/* XNFPU is always set */
 	xnthread_set_state(thread, XNFPU);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
 	fpu__activate_fpstate_read(&p->thread.fpu);
+#else
+	fpu__initialize(&p->thread.fpu);
+#endif
 #endif /* ! IPIPE_X86_FPU_EAGER */
 }
 
@@ -537,7 +551,12 @@ int mach_x86_thread_init(void)
 	xstate_cache = kmem_cache_create("cobalt_x86_xstate",
 					 fpu_kernel_xstate_size,
 					 x86_xstate_alignment,
-					 SLAB_NOTRACK, NULL);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
+					 SLAB_NOTRACK,
+#else
+					 0,
+#endif
+					 NULL);
 	if (xstate_cache == NULL)
 		return -ENOMEM;
 
Signature · 7 lines
Siemens AG
Corporate Technology
CT RDA IOT SES-DE
Otto-Hahn-Ring 6
81739 Muenchen, Germany
Mobile: +49 172 8378927
mailto: [email protected]
#7 lore raw

Re: [Xenomai] [PATCHv2 4/4] cobalt/x86: add ipipe-4.14 eager fpu support

In reply to Henning Schild
Quoted 79 lines · Henning Schild

4.14 is always eager, unfortunately we will need a few ifdefs inside the eager fpu support as well.

---
  .../arch/x86/include/asm/xenomai/wrappers.h   |  4 ++++
  kernel/cobalt/arch/x86/thread.c               | 21 ++++++++++++++++++-
  2 files changed, 24 insertions(+), 1 deletion(-)
kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +4 -0
index a47730106..a4cc368a5 100644
@@ -32,6 +32,10 @@
      LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
  #define IPIPE_X86_FPU_EAGER
  #endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)
+#define IPIPE_X86_FPU_EAGER
+#endif
+
 
  #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
  #include <asm/i387.h>
kernel/cobalt/arch/x86/thread.c +14 -0
index 18cf636e5..2668ce274 100644
@@ -42,6 +42,7 @@ static struct kmem_cache *xstate_cache;
  #define cpu_has_xsave boot_cpu_has(X86_FEATURE_XSAVE)
  #endif
 
+#ifndef IPIPE_X86_FPU_EAGER
  #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
  #include <asm/i387.h>
  #include <asm/fpu-internal.h>
@@ -72,6 +73,9 @@ static inline void x86_fpregs_activate(struct task_struct *t)
  #define x86_xstate_alignment		__alignof__(union fpregs_state)
 
  #endif
+#else /* IPIPE_X86_FPU_EAGER */
+#define x86_xstate_alignment		__alignof__(union fpregs_state)
+#endif /* ! IPIPE_X86_FPU_EAGER */
 
  #if LINUX_VERSION_CODE < KERNEL_VERSION(4,8,0)
  /*
@@ -465,9 +469,15 @@ void xnarch_leave_root(struct xnthread *root)
  	// save fpregs from in-kernel use
  	copy_fpregs_to_fpstate(rootcb->kfpu);
  	kernel_fpu_enable();
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)
+	// restore current's fpregs
+	__cpu_invalidate_fpregs_state();
+	switch_fpu_finish(&current->thread.fpu, smp_processor_id());
+#else
  	// mark current thread as not owning the FPU anymore
  	if (&current->thread.fpu.fpstate_active)
  		fpregs_deactivate(&current->thread.fpu);
+#endif
  }
 
  void xnarch_switch_fpu(struct xnthread *from, struct xnthread *to)
@@ -528,7 +538,11 @@ void xnarch_init_shadow_tcb(struct xnthread *thread)
  #else /* IPIPE_X86_FPU_EAGER */
  	/* XNFPU is always set */
  	xnthread_set_state(thread, XNFPU);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
  	fpu__activate_fpstate_read(&p->thread.fpu);
+#else
+	fpu__initialize(&p->thread.fpu);
+#endif
  #endif /* ! IPIPE_X86_FPU_EAGER */
  }
 
@@ -537,7 +551,12 @@ int mach_x86_thread_init(void)
  	xstate_cache = kmem_cache_create("cobalt_x86_xstate",
  					 fpu_kernel_xstate_size,
  					 x86_xstate_alignment,

kernel/cobalt/arch/x86/thread.c int mach_x86_thread_init(void) · line 562

Quoted 10 lines
kernel/cobalt/arch/x86/thread.c +6 -1
-					 SLAB_NOTRACK, NULL);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
+					 SLAB_NOTRACK,
+#else
+					 0,
+#endif
+					 NULL);
  	if (xstate_cache == NULL)
  		return -ENOMEM;
 

Thanks, taken the whole series to next so that we can move forward. I've just changed "//" (C++) style comments to "old-style" C. Kernel style. Please avoid them in the future.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
#8 lore raw

Re: [Xenomai] [PATCHv2 4/4] cobalt/x86: add ipipe-4.14 eager fpu support

Quoted 77 lines · Jan Kiszka
Quoted 76 lines · Henning Schild

4.14 is always eager, unfortunately we will need a few ifdefs inside the eager fpu support as well.

---
  .../arch/x86/include/asm/xenomai/wrappers.h   |  4 ++++ kernel/cobalt/arch/x86/thread.c               | 21 ++++++++++++++++++-

  2 files changed, 24 insertions(+), 1 deletion(-)
kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +4 -0
index a47730106..a4cc368a5 100644
@@ -32,6 +32,10 @@
       LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
   #define IPIPE_X86_FPU_EAGER
   #endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)
+#define IPIPE_X86_FPU_EAGER
+#endif
+
   #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
   #include <asm/i387.h>
kernel/cobalt/arch/x86/thread.c +17 -1
index 18cf636e5..2668ce274 100644
@@ -42,6 +42,7 @@ static struct kmem_cache *xstate_cache;
   #define cpu_has_xsave boot_cpu_has(X86_FEATURE_XSAVE)
   #endif
+#ifndef IPIPE_X86_FPU_EAGER
   #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
   #include <asm/i387.h>
   #include <asm/fpu-internal.h>
@@ -72,6 +73,9 @@ static inline void x86_fpregs_activate(struct task_struct *t)
   #define x86_xstate_alignment        __alignof__(union fpregs_state)
   #endif
+#else /* IPIPE_X86_FPU_EAGER */
+#define x86_xstate_alignment        __alignof__(union fpregs_state)
+#endif /* ! IPIPE_X86_FPU_EAGER */
   #if LINUX_VERSION_CODE < KERNEL_VERSION(4,8,0)
   /*
@@ -465,9 +469,15 @@ void xnarch_leave_root(struct xnthread *root)
       // save fpregs from in-kernel use
       copy_fpregs_to_fpstate(rootcb->kfpu);
       kernel_fpu_enable();
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)
+    // restore current's fpregs
+    __cpu_invalidate_fpregs_state();
+    switch_fpu_finish(&current->thread.fpu, smp_processor_id());
+#else
       // mark current thread as not owning the FPU anymore
       if (&current->thread.fpu.fpstate_active)
           fpregs_deactivate(&current->thread.fpu);
+#endif
   }
   void xnarch_switch_fpu(struct xnthread *from, struct xnthread *to)
@@ -528,7 +538,11 @@ void xnarch_init_shadow_tcb(struct xnthread *thread)
   #else /* IPIPE_X86_FPU_EAGER */
       /* XNFPU is always set */
       xnthread_set_state(thread, XNFPU);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
       fpu__activate_fpstate_read(&p->thread.fpu);
+#else
+    fpu__initialize(&p->thread.fpu);
+#endif
   #endif /* ! IPIPE_X86_FPU_EAGER */
   }
@@ -537,7 +551,12 @@ int mach_x86_thread_init(void)
       xstate_cache = kmem_cache_create("cobalt_x86_xstate",
                        fpu_kernel_xstate_size,
                        x86_xstate_alignment,
-                     SLAB_NOTRACK, NULL);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
+                     SLAB_NOTRACK,
+#else
Quoted 9 lines

kernel/cobalt/arch/x86/thread.c int mach_x86_thread_init(void) · line 562

Quoted 6 lines
kernel/cobalt/arch/x86/thread.c +3 -0
+                     0,
+#endif
+                     NULL);
       if (xstate_cache == NULL)
           return -ENOMEM;
 

Thanks, taken the whole series to next so that we can move forward. I've just changed "//" (C++) style comments to "old-style" C. Kernel style. Please avoid them in the future.

Forgot: Did you happen to try the series with stable-3.0.x as well? I consider them relevant for that branch as well, so that users can update the kernel. But I plan to leave them in next until we have ipipe kernels available and tested them a bit broader.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
#9 lore raw

Re: [Xenomai] [PATCHv2 4/4] cobalt/x86: add ipipe-4.14 eager fpu support

Am Mon, 17 Sep 2018 20:23:16 +0200
schrieb Jan Kiszka <[email protected]>:

Quoted 83 lines · Jan Kiszka
Quoted 82 lines · Henning Schild
Quoted 81 lines

4.14 is always eager, unfortunately we will need a few ifdefs inside the eager fpu support as well.

---
  .../arch/x86/include/asm/xenomai/wrappers.h   |  4 ++++ kernel/cobalt/arch/x86/thread.c               | 21 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)

kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +4 -0
index a47730106..a4cc368a5 100644
@@ -32,6 +32,10 @@
       LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
   #define IPIPE_X86_FPU_EAGER
   #endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)
+#define IPIPE_X86_FPU_EAGER
+#endif
+
   #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
   #include <asm/i387.h>
(quoted diff) +0 -0

b/kernel/cobalt/arch/x86/thread.c index 18cf636e5..2668ce274 100644

kernel/cobalt/arch/x86/thread.c +1 -0
@@ -42,6 +42,7 @@ static struct kmem_cache *xstate_cache;
   #define cpu_has_xsave boot_cpu_has(X86_FEATURE_XSAVE)
   #endif
+#ifndef IPIPE_X86_FPU_EAGER
   #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
   #include <asm/i387.h>
   #include <asm/fpu-internal.h>
@@ -72,6 +73,9 @@ static inline void x86_fpregs_activate(struct

task_struct *t) #define x86_xstate_alignment
__alignof__(union fpregs_state) #endif

kernel/cobalt/arch/x86/thread.c +2 -0
+#else /* IPIPE_X86_FPU_EAGER */
+#define x86_xstate_alignment        __alignof__(union

fpregs_state) +#endif /* ! IPIPE_X86_FPU_EAGER */
  #if LINUX_VERSION_CODE < KERNEL_VERSION(4,8,0)
  /*

kernel/cobalt/arch/x86/thread.c +6 -0
@@ -465,9 +469,15 @@ void xnarch_leave_root(struct xnthread *root)
       // save fpregs from in-kernel use
       copy_fpregs_to_fpstate(rootcb->kfpu);
       kernel_fpu_enable();
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)
+    // restore current's fpregs
+    __cpu_invalidate_fpregs_state();
+    switch_fpu_finish(&current->thread.fpu, smp_processor_id());
+#else
       // mark current thread as not owning the FPU anymore
       if (&current->thread.fpu.fpstate_active)
           fpregs_deactivate(&current->thread.fpu);
+#endif
   }

  void xnarch_switch_fpu(struct xnthread *from, struct xnthread *to) @@ -528,7 +538,11 @@ void xnarch_init_shadow_tcb(struct xnthread *thread) #else /* IPIPE_X86_FPU_EAGER */
      /* XNFPU is always set */ xnthread_set_state(thread, XNFPU);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0) fpu__activate_fpstate_read(&p->thread.fpu);

kernel/cobalt/arch/x86/thread.c +3 -0
+#else
+    fpu__initialize(&p->thread.fpu);
+#endif

  #endif /* ! IPIPE_X86_FPU_EAGER */
  }

kernel/cobalt/arch/x86/thread.c +6 -1
@@ -537,7 +551,12 @@ int mach_x86_thread_init(void)
       xstate_cache = kmem_cache_create("cobalt_x86_xstate",
                        fpu_kernel_xstate_size,
                        x86_xstate_alignment,
-                     SLAB_NOTRACK, NULL);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
+                     SLAB_NOTRACK,
+#else
+                     0,
+#endif
+                     NULL);
Quoted 8 lines
Quoted 8 lines

kernel/cobalt/arch/x86/thread.c int mach_x86_thread_init(void) · line 562

Quoted 3 lines
kernel/cobalt/arch/x86/thread.c +0 -0
       if (xstate_cache == NULL)
           return -ENOMEM;
 

Thanks, taken the whole series to next so that we can move forward. I've just changed "//" (C++) style comments to "old-style" C. Kernel style. Please avoid them in the future.

Sorry missed the // part of the review.

Quoted 4 lines

Forgot: Did you happen to try the series with stable-3.0.x as well? I consider them relevant for that branch as well, so that users can update the kernel. But I plan to leave them in next until we have ipipe kernels available and tested them a bit broader.

Did not do that yet. I guess the ifdefs should all resolve to lazy-fpu, making the series a no-op for lazy kernels. Will test against 4.9 and 4.4 and confirm that my guess is right.

Henning

Quoted 2 lines

Jan

#10 lore raw

Re: [Xenomai] [PATCHv2 4/4] cobalt/x86: add ipipe-4.14 eager fpu support

Am Mon, 17 Sep 2018 21:18:48 +0200
schrieb "[ext] Henning Schild" <[email protected]>:

Quoted 97 lines

Am Mon, 17 Sep 2018 20:23:16 +0200
schrieb Jan Kiszka <[email protected]>:

Quoted 83 lines · Jan Kiszka
Quoted 82 lines · Henning Schild
Quoted 81 lines

4.14 is always eager, unfortunately we will need a few ifdefs inside the eager fpu support as well.

---
  .../arch/x86/include/asm/xenomai/wrappers.h   |  4 ++++ kernel/cobalt/arch/x86/thread.c               | 21 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h index a47730106..a4cc368a5 100644 --- a/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h @@ -32,6 +32,10 @@ LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0) #define IPIPE_X86_FPU_EAGER
  #endif

kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +4 -0
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)
+#define IPIPE_X86_FPU_EAGER
+#endif
+

  #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
  #include <asm/i387.h>

(quoted diff) +0 -0

b/kernel/cobalt/arch/x86/thread.c index 18cf636e5..2668ce274 100644 --- a/kernel/cobalt/arch/x86/thread.c
+++ b/kernel/cobalt/arch/x86/thread.c

kernel/cobalt/arch/x86/thread.c +1 -0
@@ -42,6 +42,7 @@ static struct kmem_cache *xstate_cache;
   #define cpu_has_xsave boot_cpu_has(X86_FEATURE_XSAVE)
   #endif
+#ifndef IPIPE_X86_FPU_EAGER
   #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
   #include <asm/i387.h>
   #include <asm/fpu-internal.h>
@@ -72,6 +73,9 @@ static inline void x86_fpregs_activate(struct

task_struct *t) #define x86_xstate_alignment
__alignof__(union fpregs_state) #endif

(quoted diff) +2 -0
+#else /* IPIPE_X86_FPU_EAGER */
+#define x86_xstate_alignment        __alignof__(union

fpregs_state) +#endif /* ! IPIPE_X86_FPU_EAGER */
  #if LINUX_VERSION_CODE < KERNEL_VERSION(4,8,0)
  /*

kernel/cobalt/arch/x86/thread.c +6 -0
@@ -465,9 +469,15 @@ void xnarch_leave_root(struct xnthread
 *root) // save fpregs from in-kernel use
       copy_fpregs_to_fpstate(rootcb->kfpu);
       kernel_fpu_enable();
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)
+    // restore current's fpregs
+    __cpu_invalidate_fpregs_state();
+    switch_fpu_finish(&current->thread.fpu, smp_processor_id());
+#else
       // mark current thread as not owning the FPU anymore
       if (&current->thread.fpu.fpstate_active)
           fpregs_deactivate(&current->thread.fpu);
+#endif
   }

  void xnarch_switch_fpu(struct xnthread *from, struct xnthread *to) @@ -528,7 +538,11 @@ void xnarch_init_shadow_tcb(struct xnthread *thread) #else /* IPIPE_X86_FPU_EAGER */
      /* XNFPU is always set */ xnthread_set_state(thread, XNFPU);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0) fpu__activate_fpstate_read(&p->thread.fpu);

kernel/cobalt/arch/x86/thread.c +3 -0
+#else
+    fpu__initialize(&p->thread.fpu);
+#endif

  #endif /* ! IPIPE_X86_FPU_EAGER */
  }

kernel/cobalt/arch/x86/thread.c +6 -1
@@ -537,7 +551,12 @@ int mach_x86_thread_init(void)
       xstate_cache = kmem_cache_create("cobalt_x86_xstate",
                        fpu_kernel_xstate_size,
                        x86_xstate_alignment,
-                     SLAB_NOTRACK, NULL);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
+                     SLAB_NOTRACK,
+#else
+                     0,
+#endif
+                     NULL);
Quoted 8 lines
Quoted 8 lines

kernel/cobalt/arch/x86/thread.c int mach_x86_thread_init(void) · line 562

Quoted 3 lines
kernel/cobalt/arch/x86/thread.c +0 -0
       if (xstate_cache == NULL)
           return -ENOMEM;
 

Thanks, taken the whole series to next so that we can move forward. I've just changed "//" (C++) style comments to "old-style" C. Kernel style. Please avoid them in the future.

Sorry missed the // part of the review.

Quoted 8 lines
Quoted 4 lines

Forgot: Did you happen to try the series with stable-3.0.x as well? I consider them relevant for that branch as well, so that users can update the kernel. But I plan to leave them in next until we have ipipe kernels available and tested them a bit broader.

Did not do that yet. I guess the ifdefs should all resolve to lazy-fpu, making the series a no-op for lazy kernels. Will test against 4.9 and 4.4 and confirm that my guess is right.

Might have gotten the question wrong in the first place. I did test xenomai (next) against ipipe 4.(4|9).y. After that i backported (cherry-picked) the changes right onto stable-3.0.x and tested against a lazy 4.4 and a 4.14. So i think all combinations should be tested.

Henning

Quoted 10 lines

Henning

Quoted 2 lines

Jan

_______________________________________________
Xenomai mailing list
[email protected]
https://xenomai.org/mailman/listinfo/xenomai

Applied
#11 lore raw

Re: [Xenomai] [PATCHv2 4/4] cobalt/x86: add ipipe-4.14 eager fpu support

Quoted 105 lines · Henning Schild

Am Mon, 17 Sep 2018 21:18:48 +0200
schrieb "[ext] Henning Schild" <[email protected]>:

Quoted 102 lines

Am Mon, 17 Sep 2018 20:23:16 +0200
schrieb Jan Kiszka <[email protected]>:

Quoted 83 lines · Jan Kiszka
Quoted 82 lines · Henning Schild
Quoted 81 lines

4.14 is always eager, unfortunately we will need a few ifdefs inside the eager fpu support as well.

---
   .../arch/x86/include/asm/xenomai/wrappers.h   |  4 ++++
   kernel/cobalt/arch/x86/thread.c               | 21

++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h index a47730106..a4cc368a5 100644 --- a/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h @@ -32,6 +32,10 @@ LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
  #define IPIPE_X86_FPU_EAGER
  #endif

kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +4 -0
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)
+#define IPIPE_X86_FPU_EAGER
+#endif
+
   #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
   #include <asm/i387.h>
(quoted diff) +0 -0

b/kernel/cobalt/arch/x86/thread.c index 18cf636e5..2668ce274 100644 --- a/kernel/cobalt/arch/x86/thread.c
+++ b/kernel/cobalt/arch/x86/thread.c

kernel/cobalt/arch/x86/thread.c +1 -0
@@ -42,6 +42,7 @@ static struct kmem_cache *xstate_cache;
   #define cpu_has_xsave boot_cpu_has(X86_FEATURE_XSAVE)
   #endif
+#ifndef IPIPE_X86_FPU_EAGER
   #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
   #include <asm/i387.h>
   #include <asm/fpu-internal.h>
@@ -72,6 +73,9 @@ static inline void x86_fpregs_activate(struct

task_struct *t) #define x86_xstate_alignment
__alignof__(union fpregs_state) #endif

(quoted diff) +2 -0
+#else /* IPIPE_X86_FPU_EAGER */
+#define x86_xstate_alignment        __alignof__(union

fpregs_state) +#endif /* ! IPIPE_X86_FPU_EAGER */
  #if LINUX_VERSION_CODE < KERNEL_VERSION(4,8,0)
  /*

kernel/cobalt/arch/x86/thread.c +6 -0
@@ -465,9 +469,15 @@ void xnarch_leave_root(struct xnthread
 *root) // save fpregs from in-kernel use
       copy_fpregs_to_fpstate(rootcb->kfpu);
       kernel_fpu_enable();
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)
+    // restore current's fpregs
+    __cpu_invalidate_fpregs_state();
+    switch_fpu_finish(&current->thread.fpu, smp_processor_id());
+#else
       // mark current thread as not owning the FPU anymore
       if (&current->thread.fpu.fpstate_active)
           fpregs_deactivate(&current->thread.fpu);
+#endif
   }
   void xnarch_switch_fpu(struct xnthread *from, struct xnthread
 *to) @@ -528,7 +538,11 @@ void xnarch_init_shadow_tcb(struct

xnthread *thread) #else /* IPIPE_X86_FPU_EAGER */
      /* XNFPU is always set */
      xnthread_set_state(thread, XNFPU);

kernel/cobalt/arch/x86/thread.c +10 -1
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
       fpu__activate_fpstate_read(&p->thread.fpu);
+#else
+    fpu__initialize(&p->thread.fpu);
+#endif
   #endif /* ! IPIPE_X86_FPU_EAGER */
   }
@@ -537,7 +551,12 @@ int mach_x86_thread_init(void)
       xstate_cache = kmem_cache_create("cobalt_x86_xstate",
                        fpu_kernel_xstate_size,
                        x86_xstate_alignment,
-                     SLAB_NOTRACK, NULL);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
+                     SLAB_NOTRACK,
+#else
+                     0,
+#endif
+                     NULL);
Quoted 8 lines
Quoted 8 lines

kernel/cobalt/arch/x86/thread.c int mach_x86_thread_init(void) · line 562

Quoted 3 lines
kernel/cobalt/arch/x86/thread.c +0 -0
       if (xstate_cache == NULL)
           return -ENOMEM;
 

Thanks, taken the whole series to next so that we can move forward. I've just changed "//" (C++) style comments to "old-style" C. Kernel style. Please avoid them in the future.

Sorry missed the // part of the review.

Quoted 4 lines

Forgot: Did you happen to try the series with stable-3.0.x as well? I consider them relevant for that branch as well, so that users can update the kernel. But I plan to leave them in next until we have ipipe kernels available and tested them a bit broader.

Quoted 9 lines
Quoted 3 lines

Did not do that yet. I guess the ifdefs should all resolve to lazy-fpu, making the series a no-op for lazy kernels. Will test against 4.9 and 4.4 and confirm that my guess is right.

Might have gotten the question wrong in the first place. I did test xenomai (next) against ipipe 4.(4|9).y. After that i backported (cherry-picked) the changes right onto stable-3.0.x and tested against a lazy 4.4 and a 4.14. So i think all combinations should be tested.

Applied all four to stable - looks good.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux