From nobody Mon Jun 8 22:51:08 2026 Received: from pdx-out-011.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-011.esa.us-west-2.outbound.mail-perimeter.amazon.com [52.35.192.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 093E737AA6C for ; Mon, 25 May 2026 19:24:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.35.192.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779737088; cv=none; b=mjmBO4dZw2HG7GdYbdHSNW0gbK0EmAF6YgN8kv02S49dM5R6G54q5lDUKOLwWCYoMLKBehEFfWBiRSzXG8SNHqb9XRF5B4GzGOOj83m4eF+WyRzrU22hnxqwgbZ2eUQ/XZFW0joBU9aI2YpaX3ZpzTrJMVWFPc0cNs+E3+zo0FE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779737088; c=relaxed/simple; bh=azTXCwH49xBRtWwgaZ9G7djYnXn1pVkwd7qxKw6Db+E=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=u0ORQh0/PaMj7e0OgSf+3hABQ/8B3kq1CnS1LBjotgknK2ixB/z0CumFGJk7N7+8M7NIXuFzpN5OATW8EkSuhlrfzDH2K4U2fRA9JCMmREjok9HwWFKkbfI59a01iWmBfH/vYrvzQ8jbvihEfZFwSyURsO5S0yaIyll5e6HnW/A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=ZvbH4Yf2; arc=none smtp.client-ip=52.35.192.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="ZvbH4Yf2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1779737087; x=1811273087; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=2QDJ0Ci5tnUXgZpQao+x+lHnMzcmlGVwD9lwuM1+hIo=; b=ZvbH4Yf2i01gpjlN9+SshPI6zwQRNkH3LTkvNOatJA5RVip/YFa9eipS 6j48SdQh5Cwbfm1hd4bCKue/3vcEiqvrbfMNLMU35eoDmcMQIurMZ0dKa 60QeMHB/vcUNYJzS0yGpUy6lb+G4jZga6heHb8/k8WDQZCDIKKbpgQuLG L5dzscWGzVsIlOv2uP+ei7Fbw2syRKlRMmGFe5r+orWYIwFGPg+0+rr5P r0vdtKaVyWgeLgTVtPZw2D2dS5+8cQN7LpSasmeM+DP+KtQat1OhiqaOC 3i5X1aqL8EmFeG6b63tKayA36xGAWnafygEiVpkLht8CwzqrYzMX1fPlK w==; X-CSE-ConnectionGUID: zFNsxvV3QCaajcJssn4bXw== X-CSE-MsgGUID: M8D7rdUsQdCQoACYiL5AGQ== X-IronPort-AV: E=Sophos;i="6.24,168,1774310400"; d="scan'208";a="20208892" Received: from ip-10-5-9-48.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.9.48]) by internal-pdx-out-011.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2026 19:24:46 +0000 Received: from EX19MTAUWA001.ant.amazon.com [205.251.233.182:11789] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.1.25:2525] with esmtp (Farcaster) id 3cbd0f0a-b575-4bd6-9433-a1a8a35eed0b; Mon, 25 May 2026 19:24:46 +0000 (UTC) X-Farcaster-Flow-ID: 3cbd0f0a-b575-4bd6-9433-a1a8a35eed0b Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWA001.ant.amazon.com (10.250.64.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.37; Mon, 25 May 2026 19:24:45 +0000 Received: from dev-dsk-sieberf-metal-1a-7543e84d.eu-west-1.amazon.com (172.19.116.227) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.37; Mon, 25 May 2026 19:24:43 +0000 From: Fernand Sieber To: Tejun Heo , David Vernet CC: Andrea Righi , Changwoo Min , Ingo Molnar , Peter Zijlstra , Vincent Guittot , , , Fahad Mubeen , Hendrik Borghorst , "David Woodhouse" , Fernand Sieber Subject: [PATCH] sched/ext: add scx_bpf_cgroup_report_throttled kfunc Date: Mon, 25 May 2026 21:24:32 +0200 Message-ID: <20260525192432.20487-1-sieberf@amazon.com> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D042UWA002.ant.amazon.com (10.13.139.17) To EX19D001UWA001.ant.amazon.com (10.13.138.214) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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(struc= t task_struct *p, } #endif /* CONFIG_CGROUP_SCHED */ =20 +/** + * 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 =3D cgrp->subsys[cpu_cgrp_id] ? + container_of(cgrp->subsys[cpu_cgrp_id], struct task_group, css) : + NULL; + if (tg) { + struct cfs_bandwidth *cfs_b =3D &tg->cfs_bandwidth; + + raw_spin_lock_irq(&cfs_b->lock); + cfs_b->throttled_time +=3D 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(); =20 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_ACQ= UIRE) #endif +BTF_ID_FLAGS(func, scx_bpf_cgroup_report_throttled, KF_TRUSTED_ARGS) BTF_KFUNCS_END(scx_kfunc_ids_any) =20 static const struct btf_kfunc_id_set scx_kfunc_set_any =3D { --=20 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