[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250424070436.2380215-1-senozhatsky@chromium.org>
Date: Thu, 24 Apr 2025 16:02:43 +0900
From: Sergey Senozhatsky <senozhatsky@...omium.org>
To: Ingo Molnar <mingo@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Juri Lelli <juri.lelli@...hat.com>,
Vincent Guittot <vincent.guittot@...aro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@....com>,
Ben Segall <bsegall@...gle.com>,
Mel Gorman <mgorman@...e.de>,
Tomasz Figa <tfiga@...omium.org>,
Petr Mladek <pmladek@...e.com>,
John Ogness <john.ogness@...utronix.de>,
Steven Rostedt <rostedt@...dmis.org>,
Andrew Morton <akpm@...ux-foundation.org>,
linux-kernel@...r.kernel.org,
Sergey Senozhatsky <senozhatsky@...omium.org>
Subject: [PATCH] hung_task: configurable hung-task stacktrace loglevel
Currently, hung-task watchdog uses two different loglevels
to report hung-tasks: a) KERN_INFO for all the important task
information (e.g. sched_show_task()) and b) KERN_ERR for the
rest. This makes it a little inconvenient, especially for
automated kernel logs parsing.
Introduce CONFIG_HUNG_TASK_STACKTRACE_LOGLEVEL so that (a)
becomes configurable.
Signed-off-by: Sergey Senozhatsky <senozhatsky@...omium.org>
---
include/linux/sched/debug.h | 1 +
kernel/hung_task.c | 6 ++++--
kernel/sched/core.c | 19 +++++++++++++------
lib/Kconfig.debug | 8 ++++++++
4 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/include/linux/sched/debug.h b/include/linux/sched/debug.h
index 35ed4577a6cc..80c17cdd35a8 100644
--- a/include/linux/sched/debug.h
+++ b/include/linux/sched/debug.h
@@ -34,6 +34,7 @@ extern void show_stack(struct task_struct *task, unsigned long *sp,
const char *loglvl);
extern void sched_show_task(struct task_struct *p);
+extern void sched_show_task_log_lvl(struct task_struct *p, const char *lvl);
struct seq_file;
extern void proc_sched_show_task(struct task_struct *p,
diff --git a/kernel/hung_task.c b/kernel/hung_task.c
index d2432df2b905..8817016fd45b 100644
--- a/kernel/hung_task.c
+++ b/kernel/hung_task.c
@@ -26,6 +26,8 @@
#include <trace/events/sched.h>
+#define PR_LEVEL KERN_SOH __stringify(CONFIG_HUNG_TASK_STACKTRACE_LOGLEVEL)
+
/*
* The number of tasks checked:
*/
@@ -153,7 +155,7 @@ static void debug_show_blocker(struct task_struct *task)
task->comm, task->pid, t->comm, t->pid);
break;
}
- sched_show_task(t);
+ sched_show_task_log_lvl(t, PR_LEVEL);
return;
}
}
@@ -221,7 +223,7 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
pr_err(" Blocked by coredump.\n");
pr_err("\"echo 0 > /proc/sys/kernel/hung_task_timeout_secs\""
" disables this message.\n");
- sched_show_task(t);
+ sched_show_task_log_lvl(t, PR_LEVEL);
debug_show_blocker(t);
hung_task_show_lock = true;
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 54e7d63f7785..e9033b049092 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7751,7 +7751,7 @@ void __sched io_schedule(void)
}
EXPORT_SYMBOL(io_schedule);
-void sched_show_task(struct task_struct *p)
+void sched_show_task_log_lvl(struct task_struct *p, const char *lvl)
{
unsigned long free;
int ppid;
@@ -7759,7 +7759,8 @@ void sched_show_task(struct task_struct *p)
if (!try_get_task_stack(p))
return;
- pr_info("task:%-15.15s state:%c", p->comm, task_state_to_char(p));
+ printk("%stask:%-15.15s state:%c", lvl,
+ p->comm, task_state_to_char(p));
if (task_is_running(p))
pr_cont(" running task ");
@@ -7773,12 +7774,18 @@ void sched_show_task(struct task_struct *p)
free, task_pid_nr(p), task_tgid_nr(p),
ppid, p->flags, read_task_thread_flags(p));
- print_worker_info(KERN_INFO, p);
- print_stop_info(KERN_INFO, p);
- print_scx_info(KERN_INFO, p);
- show_stack(p, NULL, KERN_INFO);
+ print_worker_info(lvl, p);
+ print_stop_info(lvl, p);
+ print_scx_info(lvl, p);
+ show_stack(p, NULL, lvl);
put_task_stack(p);
}
+EXPORT_SYMBOL_GPL(sched_show_task_log_lvl);
+
+void sched_show_task(struct task_struct *p)
+{
+ sched_show_task_log_lvl(p, KERN_INFO);
+}
EXPORT_SYMBOL_GPL(sched_show_task);
static inline bool
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 3e40f68a4a4f..6cd266651447 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1290,6 +1290,14 @@ config DETECT_HUNG_TASK_BLOCKER
This will add overhead a bit but shows suspicious tasks and
call trace if it comes from waiting a mutex.
+config HUNG_TASK_STACKTRACE_LOGLEVEL
+ int "Log-level for hung task stacktrace (1-7)"
+ depends on DETECT_HUNG_TASK
+ default "6"
+ help
+ This option controls the log-level used to print the stacktrace
+ of the hung task. The default is 6 (KERN_INFO).
+
config WQ_WATCHDOG
bool "Detect Workqueue Stalls"
depends on DEBUG_KERNEL
--
2.49.0.805.g082f7c87e0-goog
Powered by blists - more mailing lists