All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Richard Weinberger (sigma star gmbh)" <rw@kernel.org>
To: xenomai@lists.linux.dev
Cc: upstream+xenomai@sigma-star.at, Richard Weinberger <richard@nod.at>
Subject: [PATCH 4/5] cobalt/sched-quota: charge the running group on RT throttling
Date: Tue,  1 Dec 2026 15:12:06 +0100	[thread overview]
Message-ID: <20261201141207.2876277-5-rw@kernel.org> (raw)
In-Reply-To: <20261201141207.2876277-1-rw@kernel.org>

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


  parent reply	other threads:[~2026-12-01 14:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Richard Weinberger (sigma star gmbh) [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201141207.2876277-5-rw@kernel.org \
    --to=rw@kernel.org \
    --cc=richard@nod.at \
    --cc=upstream+xenomai@sigma-star.at \
    --cc=xenomai@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.