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. And the NULL
tracehook is used to indicate one check cycle is finished, so
additional checks can be done after one hung task check cycle.

Bug: 188684133
Change-Id: I5d7dfeb071cbfda8121134c38a458202aaa3a8c6
Signed-off-by: Huang Yiwei <quic_hyiwei@quicinc.com>
This commit is contained in:
Huang Yiwei 2023-01-10 17:29:51 +08:00
parent b5a5282ca9
commit 3e4fa5265c
3 changed files with 38 additions and 5 deletions

View File

@ -45,6 +45,7 @@
#include <trace/hooks/dmabuf.h>
#include <trace/hooks/timer.h>
#include <trace/hooks/topology.h>
#include <trace/hooks/hung_task.h>
/*
* Export tracepoints that act as a bare tracehook (ie: have no trace event
@ -135,3 +136,5 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_aes_expandkey);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_aes_encrypt);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_aes_decrypt);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_timer_calc_index);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_uninterrupt_tasks);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_uninterrupt_tasks_done);

View File

@ -0,0 +1,23 @@
/* 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 <trace/hooks/vendor_hooks.h>
DECLARE_HOOK(android_vh_check_uninterrupt_tasks,
TP_PROTO(struct task_struct *t, unsigned long timeout,
bool *need_check),
TP_ARGS(t, timeout, need_check));
DECLARE_HOOK(android_vh_check_uninterrupt_tasks_done,
TP_PROTO(void *unused),
TP_ARGS(unused));
#endif /* _TRACE_HOOK_HUNG_TASK_H */
/* This part must be outside protection */
#include <trace/define_trace.h>

View File

@ -24,6 +24,8 @@
#include <linux/sched/sysctl.h>
#include <trace/events/sched.h>
#undef CREATE_TRACE_POINTS
#include <trace/hooks/hung_task.h>
/*
* The number of tasks checked:
@ -180,6 +182,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,
@ -204,12 +207,16 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
* skip the TASK_KILLABLE tasks -- these can be killed
* skip the TASK_IDLE tasks -- those are genuinely idle
*/
state = READ_ONCE(t->__state);
if ((state & TASK_UNINTERRUPTIBLE) &&
!(state & TASK_WAKEKILL) &&
!(state & TASK_NOLOAD))
check_hung_task(t, timeout);
trace_android_vh_check_uninterrupt_tasks(t, timeout, &need_check);
if (need_check) {
state = READ_ONCE(t->__state);
if ((state & TASK_UNINTERRUPTIBLE) &&
!(state & TASK_WAKEKILL) &&
!(state & TASK_NOLOAD))
check_hung_task(t, timeout);
}
}
trace_android_vh_check_uninterrupt_tasks_done(NULL);
unlock:
rcu_read_unlock();
if (hung_task_show_lock)