From 17b9c24b25bfe0c15e5075efc8a442240c4e895d Mon Sep 17 00:00:00 2001 From: Huang Yiwei Date: Wed, 7 Apr 2021 17:08:00 +0800 Subject: [PATCH] ANDROID: hung_task: Add vendor hook for hung task detect Add vendor hook for hung task detect, so we can decide which threads need to check, avoiding false alarms. Bug: 188684133 Signed-off-by: Huang Yiwei Change-Id: I5d7dfeb071cbfda8121134c38a458202aaa3a8c6 --- drivers/android/vendor_hooks.c | 3 +++ include/trace/hooks/hung_task.h | 24 ++++++++++++++++++++++++ kernel/hung_task.c | 12 +++++++++--- 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 include/trace/hooks/hung_task.h diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index c53270805362..dea206f0816f 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -55,6 +55,7 @@ #include #include #include +#include /* * Export tracepoints that act as a bare tracehook (ie: have no trace event @@ -283,3 +284,5 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_update_topology_flags_workfn); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_of_i2c_get_board_info); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cgroup_attach); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_dirty_limits); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_uninterruptible_tasks); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_uninterruptible_tasks_dn); diff --git a/include/trace/hooks/hung_task.h b/include/trace/hooks/hung_task.h new file mode 100644 index 000000000000..b355828df349 --- /dev/null +++ b/include/trace/hooks/hung_task.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM hung_task + +#define TRACE_INCLUDE_PATH trace/hooks + +#if !defined(_TRACE_HOOK_HUNG_TASK_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_HOOK_HUNG_TASK_H + +#include +#include + +DECLARE_HOOK(android_vh_check_uninterruptible_tasks, + TP_PROTO(struct task_struct *t, unsigned long timeout, + bool *need_check), + TP_ARGS(t, timeout, need_check)); + +DECLARE_HOOK(android_vh_check_uninterruptible_tasks_dn, + TP_PROTO(void *unused), + TP_ARGS(unused)); + +#endif /* _TRACE_HOOK_HUNG_TASK_H */ +/* This part must be outside protection */ +#include diff --git a/kernel/hung_task.c b/kernel/hung_task.c index 396ebaebea3f..5fc41fd89001 100644 --- a/kernel/hung_task.c +++ b/kernel/hung_task.c @@ -23,6 +23,8 @@ #include #include +#undef CREATE_TRACE_POINTS +#include /* * The number of tasks checked: @@ -177,6 +179,7 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) int max_count = sysctl_hung_task_check_count; unsigned long last_break = jiffies; struct task_struct *g, *t; + bool need_check = true; /* * If the system crashed already then all bets are off, @@ -195,10 +198,13 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout) goto unlock; last_break = jiffies; } - /* use "==" to skip the TASK_KILLABLE tasks waiting on NFS */ - if (t->state == TASK_UNINTERRUPTIBLE) - check_hung_task(t, timeout); + trace_android_vh_check_uninterruptible_tasks(t, timeout, &need_check); + if (need_check) + /* use "==" to skip the TASK_KILLABLE tasks waiting on NFS */ + if (t->state == TASK_UNINTERRUPTIBLE) + check_hung_task(t, timeout); } + trace_android_vh_check_uninterruptible_tasks_dn(NULL); unlock: rcu_read_unlock(); if (hung_task_show_lock)