From 9fec5f6775ce8c64987468b5890f3dc116b2f4f7 Mon Sep 17 00:00:00 2001 From: xiaofeng Date: Wed, 29 May 2024 20:26:03 +0800 Subject: [PATCH] ANDROID: psi: Add vendor hooks for PSI tracing Add hooks to capture various per-zone memory stats when a trigger threshold is hit. In the stability Monkey4SystemLongTime test, the camera startup will request a large amount of memory in a short period of time, resulting in a temporary shortage of system memory. In addition, other processes also need to continuously request memory.In this case, it is easy for the system to have lmkd blocked and unable to kill the process in time, resulting in OOM. This hook can be used to detect when lmkd is in D state and the memory pressure meets the set conditions, then the kill process mechanism is triggered to avoid the occurrence of OOM. In the previous test, 1/20 machines had a problem at 74.49 hours,but after the modification, 48 machines were tested for 120 hours without any problems. Bug: 268290366 Change-Id: Ibe39263ddb05ffc3fa63b5225497a90c6480c8d7 Signed-off-by: Georgi Djakov Signed-off-by: xiaofeng --- drivers/android/vendor_hooks.c | 3 +++ include/trace/hooks/psi.h | 25 +++++++++++++++++++++++++ kernel/sched/psi.c | 5 +++++ 3 files changed, 33 insertions(+) create mode 100644 include/trace/hooks/psi.h diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 645c2ec8626f..7372a3154837 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -53,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -302,6 +303,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_try_to_freeze_todo); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_try_to_freeze_todo_unfrozen); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_die_kernel_fault); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_do_sp_pc_abort); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_psi_event); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_psi_group); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_dma_buf_stats_teardown); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_dpm_wait_start); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_dpm_wait_finish); diff --git a/include/trace/hooks/psi.h b/include/trace/hooks/psi.h new file mode 100644 index 000000000000..91a008655031 --- /dev/null +++ b/include/trace/hooks/psi.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM psi + +#define TRACE_INCLUDE_PATH trace/hooks + +#if !defined(_TRACE_HOOK_PSI_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_HOOK_PSI_H + +#include + +struct psi_trigger; +struct psi_group; +DECLARE_HOOK(android_vh_psi_event, + TP_PROTO(struct psi_trigger *t), + TP_ARGS(t)); + +DECLARE_HOOK(android_vh_psi_group, + TP_PROTO(struct psi_group *group), + TP_ARGS(group)); + +#endif /* _TRACE_HOOK_PSI_H */ + +/* This part must be outside protection */ +#include diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 84dad1511d1e..1d3be71b1cb1 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -136,6 +136,7 @@ * cost-wise, yet way more sensitive and accurate than periodic * sampling of the aggregate task states would be. */ +#include static int psi_bug __read_mostly; @@ -487,6 +488,8 @@ static void update_triggers(struct psi_group *group, u64 now, if (now < t->last_event_time + t->win.size) continue; + trace_android_vh_psi_event(t); + /* Generate an event */ if (cmpxchg(&t->event, 0, 1) == 0) { if (t->of) @@ -498,6 +501,8 @@ static void update_triggers(struct psi_group *group, u64 now, /* Reset threshold breach flag once event got generated */ t->pending_event = false; } + + trace_android_vh_psi_group(group); } static u64 update_averages(struct psi_group *group, u64 now)