mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Fernand Sieber <sieberf@amazon.com>
To: Tejun Heo <tj@kernel.org>, David Vernet <void@manifault.com>
Cc: Andrea Righi <arighi@nvidia.com>,
	Changwoo Min <changwoo@igalia.com>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	<linux-kernel@vger.kernel.org>, <nh-open-source@amazon.com>,
	Fahad Mubeen <fmubeen@amazon.de>,
	Hendrik Borghorst <hborghor@amazon.de>,
	"David Woodhouse" <dwmw@amazon.co.uk>,
	Fernand Sieber <sieberf@amazon.com>
Subject: [PATCH] sched/ext: add scx_bpf_cgroup_report_throttled kfunc
Date: Mon, 25 May 2026 21:24:32 +0200	[thread overview]
Message-ID: <20260525192432.20487-1-sieberf@amazon.com> (raw)

Add a BPF kfunc that allows SCX schedulers to report throttled time
back to the kernel's cfs_bandwidth accounting. This makes cpu.stat's
throttled_usec reflect SCX-enforced throttling, not just CFS throttling.

Without this, tools reading cpu.stat see zero throttled time when
bandwidth control is handled entirely in BPF by the SCX scheduler.

Signed-off-by: Fernand Sieber <sieberf@amazon.com>
---
 kernel/sched/ext.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 65631e577..7ebdaf75d 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -9760,6 +9760,38 @@ __bpf_kfunc struct cgroup *scx_bpf_task_cgroup(struct task_struct *p,
 }
 #endif	/* CONFIG_CGROUP_SCHED */
 
+/**
+ * scx_bpf_cgroup_report_throttled - Report throttled time for a cgroup
+ * @cgrp: target cgroup
+ * @throttled_ns: amount of throttled time in nanoseconds to add
+ *
+ * BPF schedulers implementing bandwidth control should call this to update
+ * the kernel's throttled_usec accounting in cpu.stat. Without this, tools
+ * reading cpu.stat will see zero throttled time under SCX scheduling.
+ */
+__bpf_kfunc void scx_bpf_cgroup_report_throttled(struct cgroup *cgrp,
+						  u64 throttled_ns)
+{
+#ifdef CONFIG_CFS_BANDWIDTH
+	struct task_group *tg;
+
+	rcu_read_lock();
+	tg = cgrp->subsys[cpu_cgrp_id] ?
+	     container_of(cgrp->subsys[cpu_cgrp_id], struct task_group, css) :
+	     NULL;
+	if (tg) {
+		struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
+
+		raw_spin_lock_irq(&cfs_b->lock);
+		cfs_b->throttled_time += throttled_ns;
+		cfs_b->nr_throttled++;
+		cfs_b->nr_periods++;
+		raw_spin_unlock_irq(&cfs_b->lock);
+	}
+	rcu_read_unlock();
+#endif
+}
+
 __bpf_kfunc_end_defs();
 
 BTF_KFUNCS_START(scx_kfunc_ids_any)
@@ -9795,6 +9827,7 @@ BTF_ID_FLAGS(func, scx_bpf_events)
 #ifdef CONFIG_CGROUP_SCHED
 BTF_ID_FLAGS(func, scx_bpf_task_cgroup, KF_IMPLICIT_ARGS | KF_RCU | KF_ACQUIRE)
 #endif
+BTF_ID_FLAGS(func, scx_bpf_cgroup_report_throttled, KF_TRUSTED_ARGS)
 BTF_KFUNCS_END(scx_kfunc_ids_any)
 
 static const struct btf_kfunc_id_set scx_kfunc_set_any = {
-- 
2.47.3




Amazon Development Centre (South Africa) (Proprietary) Limited
29 Gogosoa Street, Observatory, Cape Town, Western Cape, 7925, South Africa
Registration Number: 2004 / 034463 / 07


             reply	other threads:[~2026-05-25 19:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-25 19:24 Fernand Sieber [this message]
2026-05-27 19:24 ` Tejun Heo
2026-05-28 10:43 ` kernel test robot
2026-05-30  0:29 ` kernel test robot

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=20260525192432.20487-1-sieberf@amazon.com \
    --to=sieberf@amazon.com \
    --cc=arighi@nvidia.com \
    --cc=changwoo@igalia.com \
    --cc=dwmw@amazon.co.uk \
    --cc=fmubeen@amazon.de \
    --cc=hborghor@amazon.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nh-open-source@amazon.com \
    --cc=peterz@infradead.org \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=void@manifault.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome