How is CPU usage calculated?

Martin Turgeon freebsd at optiksecurite.com
Mon Oct 18 18:54:02 UTC 2010


  Le 2010-10-15 03:17, Bas Smeelen a écrit :
> From: Martin Turgeon [mailto:freebsd at optiksecurite.com]
> To: freebsd-questions at freebsd.org
> Sent: Thu, 14 Oct 2010 21:46:13 +0200
> Subject: How is CPU usage calculated?
>
>    Hi list!
>
>    I did a strange observation yesterday night. The CPU usage reported by
>    top doesn't match what is indicated under it. I was seeing around 80-90%
>    user, 5% system, 1% interrupt and 10% idle. But the process details
>    under it doesn't match. mysqld was taking around 250% (WCPU) with a few
>    httpd processes at 1-2%. The system is running GENERIC 8.0-REL on a Xeon
>    E5630 (quad core with hyperthreading so 8 CPUs). MySQL and Apache each
>    have their own jail (I don't think it will matter but just in case)
>
>    I understand why the mysqld process take more than 100% but how can I
>    know what's taking the rest? Why doesn't the total user CPU usage match
>    the total of the CPU usage of each process? Is there a link with
>    hyperthreading?
>
>    There sure is a logical answer and I would really like to know it :)
> Yes if you have multiple cpu's, cores or hyperthreading than each unit can be used up to 100%
> Mysql has multiple threads, you can check with top -P to see the multiple cores and when top is running give the command H (capital H) to see the threads of each process
>
>
Thanks for your reply!

I didn't knew about -H to show individual threads, but my problem isn't 
there. My problem is that the summary printed in the first lines doesn't 
match the total of the process detailled under the summary. For example, 
I have a user CPU usage est 83.1% in the summary, but the only process 
worth mentionning in the list is mysqld that is taking 255.52% WCPU. 
That's far less than half the "CPU power" but 83% is far more. It's that 
difference that I don't understand.

How is this possible?

Martin


More information about the freebsd-questions mailing list