Re: [PATCH] kernel/hung_task: Report top CPU consumers

From: Tetsuo Handa
Date: Sat May 15 2021 - 04:35:22 EST


On 2021/05/14 21:56, zhouchuangao wrote:
> 1. If the task did not get scheduled for more than 2 minutes,
> report top 3(By default) CPU consumers.
>
> 2. By default, the CPU utilization of each process in one minute
> is calculated.

+ all_cpu_usage(false);
+ show_top_cpu_consumers(false);
+ msleep(1000);
+ all_cpu_usage(true);
+ show_top_cpu_consumers(true);

1 second than 1 minute? Too short to determine top CPU consumers?

>
> 3. Add a new member last_cpu_time to task_struct to record the CPU
> usage of the process at the beginning of the computation.

Speak of syzbot testing, in many cases the cause of hung task is simply
somebody else was consuming too much CPU resources. Therefore, without
backtraces of top CPU consumer processes, I think it is not different from
calling

call_usermodehelper("/bin/sh", { "sh", "-c", "exec top -b -d 1 -n 1 > /dev/klog", NULL }, { NULL }, UMH_WAIT_PROC | UMH_KILLABLE);

before panic().

Maybe a hook for executing some userspace commands with some timeout before panic() is more useful?