mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched/ext: add scx_bpf_cgroup_report_throttled kfunc
@ 2026-05-25 19:24 Fernand Sieber
  2026-05-27 19:24 ` Tejun Heo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Fernand Sieber @ 2026-05-25 19:24 UTC (permalink / raw)
  To: Tejun Heo, David Vernet
  Cc: Andrea Righi, Changwoo Min, Ingo Molnar, Peter Zijlstra,
	Vincent Guittot, linux-kernel, nh-open-source, Fahad Mubeen,
	Hendrik Borghorst, David Woodhouse, Fernand Sieber

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


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

end of thread, other threads:[~2026-05-30  0:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-25 19:24 [PATCH] sched/ext: add scx_bpf_cgroup_report_throttled kfunc Fernand Sieber
2026-05-27 19:24 ` Tejun Heo
2026-05-28 10:43 ` kernel test robot
2026-05-30  0:29 ` kernel test robot

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