Module: xenomai-forge
Branch: next
Commit: d300bcf19e75e0cef10f8b2b35f9a3b85e3d1712
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=d300bcf19e75e0cef10f8b2b35f9a3b85e3d1712

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Sep 22 11:50:35 2014 +0200

cobalt/arch: announce task sharing to the kernel

Use the new ancillary service available with recent I-pipe releases to
announce our intent to share a task context with the regular kernel,
e.g. like scheduling such task.

This service will provide for inits that may be required for enabling
such sharing, such as using the FPU from Xenomai kthreads.

---

 include/cobalt/kernel/thread.h |    3 +--
 kernel/cobalt/posix/process.c  |    2 +-
 kernel/cobalt/thread.c         |   30 ++++++++++++++++++++----------
 3 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h
index 6438261..68a8ca9 100644
--- a/include/cobalt/kernel/thread.h
+++ b/include/cobalt/kernel/thread.h
@@ -419,8 +419,7 @@ void xnthread_switch_fpu(struct xnsched *sched);
 static inline void xnthread_switch_fpu(struct xnsched *sched) { }
 #endif /* CONFIG_XENO_ARCH_FPU */
 
-void xnthread_init_shadow_tcb(struct xnthread *thread,
-                             struct task_struct *task);
+void xnthread_init_shadow_tcb(struct xnthread *thread);
 
 void xnthread_init_root_tcb(struct xnthread *thread);
 
diff --git a/kernel/cobalt/posix/process.c b/kernel/cobalt/posix/process.c
index 3c72db8..42a33eb 100644
--- a/kernel/cobalt/posix/process.c
+++ b/kernel/cobalt/posix/process.c
@@ -659,7 +659,7 @@ int cobalt_map_user(struct xnthread *thread, __u32 __user 
*u_winoff)
         * positive in debug code from handle_schedule_event() and
         * friends.
         */
-       xnthread_init_shadow_tcb(thread, current);
+       xnthread_init_shadow_tcb(thread);
        xnthread_suspend(thread, XNRELAX, XN_INFINITE, XN_RELATIVE, NULL);
        init_uthread_info(thread);
        xnthread_set_state(thread, XNMAPPED);
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index aec4970..f5444d3 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -222,20 +222,29 @@ err_out:
        return ret;
 }
 
-void xnthread_init_shadow_tcb(struct xnthread *thread, struct task_struct 
*task)
+void xnthread_init_shadow_tcb(struct xnthread *thread)
 {
        struct xnarchtcb *tcb = xnthread_archtcb(thread);
+       struct task_struct *p = current;
+
+       /*
+        * If the current task is a kthread, the pipeline will take
+        * the necessary steps to make the FPU usable in such
+        * context. The kernel already took care of this issue for
+        * userland tasks (e.g. setting up a clean backup area).
+        */
+       __ipipe_share_current(0);
 
        memset(tcb, 0, sizeof(*tcb));
-       tcb->core.host_task = task;
-       tcb->core.tsp = &task->thread;
-       tcb->core.mm = task->mm;
-       tcb->core.active_mm = task->mm;
+       tcb->core.host_task = p;
+       tcb->core.tsp = &p->thread;
+       tcb->core.mm = p->mm;
+       tcb->core.active_mm = p->mm;
 #ifdef CONFIG_XENO_ARCH_WANT_TIP
-       tcb->core.tip = task_thread_info(task);
+       tcb->core.tip = task_thread_info(p);
 #endif
 #ifdef CONFIG_XENO_ARCH_FPU
-       tcb->core.user_fpu_owner = task;
+       tcb->core.user_fpu_owner = p;
 #endif /* CONFIG_XENO_ARCH_FPU */
        xnarch_init_shadow_tcb(thread);
 }
@@ -243,11 +252,12 @@ void xnthread_init_shadow_tcb(struct xnthread *thread, 
struct task_struct *task)
 void xnthread_init_root_tcb(struct xnthread *thread)
 {
        struct xnarchtcb *tcb = xnthread_archtcb(thread);
+       struct task_struct *p = current;
 
        memset(tcb, 0, sizeof(*tcb));
-       tcb->core.host_task = current;
+       tcb->core.host_task = p;
        tcb->core.tsp = &tcb->core.ts;
-       tcb->core.mm = current->mm;
+       tcb->core.mm = p->mm;
 #ifdef CONFIG_XENO_ARCH_WANT_TIP
        tcb->core.tip = NULL;
 #endif
@@ -2353,7 +2363,7 @@ int xnthread_map(struct xnthread *thread, struct 
completion *done)
 
        trace_cobalt_shadow_map(thread);
 
-       xnthread_init_shadow_tcb(thread, p);
+       xnthread_init_shadow_tcb(thread);
        xnthread_suspend(thread, XNRELAX, XN_INFINITE, XN_RELATIVE, NULL);
        init_kthread_info(thread);
        xnthread_set_state(thread, XNMAPPED);


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to