From nobody Fri Oct 2 06:58:49 2026 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 12F8F3C2D for ; Tue, 4 Aug 2026 09:26:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785835565; cv=none; b=rMZoHQ+aZhpNqpbPpmXeKNZaERkiLzhWm0WjSrxI3zNT46WBzJOHUlu6hZDD4jst+WcBd63LU2KH3Q/CfKpnW1q92Ri3e60ux/7SPQ45G7C+YKdO7PjF+ukoj7QJwWv7C582OjDebmhwjZQG2zTJL4tXrhhpiSY7ykqGnbawtHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785835565; c=relaxed/simple; bh=x/k/NBA5zqb8og6NwgcDETZ4QaZjO6f9o4I88NmYKqc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s27V5Ju1YIiClqtrlh3MK4lgSFtPBGqsmUJvz/f9kDoqgFvLqrGMv2+MuIh0FvB/rXMzamfFBPA4xx3mzespb0wQWeayE8xGZOSXe5vyq1rl5fSB77oYaqevX6u2HpVI4w2AtWWYSS+oUBajZLotfRALgfnHFTaqQLMIrRg8Aj0= 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=mMzGqh8t; arc=none smtp.client-ip=209.85.216.49 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="mMzGqh8t" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-38deea72eebso4141178a91.1 for ; Tue, 04 Aug 2026 02:26:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785835563; x=1786440363; 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:content-type; bh=fdjv0QhU7h/hLtl6XoXu/SeLIR1/tpdbwAQiuWa3BAA=; b=mMzGqh8tuyZOP7JrcOlGwkTDqNkIzd39yP0KioAkGInz5I6xRGEymPkkQfKp5kXu7t BDfwJPMyTqMCTyXDzQJ6UY+oRr4xDyXqIo/n2k/KQ26Vn86tGgFXSG6lrEO+JfqRcJyQ zvjmctO/oJNr0vru+4JMYFJYKRPPm91XeOH9USpc7P+xQ/bIv4BweLHAk4k7DV3s03qx SP33mOJLOpGtBR0fpOpFYk2WNbQC6AnZK43nopzhc7sgvSdZDzfwblP2ZIrf0TGeWPl2 bjCXqNwgaimufrASXOupbRoXPd0Rwh6AmY7dPqK84Bm22vPibkKxx3WZqf46BsmTM/r2 J2bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785835563; x=1786440363; 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:content-type; bh=fdjv0QhU7h/hLtl6XoXu/SeLIR1/tpdbwAQiuWa3BAA=; b=G1u2MiP1UGgWf06lzGcZn0JqS0kWa2FXpNLA4cKmmYcK8VM5eqkm1ETefbjbTZhcYa H10CiZHVGeAYVz+YgMQqaJja0QiPfg0P/KoXU9kxXNIAqe0I2HwEI4cBkjjPjHBLeeBv KpFBIhOcqsdjJRaCfq8SDKpH9VM+zPLxBiEQGa+KTu24WO3srRoiczOEuojjKzu/Fk7u gpuCf3d2sp2ujiMU0uyTu/Nrvmm7XFd38ptFyyvl6vqaSepcVVfkDNubuM0ER3hIMnvH hRJRZsGw+oP7z3oDXN9SpWZ08tJ5VU+hYGGtGCb0fw1F6ZVNPOXTXf4OvBhSDrbfIcUU EOrg== X-Forwarded-Encrypted: i=1; AHgh+RrrA1PBnqNOW4gj6/Mq/SNK7AfnLMcTJdiFmkJfsAfiWiovUlpNirrtCodEb4MThWsIhrXe7Nyx7VkZwdE=@vger.kernel.org X-Gm-Message-State: AOJu0YzcMpzrF85JA7B9GWIW8kguLv2c7CI38KSfjIr7e3r+HtaZEwD4 uacZCGK/ulPTIdAAhjoQfsA2FE0ikB37Gk35n0jSJ+SzYgUTSVq5oPvs X-Gm-Gg: AR+sD13t7xk5caD8Ke57xI9tnwVqByU9DpHKfNc6qZzvu/fpz2R516/GTsB35CV618A OFCzFqjzOy3T/jABJF4sO1pnP8kf7QV4aWgJcBC5dMdoSYac+7vmNJBEw/6Cw3L3YUPCpuSlFSu OSZOwFzK09ISOOp0dXCQ40M1CDzdIO02SmhHDw+QJazVy1Z8c91wldpTzbqAW0AZjeu9/ARcK0U hNXnSnLbQMAiuHKiuf+Lr+/F+qixiKV3qTlvREvNHcEe6TKDIqAL8J19Pzcv1IUU4X+V/3HZujq yQCP0BNSZFCvbsYw+Rd3T6i1j0cMNQK0TgTRq1JTml4fPzwq4nrCFXOjp+zR7xyp8iWoIIqxmYk dsN9fW8G+3en4bd+UrUO2mFONFa0gZpOdJb0mn33eXeoY3g2nL/0X8JQIHjzrJCWxTBllSNIZgn yziCVytnc4IhtkuEKNqNXEMobCrCBPabrIQEoLzvKeX8j9EGNcsNYwJ9OwSBIFAshYsn6R7Xod9 +EULIBNKFsY X-Received: by 2002:a17:90b:510a:b0:38f:c925:d35c with SMTP id 98e67ed59e1d1-38fc925d3cdmr10115878a91.33.1785835563221; Tue, 04 Aug 2026 02:26:03 -0700 (PDT) Received: from osman.mioffice.cn ([43.224.245.178]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-38febfdae85sm1036329a91.3.2026.08.04.02.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Aug 2026 02:26:02 -0700 (PDT) From: Zhan Xusheng X-Google-Original-From: Zhan Xusheng To: peterz@infradead.org Cc: hannes@cmpxchg.org, mingo@redhat.com, surenb@google.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, linux-kernel@vger.kernel.org, zhanxusheng@xiaomi.com Subject: [PATCH v6] sched/psi: Skip CPUs with zero non-idle delta in per-CPU aggregation Date: Tue, 4 Aug 2026 17:25:54 +0800 Message-ID: <20260804092554.3854840-1-zhanxusheng@xiaomi.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260507135637.1245777-1-zhanxusheng@xiaomi.com> References: <20260507135637.1245777-1-zhanxusheng@xiaomi.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" collect_percpu_times() iterates over every possible CPU to build a non-idle-weighted average of the PSI state times. When a CPU has no PSI_NONIDLE delta for the current sampling interval: nonidle =3D nsecs_to_jiffies(times[PSI_NONIDLE]) =3D 0 deltas[s] +=3D times[s] * nonidle /* +=3D 0 */ so the weighted accumulation contributes nothing. get_recent_times() already sets the PSI_NONIDLE bit in cpu_changed_states iff the PSI_NONIDLE delta is non-zero. Use that bit to skip such CPUs early, as suggested by Johannes, avoiding the nsecs_to_jiffies() call and the PSI_NONIDLE * u64 mul-adds that follow. No functional change: on the skipped path the old code adds zero to deltas[] and zero to nonidle_total, which is exactly the result of not iterating. The PSI_NONIDLE bit is folded into changed_states before the skip, so the aggregator's reschedule decision is unaffected. The cost is worth trimming because collect_percpu_times() is O(nr_possible_cpus) per group and is not only called from the 2s averaging work: when a PSI trigger is armed, psi_rtpoll_work() calls it at the trigger cadence. On a 12-thread host with a "some 50000 500000" trigger armed, bpftrace measured collect_percpu_times() running ~160 times/s (vs ~0.5/s on the averaging path), and on a partially loaded box a large fraction of the per-CPU iterations per call had no PSI_NONIDLE delta and are skipped. read(/proc/pressure/cpu) median latency, QEMU/KVM A/B on mainline v7.1-rc2+ (identical config, the patch the only difference), idle guest, 100k iterations, varying -smp: -smp baseline patched delta 2 1834 ns 1799 ns -1.9% 4 1957 ns 1897 ns -3.1% 8 2204 ns 2103 ns -4.6% 12 2369 ns 2272 ns -4.1% 16 2596 ns 2363 ns -9.0% 24 3083 ns 2677 ns -13.2% 32 3740 ns 3050 ns -18.4% The saving scales with CPU count, toward the many-CPU systems that run pressure-monitoring agents. (The high -smp points use KVM oversubscription on a 12-thread host and carry scheduling noise; the trend is the signal. The all-busy case is within run-to-run noise.) Suggested-by: Johannes Weiner Signed-off-by: Zhan Xusheng --- Changes in v6: - Add the benchmark data requested on v4: the -smp scaling A/B table and the psi_rtpoll_work() call-frequency measurement. No code change vs v5. v5: reword changelog (consistency rationale; "No functional change") https://lore.kernel.org/all/20260507135637.1245777-1-zhanxusheng@xiaomi= .com/ v2: https://lore.kernel.org/all/20260512022308.4141509-1-zhanxusheng@xiaomi= .com/ kernel/sched/psi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index e2e825dcd088..e2805d32743c 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -386,6 +386,9 @@ static void collect_percpu_times(struct psi_group *grou= p, &cpu_changed_states); changed_states |=3D cpu_changed_states; =20 + if (!(cpu_changed_states & (1 << PSI_NONIDLE))) + continue; + nonidle =3D nsecs_to_jiffies(times[PSI_NONIDLE]); nonidle_total +=3D nonidle; =20 --=20 2.43.0