From nobody Tue Dec 2 01:30:19 2025 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) (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 BBE4B2E9EBF for ; Fri, 21 Nov 2025 08:12:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763712772; cv=none; b=UnuVuLgv0mZ39e3gIqrA0KcrFRjxMqVL6R3I2BW0cmP7fJfI4cAK6eVfuv0NsBpWa5MPgguv8gx9+BzeUBXcydApJwVULTKftScr7G6U2nJkhBi309nvFGbDQOUdzeKUamh0MUcCHlihMGuGDRL635XB0tdYp626vC5VaJEPx5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763712772; c=relaxed/simple; bh=D4waafJBb8GB2KQ6vTZQVqxhUUzsp+qQ0C+MVheX+EM=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=OqulJ6nuErwcFkPqOc89JTKtGo68OnV8X7rqtm7uocb7qteY6WKFycHRA4Cy4wg9iLMr+sldxTIfYEtsxyctVlwVZdzVuSNTzXMUewu6J1u14GSKIPRm0p6N1ifLEJxwkdwM3Q1I9hDAFEV72cNPnXXNJSKHuYvHXzonMh5vAts= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; dkim=pass (2048-bit key) header.d=unisoc.com header.i=@unisoc.com header.b=yTXovwUu; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=unisoc.com header.i=@unisoc.com header.b="yTXovwUu" Received: from SHSQR01.spreadtrum.com (localhost [127.0.0.2] (may be forged)) by SHSQR01.spreadtrum.com with ESMTP id 5AL7XEvl093005 for ; Fri, 21 Nov 2025 15:33:14 +0800 (+08) (envelope-from Xuewen.Yan@unisoc.com) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 5AL7Wpeu089642; Fri, 21 Nov 2025 15:32:51 +0800 (+08) (envelope-from Xuewen.Yan@unisoc.com) Received: from SHDLP.spreadtrum.com (BJMBX01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4dCRfw3DHLz2K4jL9; Fri, 21 Nov 2025 15:29:12 +0800 (CST) Received: from BJ10918NBW01.spreadtrum.com (10.0.73.73) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 21 Nov 2025 15:32:48 +0800 From: Xuewen Yan To: , , , , , , CC: , , , , , , , , , , Subject: [RESEND PATCH V4] sched: psi: Add psi events trace point Date: Fri, 21 Nov 2025 15:32:44 +0800 Message-ID: <20251121073244.9091-1-xuewen.yan@unisoc.com> X-Mailer: git-send-email 2.25.1 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 X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 5AL7Wpeu089642 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unisoc.com; s=default; t=1763710386; bh=fejQzIuat6T8lIDshKqujybLYTGkkxBVeMkR1lJfnYo=; h=From:To:CC:Subject:Date; b=yTXovwUuGL5CFIRU0JYzo/LJr4pC3pGqIClxFvigQAfrhLvyPVxhygrD6c1LOke3v QywbomAy32eO0Z1ZkxgJzRfG6yRe0/zQcgyeMeOqtPZ79tbkirZiM4yMwChfTopUYR BlCiUwBHJnFQKZzidLtckvghZGomLUjXpVxx/8F6NCgHTS1uF8Nh2jX7dGKz/G04L/ KX3viyS6CYqMReh+dWU0qXzdecTDFsNaztT+imgdwkeXUi4shej7ofJb3ULQasN2Ry JuGox0qRUbiUHNxRrPQspZ9qZa3Wx9sdkVQTkBiM+30hkXuHLulawKDibuxhpCpZuy aUNwRxs+6TRog== Content-Type: text/plain; charset="utf-8" Add trace point to psi triggers. This is useful to observe the psi events in the kernel space. One use of this is to monitor memory pressure. When the pressure is too high, we can kill the process in the kernel space to prevent OOM. Signed-off-by: Xuewen Yan Acked-by: Suren Baghdasaryan --- V4: -generate the event only after cmpxchg() passes the check --- V3: -export it in the tracefs; --- v2: -fix compilation error; -export the tp; -add more commit message; --- include/trace/events/sched.h | 27 +++++++++++++++++++++++++++ kernel/sched/psi.c | 5 +++++ 2 files changed, 32 insertions(+) diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index 7b2645b50e78..db8b8f25466e 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -826,6 +826,33 @@ TRACE_EVENT(sched_wake_idle_without_ipi, TP_printk("cpu=3D%d", __entry->cpu) ); =20 +#ifdef CONFIG_PSI +TRACE_EVENT(psi_event, + + TP_PROTO(int aggregator, int state, u64 threshold, u64 win_size), + + TP_ARGS(aggregator, state, threshold, win_size), + + TP_STRUCT__entry( + __field(int, aggregator) + __field(int, state) + __field(u64, threshold) + __field(u64, win_size) + ), + + TP_fast_assign( + __entry->aggregator =3D aggregator; + __entry->state =3D state; + __entry->threshold =3D threshold; + __entry->win_size =3D win_size; + ), + + TP_printk("aggregator=3D%d state=3D%d threshold=3D%llu window_size=3D%llu= ", + __entry->aggregator, __entry->state, __entry->threshold, + __entry->win_size) +); +#endif /* CONFIG_PSI */ + /* * Following tracepoints are not exported in tracefs and provide hooking * mechanisms only for testing and debugging purposes. diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 59fdb7ebbf22..e8a7fd04ba9f 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -141,6 +141,8 @@ #include #include "sched.h" =20 +EXPORT_TRACEPOINT_SYMBOL_GPL(psi_event); + static int psi_bug __read_mostly; =20 DEFINE_STATIC_KEY_FALSE(psi_disabled); @@ -515,6 +517,9 @@ static void update_triggers(struct psi_group *group, u6= 4 now, kernfs_notify(t->of->kn); else wake_up_interruptible(&t->event_wait); + + trace_psi_event(aggregator, t->state, t->threshold, + t->win.size); } t->last_event_time =3D now; /* Reset threshold breach flag once event got generated */ --=20 2.25.1