From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C9383DA5B2 for ; Thu, 13 Aug 2026 18:58:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786647531; cv=none; b=qeADdpuViXKqGx5gyodEzumG5skz+vbsk0qA7hV5Mww7VPCfLsKoiIEFwaKXnR/ufcWQPxcBmom7zUuACeR7VQjK2tTjQknkktLT6nuGxMHumiKKip67mpk7B1VOX3B2MlATUc7JsSTD+bADUJEqT89e6Nt6+MaxnTP4hyvi/2s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786647531; c=relaxed/simple; bh=ieT3j4ATm+VvwOP6ZEo+gWzrvv6Thjmvaatd82ACSEs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=he/jMpHHxVlG0ZYJQrOax/0ZBkPULLwtZR5DlsQgFdow4Tvr0c0nd0kPKwsK1QjGkyPUBGUGZINUZw17e1qTj462I4cq1VQG4Pkm5CmCfghLW1thn76qJj/nscXBqlDFGjWluAMc41k/nL9Jk2+9LJMoE49ZA0xwENLO/xu9+xQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pHabd6FV; arc=none smtp.client-ip=209.85.216.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pHabd6FV" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-384930ca5e2so198336a91.3 for ; Thu, 13 Aug 2026 11:58:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786647529; x=1787252329; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=DNrC+JRTptWjKfS940kfYbykFXy92wCoTM6c2X2KQos=; b=pHabd6FVq2kM0yDo4CRUVorADTmvSqg5lj/4DjK+t4U/plVyYl7ek1uXqLmdEupZwV 01RsgIsv9gfd9sLvpr8c1iKzJIjrL1yuVkP6DmsVv4YxGCtINv4hDYTgZB3aycZSbcnY NgEXCzcCMa91DeVOAAnGusdhRLPSV9joXjVRg8vHRMtdBHuedHHcoViT6uzU2K4i/lKR dDRjWOn0mzTP7ph8bCKyJt/V29ihKqURYZrf5wXxXODGB0huyUowwxeeMNBaIhQywcIe aN25LOiANQRCUEO/NEuyEe4Mm91KM/y34L4NJbw0gRzqkl7ZlGm1l6zP5Yib4Gqo9wbF J4Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786647529; x=1787252329; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=DNrC+JRTptWjKfS940kfYbykFXy92wCoTM6c2X2KQos=; b=e/aakYnmb18W1yTN6CvbZiCZm9HtzDsb1UnKbo4c0zqdNa9jB+KtCFcq6i4wokJpp3 pCZ3RFrvmB8yNoo9rky2H4AIpLu37MXePQNfIfG8EQPhULIU4us1yLWe8g8jPFVZwZZ9 1uzwGc1wpMKScEHo9p4+iI4k5S13ma6k3JhWY52uU4Gxf/D8xR4NoKMu8eiYyoZvAAjV RgXwrSdZWrTGJDDuGKjggpYk37fIJOL9DBeczB8OguqrOsxfnWs0uWzulthdpDnQ9uLp F6HoF66AhjL3CWluEqp3pnkIlwyEaQ3pgbX4n46G72NEqt1VdlJHSniGA9RrBu2WjoKh Oc/g== X-Forwarded-Encrypted: i=1; AHgh+Rr4cpqDDbh/kJ9Qv0zTvNQpBPvR/+IBe+g/LSol60ubvmhn0ovSTX7ZCLYYZkcYP9ivnqEckyWw4pCNpIY=@vger.kernel.org X-Gm-Message-State: AOJu0Yxyfa/ai82RpRao5LPZWH5At3RsDWME5/IPN2sPf7B+o55P5sgo xtwEkmhhfANJrCI/NiY4TpWTVamqbMWsxddAGirV2U5lYVCAp8BYFtMJ X-Gm-Gg: AR+sD10BCZBvT5KCgzq3ZS2Yx4MlSpXuOF6XIPt1PaJ9T5ZWVZMprreAuzqs/J8me1a Pb2eButC+8DSjuEzwK3boNc6/ipvwFKWsnUmSCiUblswudRTljcLujxtMOqUXO5ntxVDGMkEgCH gqa6txdro4uK00p3m9UkUjS3wtU0+kqEqAXUSyoH0QFRyTb0qCnSLLWRv162cazQVZGD4BNL8h5 vKUR5ymq6Y+0zLgz32vq2twp3K6LPtGW8D5c6oSNkwG76ForCPfeZ5jBtaW25WMg62a/ZB0YZ3W R0Y7p84y+FEsxJQ3TONa9x0jOBTncRJHJcq0Y0oV8393aFMile+H50MIZ0OE1pOtO/uNqDjxL4L aiozoyxZx2oyMs+glAe8bwd6uetEUTHfmo2/Hsgm+JDTaSGhnVO7ydp89T7aEArrmchw+ANOZI0 U7Tnrk/TCG7Muvp/7JgQjG6NRvlq47OO//hcMwGrQXtcMKIVzSI9JMTh+f5Y9xETwyJMY= X-Received: by 2002:a17:90b:5447:b0:38e:2860:253f with SMTP id 98e67ed59e1d1-3933e5c8557mr24629a91.12.1786647529381; Thu, 13 Aug 2026 11:58:49 -0700 (PDT) Received: from localhost ([2a03:2880:9ff:6f::]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-141387ac9b1sm943437c88.2.2026.08.13.11.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2026 11:58:48 -0700 (PDT) From: Ziyang Men To: Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Ingo Molnar , Peter Zijlstra , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi Cc: Ben Segall , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Mel Gorman , Valentin Schneider , K Prateek Nayak , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Shuah Khan , Roman Gushchin , Shakeel Butt , JP Kobryn , Mykola Lysenko , Ziyang Men , kernel-team@meta.com, bpf@vger.kernel.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 0/2] cgroup, sched: add bpf for cgroup cpu controller Date: Thu, 13 Aug 2026 11:58:44 -0700 Message-ID: <20260813185846.1216892-1-ziyang.meme@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit As the title suggests, this series adds bpf kfuncs for the cgroup CPU controller. Motivation: Collecting cgroup statistics is expensive: the existing method is to open and parse a cgroup file. memcg already has an efficient alternative through BPF; this series extends that idea to cpu. Design: - Leave reading the CFS bandwidth counters to the BPF program. They are plain fields of tg->cfs_bandwidth, so they need no kernel code. - Add one kfunc to compute the throttled time. This is necessary because it is a sum over every possible cpu, which a user cannot do itself. The only part it touches the scheduler part is to discard the static for throttled_time_self() in order to use externally. Patch 1 adds the kfuncs (kernel/cgroup/bpf_cpu.c); patch 2 adds a test_progs selftest. Tested on VM with v7.2-rc5. Ziyang Men (2): cgroup, sched: add BPF kfuncs to read a cpu cgroup's stats selftests/bpf: add cgroup_iter_cpu test for cpu cgroup kfuncs include/linux/cgroup.h | 15 + kernel/cgroup/Makefile | 2 + kernel/cgroup/bpf_cpu.c | 80 ++++++ kernel/cgroup/cgroup-internal.h | 3 + kernel/cgroup/rstat.c | 42 +++ kernel/sched/core.c | 2 +- tools/testing/selftests/bpf/cgroup_iter_cpu.h | 22 ++ tools/testing/selftests/bpf/config | 3 + .../bpf/prog_tests/cgroup_iter_cpu.c | 259 ++++++++++++++++++ .../selftests/bpf/progs/cgroup_iter_cpu.c | 53 ++++ 10 files changed, 480 insertions(+), 1 deletion(-) create mode 100644 kernel/cgroup/bpf_cpu.c create mode 100644 tools/testing/selftests/bpf/cgroup_iter_cpu.h create mode 100644 tools/testing/selftests/bpf/prog_tests/cgroup_iter_cpu.c create mode 100644 tools/testing/selftests/bpf/progs/cgroup_iter_cpu.c -- 2.53.0-Meta