Second try of this patch, now consequently basing the affinity API for
xnshadow_map on current->cpus_allowed (affects the native skin). Just
like the current code does, this patch restricts a shadow thread to a
single (the first) CPU of its affinity mask.

Jan
---
 ksrc/nucleus/shadow.c       |   35 +++++++++++++----------------------
 ksrc/skins/native/syscall.c |    3 +++
 2 files changed, 16 insertions(+), 22 deletions(-)

Index: xenomai/ksrc/nucleus/shadow.c
===================================================================
--- xenomai.orig/ksrc/nucleus/shadow.c
+++ xenomai/ksrc/nucleus/shadow.c
@@ -409,18 +409,6 @@ static void lostage_handler(void *cookie
                xnltt_log_event(xeno_ev_lohandler, reqnum, p->comm, p->pid);
 
                switch (rq->req[reqnum].type) {
-               case LO_START_REQ:
-
-#ifdef CONFIG_SMP
-                       if (xnshadow_thread(p))
-                               /* Set up the initial task affinity using the
-                                  information passed to xnpod_start_thread(). 
*/
-                               set_cpus_allowed(p,
-                                                xnshadow_thread(p)->affinity);
-#endif /* CONFIG_SMP */
-
-                       goto do_wakeup;
-
                case LO_WAKEUP_REQ:
 
 #ifdef CONFIG_SMP
@@ -443,7 +431,9 @@ static void lostage_handler(void *cookie
                        if (!xnshadow_thread(current))
                                xnpod_renice_root(XNPOD_ROOT_PRIO_BASE);
 #endif /* CONFIG_XENO_OPT_RPIDISABLE */
-                     do_wakeup:
+
+                       /* fall through */
+               case LO_START_REQ:
 
 #ifdef CONFIG_XENO_OPT_ISHIELD
                        if (xnshadow_thread(p) &&
@@ -853,22 +843,23 @@ int xnshadow_map(xnthread_t *thread, xnc
        xnshadow_thrptd(current) = thread;
        xnpod_suspend_thread(thread, XNRELAX, XN_INFINITE, NULL);
 
+       /* Restrict affinity to a single CPU of the current set */
+       affinity = xnarch_cpumask_of_cpu(
+               xnarch_first_cpu(current->cpus_allowed));
+       set_cpus_allowed(current, affinity);
+
        if (u_completion) {
                xnshadow_signal_completion(u_completion, 0);
                return 0;
        }
 
-       /* Nobody waits for us, so we may start the shadow immediately
-          after having forced the CPU affinity to the current
-          processor. Note that we don't use smp_processor_id() to prevent
-          kernel debug stuff to yell at us for calling it in a preemptible
-          section of code. */
-
-       affinity = xnarch_cpumask_of_cpu(rthal_processor_id());
-       set_cpus_allowed(current, affinity);
+       /* Nobody waits for us, so we may start the shadow immediately. */
 
        mode = thread->rrperiod != XN_INFINITE ? XNRRB : 0;
-       xnpod_start_thread(thread, mode, 0, affinity, NULL, NULL);
+       err = xnpod_start_thread(thread, mode, 0, affinity, NULL, NULL);
+
+       if (err)
+               return err;
 
        err = xnshadow_harden();
 
Index: xenomai/ksrc/skins/native/syscall.c
===================================================================
--- xenomai.orig/ksrc/skins/native/syscall.c
+++ xenomai/ksrc/skins/native/syscall.c
@@ -168,6 +168,9 @@ static int __rt_task_create(struct task_
        err = rt_task_create(task, name, 0, prio, XNFPU | XNSHADOW | mode);
 
        if (err == 0) {
+               /* Apply CPU affinity */
+               set_cpus_allowed(current, task->affinity);
+
                /* Copy back the registry handle to the ph struct. */
                ph.opaque = xnthread_handle(&task->thread_base);
                ph.opaque2 = bulk.a5;   /* hidden pthread_t identifier. */

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core

Reply via email to