From: Xuewen Yan <xuewen.yan@unisoc.com>
To: <peterz@infradead.org>, <surenb@google.com>,
<rostedt@goodmis.org>, <mhiramat@kernel.org>,
<mathieu.desnoyers@efficios.com>, <hannes@cmpxchg.org>,
<vincent.guittot@linaro.org>
Cc: <mingo@redhat.com>, <juri.lelli@redhat.com>,
<dietmar.eggemann@arm.com>, <bsegall@google.com>,
<mgorman@suse.de>, <linux-kernel@vger.kernel.org>,
<linux-trace-kernel@vger.kernel.org>, <yuming.han@unisoc.com>,
<xuewen.yan94@gmail.com>, <ke.wang@unisoc.com>,
<jstultz@google.com>
Subject: [RESEND PATCH V4] sched: psi: Add psi events trace point
Date: Fri, 21 Nov 2025 15:32:44 +0800 [thread overview]
Message-ID: <20251121073244.9091-1-xuewen.yan@unisoc.com> (raw)
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 <xuewen.yan@unisoc.com>
Acked-by: Suren Baghdasaryan <surenb@google.com>
---
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=%d", __entry->cpu)
);
+#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 = aggregator;
+ __entry->state = state;
+ __entry->threshold = threshold;
+ __entry->win_size = win_size;
+ ),
+
+ TP_printk("aggregator=%d state=%d threshold=%llu window_size=%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 <linux/psi.h>
#include "sched.h"
+EXPORT_TRACEPOINT_SYMBOL_GPL(psi_event);
+
static int psi_bug __read_mostly;
DEFINE_STATIC_KEY_FALSE(psi_disabled);
@@ -515,6 +517,9 @@ static void update_triggers(struct psi_group *group, u64 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 = now;
/* Reset threshold breach flag once event got generated */
--
2.25.1
reply other threads:[~2025-11-21 7:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251121073244.9091-1-xuewen.yan@unisoc.com \
--to=xuewen.yan@unisoc.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=hannes@cmpxchg.org \
--cc=jstultz@google.com \
--cc=juri.lelli@redhat.com \
--cc=ke.wang@unisoc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mgorman@suse.de \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=surenb@google.com \
--cc=vincent.guittot@linaro.org \
--cc=xuewen.yan94@gmail.com \
--cc=yuming.han@unisoc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox