global CPU affinity control
RFC PATCH 2/2 global CPU affinity control
This is version 4 of the /proc/xenomai/affinity feature. It has been rebased on the reworked xnshadow_map code, now applying the default affinity mask in a (hopefully) correct way also on shadow threads.
What has been said for the previous patch also applies here: test and comment! Mathias, you asked for this feature, please let us know if it fulfils your requirements.
Philippe, you were looking for documentation of this new behaviour. Please let me know where you would like to see this. Surely in the nucleus API, I guess. Anywhere else?
Jan
--- include/nucleus/pod.h | 2 + ksrc/nucleus/intr.c | 3 ++ ksrc/nucleus/module.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++ ksrc/nucleus/pod.c | 6 +++- ksrc/nucleus/shadow.c | 3 ++ ksrc/skins/native/task.c | 3 ++ 6 files changed, 72 insertions(+), 2 deletions(-)
include/nucleus/pod.h +2 -0
@@ -256,6 +256,8 @@ extern u_long nktickdef;extern char *nkmsgbuf; +extern xnarch_cpumask_t nkaffinity; + #define xnprintf(fmt,args...) xnarch_printf(fmt , ##args) #define xnloginfo(fmt,args...) xnarch_loginfo(fmt , ##args) #define xnlogwarn(fmt,args...) xnarch_logwarn(fmt , ##args)
ksrc/nucleus/module.c +57 -0
75 lines not on this page · raw message
ksrc/nucleus/pod.c +4 -2
@@ -70,6 +70,8 @@ MODULE_PARM_DESC(tick_arg, "Fixed clockchar *nkmsgbuf =NULL ; +xnarch_cpumask_t nkaffinity =XNPOD_ALL_CPUS ; +const char *xnpod_fatal_helper (const char *format, ...) {const unsigned nr_cpus =xnarch_num_online_cpus ();
@@ -909,8 +911,8 @@ int xnpod_start_thread(xnthread_t *threaif (!testbits (thread->status,XNDORMANT ))return -EBUSY ; -if (xnarch_cpus_empty (affinity)) - affinity =XNARCH_CPU_MASK_ALL ; +if (xnarch_cpus_equal (affinity,XNPOD_ALL_CPUS )) + affinity = nkaffinity;xnlock_get_irqsave (&nklock, s);
ksrc/nucleus/shadow.c +3 -0
@@ -847,6 +847,9 @@ int xnshadow_map(xnthread_t *thread, xncxnshadow_thrptd (current) = thread;xnpod_suspend_thread (thread,XNRELAX ,XN_INFINITE ,NULL ); +if (xnarch_cpus_equal (affinity,XNPOD_ALL_CPUS )) + affinity = nkaffinity; +/* Apply provided cpumask on the Linux task. */ set_cpus_allowed (current, affinity);
ksrc/skins/native/task.c +3 -0
@@ -255,6 +255,9 @@ int rt_task_create(RT_TASK *task,if (cpumask &1 )xnarch_cpu_set (cpu, task->affinity); +if (xnarch_cpus_empty (task->affinity)) + task->affinity =XNPOD_ALL_CPUS ; +#ifdef CONFIG_XENO_OPT_NATIVE_MPS xnsynch_init (&task->mrecv,XNSYNCH_FIFO );xnsynch_init (&task->msendq,XNSYNCH_PRIO |XNSYNCH_PIP );
ksrc/nucleus/intr.c +3 -0
@@ -626,6 +626,9 @@ int xnintr_attach(xnintr_t *intr, void *xnlock_get_irqsave (&intrlock, s); +#ifdef CONFIG_SMP +xnarch_set_irq_affinity (intr->irq, nkaffinity); +#endif /* CONFIG_SMP */ err =xnintr_irq_attach (intr);xnlock_put_irqrestore (&intrlock, s);
Quoted 18 lines · Jan Kiszka
This is version 4 of the
/proc/xenomai/affinityfeature. It has been rebased on the reworkedxnshadow_mapcode, now applying the default affinity mask in a (hopefully) correct way also on shadow threads.What has been said for the previous patch also applies here: test and comment! Mathias, you asked for this feature, please let us know if it fulfils your requirements.
Philippe, you were looking for documentation of this new behaviour. Please let me know where you would like to see this. Surely in the nucleus API, I guess. Anywhere else?
Jan
------------------------------------------------------------------------
(...)
ksrc/nucleus/pod.c int xnpod_start_thread(xnthread_t *threa · line 915
Quoted 7 lines
ksrc/nucleus/pod.c +2
-2@@ -909,8 +911,8 @@ int xnpod_start_thread(xnthread_t *threaif (!testbits (thread->status,XNDORMANT ))return -EBUSY ; -if (xnarch_cpus_empty (affinity)) - affinity =XNARCH_CPU_MASK_ALL ; +if (xnarch_cpus_equal (affinity,XNPOD_ALL_CPUS )) + affinity = nkaffinity;
Should not this be:
if (xnarch_cpus_empty(affinity)) affinity = XNARCH_CPU_MASK_ALL; xnarch_cpus_and(affinity, affinity, nkaffinity); if (xnarch_cpus_empty(affinity)) return -EINVAL;
so that no thread could escape the rule imposed by nkaffinity.
Signature · 1 line
Gilles Chanteperdrix
Quoted 28 lines · Gilles Chanteperdrix
Quoted 18 lines · Jan Kiszka
This is version 4 of the
/proc/xenomai/affinityfeature. It has been rebased on the reworkedxnshadow_mapcode, now applying the default affinity mask in a (hopefully) correct way also on shadow threads.What has been said for the previous patch also applies here: test and comment! Mathias, you asked for this feature, please let us know if it fulfils your requirements.
Philippe, you were looking for documentation of this new behaviour. Please let me know where you would like to see this. Surely in the nucleus API, I guess. Anywhere else?
Jan
------------------------------------------------------------------------
(...)ksrc/nucleus/pod.c int xnpod_start_thread(xnthread_t *threa · line 915
Quoted 7 lines
ksrc/nucleus/pod.c +2
-2@@ -909,8 +911,8 @@ int xnpod_start_thread(xnthread_t *threaif (!testbits (thread->status,XNDORMANT ))return -EBUSY ; -if (xnarch_cpus_empty (affinity)) - affinity =XNARCH_CPU_MASK_ALL ; +if (xnarch_cpus_equal (affinity,XNPOD_ALL_CPUS )) + affinity = nkaffinity;Should not this be:
Quoted 8 lines
if (xnarch_cpus_empty(affinity)) affinity = XNARCH_CPU_MASK_ALL; xnarch_cpus_and(affinity, affinity, nkaffinity); if (xnarch_cpus_empty(affinity)) return -EINVAL;so that no thread could escape the rule imposed by nkaffinity.
Nope, that's intentional (forgot to repeat this fact, was explained earlier): Users can always override nkaffinity by their own mask. Only the "I-don't-care" XNPOD_ALL_CPUS activates this new selection mechanism.
Jan
Quoted 7 lines · M. Koehrer
Hi Jan,
thanks for the patch!
This looks fine to me. This allows me easily to set the affinity of the xenomai tasks.As far as I understood, I have to specify
XNPOD_ALL_CPUSas parameter atrt_task_create()to use this feature.
...or an empty mask, both works.
Quoted 3 lines
What about the rtnet internal (kernel) task (created via RTDM)?
Will it use this affinity as well or do I have to "force" rtnet somehow to use the "global" xenomai affinity?
Yes, it affects any Xenomai thread that doesn't specify an explicit mask. And it forces all IRQs that are newly attached to the specified affinity. You should be able to watch this under /proc/irq/<n>/smp_affinity. That avoids e.g. that the NIC IRQ pops up on CPU 0 but has to wake up the stack manager on CPU 1.
Jan
Quoted 3 lines · Jan Kiszka
Nope, that's intentional (forgot to repeat this fact, was explained earlier): Users can always override nkaffinity by their own mask. Only the "I-don't-care"
XNPOD_ALL_CPUSactivates this new selection mechanism.
Ok. But there is still something wrong: if the affinity is empty, it will remain empty whereas it was replaced by XNARCH_CPU_MASK_ALL in the current version.
Signature · 1 line
Gilles Chanteperdrix
Quoted 9 lines · Gilles Chanteperdrix
Quoted 3 lines · Jan Kiszka
Nope, that's intentional (forgot to repeat this fact, was explained earlier): Users can always override nkaffinity by their own mask. Only the "I-don't-care"
XNPOD_ALL_CPUSactivates this new selection mechanism.Ok. But there is still something wrong: if the affinity is empty, it will remain empty whereas it was replaced by
XNARCH_CPU_MASK_ALLin the current version.
The policy is that no skin should invoke xnshadow_map or xnpod_start_thread with an empty mask anymore. So far only the native skin made use of this, and that is changed by the patch.
Version 5 is basically a rebase over the first patch of this series. It also enforces that cpus_allowed of a shadow thread only contains a single CPU.
Only compile-tested.
Jan
--- include/nucleus/pod.h | 2 + ksrc/nucleus/intr.c | 3 ++ ksrc/nucleus/module.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++ ksrc/nucleus/pod.c | 6 +++- ksrc/nucleus/shadow.c | 12 ++++++--- ksrc/skins/native/task.c | 3 ++ 6 files changed, 77 insertions(+), 6 deletions(-)
include/nucleus/pod.h +2 -0
@@ -253,6 +253,8 @@ extern u_long nktickdef;extern char *nkmsgbuf; +extern xnarch_cpumask_t nkaffinity; + #define xnprintf(fmt,args...) xnarch_printf(fmt , ##args) #define xnloginfo(fmt,args...) xnarch_loginfo(fmt , ##args) #define xnlogwarn(fmt,args...) xnarch_logwarn(fmt , ##args)
ksrc/nucleus/module.c +57 -0
75 lines not on this page · raw message
ksrc/nucleus/pod.c +4 -2
@@ -70,6 +70,8 @@ MODULE_PARM_DESC(tick_arg, "Fixed clockchar *nkmsgbuf =NULL ; +xnarch_cpumask_t nkaffinity =XNPOD_ALL_CPUS ; +const char *xnpod_fatal_helper (const char *format, ...) {const unsigned nr_cpus =xnarch_num_online_cpus ();
@@ -909,8 +911,8 @@ int xnpod_start_thread(xnthread_t *threaif (!testbits (thread->status,XNDORMANT ))return -EBUSY ; -if (xnarch_cpus_empty (affinity)) - affinity =XNARCH_CPU_MASK_ALL ; +if (xnarch_cpus_equal (affinity,XNPOD_ALL_CPUS )) + affinity = nkaffinity;xnlock_get_irqsave (&nklock, s);
ksrc/skins/native/task.c +3 -0
@@ -255,6 +255,9 @@ int rt_task_create(RT_TASK *task,if (cpumask &1 )xnarch_cpu_set (cpu, task->affinity); +if (xnarch_cpus_empty (task->affinity)) + task->affinity =XNPOD_ALL_CPUS ; +#ifdef CONFIG_XENO_OPT_NATIVE_MPS xnsynch_init (&task->mrecv,XNSYNCH_FIFO );xnsynch_init (&task->msendq,XNSYNCH_PRIO |XNSYNCH_PIP );
ksrc/nucleus/intr.c +3 -0
@@ -626,6 +626,9 @@ int xnintr_attach(xnintr_t *intr, void *xnlock_get_irqsave (&intrlock, s); +#ifdef CONFIG_SMP +xnarch_set_irq_affinity (intr->irq, nkaffinity); +#endif /* CONFIG_SMP */ err =xnintr_irq_attach (intr);xnlock_put_irqrestore (&intrlock, s);
ksrc/nucleus/shadow.c +8 -4
@@ -797,7 +797,7 @@ int xnshadow_map(xnthread_t *thread, xnc {xnarch_cpumask_t affinity;unsigned muxid, magic; -int mode, prio, err; +int mode, prio, err, cpu;/* Increment the interface reference count. */ magic =xnthread_get_magic (thread);
@@ -843,9 +843,13 @@ int xnshadow_map(xnthread_t *thread, xncxnshadow_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)); +/* Restrict affinity to a single CPU of nkaffinity or +the current set. */ +if (xnarch_cpus_equal (current->cpus_allowed,XNPOD_ALL_CPUS )) + cpu =xnarch_first_cpu (nkaffinity); +else + cpu =xnarch_first_cpu (current->cpus_allowed); + affinity =xnarch_cpumask_of_cpu (cpu);set_cpus_allowed (current, affinity);if (u_completion) {