From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 76456377004 for ; Sun, 3 May 2026 16:51:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777827075; cv=none; b=tZh1deIsOHbDjF3H/Wf5UevfJh50C+FsogKUAMcOzHXrQ/4CFKP2eHPPm9FGvF6ZawgARVDEoOAAffH5TDS4DDwt0p33UTO0HrceZQHYg2/fT6qEfnIhN1qiHzUKoSUhxePtaMTRjlopmEfP81SC3XwfGXm/WalzfrpVeqYA9Uw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777827075; c=relaxed/simple; bh=cg0Bbj9AjsnGxOq+y64e/b7OOW2yTNEQkbhwRm29D18=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PLXIe0yOxP7TVqZpWmuTNPRd0euaem3ZBxoQbZfBPGyixaDbPmoUPj+gvwjXk+j80FXSgJt0tyC/+AwHnSPvCre/dz6Wbd4eXfLkmDSrT1giM9jnLpEPG5rYr+Bm8A9zR2wpzRARhg4fsqEd8Txqbnd99EJ+am1fRf3SG+nnXr0= 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=F8uc6kUE; arc=none smtp.client-ip=209.85.214.181 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="F8uc6kUE" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2b45cb89f7eso21915975ad.0 for ; Sun, 03 May 2026 09:51:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777827070; x=1778431870; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=54CfH1z6TNt780aoevT0/jV5wyQdFbwCsijFcJJLlPI=; b=F8uc6kUE4I6zWfN5IDXIex5D7Mpv+4viKNr/FUdgjEpJtG6ECX2Htn1wSq6dxFng42 lERQ3CqDvSR7kftoEHGNv5i6E6cW+3zoj5lLucwIGcur3DR9tvKf+7fDeuRmOswKtS7i dGeIr2BRUN7lVaL4AOjEQ4IZCRewz3T5a61Ji5clBsR/vFlduKYn9Whsn031jBn782xJ CXsJvcYOPP0pmcoRrLP+3Dj3LSc8RDKhoBYh4U9bPdfFvFcxzPYbzUYLSftiPj2XIGXm oOs5UFrj7rbgPlGCcVnKE9Ic5mXdwB3Bt4DvJZNhGPxlHHpQFlAqERf8LitN9o54OkZ3 s5uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777827070; x=1778431870; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=54CfH1z6TNt780aoevT0/jV5wyQdFbwCsijFcJJLlPI=; b=KktAGCvl/Glz8DUF4ye8zorokhqea0j51Oei3UawvCa943Af8BBjOovILa037sbRp/ m4048bph3tqY/DUZoNE92/U34WcK3YyuvowyYok6djyFYcTOk8Pmvoerdi68+pP6xrZa HsrwS4diQNYLilTbX41KDFO5+HgcSizTCGLrl958Mu1ZQpun0zWkEMzFRdVw1z+UB65l EyMxdS5qW4b8tlePT1mRUyUZFhexsf4XCfsTXv4M9enZ4gUISQ4Ofoeu59/JgKQn9mqg MDU6jrvqJT6hjcfZkojffpgGSBlYMNlex6222i562EC6IFuQE6lh6rmmBdC4d4F2wc45 FDoA== X-Gm-Message-State: AOJu0Yw8u+t7Ni4dBPoou3ITqyRB4DGGkQoNo9gnMDjHuj8osd1ptt0W aAiqTRh+9QjB+V6h8rxIBAJ0UlhUwrUOLnktylZCWwy/ya8sCAIcg6Oc X-Gm-Gg: AeBDiet2oi2dc9dua+/fsmHldLnieozeAOd+Hljq5KjGYWBQsy8g1qopUPP2O4w+NKy jW868qcmMtV8vM3bGyZOL+WjKkamqjzJmmyHH9++mRf4w8J336hwar0DO68RJauNnl9m0NqPhD2 kEl+tpTcSRaWroqg3VPeT0hKrwqCv6ltf7BsgODhCJmZVbdNh14DOD/qmdLeZcTncmpXCTux2Pi dVb5e+LTIoDXIQazCeYqeLoBYCaoUSbbulqqqwGQR2W5pIq0K6pWPYlcmPMk8rZ8MQ7rzNM6sP8 G+Bc1rpMlzLQGhW4MuPsBdgYhowmYvzVXQGC+3vrdHi6xeMaGrRaBKomFpq3b2ek1jxBycS4own ENXt3Nqn+Xdfbg3Xxt9WyREXq2ol0YsLEidMBFRfPwQoukntTEIAsdPw+RkBGbv7DLhreiwvTtf bQJH6jdvbJtjsQrFrXi+uXyL7nzTHiZieTBxUXaOo3EhUufgI= X-Received: by 2002:a05:6a20:4327:b0:3a0:b65a:5df0 with SMTP id adf61e73a8af0-3a7f1bc4159mr6507949637.29.1777827069644; Sun, 03 May 2026 09:51:09 -0700 (PDT) Received: from localhost.localdomain ([114.231.84.174]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83707fab756sm1494277b3a.44.2026.05.03.09.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 May 2026 09:51:09 -0700 (PDT) From: Vernon Yang To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, roman.gushchin@linux.dev, inwardvessel@gmail.com, shakeel.butt@linux.dev, ast@kernel.org, daniel@iogearbox.net, surenb@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, baohua@kernel.org, lance.yang@linux.dev, dev.jain@arm.com, Vernon Yang Subject: [PATCH 2/4] bpf: add bpf_cgroup_{flush_stats,stall} function Date: Mon, 4 May 2026 00:50:22 +0800 Message-ID: <20260503165024.1526680-3-vernon2gm@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260503165024.1526680-1-vernon2gm@gmail.com> References: <20260503165024.1526680-1-vernon2gm@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Vernon Yang Add bpf_cgroup_{flush_stats,stall} function to prepare for the subsequent mthp_ext ebpf program. no function changes. Signed-off-by: Vernon Yang --- kernel/bpf/helpers.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index 2bb60200c266..87f3072adce3 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "../../lib/kstrtox.h" @@ -2819,6 +2820,32 @@ __bpf_kfunc struct cgroup *bpf_cgroup_from_id(u64 cgid) return cgrp; } +/** + * bpf_cgroup_stall - acquire the total stall time of cgroup + * @cgrp: cgroup struct + * @states: psi states + * + * Return the total stall time. + */ +__bpf_kfunc unsigned long bpf_cgroup_stall(struct cgroup *cgrp, + enum psi_states states) +{ + struct psi_group *group = cgroup_psi(cgrp); + + return div_u64(group->total[PSI_AVGS][states], NSEC_PER_MSEC); +} + +/** + * bpf_cgroup_flush_stats - Flush cgroup's statistics + * @cgrp: cgroup struct + */ +__bpf_kfunc void bpf_cgroup_flush_stats(struct cgroup *cgrp) +{ + struct psi_group *group = cgroup_psi(cgrp); + + psi_group_flush_stats(group); +} + /** * bpf_task_under_cgroup - wrap task_under_cgroup_hierarchy() as a kfunc, test * task's membership of cgroup ancestry. @@ -4732,6 +4759,8 @@ BTF_ID_FLAGS(func, bpf_cgroup_acquire, KF_ACQUIRE | KF_RCU | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_cgroup_release, KF_RELEASE) BTF_ID_FLAGS(func, bpf_cgroup_ancestor, KF_ACQUIRE | KF_RCU | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_cgroup_from_id, KF_ACQUIRE | KF_RET_NULL) +BTF_ID_FLAGS(func, bpf_cgroup_stall) +BTF_ID_FLAGS(func, bpf_cgroup_flush_stats, KF_SLEEPABLE) BTF_ID_FLAGS(func, bpf_task_under_cgroup, KF_RCU) BTF_ID_FLAGS(func, bpf_task_get_cgroup1, KF_ACQUIRE | KF_RCU | KF_RET_NULL) #endif -- 2.53.0