lkml.org 
[lkml]   [1996]   [Jun]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: CPU Utilization


On 30 Jun 1996, H. Peter Anvin wrote:
>
> The *instantaneous* CPU usage, when measured, is always 100% since
> your measuring process is obviously running at that time, the CPU is
> being utilized... hence, it is a useless metric, and the reason a
> decaying average is used instead.

Actually, depending on your definition of "instantaneous", what you might
be searching for is the number of currently runnable processes. That's
easy to get, just do a

linux$ cat /proc/loadavg
0.00 0.00 0.00 2/52 15207

And look at the "X/Y" part. The "X" (2 above) is the number of currently
runnable processes, while "Y" is the total number of processes in the system
(52 here).

Now, obviously the process that checks the loadaverage is always counted into
it, so you have to subtract 1 from X to get a reasonable number. Also, Linux
actually counts the idle tasks (one for each CPU) into the number of runnable
processes, so you should actually subtract (1+CPUnr) from the number (as you
can see from the loadaverage, my machine is pretty idle right now, I'm just
reading email and news, load=0). You can get the number of CPU's by looking
at /proc/cpuinfo, so you _can_ get all the info for some kind of
"instantaneous" load.

I don't know if that number makes any _sense_, but it's there if you want
it.

Linus

PS. The normal "loadaverage" numbers actually count processes in disk sleep
toward the loadaverage, because that is usually a better indication of load
than just counting the number of runnable processes. The X/Y number (or
rather, "X"), only counts the number of _running_ processes, though. So the
/proc/loadavg numbers don't actually count the same things..



\
 
 \ /
  Last update: 2005-03-22 13:37    [W:0.103 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site