Skip to contentSkip to conversation

Eager FPU support for x86

PATCH Superseded Henning Schild 2 participants 12 messages Aug 27, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Eager FPU support for x86

These patches incementally add eager fpu support for the 4.9/4.4 and finally the 4.14 kernel. For a final round they can probably be squashed. If they are not, some changes from the 4.14 one should go into the first one.

I will post the corresponding 4.9.y patch against the kernel as well.

Both 4.9 and 4.4 are tested, 4.14 not yet.

Henning Schild (3):
cobalt/x86: add support for eager fpu handling
cobalt/x86: add ipipe-4.4 eager fpu support
cobalt/x86: add ipipe-4.14 eager fpu support

 .../cobalt/arch/x86/include/asm/xenomai/thread.h   |  8 +-
 .../cobalt/arch/x86/include/asm/xenomai/wrappers.h | 16 ++++
 kernel/cobalt/arch/x86/thread.c                    | 85 ++++++++++++++++++++--
 .../cobalt/include/asm-generic/xenomai/syscall.h   |  4 +
 4 files changed, 107 insertions(+), 6 deletions(-)
Signature · 1 line
2.16.4
#1 lore raw

PATCH 1/3 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.

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.

---
 .../cobalt/arch/x86/include/asm/xenomai/thread.h   |  8 ++-
 .../cobalt/arch/x86/include/asm/xenomai/wrappers.h |  6 ++
 kernel/cobalt/arch/x86/thread.c                    | 67 +++++++++++++++++++++-
 3 files changed, 78 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 +6 -0
index 5f9cff3c9..73df60cc6 100644
@@ -24,6 +24,12 @@
 #define __get_user_inatomic __get_user
 #define __put_user_inatomic __put_user
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,9,0) && \
+    LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0) && \
+    LINUX_VERSION_CODE > KERNEL_VERSION(4,9,108)
+#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 +65 -2

141 lines not on this page · raw message

Signature · 1 line
2.16.4
#2 lore raw

Re: [Xenomai] [PATCH 1/3] cobalt/x86: add support for eager fpu handling

Quoted 62 lines · Henning Schild

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.

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.

---
  .../cobalt/arch/x86/include/asm/xenomai/thread.h   |  8 ++-
  .../cobalt/arch/x86/include/asm/xenomai/wrappers.h |  6 ++
  kernel/cobalt/arch/x86/thread.c                    | 67 +++++++++++++++++++++-
  3 files changed, 78 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 +0 -0
index 5f9cff3c9..73df60cc6 100644

kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h line 27

Quoted 4 lines
kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +1 -0
@@ -24,6 +24,12 @@
  #define __get_user_inatomic __get_user
  #define __put_user_inatomic __put_user
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,9,0) && \

This condition it redundant to > 4.9.108.

Quoted 52 lines
kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +5 -0
+    LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0) && \
+    LINUX_VERSION_CODE > KERNEL_VERSION(4,9,108)
+#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 +8 -0
index 7fb136300..54bc5c008 100644
@@ -28,9 +28,13 @@
 
  static struct kmem_cache *xstate_cache;
 
+#ifdef IPIPE_X86_FPU_EAGER
+#define fpu_kernel_xstate_size sizeof(struct fpu)
+#else
  #if LINUX_VERSION_CODE < KERNEL_VERSION(4,7,0)
  #define fpu_kernel_xstate_size xstate_size
  #endif
+#endif
 
  #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0)
  #define cpu_has_xmm boot_cpu_has(X86_FEATURE_XMM)
@@ -199,20 +203,24 @@ void xnarch_switch_to(struct xnthread *out, struct xnthread *in)
  	struct mm_struct *prev_mm, *next_mm;
 
  	prev = out_tcb->core.host_task;
+#ifndef IPIPE_X86_FPU_EAGER
  	if (x86_fpregs_active(prev))
  		/*
  		 * __switch_to will try and use __unlazy_fpu, so we
  		 * need to clear the ts bit.
  		 */
  		clts();
+#endif
 
  	next = in_tcb->core.host_task;
+#ifndef IPIPE_X86_FPU_EAGER
  #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)
  	next->thread.fpu.counter = 0;
  #elif LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0)
  	next->thread.fpu_counter = 0;
  #else
  	next->fpu_counter = 0;
+#endif
  #endif
  	prev_mm = out_tcb->core.active_mm;
  	next_mm = in_tcb->core.mm;

kernel/cobalt/arch/x86/thread.c void xnarch_switch_to(struct xnthread *out, struct xnthread *in) · line 261

Quoted 9 lines
kernel/cobalt/arch/x86/thread.c +3 -0
@@ -245,9 +253,13 @@ void xnarch_switch_to(struct xnthread *out, struct xnthread *in)
  	switch_to(prev, next, last);
  #endif /* LINUX_VERSION_CODE >= 4.8 */
 
+#ifndef IPIPE_X86_FPU_EAGER
  	stts();
+#endif
  }
 
+#ifndef IPIPE_X86_FPU_EAGER

I would put the EAGER case in front, also to avoid the negation whenever there is an #else.

kernel/cobalt/arch/x86/thread.c int xnarch_handle_fpu_fault(struct xnthread *from, · line 374

Quoted 9 lines
kernel/cobalt/arch/x86/thread.c +2 -0
+
  #ifdef CONFIG_X86_64
  #define XSAVE_PREFIX	"0x48,"
  #define XSAVE_SUFFIX	"q"
@@ -359,11 +371,20 @@ int xnarch_handle_fpu_fault(struct xnthread *from,
 
  	return 1;
  }
+#else /* !IPIPE_X86_FPU_EAGER */

Would be "/* IPIPE_X86_FPU_EAGER */", until you reorder.

kernel/cobalt/arch/x86/thread.c int xnarch_handle_fpu_fault(struct xnthread *from, · line 387

Quoted 13 lines
kernel/cobalt/arch/x86/thread.c +8 -0
+
+int xnarch_handle_fpu_fault(struct xnthread *from,
+			struct xnthread *to, struct ipipe_trap_data *d)
+{
+	BUG_ON(1);
+}
+#endif /* IPIPE_X86_FPU_EAGER */
 
  #define current_task_used_kfpu() kernel_fpu_disabled()
 
  #define tcb_used_kfpu(t) ((t)->root_kfpu)
 
+#ifndef IPIPE_X86_FPU_EAGER

Same here.

Quoted 8 lines
kernel/cobalt/arch/x86/thread.c +1 -0
  void xnarch_leave_root(struct xnthread *root)
  {
  	struct xnarchtcb *const rootcb = xnthread_archtcb(root);
@@ -430,6 +451,35 @@ void xnarch_switch_fpu(struct xnthread *from, struct xnthread *to)
  		p->flags &= ~PF_USED_MATH;
  	}
  }
+#else

kernel/cobalt/arch/x86/thread.c void xnarch_switch_fpu(struct xnthread *from, struct xnthread *to) · line 464

Quoted 10 lines
kernel/cobalt/arch/x86/thread.c +10 -0
+void xnarch_leave_root(struct xnthread *root)
+{
+	struct xnarchtcb *const rootcb = xnthread_archtcb(root);
+
+	rootcb->root_kfpu = current_task_used_kfpu();
+
+	if (!tcb_used_kfpu(rootcb))
+		return;
+
+	// the kernel never marked the task as not being the fpu owner anymore

No C++-style comments, please.

Quoted 22 lines
kernel/cobalt/arch/x86/thread.c +18 -0
+	if (&current->thread.fpu.fpstate_active)
+		fpregs_deactivate(&current->thread.fpu);
+
+	copy_fpregs_to_fpstate(rootcb->kfpu);
+	kernel_fpu_enable();
+}
+
+void xnarch_switch_fpu(struct xnthread *from, struct xnthread *to)
+{
+	struct xnarchtcb *const to_tcb = xnthread_archtcb(to);
+
+	if (!tcb_used_kfpu(to_tcb))
+		return;
+
+	copy_kernel_to_fpregs(&to_tcb->kfpu->state);
+	kernel_fpu_disable();
+}
+#endif /* IPIPE_X86_FPU_EAGER */
 
  void xnarch_init_root_tcb(struct xnthread *thread)
  {

kernel/cobalt/arch/x86/thread.c void xnarch_init_root_tcb(struct xnthread *thread) · line 493

Quoted 4 lines
kernel/cobalt/arch/x86/thread.c +1 -0
@@ -440,9 +490,13 @@ void xnarch_init_root_tcb(struct xnthread *thread)
  	tcb->spp = &tcb->sp;
  	tcb->ipp = &tcb->ip;
  #endif	
+#ifndef IPIPE_X86_FPU_EAGER

Ordering

Quoted 11 lines
kernel/cobalt/arch/x86/thread.c +4 -1
  	tcb->fpup = NULL;
-	tcb->root_kfpu = 0;
  	tcb->kfpu_state = kmem_cache_zalloc(xstate_cache, GFP_KERNEL);
+#else
+	tcb->kfpu = kmem_cache_zalloc(xstate_cache, GFP_KERNEL);
+#endif
+	tcb->root_kfpu = 0;
  }
 
  void xnarch_init_shadow_tcb(struct xnthread *thread)

kernel/cobalt/arch/x86/thread.c void xnarch_init_shadow_tcb(struct xnthread *thread) · line 516

Quoted 4 lines
kernel/cobalt/arch/x86/thread.c +1 -0
@@ -459,12 +513,21 @@ void xnarch_init_shadow_tcb(struct xnthread *thread)
  	tcb->ipp = &p->thread.rip; /* <!> raw naming intended. */
  #endif
  #endif
+#ifndef IPIPE_X86_FPU_EAGER

And again.

Quoted 9 lines
kernel/cobalt/arch/x86/thread.c +4 -1
  	tcb->fpup = x86_fpustate_ptr(&p->thread);
-	tcb->root_kfpu = 0;
  	tcb->kfpu_state = NULL;
+#else
+	tcb->kfpu = NULL;
+#endif
+	tcb->root_kfpu = 0;
 

kernel/cobalt/arch/x86/thread.c void xnarch_init_shadow_tcb(struct xnthread *thread) · line 533

Quoted 10 lines
kernel/cobalt/arch/x86/thread.c +5 -0
  	/* XNFPU is set upon first FPU fault */
  	xnthread_clear_state(thread, XNFPU);
+
+#ifdef IPIPE_X86_FPU_EAGER
+	xnthread_set_state(thread, XNFPU);
+	fpu__activate_fpstate_read(&p->thread.fpu);
+#endif
  }
 
  int mach_x86_thread_init(void)

Jan

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

Re: [Xenomai] [PATCH 1/3] cobalt/x86: add support for eager fpu handling

As all these ifdefs are getting pretty confusing and hard to read, especially when looking at patches, i will probably rework this one.

The idea would be to have the old way on top and the new way at the end of the file. No attempt to keep the two versions of functions close to each other or "reuse" code from the other. That will increase readability and allow for easy removal of the "lazy-path" when the time has come.

Henning

Am Mon, 27 Aug 2018 18:12:39 +0200
schrieb Jan Kiszka <[email protected]>:

Quoted 256 lines · Henning Schild
Quoted 66 lines

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.

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.

---
  .../cobalt/arch/x86/include/asm/xenomai/thread.h   |  8 ++-
  .../cobalt/arch/x86/include/asm/xenomai/wrappers.h |  6 ++
  kernel/cobalt/arch/x86/thread.c                    | 67

+++++++++++++++++++++- 3 files changed, 78 insertions(+), 3 deletions(-)

(quoted diff) +0 -0

b/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h index f174a82c0..0c5c4da9c 100644 --- a/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/thread.h @@ -24,6 +24,7 @@ #include <asm/xenomai/wrappers.h>
#include <asm/traps.h>

kernel/cobalt/arch/x86/include/asm/xenomai/thread.h +7 -1
+#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;
(quoted diff) +0 -0

b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h index 5f9cff3c9..73df60cc6 100644 --- a/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h @@ -24,6 +24,12 @@ #define __get_user_inatomic __get_user
#define __put_user_inatomic __put_user

Quoted 1 line

+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,9,0) && \

This condition it redundant to > 4.9.108.

Quoted 53 lines
kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +5 -0
+    LINUX_VERSION_CODE < KERNEL_VERSION(4,10,0) && \
+    LINUX_VERSION_CODE > KERNEL_VERSION(4,9,108)
+#define IPIPE_X86_FPU_EAGER
+#endif
+
  #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
  #include <asm/i387.h>
  #include <asm/fpu-internal.h>
(quoted diff) +0 -0

b/kernel/cobalt/arch/x86/thread.c index 7fb136300..54bc5c008 100644

kernel/cobalt/arch/x86/thread.c +5 -0
@@ -28,9 +28,13 @@
 
  static struct kmem_cache *xstate_cache;
 
+#ifdef IPIPE_X86_FPU_EAGER
+#define fpu_kernel_xstate_size sizeof(struct fpu)
+#else
  #if LINUX_VERSION_CODE < KERNEL_VERSION(4,7,0)
  #define fpu_kernel_xstate_size xstate_size
  #endif
+#endif
 
  #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0)
  #define cpu_has_xmm boot_cpu_has(X86_FEATURE_XMM)
@@ -199,20 +203,24 @@ void xnarch_switch_to(struct xnthread *out,
 struct xnthread *in) struct mm_struct *prev_mm, *next_mm;
 
  	prev = out_tcb->core.host_task;
+#ifndef IPIPE_X86_FPU_EAGER
  	if (x86_fpregs_active(prev))
  		/*
  		 * __switch_to will try and use __unlazy_fpu, so

we
* need to clear the ts bit.
*/
clts();

kernel/cobalt/arch/x86/thread.c +3 -0
+#endif
 
  	next = in_tcb->core.host_task;
+#ifndef IPIPE_X86_FPU_EAGER
  #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)
  	next->thread.fpu.counter = 0;
  #elif LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0)
  	next->thread.fpu_counter = 0;
  #else
  	next->fpu_counter = 0;
+#endif
  #endif
  	prev_mm = out_tcb->core.active_mm;
  	next_mm = in_tcb->core.mm;

kernel/cobalt/arch/x86/thread.c void xnarch_switch_to(struct xnthread *out, · line 261

Quoted 9 lines
kernel/cobalt/arch/x86/thread.c +3 -0
@@ -245,9 +253,13 @@ void xnarch_switch_to(struct xnthread *out,
 struct xnthread *in) switch_to(prev, next, last);
  #endif /* LINUX_VERSION_CODE >= 4.8 */
 
+#ifndef IPIPE_X86_FPU_EAGER
  	stts();
+#endif
  }
 
+#ifndef IPIPE_X86_FPU_EAGER  

I would put the EAGER case in front, also to avoid the negation whenever there is an #else.

kernel/cobalt/arch/x86/thread.c int xnarch_handle_fpu_fault(struct xnthread · line 374

Quoted 9 lines
kernel/cobalt/arch/x86/thread.c +2 -0
+
  #ifdef CONFIG_X86_64
  #define XSAVE_PREFIX	"0x48,"
  #define XSAVE_SUFFIX	"q"
@@ -359,11 +371,20 @@ int xnarch_handle_fpu_fault(struct xnthread
 *from, 
  	return 1;
  }
+#else /* !IPIPE_X86_FPU_EAGER */  

Would be "/* IPIPE_X86_FPU_EAGER */", until you reorder.

kernel/cobalt/arch/x86/thread.c int xnarch_handle_fpu_fault(struct xnthread *from, · line 387

Quoted 13 lines
kernel/cobalt/arch/x86/thread.c +7 -0
+
+int xnarch_handle_fpu_fault(struct xnthread *from,
+			struct xnthread *to, struct
 ipipe_trap_data *d) +{
+	BUG_ON(1);
+}
+#endif /* IPIPE_X86_FPU_EAGER */
 
  #define current_task_used_kfpu() kernel_fpu_disabled()
 
  #define tcb_used_kfpu(t) ((t)->root_kfpu)
 
+#ifndef IPIPE_X86_FPU_EAGER  

Same here.

Quoted 18 lines
kernel/cobalt/arch/x86/thread.c +11 -0
  void xnarch_leave_root(struct xnthread *root)
  {
  	struct xnarchtcb *const rootcb = xnthread_archtcb(root);
@@ -430,6 +451,35 @@ void xnarch_switch_fpu(struct xnthread *from,
 struct xnthread *to) p->flags &= ~PF_USED_MATH;
  	}
  }
+#else
+void xnarch_leave_root(struct xnthread *root)
+{
+	struct xnarchtcb *const rootcb = xnthread_archtcb(root);
+
+	rootcb->root_kfpu = current_task_used_kfpu();
+
+	if (!tcb_used_kfpu(rootcb))
+		return;
+
+	// the kernel never marked the task as not being the fpu
Quoted 1 line

owner anymore

No C++-style comments, please.

Quoted 22 lines
kernel/cobalt/arch/x86/thread.c +18 -0
+	if (&current->thread.fpu.fpstate_active)
+		fpregs_deactivate(&current->thread.fpu);
+
+	copy_fpregs_to_fpstate(rootcb->kfpu);
+	kernel_fpu_enable();
+}
+
+void xnarch_switch_fpu(struct xnthread *from, struct xnthread *to)
+{
+	struct xnarchtcb *const to_tcb = xnthread_archtcb(to);
+
+	if (!tcb_used_kfpu(to_tcb))
+		return;
+
+	copy_kernel_to_fpregs(&to_tcb->kfpu->state);
+	kernel_fpu_disable();
+}
+#endif /* IPIPE_X86_FPU_EAGER */
 
  void xnarch_init_root_tcb(struct xnthread *thread)
  {

kernel/cobalt/arch/x86/thread.c void xnarch_init_root_tcb(struct xnthread · line 493

Quoted 4 lines
kernel/cobalt/arch/x86/thread.c +1 -0
@@ -440,9 +490,13 @@ void xnarch_init_root_tcb(struct xnthread
 *thread) tcb->spp = &tcb->sp;
  	tcb->ipp = &tcb->ip;
  #endif	
+#ifndef IPIPE_X86_FPU_EAGER  

Ordering

Quoted 11 lines
kernel/cobalt/arch/x86/thread.c +0 -1
  	tcb->fpup = NULL;
-	tcb->root_kfpu = 0;
  	tcb->kfpu_state = kmem_cache_zalloc(xstate_cache,

GFP_KERNEL); +#else

kernel/cobalt/arch/x86/thread.c +3 -0
+	tcb->kfpu = kmem_cache_zalloc(xstate_cache, GFP_KERNEL);
+#endif
+	tcb->root_kfpu = 0;
  }
 
  void xnarch_init_shadow_tcb(struct xnthread *thread)

kernel/cobalt/arch/x86/thread.c void xnarch_init_shadow_tcb(struct xnthread · line 516

Quoted 4 lines
kernel/cobalt/arch/x86/thread.c +1 -0
@@ -459,12 +513,21 @@ void xnarch_init_shadow_tcb(struct xnthread
 *thread) tcb->ipp = &p->thread.rip; /* <!> raw naming intended. */
  #endif
  #endif
+#ifndef IPIPE_X86_FPU_EAGER  

And again.

Quoted 9 lines
kernel/cobalt/arch/x86/thread.c +4 -1
  	tcb->fpup = x86_fpustate_ptr(&p->thread);
-	tcb->root_kfpu = 0;
  	tcb->kfpu_state = NULL;
+#else
+	tcb->kfpu = NULL;
+#endif
+	tcb->root_kfpu = 0;
 

kernel/cobalt/arch/x86/thread.c void xnarch_init_shadow_tcb(struct xnthread *thread) · line 533

Quoted 10 lines
kernel/cobalt/arch/x86/thread.c +5 -0
  	/* XNFPU is set upon first FPU fault */
  	xnthread_clear_state(thread, XNFPU);
+
+#ifdef IPIPE_X86_FPU_EAGER
+	xnthread_set_state(thread, XNFPU);
+	fpu__activate_fpstate_read(&p->thread.fpu);
+#endif
  }
 
  int mach_x86_thread_init(void)

Jan

#4 lore raw

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

In reply to Henning Schild
---
 kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h | 6 ++++++
 1 file changed, 6 insertions(+)
kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +6 -0
index 73df60cc6..0156e86f0 100644
@@ -29,6 +29,12 @@
     LINUX_VERSION_CODE > KERNEL_VERSION(4,9,108)
 #define IPIPE_X86_FPU_EAGER
 #endif
+// actually 4.4.138 drops lazy, but in IPIPE we do it at 72
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0) && \
+    LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0) && \
+    LINUX_VERSION_CODE > KERNEL_VERSION(4,4,71)
+#define IPIPE_X86_FPU_EAGER
+#endif
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
 #include <asm/i387.h>
Signature · 1 line
2.16.4
#5 lore raw

Re: [Xenomai] [PATCH 2/3] cobalt/x86: add ipipe-4.4 eager fpu support

Quoted 10 lines · Henning Schild
---
  kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h | 6 ++++++
  1 file changed, 6 insertions(+)
kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +0 -0
index 73df60cc6..0156e86f0 100644

kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h line 32

Quoted 4 lines
kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +1 -0
@@ -29,6 +29,12 @@
      LINUX_VERSION_CODE > KERNEL_VERSION(4,9,108)
  #define IPIPE_X86_FPU_EAGER
  #endif
+// actually 4.4.138 drops lazy, but in IPIPE we do it at 72

Huh? We also do lazy up to 4.4.137, at least in x86 staging (latest release was .71, indeed). But nothing has been removed from that old version to prevent laziness.

kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h line 33

Quoted 1 line
kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +1 -0
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0) && \

Again, redundant condition.

kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h line 40

Quoted 8 lines
kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +4 -0
+    LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0) && \
+    LINUX_VERSION_CODE > KERNEL_VERSION(4,4,71)
+#define IPIPE_X86_FPU_EAGER
+#endif
 
  #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
  #include <asm/i387.h>

Jan

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

Re: [Xenomai] [PATCH 2/3] cobalt/x86: add ipipe-4.4 eager fpu support

Am Mon, 27 Aug 2018 18:18:01 +0200
schrieb Jan Kiszka <[email protected]>:

Quoted 6 lines · Henning Schild
Quoted 5 lines
---
  kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h | 6 ++++++
  1 file changed, 6 insertions(+)
Quoted 13 lines
Quoted 9 lines
(quoted diff) +0 -0

b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h index 73df60cc6..0156e86f0 100644 --- a/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h @@ -29,6 +29,12 @@ LINUX_VERSION_CODE > KERNEL_VERSION(4,9,108)
#define IPIPE_X86_FPU_EAGER
#endif
+// actually 4.4.138 drops lazy, but in IPIPE we do it at 72

Huh? We also do lazy up to 4.4.137, at least in x86 staging (latest release was .71, indeed). But nothing has been removed from that old version to prevent laziness.

The idea of these numbers is to make them work right after a (small) merge has been done on the kernel side. ipipe-4.4.y is at 71 so i chose 72, because we can switch to eager before we have to.

In fact i do not care but that was the easiest for testing, because it allowed testing without dealing with what happened between 71 and 152. I started off with that (big) merge and when conflicts came up i decided to devide the problem.

What we could do to stay in line with 4.9 is merge in the minor right before the upstream change (137), apply the patch with the exact number (138), and possibly merge 152 after that. But hey we can go eager whenever we want ... So i prefer the current way. Go eager in 72 and later merge 152+.

Where is that staging branch you are talking about?

Henning

Quoted 15 lines
Quoted 1 line

+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0) && \

Again, redundant condition.

kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h line 40

Quoted 8 lines
kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +4 -0
+    LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0) && \
+    LINUX_VERSION_CODE > KERNEL_VERSION(4,4,71)
+#define IPIPE_X86_FPU_EAGER
+#endif
 
  #if LINUX_VERSION_CODE < KERNEL_VERSION(4,2,0)
  #include <asm/i387.h>

Jan

#7 lore raw

Re: [Xenomai] [PATCH 2/3] cobalt/x86: add ipipe-4.4 eager fpu support

Quoted 32 lines · Henning Schild

Am Mon, 27 Aug 2018 18:18:01 +0200
schrieb Jan Kiszka <[email protected]>:

Quoted 6 lines · Henning Schild
Quoted 5 lines
---
   kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h | 6 ++++++
   1 file changed, 6 insertions(+)
Quoted 13 lines
Quoted 9 lines
(quoted diff) +0 -0

b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h index 73df60cc6..0156e86f0 100644 --- a/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h @@ -29,6 +29,12 @@ LINUX_VERSION_CODE > KERNEL_VERSION(4,9,108)

   #define IPIPE_X86_FPU_EAGER
   #endif

+// actually 4.4.138 drops lazy, but in IPIPE we do it at 72

Huh? We also do lazy up to 4.4.137, at least in x86 staging (latest release was .71, indeed). But nothing has been removed from that old version to prevent laziness.

The idea of these numbers is to make them work right after a (small) merge has been done on the kernel side. ipipe-4.4.y is at 71 so i chose 72, because we can switch to eager before we have to.

In fact i do not care but that was the easiest for testing, because it allowed testing without dealing with what happened between 71 and 152. I started off with that (big) merge and when conflicts came up i decided to devide the problem.

Quoted 7 lines

What we could do to stay in line with 4.9 is merge in the minor right before the upstream change (137), apply the patch with the exact number (138), and possibly merge 152 after that. But hey we can go eager whenever we want ... So i prefer the current way. Go eager in 72 and later merge 152+.

Where is that staging branch you are talking about?

https://gitlab.denx.de/Xenomai/ipipe-x86/tree/for-upstream/4.4

ipipe-x86/ipipe-4.4.y is just the mirror of upstream, thus will only start to carry that changes when upstream picked them up. I think I didn't send a PR so far, though.

Jan

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

Re: [Xenomai] [PATCH 2/3] cobalt/x86: add ipipe-4.4 eager fpu support

Am Mon, 27 Aug 2018 18:41:39 +0200
schrieb Jan Kiszka <[email protected]>:

Quoted 39 lines · Henning Schild
Quoted 38 lines

Am Mon, 27 Aug 2018 18:18:01 +0200
schrieb Jan Kiszka <[email protected]>:

Quoted 6 lines · Henning Schild
Quoted 5 lines
---
   kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h | 6

++++++ 1 file changed, 6 insertions(+)

Quoted 13 lines
Quoted 9 lines
(quoted diff) +0 -0

b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h index 73df60cc6..0156e86f0 100644 --- a/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h @@ -29,6 +29,12 @@ LINUX_VERSION_CODE > KERNEL_VERSION(4,9,108)

   #define IPIPE_X86_FPU_EAGER
   #endif

+// actually 4.4.138 drops lazy, but in IPIPE we do it at 72

Huh? We also do lazy up to 4.4.137, at least in x86 staging (latest release was .71, indeed). But nothing has been removed from that old version to prevent laziness.

The idea of these numbers is to make them work right after a (small) merge has been done on the kernel side. ipipe-4.4.y is at 71 so i chose 72, because we can switch to eager before we have to.

In fact i do not care but that was the easiest for testing, because it allowed testing without dealing with what happened between 71 and 152. I started off with that (big) merge and when conflicts came up i decided to devide the problem.

What we could do to stay in line with 4.9 is merge in the minor right before the upstream change (137), apply the patch with the exact number (138), and possibly merge 152 after that. But hey we can go eager whenever we want ... So i prefer the current way. Go eager in 72 and later merge 152+.

Quoted 7 lines
Quoted 1 line

Where is that staging branch you are talking about?

https://gitlab.denx.de/Xenomai/ipipe-x86/tree/for-upstream/4.4

ipipe-x86/ipipe-4.4.y is just the mirror of upstream, thus will only start to carry that changes when upstream picked them up. I think I didn't send a PR so far, though.

Ok, i will change that number to >= 138.

Henning

Quoted 2 lines

Jan

#9 lore raw

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

In reply to Henning Schild
---
 kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h |  4 ++++
 kernel/cobalt/arch/x86/thread.c                       | 18 +++++++++++++++---
 kernel/cobalt/include/asm-generic/xenomai/syscall.h   |  4 ++++
 3 files changed, 23 insertions(+), 3 deletions(-)
kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +4 -0
index 0156e86f0..4389d1202 100644
@@ -35,6 +35,10 @@
     LINUX_VERSION_CODE > KERNEL_VERSION(4,4,71)
 #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 +15 -3
index 54bc5c008..30dd37dab 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>
@@ -68,11 +69,11 @@ static inline void x86_fpregs_activate(struct task_struct *t)
 	if (!x86_fpregs_active(t))
 		__fpregs_activate(&t->thread.fpu);
 }
+#endif
+#endif /* !IPIPE_X86_FPU_EAGER */
 
 #define x86_xstate_alignment		__alignof__(union fpregs_state)
 
-#endif
-
 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,8,0)
 /*
  * This is obsolete context switch code uselessly duplicating
@@ -462,7 +463,9 @@ void xnarch_leave_root(struct xnthread *root)
 		return;
 
 	// the kernel never marked the task as not being the fpu owner anymore
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
 	if (&current->thread.fpu.fpstate_active)
+#endif
 		fpregs_deactivate(&current->thread.fpu);
 
 	copy_fpregs_to_fpstate(rootcb->kfpu);
@@ -526,7 +529,11 @@ void xnarch_init_shadow_tcb(struct xnthread *thread)
 
 #ifdef IPIPE_X86_FPU_EAGER
 	xnthread_set_state(thread, XNFPU);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
 	fpu__activate_fpstate_read(&p->thread.fpu);
+#else
+	fpu__prepare_read(&p->thread.fpu);
+#endif
 #endif
 }
 
@@ -535,7 +542,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;
 
kernel/cobalt/include/asm-generic/xenomai/syscall.h +4 -0
index f11ade8e7..9d57eaf74 100644
@@ -20,7 +20,11 @@
 #define _COBALT_ASM_GENERIC_SYSCALL_H
 
 #include <linux/types.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.16.4
#10 lore raw

Re: [Xenomai] [PATCH 3/3] cobalt/x86: add ipipe-4.14 eager fpu support

Quoted 1 line · Henning Schild

As this is more than adding the version filter, some commit message would be nice.

Quoted 34 lines
---
  kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h |  4 ++++
  kernel/cobalt/arch/x86/thread.c                       | 18 +++++++++++++++---
  kernel/cobalt/include/asm-generic/xenomai/syscall.h   |  4 ++++
  3 files changed, 23 insertions(+), 3 deletions(-)
kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +4 -0
index 0156e86f0..4389d1202 100644
@@ -35,6 +35,10 @@
      LINUX_VERSION_CODE > KERNEL_VERSION(4,4,71)
  #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 +1 -0
index 54bc5c008..30dd37dab 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>

kernel/cobalt/arch/x86/thread.c static inline void x86_fpregs_activate(struct task_struct *t) · line 72

Quoted 4 lines
kernel/cobalt/arch/x86/thread.c +1 -0
@@ -68,11 +69,11 @@ static inline void x86_fpregs_activate(struct task_struct *t)
  	if (!x86_fpregs_active(t))
  		__fpregs_activate(&t->thread.fpu);
  }
+#endif

I suspect that this is "< 4.2.0", right?

kernel/cobalt/arch/x86/thread.c static inline void x86_fpregs_activate(struct task_struct *t) · line 75

Quoted 6 lines
kernel/cobalt/arch/x86/thread.c +1 -2
+#endif /* !IPIPE_X86_FPU_EAGER */
 
  #define x86_xstate_alignment		__alignof__(union fpregs_state)
 
-#endif
-

That looks weird. Are you sure you want to enable that define unconditionally?

kernel/cobalt/arch/x86/thread.c void xnarch_leave_root(struct xnthread *root) · line 466

Quoted 8 lines
kernel/cobalt/arch/x86/thread.c +1 -0
  #if LINUX_VERSION_CODE < KERNEL_VERSION(4,8,0)
  /*
   * This is obsolete context switch code uselessly duplicating
@@ -462,7 +463,9 @@ void xnarch_leave_root(struct xnthread *root)
  		return;
 
  	// the kernel never marked the task as not being the fpu owner anymore
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)

The comment should address the version differences.

Quoted 38 lines
kernel/cobalt/arch/x86/thread.c +11 -1
  	if (&current->thread.fpu.fpstate_active)
+#endif
  		fpregs_deactivate(&current->thread.fpu);
 
  	copy_fpregs_to_fpstate(rootcb->kfpu);
@@ -526,7 +529,11 @@ void xnarch_init_shadow_tcb(struct xnthread *thread)
 
  #ifdef IPIPE_X86_FPU_EAGER
  	xnthread_set_state(thread, XNFPU);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
  	fpu__activate_fpstate_read(&p->thread.fpu);
+#else
+	fpu__prepare_read(&p->thread.fpu);
+#endif
  #endif
  }
 
@@ -535,7 +542,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;
 
kernel/cobalt/include/asm-generic/xenomai/syscall.h +0 -0
index f11ade8e7..9d57eaf74 100644
@@ -20,7 +20,11 @@
  #define _COBALT_ASM_GENERIC_SYSCALL_H

kernel/cobalt/include/asm-generic/xenomai/syscall.h line 30

Quoted 10 lines
kernel/cobalt/include/asm-generic/xenomai/syscall.h +4 -0
 
  #include <linux/types.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>

Jan

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

Re: [Xenomai] [PATCH 3/3] cobalt/x86: add ipipe-4.14 eager fpu support

Am Mon, 27 Aug 2018 18:28:52 +0200
schrieb Jan Kiszka <[email protected]>:

Quoted 5 lines · Henning Schild
Quoted 1 line

As this is more than adding the version filter, some commit message would be nice.

I know, i think the final one would just be all three in one patch. As said in the cover letter, that should be seen as an early version where i was looking for higher level review. ... general approach/correctness

And to share the current state with others, while i am still trying to get 4.14 with Xenomai to boot.

Henning

Quoted 114 lines
Quoted 35 lines
---
  kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h |  4 ++++
  kernel/cobalt/arch/x86/thread.c                       | 18

+++++++++++++++---
kernel/cobalt/include/asm-generic/xenomai/syscall.h | 4 ++++ 3
files changed, 23 insertions(+), 3 deletions(-)

(quoted diff) +0 -0

b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h index 0156e86f0..4389d1202 100644 --- a/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h +++ b/kernel/cobalt/arch/x86/include/asm/xenomai/wrappers.h @@ -35,6 +35,10 @@ LINUX_VERSION_CODE > KERNEL_VERSION(4,4,71)
#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 54bc5c008..30dd37dab 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>

kernel/cobalt/arch/x86/thread.c static inline void x86_fpregs_activate(struct · line 72

Quoted 4 lines
kernel/cobalt/arch/x86/thread.c +1 -0
@@ -68,11 +69,11 @@ static inline void x86_fpregs_activate(struct
 task_struct *t) if (!x86_fpregs_active(t))
  		__fpregs_activate(&t->thread.fpu);
  }
+#endif  

I suspect that this is "< 4.2.0", right?

kernel/cobalt/arch/x86/thread.c static inline void x86_fpregs_activate(struct task_struct *t) · line 75

Quoted 6 lines
kernel/cobalt/arch/x86/thread.c +1 -2
+#endif /* !IPIPE_X86_FPU_EAGER */
 
  #define x86_xstate_alignment		__alignof__(union
 fpregs_state) 
-#endif
-  

That looks weird. Are you sure you want to enable that define unconditionally?

kernel/cobalt/arch/x86/thread.c void xnarch_leave_root(struct xnthread *root) · line 466

Quoted 8 lines
kernel/cobalt/arch/x86/thread.c +0 -0
  #if LINUX_VERSION_CODE < KERNEL_VERSION(4,8,0)
  /*
   * This is obsolete context switch code uselessly duplicating
@@ -462,7 +463,9 @@ void xnarch_leave_root(struct xnthread *root)
  		return;
 
  	// the kernel never marked the task as not being the fpu
 owner anymore +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)  

The comment should address the version differences.

Quoted 40 lines
kernel/cobalt/arch/x86/thread.c +11 -1
  	if (&current->thread.fpu.fpstate_active)
+#endif
  		fpregs_deactivate(&current->thread.fpu);
 
  	copy_fpregs_to_fpstate(rootcb->kfpu);
@@ -526,7 +529,11 @@ void xnarch_init_shadow_tcb(struct xnthread
 *thread) 
  #ifdef IPIPE_X86_FPU_EAGER
  	xnthread_set_state(thread, XNFPU);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
  	fpu__activate_fpstate_read(&p->thread.fpu);
+#else
+	fpu__prepare_read(&p->thread.fpu);
+#endif
  #endif
  }
 
@@ -535,7 +542,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;
 
(quoted diff) +0 -0

b/kernel/cobalt/include/asm-generic/xenomai/syscall.h index f11ade8e7..9d57eaf74 100644 --- a/kernel/cobalt/include/asm-generic/xenomai/syscall.h +++ b/kernel/cobalt/include/asm-generic/xenomai/syscall.h @@ -20,7 +20,11 @@ #define _COBALT_ASM_GENERIC_SYSCALL_H

  #include <linux/types.h>

kernel/cobalt/include/asm-generic/xenomai/syscall.h line 30

Quoted 8 lines
kernel/cobalt/include/asm-generic/xenomai/syscall.h +4 -0
+#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>

Jan