Bug 4081 - CPU usage for threads not displayed correctly in top (only with NPTL threads)
Summary: CPU usage for threads not displayed correctly in top (only with NPTL threads)
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.18.x
Hardware: Other Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-24 15:00 UTC by Ronald Wahl
Modified: 2011-08-28 09:58 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
small test programm (448 bytes, text/x-csrc)
2011-08-24 15:00 UTC, Ronald Wahl
Details
Proposal for a fix (1.62 KB, patch)
2011-08-24 16:50 UTC, Ronald Wahl
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ronald Wahl 2011-08-24 15:00:49 UTC
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.
Comment 1 Ronald Wahl 2011-08-24 16:50:06 UTC
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.
Comment 2 Denys Vlasenko 2011-08-28 09:58:35 UTC
Applied to git. Will be in 1.19.1. Thanks!