Skip to content

Commit

Permalink
ANDROID: hung_task: Add vendor hook for hung task detect
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Huang Yiwei committed Jan 30, 2023
1 parent b5a5282 commit 3e4fa52
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
3 changes: 3 additions & 0 deletions drivers/android/vendor_hooks.c
Expand Up @@ -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
Expand Down Expand Up @@ -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);
23 changes: 23 additions & 0 deletions include/trace/hooks/hung_task.h
@@ -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>
17 changes: 12 additions & 5 deletions kernel/hung_task.c
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 3e4fa52

Please sign in to comment.