* [RFC PATCH 0/5] RT throttling
@ 2026-12-01 14:12 Richard Weinberger (sigma star gmbh)
2026-12-01 14:12 ` [PATCH 1/5] cobalt/trace: add cobalt_sched_throttle tracepoint Richard Weinberger (sigma star gmbh)
` (5 more replies)
0 siblings, 6 replies; 11+ messages in thread
From: Richard Weinberger (sigma star gmbh) @ 2026-12-01 14:12 UTC (permalink / raw)
To: xenomai; +Cc: upstream+xenomai, Richard Weinberger
From: Richard Weinberger <richard@nod.at>
This patch series implements an RT throttle like Linux has.
It allows limiting the total CPU time used by Cobalt threads,
if the limit is reached, Linux gets the CPU.
That way, misbehaving applications won't kill the system and
will only get throttled instead of killed by the Xenomai runaway
thread detection.
The main reason I need this feature is because for a rather specific
use case, I need to limit the total available CPU time for all
userspace, so Xenomai plus Linux.
I'm curious to read how much you'll hate this. ;-)
Thanks,
//richard
Richard Weinberger (5):
cobalt/trace: add cobalt_sched_throttle tracepoint
cobalt/sched: add RT throttling
cobalt/sched-sporadic: stop budget accounting on RT throttling
cobalt/sched-quota: charge the running group on RT throttling
testsuite/smokey: add sched-throttle test
configure.ac | 1 +
doc/asciidoc/README.INSTALL.adoc | 12 +
include/cobalt/kernel/sched-throttle.h | 92 ++++++
include/cobalt/kernel/sched.h | 25 +-
kernel/cobalt/Kconfig | 26 ++
kernel/cobalt/Makefile | 1 +
kernel/cobalt/sched-quota.c | 39 ++-
kernel/cobalt/sched-sporadic.c | 7 +
kernel/cobalt/sched-throttle.c | 266 ++++++++++++++++++
kernel/cobalt/sched.c | 31 +-
kernel/cobalt/trace/cobalt-core.h | 17 ++
testsuite/smokey/Makefile.am | 2 +
testsuite/smokey/sched-throttle/Makefile.am | 8 +
.../smokey/sched-throttle/sched-throttle.c | 251 +++++++++++++++++
14 files changed, 763 insertions(+), 15 deletions(-)
create mode 100644 include/cobalt/kernel/sched-throttle.h
create mode 100644 kernel/cobalt/sched-throttle.c
create mode 100644 testsuite/smokey/sched-throttle/Makefile.am
create mode 100644 testsuite/smokey/sched-throttle/sched-throttle.c
--
2.56.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/5] cobalt/trace: add cobalt_sched_throttle tracepoint
2026-12-01 14:12 [RFC PATCH 0/5] RT throttling Richard Weinberger (sigma star gmbh)
@ 2026-12-01 14:12 ` Richard Weinberger (sigma star gmbh)
2026-12-01 14:12 ` [PATCH 2/5] cobalt/sched: add RT throttling Richard Weinberger (sigma star gmbh)
` (4 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Richard Weinberger (sigma star gmbh) @ 2026-12-01 14:12 UTC (permalink / raw)
To: xenomai; +Cc: upstream+xenomai, Richard Weinberger
From: Richard Weinberger <richard@nod.at>
Add a tracepoint for RT throttling, to be emitted when a CPU gets
throttled and when the throttle is lifted.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
kernel/cobalt/trace/cobalt-core.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/kernel/cobalt/trace/cobalt-core.h b/kernel/cobalt/trace/cobalt-core.h
index f534121cb..4cd72d5ee 100644
--- a/kernel/cobalt/trace/cobalt-core.h
+++ b/kernel/cobalt/trace/cobalt-core.h
@@ -197,6 +197,23 @@ TRACE_EVENT(cobalt_schedule_remote,
TP_printk("status=0x%lx", __entry->status)
);
+TRACE_EVENT(cobalt_sched_throttle,
+ TP_PROTO(int cpu, bool throttled),
+ TP_ARGS(cpu, throttled),
+
+ TP_STRUCT__entry(
+ __field(int, cpu)
+ __field(bool, throttled)
+ ),
+
+ TP_fast_assign(
+ __entry->cpu = cpu;
+ __entry->throttled = throttled;
+ ),
+
+ TP_printk("cpu=%d throttled=%d", __entry->cpu, __entry->throttled)
+);
+
TRACE_EVENT(cobalt_switch_context,
TP_PROTO(struct xnthread *prev, struct xnthread *next),
TP_ARGS(prev, next),
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/5] cobalt/sched: add RT throttling
2026-12-01 14:12 [RFC PATCH 0/5] RT throttling Richard Weinberger (sigma star gmbh)
2026-12-01 14:12 ` [PATCH 1/5] cobalt/trace: add cobalt_sched_throttle tracepoint Richard Weinberger (sigma star gmbh)
@ 2026-12-01 14:12 ` Richard Weinberger (sigma star gmbh)
2026-12-01 14:12 ` [PATCH 3/5] cobalt/sched-sporadic: stop budget accounting on " Richard Weinberger (sigma star gmbh)
` (3 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Richard Weinberger (sigma star gmbh) @ 2026-12-01 14:12 UTC (permalink / raw)
To: xenomai; +Cc: upstream+xenomai, Richard Weinberger
From: Richard Weinberger <richard@nod.at>
Add an optional per-CPU limit on the CPU time Cobalt may use,
similar to sched_rt_runtime_us/sched_rt_period_us in Linux. Within
each window of xenomai.sched_rt_period_us, Cobalt threads may run for
at most xenomai.sched_rt_runtime_us. Once the budget is used up, Linux
gets the CPU until the window ends.
The use cases are CPU bandwidth throttling and a safety net against
buggy real-time applications, which would otherwise lock up a CPU and
starve Linux.
The limit applies to every Cobalt thread regardless of its scheduling
class and overrides the scheduler lock. The parameters can only be set
at boot time.
Scheduling classes keeping per-thread budgets can implement the new
sched_throttle hook to stop accounting when the throttle switches a
thread out.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
doc/asciidoc/README.INSTALL.adoc | 12 ++
include/cobalt/kernel/sched-throttle.h | 92 +++++++++
include/cobalt/kernel/sched.h | 25 ++-
kernel/cobalt/Kconfig | 26 +++
kernel/cobalt/Makefile | 1 +
kernel/cobalt/sched-throttle.c | 266 +++++++++++++++++++++++++
kernel/cobalt/sched.c | 31 ++-
7 files changed, 450 insertions(+), 3 deletions(-)
create mode 100644 include/cobalt/kernel/sched-throttle.h
create mode 100644 kernel/cobalt/sched-throttle.c
diff --git a/doc/asciidoc/README.INSTALL.adoc b/doc/asciidoc/README.INSTALL.adoc
index 5797b8fc0..8f8d7a0aa 100644
--- a/doc/asciidoc/README.INSTALL.adoc
+++ b/doc/asciidoc/README.INSTALL.adoc
@@ -150,6 +150,18 @@ This option activates a watchdog aimed at detecting runaway Cobalt threads.
Timeout value can be set via CONFIG_XENO_OPT_WATCHDOG_TIMEOUT, with a range
from 1 to 60. | 4
+|xenomai.sched_rt_period_us=<usecs> | Length of the real-time throttling
+window. Requires CONFIG_XENO_OPT_SCHED_THROTTLE to be enabled in kernel
+configuration.
+| 1000000
+
+|xenomai.sched_rt_runtime_us=<usecs> | CPU time Cobalt threads may
+consume on each CPU within every throttling window, regardless of their
+scheduling class. Once exhausted, Linux runs until the window ends, even
+if a Cobalt thread holds the scheduler lock. -1 disables throttling.
+Requires CONFIG_XENO_OPT_SCHED_THROTTLE to be enabled in kernel configuration.
+| 950000
+
|xenomai.smi=<state> | *x86-specific*: Set the state of the SMI
workaround. The possible values are _disabled_, _detect_ and
_enabled_. See the discussion about link:dealing-with-x86-SMI[SMIs]
diff --git a/include/cobalt/kernel/sched-throttle.h b/include/cobalt/kernel/sched-throttle.h
new file mode 100644
index 000000000..fe2022fc1
--- /dev/null
+++ b/include/cobalt/kernel/sched-throttle.h
@@ -0,0 +1,92 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2026 Richard Weinberger
+ */
+#ifndef _COBALT_KERNEL_SCHED_THROTTLE_H
+#define _COBALT_KERNEL_SCHED_THROTTLE_H
+
+#ifndef _COBALT_KERNEL_SCHED_H
+#error "please don't include cobalt/kernel/sched-throttle.h directly"
+#endif
+
+/**
+ * @addtogroup cobalt_core_sched
+ * @{
+ */
+
+struct xnsched;
+struct xnvfile_directory;
+
+#ifdef CONFIG_XENO_OPT_SCHED_THROTTLE
+
+#include <linux/jump_label.h>
+
+/*
+ * Per-CPU RT throttling state. All dates and durations are in ns,
+ * read from nkclock.
+ */
+struct xnsched_throttle {
+ /* Fires when the budget is used up or the window ends. */
+ struct xntimer budget_timer;
+ /* Fires at the end of the window the CPU is throttled in. */
+ struct xntimer window_timer;
+ /* Start of the current window, a multiple of the period. */
+ xnticks_t window_start;
+ /* Cobalt time charged to the current window. */
+ xnticks_t used;
+ /* Cobalt time since this date is not charged yet. */
+ xnticks_t charge_from;
+ /* Number of times the budget was used up. */
+ unsigned long count;
+};
+
+DECLARE_STATIC_KEY_FALSE(xnsched_throttle_enabled);
+
+void xnsched_throttle_setup(void);
+
+void xnsched_throttle_init(struct xnsched *sched);
+
+void xnsched_throttle_destroy(struct xnsched *sched);
+
+void __xnsched_throttle_leave_root(struct xnsched *sched);
+
+void __xnsched_throttle_enter_root(struct xnsched *sched);
+
+/* Linux hands the CPU over to Cobalt: start charging. */
+static inline void xnsched_throttle_leave_root(struct xnsched *sched)
+{
+ if (static_branch_unlikely(&xnsched_throttle_enabled))
+ __xnsched_throttle_leave_root(sched);
+}
+
+/* Cobalt hands the CPU back to Linux: stop charging. */
+static inline void xnsched_throttle_enter_root(struct xnsched *sched)
+{
+ if (static_branch_unlikely(&xnsched_throttle_enabled))
+ __xnsched_throttle_enter_root(sched);
+}
+
+int xnsched_throttle_init_proc(struct xnvfile_directory *vfroot);
+
+void xnsched_throttle_cleanup_proc(void);
+
+#else /* !CONFIG_XENO_OPT_SCHED_THROTTLE */
+
+static inline void xnsched_throttle_setup(void) { }
+static inline void xnsched_throttle_init(struct xnsched *sched) { }
+static inline void xnsched_throttle_destroy(struct xnsched *sched) { }
+static inline void xnsched_throttle_leave_root(struct xnsched *sched) { }
+static inline void xnsched_throttle_enter_root(struct xnsched *sched) { }
+
+static inline int xnsched_throttle_init_proc(struct xnvfile_directory *vfroot)
+{
+ return 0;
+}
+
+static inline void xnsched_throttle_cleanup_proc(void) { }
+
+#endif /* !CONFIG_XENO_OPT_SCHED_THROTTLE */
+
+/** @} */
+
+#endif /* !_COBALT_KERNEL_SCHED_THROTTLE_H */
diff --git a/include/cobalt/kernel/sched.h b/include/cobalt/kernel/sched.h
index e0b4249a4..539d4148e 100644
--- a/include/cobalt/kernel/sched.h
+++ b/include/cobalt/kernel/sched.h
@@ -28,6 +28,7 @@
#include <cobalt/kernel/sched-sporadic.h>
#include <cobalt/kernel/sched-quota.h>
#include <cobalt/kernel/vfile.h>
+#include <cobalt/kernel/sched-throttle.h>
#include <cobalt/kernel/assert.h>
#include <asm/xenomai/machine.h>
#include <pipeline/sched.h>
@@ -47,6 +48,7 @@
#define XNHTICK 0x00008000 /* Host tick pending */
#define XNINIRQ 0x00004000 /* In IRQ handling context */
#define XNHDEFER 0x00002000 /* Host tick deferred */
+#define XNTHROTTLED 0x00001000 /* RT budget exhausted */
/*
* Hardware timer is stopped.
@@ -108,6 +110,10 @@ struct xnsched {
/*!< Watchdog timer object. */
struct xntimer wdtimer;
#endif
+#ifdef CONFIG_XENO_OPT_SCHED_THROTTLE
+ /*!< RT throttling state. */
+ struct xnsched_throttle throttle;
+#endif
#ifdef CONFIG_XENO_OPT_STATS
/*!< Last account switch date (ticks). */
xnticks_t last_account_switch;
@@ -179,6 +185,14 @@ struct xnsched_class {
const union xnsched_policy_param *p);
void (*sched_forget)(struct xnthread *thread);
void (*sched_kick)(struct xnthread *thread);
+ /**
+ * Called on the base class of @a curr when RT throttling
+ * switches it out in favour of the root thread, bypassing
+ * sched_pick(). Classes that keep per-thread budgets should
+ * stop accounting @a curr here, as they would when picking a
+ * successor.
+ */
+ void (*sched_throttle)(struct xnthread *curr);
#ifdef CONFIG_XENO_OPT_VFILE
int (*sched_init_vfile)(struct xnsched_class *schedclass,
struct xnvfile_directory *vfroot);
@@ -307,6 +321,12 @@ static inline int __xnsched_run(struct xnsched *sched)
return pipeline_schedule(sched);
}
+/* RT budget used up, Linux owns the CPU until the window ends. */
+static inline bool xnsched_throttled(struct xnsched *sched)
+{
+ return sched->lflags & XNTHROTTLED;
+}
+
static inline int xnsched_run(void)
{
struct xnsched *sched = xnsched_current();
@@ -323,7 +343,10 @@ static inline int xnsched_run(void)
* If running over the root thread, hard irqs must be off
* (asserted out of line in ___xnsched_run()).
*/
- return curr->lock_count > 0 ? 0 : __xnsched_run(sched);
+ if (curr->lock_count > 0 && !xnsched_throttled(sched))
+ return 0;
+
+ return __xnsched_run(sched);
}
void xnsched_lock(void);
diff --git a/kernel/cobalt/Kconfig b/kernel/cobalt/Kconfig
index 4b61b2f59..266643a0d 100644
--- a/kernel/cobalt/Kconfig
+++ b/kernel/cobalt/Kconfig
@@ -126,6 +126,32 @@ config XENO_OPT_SCHED_QUOTA_NR_GROUPS
The overall number of thread groups which may be defined
across all CPUs.
+config XENO_OPT_SCHED_THROTTLE
+ bool "Real-time throttling"
+ default n
+ help
+ Limit the CPU time Cobalt threads may consume on each CPU,
+ similar to the RT throttling of the Linux scheduler. Within
+ every period of xenomai.sched_rt_period_us microseconds,
+ Cobalt threads may run for at most
+ xenomai.sched_rt_runtime_us microseconds on a given CPU.
+ Once this budget is exhausted, Linux gets the CPU until the
+ period ends. Both parameters are boot-time only. Setting
+ xenomai.sched_rt_runtime_us to -1 disables throttling.
+
+ Windows are aligned to multiples of the period. Every Cobalt
+ thread counts against the budget, whatever its scheduling
+ class (including SCHED_WEAK threads running in primary
+ mode), and throttling overrides the scheduler lock. Threads
+ which wake up, switch to primary mode or need to relax while
+ the CPU is throttled wait until the window ends.
+
+ Throttling preempts real-time threads regardless of their
+ priority, so enabling it voids real-time guarantees whenever
+ the budget runs out. Use with care.
+
+ If in doubt, say N.
+
config XENO_OPT_STATS
bool "Runtime statistics"
depends on XENO_OPT_VFILE
diff --git a/kernel/cobalt/Makefile b/kernel/cobalt/Makefile
index 6cd2d5994..4bba9a742 100644
--- a/kernel/cobalt/Makefile
+++ b/kernel/cobalt/Makefile
@@ -21,6 +21,7 @@ xenomai-$(CONFIG_XENO_OPT_SCHED_QUOTA) += sched-quota.o
xenomai-$(CONFIG_XENO_OPT_SCHED_WEAK) += sched-weak.o
xenomai-$(CONFIG_XENO_OPT_SCHED_SPORADIC) += sched-sporadic.o
xenomai-$(CONFIG_XENO_OPT_SCHED_TP) += sched-tp.o
+xenomai-$(CONFIG_XENO_OPT_SCHED_THROTTLE) += sched-throttle.o
xenomai-$(CONFIG_XENO_OPT_DEBUG) += debug.o
xenomai-$(CONFIG_XENO_OPT_PIPE) += pipe.o
xenomai-$(CONFIG_XENO_OPT_MAP) += map.o
diff --git a/kernel/cobalt/sched-throttle.c b/kernel/cobalt/sched-throttle.c
new file mode 100644
index 000000000..a116caf95
--- /dev/null
+++ b/kernel/cobalt/sched-throttle.c
@@ -0,0 +1,266 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 Richard Weinberger
+ *
+ * RT throttling: limit the CPU time Cobalt may use on each CPU, like
+ * sched_rt_runtime_us/sched_rt_period_us do for Linux.
+ *
+ * Time is cut into windows of throttle_period ns, aligned to
+ * multiples of the period. Whenever a Cobalt thread runs instead of
+ * Linux (i.e. between leave_root() and enter_root()), that time is
+ * charged to the current window, whatever the scheduling class of
+ * the thread. Once throttle_runtime ns have been charged, the CPU is
+ * throttled: xnsched_pick_next() hands it to Linux until the window
+ * ends, overriding the scheduler lock.
+ *
+ * Two timers per CPU drive this, since Cobalt has no periodic tick:
+ * the budget timer runs while Cobalt has the CPU and fires when the
+ * budget is used up or the window ends; the window timer runs while
+ * the CPU is throttled and lifts the throttle at the end of the
+ * window.
+ */
+#include <linux/module.h>
+#include <linux/jump_label.h>
+#include <linux/math64.h>
+#include <cobalt/kernel/sched.h>
+#include <cobalt/kernel/timer.h>
+#include <cobalt/kernel/clock.h>
+#include <trace/events/cobalt-core.h>
+
+/* Boot-time settings, see xnsched_throttle_setup(). */
+static unsigned long period_us = 1000000;
+module_param_named(sched_rt_period_us, period_us, ulong, 0444);
+
+static long runtime_us = 950000;
+module_param_named(sched_rt_runtime_us, runtime_us, long, 0444);
+
+DEFINE_STATIC_KEY_FALSE(xnsched_throttle_enabled);
+
+static xnticks_t throttle_period __read_mostly; /* window length, ns */
+static xnticks_t throttle_runtime __read_mostly; /* budget per window, ns */
+
+void xnsched_throttle_setup(void)
+{
+ if (runtime_us < 0 || (unsigned long)runtime_us >= period_us) {
+ printk(XENO_INFO "RT throttling disabled\n");
+ return;
+ }
+
+ throttle_period = period_us * 1000ULL;
+ throttle_runtime = runtime_us * 1000ULL;
+ static_branch_enable(&xnsched_throttle_enabled);
+ printk(XENO_INFO "RT throttling: %ld us every %lu us\n",
+ runtime_us, period_us);
+}
+
+/* Move to the window containing @date, which must not precede it. */
+static void throttle_window_advance(struct xnsched_throttle *t,
+ xnticks_t date)
+{
+ t->window_start += div64_u64(date - t->window_start,
+ throttle_period) * throttle_period;
+ t->used = 0;
+}
+
+static bool throttle_window_over(struct xnsched_throttle *t, xnticks_t now)
+{
+ return (xnsticks_t)(now - t->window_start) >=
+ (xnsticks_t)throttle_period;
+}
+
+/* Charge the Cobalt time elapsed since t->charge_from. */
+static void throttle_charge(struct xnsched_throttle *t, xnticks_t now)
+{
+ if (throttle_window_over(t, now)) {
+ throttle_window_advance(t, now);
+ /* Only the time spent in the new window counts. */
+ if ((xnsticks_t)(t->charge_from - t->window_start) < 0)
+ t->charge_from = t->window_start;
+ }
+
+ t->used += now - t->charge_from;
+ t->charge_from = now;
+}
+
+/* Arm the budget timer for the budget left or the window end. */
+static void throttle_arm_budget_timer(struct xnsched_throttle *t,
+ xnticks_t now)
+{
+ xnticks_t left = 0, window_left;
+
+ if (t->used < throttle_runtime)
+ left = throttle_runtime - t->used;
+
+ window_left = t->window_start + throttle_period - now;
+ if ((xnsticks_t)window_left < 0)
+ window_left = 0;
+
+ xntimer_start(&t->budget_timer, min(left, window_left),
+ XN_INFINITE, XN_RELATIVE);
+}
+
+static void throttle_start(struct xnsched *sched, xnticks_t now)
+{
+ struct xnsched_throttle *t = &sched->throttle;
+ xnticks_t window_left;
+
+ sched->lflags |= XNTHROTTLED;
+ t->count++;
+
+ window_left = t->window_start + throttle_period - now;
+ if ((xnsticks_t)window_left < 0)
+ window_left = 0;
+
+ xntimer_start(&t->window_timer, window_left, XN_INFINITE, XN_RELATIVE);
+ xnsched_set_self_resched(sched);
+ trace_cobalt_sched_throttle(xnsched_cpu(sched), true);
+ printk_once(XENO_WARNING "RT throttling activated\n");
+}
+
+/* Budget timer handler: budget used up or window over. */
+static void throttle_budget_timeout(struct xntimer *timer)
+{
+ struct xnsched *sched = container_of(timer, struct xnsched,
+ throttle.budget_timer);
+ struct xnsched_throttle *t = &sched->throttle;
+ xnticks_t now = xnclock_read_monotonic(&nkclock);
+
+ /*
+ * enter_root() stops this timer under nklock, so curr should
+ * never be root here. If it ever were, charging would bill
+ * Linux time to Cobalt and throttle it for nothing.
+ */
+ if (xnthread_test_state(sched->curr, XNROOT)) {
+ XENO_WARN_ON_ONCE(COBALT, 1);
+ return;
+ }
+
+ throttle_charge(t, now);
+
+ if (t->used >= throttle_runtime)
+ throttle_start(sched, now);
+ else /* Window over with budget left, charge the next one. */
+ throttle_arm_budget_timer(t, now);
+}
+
+/* Window timer handler: lift the throttle. */
+static void throttle_window_timeout(struct xntimer *timer)
+{
+ struct xnsched *sched = container_of(timer, struct xnsched,
+ throttle.window_timer);
+ struct xnsched_throttle *t = &sched->throttle;
+
+ sched->lflags &= ~XNTHROTTLED;
+ trace_cobalt_sched_throttle(xnsched_cpu(sched), false);
+
+ /* Not from the clock: the timer may fire early (gravity). */
+ throttle_window_advance(t, t->window_start + throttle_period);
+
+ /*
+ * If the window ended before the throttled thread could be
+ * switched out, it is still running and leave_root() won't
+ * be called for it: charge it to the new window from here.
+ */
+ if (!xnthread_test_state(sched->curr, XNROOT))
+ throttle_arm_budget_timer(t, xnclock_read_monotonic(&nkclock));
+
+ xnsched_set_self_resched(sched);
+}
+
+void xnsched_throttle_init(struct xnsched *sched)
+{
+ struct xnsched_throttle *t = &sched->throttle;
+
+ /* The first leave_root() advances to the current window. */
+ t->window_start = 0;
+ t->used = 0;
+ t->count = 0;
+
+ xntimer_init(&t->budget_timer, &nkclock, throttle_budget_timeout,
+ sched, XNTIMER_IGRAVITY);
+ xntimer_set_name(&t->budget_timer, "[throttle-budget]");
+ xntimer_set_priority(&t->budget_timer, XNTIMER_LOPRIO);
+ xntimer_init(&t->window_timer, &nkclock, throttle_window_timeout,
+ sched, XNTIMER_IGRAVITY);
+ xntimer_set_name(&t->window_timer, "[throttle-window]");
+ xntimer_set_priority(&t->window_timer, XNTIMER_LOPRIO);
+}
+
+void xnsched_throttle_destroy(struct xnsched *sched)
+{
+ xntimer_destroy(&sched->throttle.budget_timer);
+ xntimer_destroy(&sched->throttle.window_timer);
+}
+
+/* nklock held, irqs off. */
+void __xnsched_throttle_leave_root(struct xnsched *sched)
+{
+ struct xnsched_throttle *t = &sched->throttle;
+ xnticks_t now = xnclock_read_monotonic(&nkclock);
+
+ if (throttle_window_over(t, now))
+ throttle_window_advance(t, now);
+
+ t->charge_from = now;
+ throttle_arm_budget_timer(t, now);
+}
+
+/* nklock held, irqs off. */
+void __xnsched_throttle_enter_root(struct xnsched *sched)
+{
+ struct xnsched_throttle *t = &sched->throttle;
+
+ xntimer_stop(&t->budget_timer);
+ throttle_charge(t, xnclock_read_monotonic(&nkclock));
+}
+
+#ifdef CONFIG_XENO_OPT_VFILE
+
+static int throttle_vfile_show(struct xnvfile_regular_iterator *it,
+ void *data)
+{
+ struct xnsched *sched;
+ unsigned long count;
+ bool throttled;
+ int cpu;
+ spl_t s;
+
+ xnvfile_printf(it, "%-3s %-9s %-10s %-10s %s\n",
+ "CPU", "THROTTLED", "PERIOD(us)", "BUDGET(us)", "COUNT");
+
+ for_each_realtime_cpu(cpu) {
+ sched = xnsched_struct(cpu);
+ xnlock_get_irqsave(&nklock, s);
+ throttled = sched->lflags & XNTHROTTLED;
+ count = sched->throttle.count;
+ xnlock_put_irqrestore(&nklock, s);
+
+ /* Both are zero if throttling is disabled. */
+ xnvfile_printf(it, "%3d %-9s %-10llu %-10llu %lu\n",
+ cpu, throttled ? "yes" : "no",
+ div_u64(throttle_period, 1000),
+ div_u64(throttle_runtime, 1000), count);
+ }
+
+ return 0;
+}
+
+static struct xnvfile_regular_ops throttle_vfile_ops = {
+ .show = throttle_vfile_show,
+};
+
+static struct xnvfile_regular throttle_vfile = {
+ .ops = &throttle_vfile_ops,
+};
+
+int xnsched_throttle_init_proc(struct xnvfile_directory *vfroot)
+{
+ return xnvfile_init_regular("throttle", &throttle_vfile, vfroot);
+}
+
+void xnsched_throttle_cleanup_proc(void)
+{
+ xnvfile_destroy_regular(&throttle_vfile);
+}
+
+#endif /* CONFIG_XENO_OPT_VFILE */
diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c
index ed99ddd0a..e0e01a222 100644
--- a/kernel/cobalt/sched.c
+++ b/kernel/cobalt/sched.c
@@ -149,6 +149,7 @@ static void watchdog_handler(struct xntimer *timer)
#endif /* CONFIG_XENO_OPT_WATCHDOG */
+
static void roundrobin_handler(struct xntimer *timer)
{
struct xnsched *sched = container_of(timer, struct xnsched, rrbtimer);
@@ -223,6 +224,7 @@ static void xnsched_init(struct xnsched *sched, int cpu)
xntimer_set_name(&sched->wdtimer, "[watchdog]");
xntimer_set_priority(&sched->wdtimer, XNTIMER_LOPRIO);
#endif /* CONFIG_XENO_OPT_WATCHDOG */
+ xnsched_throttle_init(sched);
}
void xnsched_init_all(void)
@@ -230,6 +232,8 @@ void xnsched_init_all(void)
struct xnsched *sched;
int cpu;
+ xnsched_throttle_setup();
+
for_each_online_cpu(cpu) {
sched = &per_cpu(nksched, cpu);
xnsched_init(sched, cpu);
@@ -247,6 +251,7 @@ static void xnsched_destroy(struct xnsched *sched)
#ifdef CONFIG_XENO_OPT_WATCHDOG
xntimer_destroy(&sched->wdtimer);
#endif /* CONFIG_XENO_OPT_WATCHDOG */
+ xnsched_throttle_destroy(sched);
}
void xnsched_destroy_all(void)
@@ -297,9 +302,9 @@ struct xnthread *xnsched_pick_next(struct xnsched *sched)
if (!xnthread_test_state(curr, XNTHREAD_BLOCK_BITS | XNZOMBIE)) {
/*
* Do not preempt the current thread if it holds the
- * scheduler lock.
+ * scheduler lock, unless the RT budget is exhausted.
*/
- if (curr->lock_count > 0) {
+ if (curr->lock_count > 0 && !xnsched_throttled(sched)) {
xnsched_set_self_resched(sched);
return curr;
}
@@ -314,6 +319,21 @@ struct xnthread *xnsched_pick_next(struct xnsched *sched)
}
}
+ /*
+ * Hand the CPU over to Linux until the RT window ends. This
+ * applies to every scheduling class and overrides the
+ * scheduler lock: the holder keeps its lock count and no
+ * other Cobalt thread can run until the window ends.
+ */
+ if (unlikely(xnsched_throttled(sched))) {
+ /* Per-thread budgets belong to the base class. */
+ if (curr->base_class->sched_throttle)
+ curr->base_class->sched_throttle(curr);
+ thread = &sched->rootcb;
+ set_thread_running(sched, thread);
+ return thread;
+ }
+
/*
* Find the runnable thread having the highest priority among
* all scheduling classes, scanned by decreasing priority.
@@ -876,6 +896,7 @@ static inline void enter_root(struct xnthread *root)
#ifdef CONFIG_XENO_OPT_WATCHDOG
xntimer_stop(&root->sched->wdtimer);
#endif
+ xnsched_throttle_enter_root(root->sched);
}
static inline void leave_root(struct xnthread *root)
@@ -886,6 +907,7 @@ static inline void leave_root(struct xnthread *root)
xntimer_start(&root->sched->wdtimer, get_watchdog_timeout(),
XN_INFINITE, XN_RELATIVE);
#endif
+ xnsched_throttle_leave_root(root->sched);
}
static inline void do_lazy_user_work(struct xnthread *curr)
@@ -1412,6 +1434,10 @@ int xnsched_init_proc(void)
xnvfile_init_regular("affinity", &affinity_vfile, &cobalt_vfroot);
#endif /* CONFIG_SMP */
+ ret = xnsched_throttle_init_proc(&sched_vfroot);
+ if (ret)
+ return ret;
+
return 0;
}
@@ -1424,6 +1450,7 @@ void xnsched_cleanup_proc(void)
p->sched_cleanup_vfile(p);
}
+ xnsched_throttle_cleanup_proc();
#ifdef CONFIG_SMP
xnvfile_destroy_regular(&affinity_vfile);
#endif /* CONFIG_SMP */
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/5] cobalt/sched-sporadic: stop budget accounting on RT throttling
2026-12-01 14:12 [RFC PATCH 0/5] RT throttling Richard Weinberger (sigma star gmbh)
2026-12-01 14:12 ` [PATCH 1/5] cobalt/trace: add cobalt_sched_throttle tracepoint Richard Weinberger (sigma star gmbh)
2026-12-01 14:12 ` [PATCH 2/5] cobalt/sched: add RT throttling Richard Weinberger (sigma star gmbh)
@ 2026-12-01 14:12 ` Richard Weinberger (sigma star gmbh)
2026-12-01 14:12 ` [PATCH 4/5] cobalt/sched-quota: charge the running group " Richard Weinberger (sigma star gmbh)
` (2 subsequent siblings)
5 siblings, 0 replies; 11+ messages in thread
From: Richard Weinberger (sigma star gmbh) @ 2026-12-01 14:12 UTC (permalink / raw)
To: xenomai; +Cc: upstream+xenomai, Richard Weinberger
From: Richard Weinberger <richard@nod.at>
When RT throttling switches a sporadic thread out, sched_pick() is
bypassed and sporadic_suspend_activity() is not called. The drop
timer keeps running while the CPU is throttled, charging the thread
for time it did not run and possibly demoting it to its low priority.
Implement the sched_throttle hook to suspend budget accounting.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
kernel/cobalt/sched-sporadic.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/kernel/cobalt/sched-sporadic.c b/kernel/cobalt/sched-sporadic.c
index bec8dcb53..78687bf92 100644
--- a/kernel/cobalt/sched-sporadic.c
+++ b/kernel/cobalt/sched-sporadic.c
@@ -395,6 +395,12 @@ swap:
return next;
}
+static void xnsched_sporadic_throttle(struct xnthread *curr)
+{
+ if (curr->pss)
+ sporadic_suspend_activity(curr);
+}
+
#ifdef CONFIG_XENO_OPT_VFILE
struct xnvfile_directory sched_sporadic_vfroot;
@@ -549,6 +555,7 @@ struct xnsched_class xnsched_class_sporadic = {
.sched_declare = xnsched_sporadic_declare,
.sched_forget = xnsched_sporadic_forget,
.sched_kick = NULL,
+ .sched_throttle = xnsched_sporadic_throttle,
#ifdef CONFIG_XENO_OPT_VFILE
.sched_init_vfile = xnsched_sporadic_init_vfile,
.sched_cleanup_vfile = xnsched_sporadic_cleanup_vfile,
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 4/5] cobalt/sched-quota: charge the running group on RT throttling
2026-12-01 14:12 [RFC PATCH 0/5] RT throttling Richard Weinberger (sigma star gmbh)
` (2 preceding siblings ...)
2026-12-01 14:12 ` [PATCH 3/5] cobalt/sched-sporadic: stop budget accounting on " Richard Weinberger (sigma star gmbh)
@ 2026-12-01 14:12 ` Richard Weinberger (sigma star gmbh)
2026-12-01 14:12 ` [PATCH 5/5] testsuite/smokey: add sched-throttle test Richard Weinberger (sigma star gmbh)
2026-12-01 15:29 ` [RFC PATCH 0/5] RT throttling Jan Kiszka
5 siblings, 0 replies; 11+ messages in thread
From: Richard Weinberger (sigma star gmbh) @ 2026-12-01 14:12 UTC (permalink / raw)
To: xenomai; +Cc: upstream+xenomai, Richard Weinberger
From: Richard Weinberger <richard@nod.at>
When RT throttling switches a quota thread out, xnsched_quota_pick()
is bypassed, so the time the thread ran since it was picked is never
charged to its group.
Implement the sched_throttle hook to charge the group and stop the
limit timer, factoring the charging out of xnsched_quota_pick().
Signed-off-by: Richard Weinberger <richard@nod.at>
---
kernel/cobalt/sched-quota.c | 39 +++++++++++++++++++++++++------------
1 file changed, 27 insertions(+), 12 deletions(-)
diff --git a/kernel/cobalt/sched-quota.c b/kernel/cobalt/sched-quota.c
index f821f54bd..16a50aca3 100644
--- a/kernel/cobalt/sched-quota.c
+++ b/kernel/cobalt/sched-quota.c
@@ -405,27 +405,32 @@ static void xnsched_quota_requeue(struct xnthread *thread)
tg->nr_active++;
}
+/*
+ * Charge the time consumed by the outgoing thread to the group it
+ * belongs to.
+ */
+static void quota_charge(struct xnsched_quota_group *tg, xnticks_t now)
+{
+ xnticks_t elapsed = now - tg->run_start_ns;
+
+ if (elapsed < tg->run_budget_ns)
+ tg->run_budget_ns -= elapsed;
+ else
+ tg->run_budget_ns = 0;
+}
+
static struct xnthread *xnsched_quota_pick(struct xnsched *sched)
{
struct xnthread *next, *curr = sched->curr;
struct xnsched_quota *qs = &sched->quota;
struct xnsched_quota_group *otg, *tg;
- xnticks_t now, elapsed;
+ xnticks_t now;
int ret;
now = xnclock_read_monotonic(&nkclock);
otg = curr->quota;
- if (otg == NULL)
- goto pick;
- /*
- * Charge the time consumed by the outgoing thread to the
- * group it belongs to.
- */
- elapsed = now - otg->run_start_ns;
- if (elapsed < otg->run_budget_ns)
- otg->run_budget_ns -= elapsed;
- else
- otg->run_budget_ns = 0;
+ if (otg)
+ quota_charge(otg, now);
pick:
next = xnsched_getq(&sched->rt.runnable);
if (next == NULL) {
@@ -690,6 +695,15 @@ EXPORT_SYMBOL_GPL(xnsched_quota_sum_all);
/** @} */
+static void xnsched_quota_throttle(struct xnthread *curr)
+{
+ if (curr->quota == NULL)
+ return;
+
+ quota_charge(curr->quota, xnclock_read_monotonic(&nkclock));
+ xntimer_stop(&curr->sched->quota.limit_timer);
+}
+
#ifdef CONFIG_XENO_OPT_VFILE
struct xnvfile_directory sched_quota_vfroot;
@@ -824,6 +838,7 @@ struct xnsched_class xnsched_class_quota = {
.sched_protectprio = xnsched_quota_protectprio,
.sched_forget = xnsched_quota_forget,
.sched_kick = xnsched_quota_kick,
+ .sched_throttle = xnsched_quota_throttle,
#ifdef CONFIG_XENO_OPT_VFILE
.sched_init_vfile = xnsched_quota_init_vfile,
.sched_cleanup_vfile = xnsched_quota_cleanup_vfile,
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 5/5] testsuite/smokey: add sched-throttle test
2026-12-01 14:12 [RFC PATCH 0/5] RT throttling Richard Weinberger (sigma star gmbh)
` (3 preceding siblings ...)
2026-12-01 14:12 ` [PATCH 4/5] cobalt/sched-quota: charge the running group " Richard Weinberger (sigma star gmbh)
@ 2026-12-01 14:12 ` Richard Weinberger (sigma star gmbh)
2026-12-01 15:29 ` [RFC PATCH 0/5] RT throttling Jan Kiszka
5 siblings, 0 replies; 11+ messages in thread
From: Richard Weinberger (sigma star gmbh) @ 2026-12-01 14:12 UTC (permalink / raw)
To: xenomai; +Cc: upstream+xenomai, Richard Weinberger
From: Richard Weinberger <richard@nod.at>
Spin a SCHED_FIFO thread on one CPU next to a regular Linux thread
pinned to the same CPU, once normally and once with the scheduler
locked. Check that the Linux thread makes progress and that the
throttle counter in /proc/xenomai/sched/throttle went up about once
per window.
The test is skipped if RT throttling is not enabled.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
configure.ac | 1 +
testsuite/smokey/Makefile.am | 2 +
testsuite/smokey/sched-throttle/Makefile.am | 8 +
.../smokey/sched-throttle/sched-throttle.c | 251 ++++++++++++++++++
4 files changed, 262 insertions(+)
create mode 100644 testsuite/smokey/sched-throttle/Makefile.am
create mode 100644 testsuite/smokey/sched-throttle/sched-throttle.c
diff --git a/configure.ac b/configure.ac
index d707fb11d..8aaae4589 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1073,6 +1073,7 @@ AC_CONFIG_FILES([ \
testsuite/smokey/arith/Makefile \
testsuite/smokey/dlopen/Makefile \
testsuite/smokey/sched-quota/Makefile \
+ testsuite/smokey/sched-throttle/Makefile \
testsuite/smokey/sched-tp/Makefile \
testsuite/smokey/setsched/Makefile \
testsuite/smokey/rtdm/Makefile \
diff --git a/testsuite/smokey/Makefile.am b/testsuite/smokey/Makefile.am
index c49a5d77f..ee6791fbb 100644
--- a/testsuite/smokey/Makefile.am
+++ b/testsuite/smokey/Makefile.am
@@ -33,6 +33,7 @@ COBALT_SUBDIRS = \
posix-select \
rtdm \
sched-quota \
+ sched-throttle \
sched-tp \
setsched \
sigdebug \
@@ -78,6 +79,7 @@ DIST_SUBDIRS = \
posix-select \
rtdm \
sched-quota \
+ sched-throttle \
sched-tp \
setsched \
sigdebug \
diff --git a/testsuite/smokey/sched-throttle/Makefile.am b/testsuite/smokey/sched-throttle/Makefile.am
new file mode 100644
index 000000000..2e7e03275
--- /dev/null
+++ b/testsuite/smokey/sched-throttle/Makefile.am
@@ -0,0 +1,8 @@
+
+noinst_LIBRARIES = libsched-throttle.a
+
+libsched_throttle_a_SOURCES = sched-throttle.c
+
+libsched_throttle_a_CPPFLAGS = \
+ @XENO_USER_CFLAGS@ \
+ -I$(top_srcdir)/include
diff --git a/testsuite/smokey/sched-throttle/sched-throttle.c b/testsuite/smokey/sched-throttle/sched-throttle.c
new file mode 100644
index 000000000..ec5afc4b2
--- /dev/null
+++ b/testsuite/smokey/sched-throttle/sched-throttle.c
@@ -0,0 +1,251 @@
+/*
+ * Real-time throttling test.
+ *
+ * Copyright (C) 2026 Richard Weinberger
+ *
+ * Released under the terms of GPLv2.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sched.h>
+#include <time.h>
+#include <pthread.h>
+#include <smokey/smokey.h>
+
+smokey_test_plugin(sched_throttle,
+ SMOKEY_ARGLIST(
+ SMOKEY_INT(cpu),
+ SMOKEY_INT(duration),
+ SMOKEY_BOOL(lock),
+ ),
+ "Check real-time throttling (CONFIG_XENO_OPT_SCHED_THROTTLE).\n"
+ "\tA SCHED_FIFO thread spins on one CPU for the given duration\n"
+ "\t(seconds, default 3), next to a regular Linux thread pinned to\n"
+ "\tthe same CPU. The test passes if the Linux thread makes progress\n"
+ "\twhile the real-time thread spins, and if the throttle counter of\n"
+ "\tthat CPU went up once per elapsed window. The test runs twice,\n"
+ "\tthe second time with the scheduler locked by the spinning\n"
+ "\tthread; lock=0 or lock=1 selects a single run."
+);
+
+#define PARAM_DIR "/sys/module/xenomai/parameters/"
+#define THROTTLE_VFILE "/proc/xenomai/sched/throttle"
+
+static volatile unsigned long linux_count;
+static volatile int linux_stop;
+static unsigned long linux_progress;
+static int spin_secs = 3;
+static int test_cpu;
+static int lock_sched;
+
+static int read_param(const char *name, long *val)
+{
+ FILE *fp;
+ int ret;
+
+ fp = fopen(name, "r");
+ if (fp == NULL)
+ return -errno;
+
+ ret = fscanf(fp, "%ld", val) == 1 ? 0 : -EINVAL;
+ fclose(fp);
+
+ return ret;
+}
+
+static int read_throttle_count(int cpu, unsigned long *count)
+{
+ unsigned long long period, budget;
+ char line[128], state[16];
+ unsigned long n;
+ int ret = -ENOENT;
+ FILE *fp;
+ int c;
+
+ fp = fopen(THROTTLE_VFILE, "r");
+ if (fp == NULL)
+ return -errno;
+
+ while (fgets(line, sizeof(line), fp)) {
+ if (sscanf(line, "%d %15s %llu %llu %lu",
+ &c, state, &period, &budget, &n) != 5)
+ continue; /* Header. */
+ if (c == cpu) {
+ *count = n;
+ ret = 0;
+ break;
+ }
+ }
+
+ fclose(fp);
+
+ return ret;
+}
+
+static void set_cpu(pthread_attr_t *attr, int cpu)
+{
+ cpu_set_t set;
+
+ CPU_ZERO(&set);
+ CPU_SET(cpu, &set);
+ pthread_attr_setaffinity_np(attr, sizeof(set), &set);
+}
+
+static void *linux_thread(void *arg)
+{
+ while (!linux_stop)
+ linux_count++;
+
+ return NULL;
+}
+
+static void *rt_thread(void *arg)
+{
+ struct timespec now, end;
+ unsigned long start;
+
+ if (lock_sched)
+ pthread_setmode_np(0, PTHREAD_LOCK_SCHED, NULL);
+
+ clock_gettime(CLOCK_MONOTONIC, &end);
+ end.tv_sec += spin_secs;
+ start = linux_count;
+
+ do
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ while (now.tv_sec < end.tv_sec ||
+ (now.tv_sec == end.tv_sec && now.tv_nsec < end.tv_nsec));
+
+ linux_progress = linux_count - start;
+
+ if (lock_sched)
+ pthread_setmode_np(PTHREAD_LOCK_SCHED, 0, NULL);
+
+ return NULL;
+}
+
+static int start_linux_thread(pthread_t *tid)
+{
+ pthread_attr_t attr;
+ int ret;
+
+ pthread_attr_init(&attr);
+ set_cpu(&attr, test_cpu);
+ ret = __STD(pthread_create(tid, &attr, linux_thread, NULL));
+ pthread_attr_destroy(&attr);
+
+ return -ret;
+}
+
+static int run_rt_thread(void)
+{
+ struct sched_param param = { .sched_priority = 1 };
+ pthread_attr_t attr;
+ pthread_t tid;
+ int ret;
+
+ pthread_attr_init(&attr);
+ pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
+ pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
+ pthread_attr_setschedparam(&attr, ¶m);
+ set_cpu(&attr, test_cpu);
+ ret = pthread_create(&tid, &attr, rt_thread, NULL);
+ pthread_attr_destroy(&attr);
+ if (ret)
+ return -ret;
+
+ return -pthread_join(tid, NULL);
+}
+
+static int run_spinner(int lock, long period_us)
+{
+ unsigned long before, after, expected;
+ pthread_t linux_tid;
+ int ret;
+
+ lock_sched = lock;
+ linux_stop = 0;
+ linux_progress = 0;
+
+ ret = read_throttle_count(test_cpu, &before);
+ if (ret)
+ return ret;
+
+ ret = start_linux_thread(&linux_tid);
+ if (ret)
+ return ret;
+
+ ret = run_rt_thread();
+
+ linux_stop = 1;
+ __STD(pthread_join(linux_tid, NULL));
+
+ if (ret)
+ return ret;
+
+ ret = read_throttle_count(test_cpu, &after);
+ if (ret)
+ return ret;
+
+ /* The first and last windows may be cut short. */
+ expected = spin_secs * 1000000UL / period_us;
+ if (expected > 2)
+ expected -= 2;
+ else
+ expected = 1;
+
+ smokey_trace("cpu %d%s: %lu throttles in %d s, linux progress %lu",
+ test_cpu, lock ? " (scheduler locked)" : "",
+ after - before, spin_secs, linux_progress);
+
+ if (!smokey_assert(linux_progress > 0))
+ return -EINVAL;
+
+ if (!smokey_assert(after - before >= expected))
+ return -EINVAL;
+
+ return 0;
+}
+
+static int run_sched_throttle(struct smokey_test *t,
+ int argc, char *const argv[])
+{
+ long period_us, runtime_us;
+ int ret;
+
+ smokey_parse_args(t, argc, argv);
+
+ if (SMOKEY_ARG_ISSET(sched_throttle, cpu))
+ test_cpu = SMOKEY_ARG_INT(sched_throttle, cpu);
+ if (SMOKEY_ARG_ISSET(sched_throttle, duration))
+ spin_secs = SMOKEY_ARG_INT(sched_throttle, duration);
+
+ if (read_param(PARAM_DIR "sched_rt_period_us", &period_us) ||
+ read_param(PARAM_DIR "sched_rt_runtime_us", &runtime_us)) {
+ smokey_note("sched_throttle: CONFIG_XENO_OPT_SCHED_THROTTLE disabled");
+ return -ENOSYS;
+ }
+
+ /*
+ * Without throttling, the spinning thread would lock up the
+ * CPU and trigger the watchdog.
+ */
+ if (runtime_us < 0 || runtime_us >= period_us) {
+ smokey_note("sched_throttle: throttling disabled at boot");
+ return -ENOSYS;
+ }
+
+ if (SMOKEY_ARG_ISSET(sched_throttle, lock))
+ return run_spinner(SMOKEY_ARG_BOOL(sched_throttle, lock),
+ period_us);
+
+ ret = run_spinner(0, period_us);
+ if (ret)
+ return ret;
+
+ return run_spinner(1, period_us);
+}
--
2.56.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [RFC PATCH 0/5] RT throttling
2026-12-01 14:12 [RFC PATCH 0/5] RT throttling Richard Weinberger (sigma star gmbh)
` (4 preceding siblings ...)
2026-12-01 14:12 ` [PATCH 5/5] testsuite/smokey: add sched-throttle test Richard Weinberger (sigma star gmbh)
@ 2026-12-01 15:29 ` Jan Kiszka
2026-12-01 15:32 ` Richard Weinberger
5 siblings, 1 reply; 11+ messages in thread
From: Jan Kiszka @ 2026-12-01 15:29 UTC (permalink / raw)
To: Richard Weinberger (sigma star gmbh), xenomai
Cc: upstream+xenomai, Richard Weinberger
On 01.12.26 15:12, Richard Weinberger (sigma star gmbh) wrote:
> From: Richard Weinberger <richard@nod.at>
>
> This patch series implements an RT throttle like Linux has.
> It allows limiting the total CPU time used by Cobalt threads,
> if the limit is reached, Linux gets the CPU.
>
> That way, misbehaving applications won't kill the system and
> will only get throttled instead of killed by the Xenomai runaway
> thread detection.
> The main reason I need this feature is because for a rather specific
> use case, I need to limit the total available CPU time for all
> userspace, so Xenomai plus Linux.
>
> I'm curious to read how much you'll hate this. ;-)
>
We unfortunately still have to fix the quota scheduler first. Then the
test case should operate over all scheduler types.
And the watchdog should be come a feature on top of the throttling: When
enabled, also signal the currently running thread. When not, just throttle.
Jan
--
Siemens AG, Foundational Technologies
Linux Expert Center
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC PATCH 0/5] RT throttling
2026-12-01 15:29 ` [RFC PATCH 0/5] RT throttling Jan Kiszka
@ 2026-12-01 15:32 ` Richard Weinberger
2026-12-01 15:36 ` Jan Kiszka
0 siblings, 1 reply; 11+ messages in thread
From: Richard Weinberger @ 2026-12-01 15:32 UTC (permalink / raw)
To: Richard Weinberger (sigma star gmbh), xenomai, upstream
Cc: upstream+xenomai, Richard Weinberger, Jan Kiszka
On Dienstag, 1. Dezember 2026 16:29 'Jan Kiszka' via upstream wrote:
> On 01.12.26 15:12, Richard Weinberger (sigma star gmbh) wrote:
> > From: Richard Weinberger <richard@nod.at>
> >
> > This patch series implements an RT throttle like Linux has.
> > It allows limiting the total CPU time used by Cobalt threads,
> > if the limit is reached, Linux gets the CPU.
> >
> > That way, misbehaving applications won't kill the system and
> > will only get throttled instead of killed by the Xenomai runaway
> > thread detection.
> > The main reason I need this feature is because for a rather specific
> > use case, I need to limit the total available CPU time for all
> > userspace, so Xenomai plus Linux.
> >
> > I'm curious to read how much you'll hate this. ;-)
> >
>
> We unfortunately still have to fix the quota scheduler first. Then the
> test case should operate over all scheduler types.
What is broken about the quota scheduler?
I have never used it TBH.
> And the watchdog should be come a feature on top of the throttling: When
> enabled, also signal the currently running thread. When not, just throttle.
Fair.
Thanks,
//richard
--
sigma star gmbh | Eduard-Bodem-Gasse 6, 6020 Innsbruck, AUT UID/VAT Nr:
ATU 66964118 | FN: 374287y
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC PATCH 0/5] RT throttling
2026-12-01 15:32 ` Richard Weinberger
@ 2026-12-01 15:36 ` Jan Kiszka
2026-12-01 15:38 ` Richard Weinberger
0 siblings, 1 reply; 11+ messages in thread
From: Jan Kiszka @ 2026-12-01 15:36 UTC (permalink / raw)
To: Richard Weinberger, Richard Weinberger (sigma star gmbh), xenomai,
upstream
Cc: upstream+xenomai, Richard Weinberger
On 01.12.26 16:32, Richard Weinberger wrote:
> On Dienstag, 1. Dezember 2026 16:29 'Jan Kiszka' via upstream wrote:
>> On 01.12.26 15:12, Richard Weinberger (sigma star gmbh) wrote:
>>> From: Richard Weinberger <richard@nod.at>
>>>
>>> This patch series implements an RT throttle like Linux has.
>>> It allows limiting the total CPU time used by Cobalt threads,
>>> if the limit is reached, Linux gets the CPU.
>>>
>>> That way, misbehaving applications won't kill the system and
>>> will only get throttled instead of killed by the Xenomai runaway
>>> thread detection.
>>> The main reason I need this feature is because for a rather specific
>>> use case, I need to limit the total available CPU time for all
>>> userspace, so Xenomai plus Linux.
>>>
>>> I'm curious to read how much you'll hate this. ;-)
>>>
>>
>> We unfortunately still have to fix the quota scheduler first. Then the
>> test case should operate over all scheduler types.
>
> What is broken about the quota scheduler?
> I have never used it TBH.
Everything. Still in my backlock to finalize the fix qualification.
You triggered that finding back then via the SIGSHADOW analysis. ;)
>
>> And the watchdog should be come a feature on top of the throttling: When
>> enabled, also signal the currently running thread. When not, just throttle.
>
> Fair.
>
> Thanks,
> //richard
>
Jan
--
Siemens AG, Foundational Technologies
Linux Expert Center
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC PATCH 0/5] RT throttling
2026-12-01 15:36 ` Jan Kiszka
@ 2026-12-01 15:38 ` Richard Weinberger
2026-12-01 15:40 ` Jan Kiszka
0 siblings, 1 reply; 11+ messages in thread
From: Richard Weinberger @ 2026-12-01 15:38 UTC (permalink / raw)
To: Richard Weinberger (sigma star gmbh), xenomai, upstream,
Jan Kiszka
Cc: upstream+xenomai, Richard Weinberger
On Dienstag, 1. Dezember 2026 16:36 Jan Kiszka wrote:
> >> We unfortunately still have to fix the quota scheduler first. Then the
> >> test case should operate over all scheduler types.
> >
> > What is broken about the quota scheduler?
> > I have never used it TBH.
>
> Everything. Still in my backlock to finalize the fix qualification.
>
> You triggered that finding back then via the SIGSHADOW analysis. ;)
When it's broken all over the place, it has likely no users, so let's drop it?
Thanks,
/richard
--
sigma star gmbh | Eduard-Bodem-Gasse 6, 6020 Innsbruck, AUT UID/VAT Nr:
ATU 66964118 | FN: 374287y
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC PATCH 0/5] RT throttling
2026-12-01 15:38 ` Richard Weinberger
@ 2026-12-01 15:40 ` Jan Kiszka
0 siblings, 0 replies; 11+ messages in thread
From: Jan Kiszka @ 2026-12-01 15:40 UTC (permalink / raw)
To: Richard Weinberger, Richard Weinberger (sigma star gmbh), xenomai,
upstream
Cc: upstream+xenomai, Richard Weinberger
On 01.12.26 16:38, Richard Weinberger wrote:
> On Dienstag, 1. Dezember 2026 16:36 Jan Kiszka wrote:
>>>> We unfortunately still have to fix the quota scheduler first. Then the
>>>> test case should operate over all scheduler types.
>>>
>>> What is broken about the quota scheduler?
>>> I have never used it TBH.
>>
>> Everything. Still in my backlock to finalize the fix qualification.
>>
>> You triggered that finding back then via the SIGSHADOW analysis. ;)
>
> When it's broken all over the place, it has likely no users, so let's drop it?
>
It's part of Xenomai 4 as well, probably fixed there, but we need to
qualify both anyway.
Jan
--
Siemens AG, Foundational Technologies
Linux Expert Center
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-12-01 15:40 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 14:12 [RFC PATCH 0/5] RT throttling Richard Weinberger (sigma star gmbh)
2026-12-01 14:12 ` [PATCH 1/5] cobalt/trace: add cobalt_sched_throttle tracepoint Richard Weinberger (sigma star gmbh)
2026-12-01 14:12 ` [PATCH 2/5] cobalt/sched: add RT throttling Richard Weinberger (sigma star gmbh)
2026-12-01 14:12 ` [PATCH 3/5] cobalt/sched-sporadic: stop budget accounting on " Richard Weinberger (sigma star gmbh)
2026-12-01 14:12 ` [PATCH 4/5] cobalt/sched-quota: charge the running group " Richard Weinberger (sigma star gmbh)
2026-12-01 14:12 ` [PATCH 5/5] testsuite/smokey: add sched-throttle test Richard Weinberger (sigma star gmbh)
2026-12-01 15:29 ` [RFC PATCH 0/5] RT throttling Jan Kiszka
2026-12-01 15:32 ` Richard Weinberger
2026-12-01 15:36 ` Jan Kiszka
2026-12-01 15:38 ` Richard Weinberger
2026-12-01 15:40 ` 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.