Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to determine the CPU usage of a program by looking at the output from Top in Linux. I understand that %us means userspace and %sy means system/kernel etc. But say I see 100%us. Does this mean that the CPU is really only doing useful work? What if a CPU is tied up waiting for resources that are not avaliable, or cache misses, would it also show up in the %us column, or any other column?

Thank you.

share|improve this question

migrated from stackoverflow.com Apr 9 '10 at 1:38

This question came from our site for professional and enthusiast programmers.

    
You might be interested in "htop" for interactive use. But that's tangential to the question. –  detly Apr 8 '10 at 4:15
    
Depends on the definition of "useful." If a program is in a spin-wait for I/O, it's technically running in user space but not doing anything useful (and that's just one of many examples of running in user time but not doing useful work). –  Travis Gockel Apr 8 '10 at 4:18
2  
Not programming related - voting to migrate to superuser.com –  danben Apr 8 '10 at 4:43
add comment

1 Answer 1

up vote 1 down vote accepted

As Travis pointed out this is a tricky question, and one that really depends on defining what useful work actually is - but that's more of an academic question.

I think that the way this is likely calculated is the percentage of total CPU cycles run in user space that is not spent in idling. As long as the program goes to sleep while waiting for certain resources, it shouldn't consume CPU.

If it can't do this for some reason top does tell you the percentage of time spent specifically waiting for IO as %wa.

Short answer: %us of 100% probably includes some busywork, but the exact amount will depend on the type of processor you have, the type of software you're running and a dozen other factors. To get the full story of exactly what top is telling you, you'd probably need to go to the source code (which thankfully, is freely available).

share|improve this answer
    
Is cache thrashing considered busywork and thus show up in the %us column? –  Rayne Apr 8 '10 at 5:36
    
That would depend on what top considers IO and thus what it puts into %us versus %wa. At a guess without doing more digging I would say thrashing between different levels of memory (i.e. L1, L2, etc.) would go under %us while thrashing that involved calls to disk/secondary storage while the processor was forced to wait (as opposed to being able to do other things if it's multithreaded) would go under %wa. But for that level of detail you need to check the source or other detailed documentation. –  Jacinda Apr 8 '10 at 7:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.