All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5] Allow changing CPU affinity of RTDM tasks
@ 2026-01-28 11:28 Richard Weinberger
  2026-01-28 11:28 ` [PATCH 2/5] Make RTDM tasks behave, part I Richard Weinberger
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Richard Weinberger @ 2026-01-28 11:28 UTC (permalink / raw)
  To: xenomai; +Cc: upstream+xenomai, Richard Weinberger

Currently, calling sched_affinity() on an RTDM 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 RTDM tasks utilize
it automatically.

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).

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 include/cobalt/kernel/rtdm/driver.h | 21 +++++++++++++++++++++
 kernel/cobalt/rtdm/drvlib.c         |  4 ++++
 kernel/cobalt/thread.c              | 10 ++++++++--
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h b/include/cobalt/kernel/rtdm/driver.h
index 604d54b2b..3fc5573cb 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,28 @@ 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)
+{
+	int sig;
+
+	if (signal_pending(current)) {
+		if (!xnthread_test_state(xnthread_current(), XNRELAX))
+			xnthread_relax(0, 0);
+		sig = kernel_dequeue_signal();
+		XENO_WARN_ON(COBALT, sig != 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/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index 86788743f..08e113904 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -90,6 +90,10 @@ nanosecs_abs_t rtdm_clock_read_monotonic(void);
  * After initialising a task, the task handle remains valid and can be
  * passed to RTDM services until either rtdm_task_destroy() or
  * rtdm_task_join() was invoked.
+ * RTDM tasks are required to use rtdm_task_should_stop() in their thread loop
+ * and must handle interrupted RTDM services, such as rtdm_event_wait().
+ * The -EINTR return code is not a fatal error. It should simply trigger a
+ * continuation of the thread loop.
  *
  * @param[in,out] task Task handle
  * @param[in] name Optional task name
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 607f115a7..3f0ed98ef 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,12 @@ 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 (sig != SIGSHADOW) {
+			XENO_WARN(COBALT, 1, "unexpected signal: %i", sig);
+			return;
+		}
+	}
 
 	slot = get_slot_index_from_sig(sig, arg);
 	if (WARN_ON_ONCE(slot < 0))
-- 
2.51.0


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

end of thread, other threads:[~2026-01-29  9:54 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-28 11:28 [PATCH 1/5] Allow changing CPU affinity of RTDM tasks Richard Weinberger
2026-01-28 11:28 ` [PATCH 2/5] Make RTDM tasks behave, part I Richard Weinberger
2026-01-28 13:23   ` Philippe Gerum
2026-01-28 13:31     ` Richard Weinberger
2026-01-28 13:54       ` Richard Weinberger
2026-01-28 16:37         ` Philippe Gerum
2026-01-28 11:28 ` [PATCH 3/5] Make RTDM tasks behave, part II Richard Weinberger
2026-01-29  9:45   ` Jan Kiszka
2026-01-28 11:28 ` [PATCH 4/5] Warn on unexpected RTDM task termination Richard Weinberger
2026-01-29  9:50   ` Jan Kiszka
2026-01-29  9:54     ` Florian Bezdeka
2026-01-28 11:28 ` [PATCH 5/5] Allow specifying CPU affinity in rtdm_task_init() Richard Weinberger
2026-01-29  9:53   ` Jan Kiszka

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.