All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Allow changing CPU affinity of RT kernel tasks
@ 2026-01-26 12:57 Richard Weinberger
  2026-01-26 14:28 ` Jan Kiszka
  2026-01-26 15:50 ` Florian Bezdeka
  0 siblings, 2 replies; 8+ messages in thread
From: Richard Weinberger @ 2026-01-26 12:57 UTC (permalink / raw)
  To: xenomai; +Cc: upstream+xenomai, Richard Weinberger

Currently, calling sched_affinity() on an RT kernel task has no effect
on the Xenomai side, even though the shadow task reflects the desired
affinity. This discrepancy causes confusion because the failure is not
immediately visible.
A cryptic WARN_ON() triggers only when CONFIG_XENO_OPT_DEBUG_COBALT is
enabled.

This change addresses the issue by implementing an approach similar to
that used for userspace tasks: forcing a relaxation and hardening cycle
to apply the new affinity upon receiving SIGSHADOW.

A new helper, rtdm_task_test_sigshadow(), checks whether SIGSHADOW is
pending for the shadow task. If so, the signal is consumed, and a
relax/harden cycle is performed. This works because signal_pending()
only checks a flag and does not cause a domain switch. The new helper
is integrated into rtdm_task_should_stop(), so existing RT tasks utilize
it automatically.

RFC Discussion: Sending SIGSHADOW to a kernel task causes blocking
functions to return -EINTR. Currently, almost all RT kernel tasks treat
non-zero returns from functions like rtdm_event_wait() as fatal errors
and terminate. With this change, blocking functions that return -EINTR
require restarting (continuing the thread loop).

An alternative approach would be implementing restart logic in the rtdm_*
wrapper functions. If XNBREAK is set and it is a kernel task, the wrapper
could run rtdm_task_test_sigshadow() and restart the call internally
instead of returning -EINTR.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 include/cobalt/kernel/rtdm/driver.h | 17 +++++++++++++++++
 kernel/cobalt/thread.c              |  7 +++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h b/include/cobalt/kernel/rtdm/driver.h
index 604d54b2b..d06e1126c 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -34,6 +34,7 @@
 #include <linux/cdev.h>
 #include <linux/wait.h>
 #include <linux/notifier.h>
+#include <linux/sched/signal.h>
 #include <pipeline/lock.h>
 #include <xenomai/version.h>
 #include <cobalt/kernel/heap.h>
@@ -1043,8 +1044,24 @@ static inline void rtdm_task_destroy(rtdm_task_t *task)
 	xnthread_join(task, true);
 }
 
+static inline int __rtdm_task_should_stop(void)
+{
+	return xnthread_test_info(xnthread_current(), XNCANCELD);
+}
+
+static inline void rtdm_task_test_sigshadow(void)
+{
+	if (signal_pending(current)) {
+		xnthread_relax(0, 0);
+		XENO_WARN_ON(COBALT, kernel_dequeue_signal() != SIGSHADOW);
+		xnthread_harden();
+	}
+}
+
 static inline int rtdm_task_should_stop(void)
 {
+	rtdm_task_test_sigshadow();
+
 	return xnthread_test_info(xnthread_current(), XNCANCELD);
 }
 
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 607f115a7..e9baf38e1 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -204,6 +204,8 @@ static int kthread_trampoline(void *arg)
 		return ret;
 	}
 
+	allow_signal(SIGSHADOW);
+
 	trace_cobalt_shadow_entry(thread);
 
 	thread->entry(thread->cookie);
@@ -2373,8 +2375,9 @@ void __xnthread_signal(struct xnthread *thread, int sig, int arg)
 	struct lostage_signal *sigwork;
 	int slot;
 
-	if (XENO_WARN_ON(COBALT, !xnthread_test_state(thread, XNUSER)))
-		return;
+	if (!xnthread_test_state(thread, XNUSER))
+		if (XENO_WARN_ON(COBALT, sig != SIGSHADOW))
+			return;
 
 	slot = get_slot_index_from_sig(sig, arg);
 	if (WARN_ON_ONCE(slot < 0))
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-01-27  6:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-26 12:57 [PATCH] Allow changing CPU affinity of RT kernel tasks Richard Weinberger
2026-01-26 14:28 ` Jan Kiszka
2026-01-26 15:11   ` Richard Weinberger
2026-01-26 16:26     ` Jan Kiszka
2026-01-26 22:05       ` Richard Weinberger
2026-01-27  6:15         ` Jan Kiszka
2026-01-26 15:50 ` Florian Bezdeka
2026-01-26 16:04   ` Richard Weinberger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.