Skip to contentSkip to conversation

hung_task: Add detection count to hung task warning message

PATCH In review Ye Liu 3 participants 4 messages Jul 24, 2025 – Jul 25, 2025 Hung task detector

lore
Share & tools
lore

Ye Liu

author
#0 lore raw

PATCH v2 1/1 hung_task: Add detection count to hung task warning message

From: Ye Liu <[email protected]>

Add [#N] to hung task warnings to show occurrence count. This helps quickly identify warning order when multiple messages appear in logs.

Changes in v2:
- Directly use sysctl_hung_task_detect_count.
- Link to v1:https://lore.kernel.org/all/[email protected]/

---
 kernel/hung_task.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/hung_task.c +3 -2
index 8708a1205f82..231afdb68bb2 100644
@@ -232,8 +232,9 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
 	if (sysctl_hung_task_warnings || hung_task_call_panic) {
 		if (sysctl_hung_task_warnings > 0)
 			sysctl_hung_task_warnings--;
-		pr_err("INFO: task %s:%d blocked for more than %ld seconds.\n",
-		       t->comm, t->pid, (jiffies - t->last_switch_time) / HZ);
+		pr_err("INFO: task %s:%d blocked for more than %ld seconds. [#%ld]\n",
+		       t->comm, t->pid, (jiffies - t->last_switch_time) / HZ,
+		       sysctl_hung_task_detect_count);
 		pr_err("      %s %s %.*s\n",
 			print_tainted(), init_utsname()->release,
 			(int)strcspn(init_utsname()->version, " "),
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 5 lines · Ye Liu

From: Ye Liu <[email protected]>

Add [#N] to hung task warnings to show occurrence count. This helps quickly identify warning order when multiple messages appear in logs.

Hmm... once we have this number, what do we do with it?

While I totally get the desire for a quick reference number, my thinking is that the hung_task_detect_count counter is the intended and more reliable way for users to check.

But like I said before, let's see what Andrew thinks ;)

Thanks,
Lance

Quoted 26 lines

Changes in v2:
- Directly use sysctl_hung_task_detect_count.
- Link to v1:https://lore.kernel.org/all/[email protected]/

---
  kernel/hung_task.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
kernel/hung_task.c +3 -2
index 8708a1205f82..231afdb68bb2 100644
@@ -232,8 +232,9 @@ static void check_hung_task(struct task_struct *t, unsigned long timeout)
  	if (sysctl_hung_task_warnings || hung_task_call_panic) {
  		if (sysctl_hung_task_warnings > 0)
  			sysctl_hung_task_warnings--;
-		pr_err("INFO: task %s:%d blocked for more than %ld seconds.\n",
-		       t->comm, t->pid, (jiffies - t->last_switch_time) / HZ);
+		pr_err("INFO: task %s:%d blocked for more than %ld seconds. [#%ld]\n",
+		       t->comm, t->pid, (jiffies - t->last_switch_time) / HZ,
+		       sysctl_hung_task_detect_count);
  		pr_err("      %s %s %.*s\n",
  			print_tainted(), init_utsname()->release,
  			(int)strcspn(init_utsname()->version, " "),
maintainer
#2 lore raw
Quoted 10 lines · On Thu, 24 Jul 2025 20:06:52 +0800 Lance Yang <[email protected]> wrote:
Quoted 5 lines · Ye Liu

From: Ye Liu <[email protected]>

Add [#N] to hung task warnings to show occurrence count. This helps quickly identify warning order when multiple messages appear in logs.

Hmm... once we have this number, what do we do with it?

Yes, adding to the changelog a more comprehensive description of the use-cases would help get this patch into Linux.

Quoted 3 lines

While I totally get the desire for a quick reference number, my thinking is that the hung_task_detect_count counter is the intended and more reliable way for users to check.

But that's what this patch does? Confused.

Quoted 1 line

But like I said before, let's see what Andrew thinks ;)

Andrew thinks it's a pain when the title of a patch is changed! Fortunately the changelog had a "Link to v1".

maintainer
#3 lore raw
Quoted 7 lines · Andrew Morton
Quoted 5 lines · On Thu, 24 Jul 2025 20:06:52 +0800 Lance Yang <[email protected]> wrote:
Quoted 2 lines · Ye Liu

From: Ye Liu <[email protected]>

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Add [#N] to hung task warnings to show occurrence count. This helps quickly identify warning order when multiple messages appear in logs.

Hmm... once we have this number, what do we do with it?

Yes, adding to the changelog a more comprehensive description of the use-cases would help get this patch into Linux.

Yep, exactly. Please sell this change to us! A good changelog should explain not just what the patch does, but why it's necessary ;p

Quoted 6 lines
Quoted 4 lines

While I totally get the desire for a quick reference number, my thinking is that the hung_task_detect_count counter is the intended and more reliable way for users to check.

But that's what this patch does? Confused.

I'm just not sure if this quick reference number is something users actually need, as there doesn't seem to be a strong use-case for it yet.

My point was that actively checking the sysctl is the proper way to get the total count. But of course, if users genuinely need this inline number, I have no objection ;)

Quoted 5 lines
Quoted 2 lines

But like I said before, let's see what Andrew thinks ;)

Andrew thinks it's a pain when the title of a patch is changed! Fortunately the changelog had a "Link to v1".

https://lore.kernel.org/lkml/[email protected]/

Thanks,
Lance