Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
top(1) reporting bad cpu percentage [SOLVED]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
zzaappp
Apprentice
Apprentice


Joined: 06 Jun 2003
Posts: 176

PostPosted: Sat Jul 19, 2008 2:45 pm    Post subject: top(1) reporting bad cpu percentage [SOLVED] Reply with quote

I was doing a trivial compile build today on the spanking new box I just built, and was a bit surprised to see top(1) reporting the C++ compiler using more than 1000% of available cpu. See the first line of the process report, "cc1plus", below, and look under the "CPU%" column:
Code:
top - 10:35:55 up 14 min,  4 users,  load average: 1.66, 0.59, 0.28
Tasks: 131 total,   4 running, 127 sleeping,   0 stopped,   0 zombie
Cpu(s):  4.2%us,  0.4%sy,  0.0%ni, 94.5%id,  0.8%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   8310568k total,   346292k used,  7964276k free,    19936k buffers
Swap:        0k total,        0k used,        0k free,   151792k cached
 
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                           
 7623 root      20   0 48956  41m 4596 R 1805  0.5   0:09.11 cc1plus                             
 7659 root      20   0 19072  14m 4396 R   22  0.2   0:00.11 cc1plus                             
 5384 root      20   0  268m  64m  25m S    4  0.8   1:09.67 java                               
 4330 root      20   0 10516 8536 1956 R    2  0.1   0:55.29 Xvnc                               
    1 root      20   0  1596  548  476 S    0  0.0   0:14.63 init                               
    2 root      15  -5     0    0    0 S    0  0.0   0:00.00 kthreadd                           
    3 root      RT  -5     0    0    0 S    0  0.0   0:00.00 migration/0                         
    4 root      15  -5     0    0    0 S    0  0.0   0:00.00 ksoftirqd/0                         
    5 root      RT  -5     0    0    0 S    0  0.0   0:00.00 migration/1                         
    6 root      15  -5     0    0    0 S    0  0.0   0:04.29 ksoftirqd/1                         
    7 root      RT  -5     0    0    0 S    0  0.0   0:00.00 migration/2                         
    8 root      15  -5     0    0    0 S    0  0.0   0:00.00 ksoftirqd/2                         
    9 root      RT  -5     0    0    0 S    0  0.0   0:00.00 migration/3                         
   10 root      15  -5     0    0    0 S    0  0.0   0:12.88 ksoftirqd/3                         
   11 root      15  -5     0    0    0 S    0  0.0   0:00.00 events/0                           
   12 root      15  -5     0    0    0 S    0  0.0   0:00.08 events/1                           
   13 root      15  -5     0    0    0 S    0  0.0   0:00.00 events/2                           
   14 root      15  -5     0    0    0 S    0  0.0   0:00.00 events/3                           
   15 root      15  -5     0    0    0 S    0  0.0   0:25.76 khelper                             
   87 root      15  -5     0    0    0 S    0  0.0   0:00.02 kblockd/0                           
   88 root      15  -5     0    0    0 S    0  0.0   0:00.00 kblockd/1                           
   89 root      15  -5     0    0    0 S    0  0.0   0:00.00 kblockd/2                           
   90 root      15  -5     0    0    0 S    0  0.0   0:00.00 kblockd/3                           
   92 root      15  -5     0    0    0 S    0  0.0   0:00.00 kacpid                             
   93 root      15  -5     0    0    0 S    0  0.0   0:04.28 kacpi_notify                       
  176 root      15  -5     0    0    0 S    0  0.0   0:00.00 cqueue                             
  182 root      15  -5     0    0    0 S    0  0.0   0:00.00 ata/0                               
  183 root      15  -5     0    0    0 S    0  0.0   0:00.00 ata/1                               
  184 root      15  -5     0    0    0 S    0  0.0   0:00.00 ata/2                               
  185 root      15  -5     0    0    0 S    0  0.0   0:00.00 ata/3                               
  186 root      15  -5     0    0    0 S    0  0.0   0:00.00 ata_aux                             
  187 root      15  -5     0    0    0 S    0  0.0   0:00.00 ksuspend_usbd                       
  192 root      15  -5     0    0    0 S    0  0.0   0:00.71 khubd                               
  195 root      15  -5     0    0    0 S    0  0.0   0:00.07 kseriod                             
  198 root      15  -5     0    0    0 S    0  0.0   0:00.00 kmmcd                               
  261 root      20   0     0    0    0 S    0  0.0   0:00.00 pdflush                             
  262 root      20   0     0    0    0 S    0  0.0   0:00.00 pdflush                             
  263 root      15  -5     0    0    0 S    0  0.0   0:00.00 kswapd0


I originally compiled the kernel as Tickless. When I saw this report, I rebuilt it with Tickless disabled. That made no difference. Just an FYI, this is using an intel Quad Core cpu for a total of 4 cpu cores.

I recall an article a few months ago in LINUX JOURNAL that spoke of a bug in top(1)'s way of calculating cpu usage, but I'm fuzzy on the details, the context that causes it. Has anyone seen this behavior before?



Many thanks!

-z


Last edited by zzaappp on Sun Jul 20, 2008 5:31 pm; edited 1 time in total
Back to top
View user's profile Send private message
alex.blackbit
Advocate
Advocate


Joined: 26 Jul 2005
Posts: 2397

PostPosted: Sat Jul 19, 2008 6:26 pm    Post subject: Reply with quote

very interesting.
the summary on the top says that your system is almost idle. very strange.
when you hit "1", you see the load distribution over the cpus.
you can also try using "htop" maybe it gives different results.
Back to top
View user's profile Send private message
zzaappp
Apprentice
Apprentice


Joined: 06 Jun 2003
Posts: 176

PostPosted: Sun Jul 20, 2008 5:31 am    Post subject: Reply with quote

I tried htop(1) concurrently with top(1) so I could see both sets of numbers. I then ran the build test so that the CPU's were ramped up fairly high. Straight away there was a clear difference: htop's numbers stayed realistic, and top's numbers spiked impossibly high.

Evidently there is a bug in top. Has something in /proc changed lately? I would really like to take a peek at the code and see what the differences are between the two utilities.

Either way, thanks for the info!

-z
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 23089

PostPosted: Sun Jul 20, 2008 4:02 pm    Post subject: Reply with quote

You could use dev-util/strace to monitor the system calls of the two processes. It will produce quite a lot of output, but it should show you how each of them is getting their respective inputs, which may give you a clue about what part of /proc to investigate.
Back to top
View user's profile Send private message
zzaappp
Apprentice
Apprentice


Joined: 06 Jun 2003
Posts: 176

PostPosted: Sun Jul 20, 2008 5:30 pm    Post subject: Reply with quote

I did a quick analysis of the code in top. Top lives in the procps project along with a number of other utilities that need access to /proc. In the case of top(1), a call is made into the procps library to a function called readproc(); readproc parses the contents of files in /proc/%id%/task/*. Evidently the structure of one or more files in /proc/%id%/task/ have changed, and readproc is unaware, or perhaps not compiled correctly to handle it.

htop(1), on the other hand, has its own parser and doesn't use the readproc call that procps provides to top(1).

I could dig deeper, but I think I'll use htop instead.

-z
Back to top
View user's profile Send private message
alex.blackbit
Advocate
Advocate


Joined: 26 Jul 2005
Posts: 2397

PostPosted: Sun Jul 20, 2008 6:13 pm    Post subject: Reply with quote

htop isn't a standard unix tool, but i use it myself a lot, because it just works very well and is feature rich.
good choice.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum