hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/kernel/hung_task.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Detect Hung Task
34 *
....@@ -19,8 +20,11 @@
1920 #include <linux/utsname.h>
2021 #include <linux/sched/signal.h>
2122 #include <linux/sched/debug.h>
23
+#include <linux/sched/sysctl.h>
2224
2325 #include <trace/events/sched.h>
26
+#undef CREATE_TRACE_POINTS
27
+#include <trace/hooks/hung_task.h>
2428
2529 /*
2630 * The number of tasks checked:
....@@ -51,8 +55,17 @@
5155 static int __read_mostly did_panic;
5256 static bool hung_task_show_lock;
5357 static bool hung_task_call_panic;
58
+static bool hung_task_show_all_bt;
5459
5560 static struct task_struct *watchdog_task;
61
+
62
+#ifdef CONFIG_SMP
63
+/*
64
+ * Should we dump all CPUs backtraces in a hung task event?
65
+ * Defaults to 0, can be changed via sysctl.
66
+ */
67
+unsigned int __read_mostly sysctl_hung_task_all_cpu_backtrace;
68
+#endif /* CONFIG_SMP */
5669
5770 /*
5871 * Should we panic (and reboot, if panic_timeout= is set) when a
....@@ -60,16 +73,6 @@
6073 */
6174 unsigned int __read_mostly sysctl_hung_task_panic =
6275 CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE;
63
-
64
-static int __init hung_task_panic_setup(char *str)
65
-{
66
- int rc = kstrtouint(str, 0, &sysctl_hung_task_panic);
67
-
68
- if (rc)
69
- return rc;
70
- return 1;
71
-}
72
-__setup("hung_task_panic=", hung_task_panic_setup);
7376
7477 static int
7578 hung_task_panic(struct notifier_block *this, unsigned long event, void *ptr)
....@@ -91,8 +94,8 @@
9194 * Ensure the task is not frozen.
9295 * Also, skip vfork and any other user process that freezer should skip.
9396 */
94
- if (unlikely(t->flags & (PF_FROZEN | PF_FREEZER_SKIP)))
95
- return;
97
+ if (unlikely(frozen_or_skipped(t)))
98
+ return;
9699
97100 /*
98101 * When a freshly created task is scheduled once, changes its state to
....@@ -126,7 +129,7 @@
126129 if (sysctl_hung_task_warnings > 0)
127130 sysctl_hung_task_warnings--;
128131 pr_err("INFO: task %s:%d blocked for more than %ld seconds.\n",
129
- t->comm, t->pid, timeout);
132
+ t->comm, t->pid, (jiffies - t->last_switch_time) / HZ);
130133 pr_err(" %s %s %.*s\n",
131134 print_tainted(), init_utsname()->release,
132135 (int)strcspn(init_utsname()->version, " "),
....@@ -135,6 +138,9 @@
135138 " disables this message.\n");
136139 sched_show_task(t);
137140 hung_task_show_lock = true;
141
+
142
+ if (sysctl_hung_task_all_cpu_backtrace)
143
+ hung_task_show_all_bt = true;
138144 }
139145
140146 touch_nmi_watchdog();
....@@ -173,6 +179,7 @@
173179 int max_count = sysctl_hung_task_check_count;
174180 unsigned long last_break = jiffies;
175181 struct task_struct *g, *t;
182
+ bool need_check = true;
176183
177184 /*
178185 * If the system crashed already then all bets are off,
....@@ -191,18 +198,25 @@
191198 goto unlock;
192199 last_break = jiffies;
193200 }
194
- /* use "==" to skip the TASK_KILLABLE tasks waiting on NFS */
195
- if (t->state == TASK_UNINTERRUPTIBLE)
196
- check_hung_task(t, timeout);
201
+ trace_android_vh_check_uninterruptible_tasks(t, timeout, &need_check);
202
+ if (need_check)
203
+ /* use "==" to skip the TASK_KILLABLE tasks waiting on NFS */
204
+ if (t->state == TASK_UNINTERRUPTIBLE)
205
+ check_hung_task(t, timeout);
197206 }
207
+ trace_android_vh_check_uninterruptible_tasks_dn(NULL);
198208 unlock:
199209 rcu_read_unlock();
200210 if (hung_task_show_lock)
201211 debug_show_all_locks();
202
- if (hung_task_call_panic) {
212
+
213
+ if (hung_task_show_all_bt) {
214
+ hung_task_show_all_bt = false;
203215 trigger_all_cpu_backtrace();
204
- panic("hung_task: blocked tasks");
205216 }
217
+
218
+ if (hung_task_call_panic)
219
+ panic("hung_task: blocked tasks");
206220 }
207221
208222 static long hung_timeout_jiffies(unsigned long last_checked,
....@@ -217,8 +231,7 @@
217231 * Process updating of timeout sysctl
218232 */
219233 int proc_dohung_task_timeout_secs(struct ctl_table *table, int write,
220
- void __user *buffer,
221
- size_t *lenp, loff_t *ppos)
234
+ void *buffer, size_t *lenp, loff_t *ppos)
222235 {
223236 int ret;
224237