Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796134343; b=nmvb2/ARONuQuynxTdf//aPHwG4PGa2V4+VCOo5x/pw7R9aP4/S6MUbJpVO5xWycMkS8 PBOAG5BcuLQ3e5nXgZlUSW+0v+7RrQLDFb3e6yNaELtYIppm4LwME6rWJcIuEI+VenF+f 9GhdadUyqFMi8MIUdJB+SpnNHBJ5Ady4ZIfPFFwT2faTFHxa8liykqXWLg/T5pimm8npg YjbmReJ32P0UnTWWysapViD8omZytNAl4q6hJPV/35LdtUXD3HJpmQqkHdwoAUWA3RC/a iiR/xhFmYJi+tyUPtJHABQDK7LtUA+Yz8AwPJrzKJhAInafSgPiVdw/7SGnXvb5802Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796134343; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=b9SztUJGGS8UjtkW2slaylxDYu8VuYmWzL/QQ4l6YiA=; b=y7sEPLL0If+Fz7Ip9EG44EpXAGky96Y3aVc+AxaSj27Rv30HzN3pW+PuC6TfodHJgwub YIItsI8jqgo27JXHJCtcWJD8d42PZVlzscZlJqv/2kSZ0xf2eGsM67IRETfg8P1TSMk1F g/mMXpwjA6FxuU+x8AzEty1z9aggeTSwDghvpFH2TgaXRIcbe/S8+zGhGw5CIU98gP9g4 emy8lYlDEUAag2p4+WCByHC/O04vRltYnI46Mg4goGEqlgme+vYFCQFoLLcmDIyHVIPoA 1iR6/6yZN3z+87DJ6G4uG6sBc9m4E5w+toO2PxB3Qjr8SBQElhIa1yyya9nh9ePMyVg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Vy9DVs0v; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C0B7606A31A for ; Tue, 1 Dec 2026 14:12:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Vy9DVs0v Received: by smtp.kernel.org (Postfix) with ESMTPSA id 874161F00893; Tue, 1 Dec 2026 14:12:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796134342; bh=b9SztUJGGS8UjtkW2slaylxDYu8VuYmWzL/QQ4l6YiA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Vy9DVs0vpKzNsLDCCBw9b7siipK5j0KFx5smuPua6mnkAO5ff099omb5sa1LSjk/c u3SdbDl7MV6No2vW0duhRKSwbJxnfSMj+ClX+XGtYVtC97/c/MtBjf4K++s8hQv1zz xgYIU4bw2VA6Si4YeM3pTyEchpTZ5Ta6QEhAcXsZqFBsjUNjegjjlLwQHEk/bvWMFh IVJW8F8RlwkHffBTXGFzbgiR6c5IGH8Sec8ZSak+kXTV92w5GvQdQF5ApsT628Atvk 93kC/1DpTCx5D0zlep05pdfmPvj18wsA9KmGM4soNndIUnIuN8AlFqniKIukKgAmJn jQXOogUDePHRw== From: "Richard Weinberger (sigma star gmbh)" To: xenomai@lists.linux.dev Cc: upstream+xenomai@sigma-star.at, Richard Weinberger Subject: [PATCH 4/5] cobalt/sched-quota: charge the running group on RT throttling Date: Tue, 1 Dec 2026 15:12:06 +0100 Message-ID: <20261201141207.2876277-5-rw@kernel.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261201141207.2876277-1-rw@kernel.org> References: <20261201141207.2876277-1-rw@kernel.org> X-Mailing-List: xenomai@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Richard Weinberger 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 --- 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