Created attachment 3541 [details] small test programm When calling top and enabling the display of threads by pressing 'h' then the CPU usage for a multi-threaded process is distributed over all threads of the process equally. For example if I have a process with three threads where one thread is taking ~100% CPU and the other threads sleep then top shows ~33% CPU usage for each thread which is plainly wrong. The CPU usage reported for each thread should reflect the reality. Checking /proc/<pid>/stat and /proc/<pid>/task/<tid> directly everything is fine, i.e. /proc/<pid>/stat shows the CPU usage of the whole process including all threads respective proc/<pid>/task/<tid> shows the CPU usage of each thread separately. This whole issue exists only when using NPTL threads. For quick testing you can use the attached test program which starts two extra threads - one thread eating all cpu time and one thread which is sleeping. The main thread is sleeping as well.
Created attachment 3547 [details] Proposal for a fix The original code only reads the /proc/<pid>/stat file instead of the /proc/<pid>/task/<tid>/stat file. The attached patch fixes this.
Applied to git. Will be in 1.19.1. Thanks!