Operating System - HP-UX
1832935 Members
2939 Online
110048 Solutions
New Discussion

Regarding Cpu Utilization in Top output

 
Sunil Surve
Advisor

Regarding Cpu Utilization in Top output

I have a query regarding the top output -

for ex:
Cpu states:
CPU LOAD USER NICE SYS IDLE BLOCK SWAIT INTR SSYS
0 0.03 0.0% 0.0% 0.2% 99.8% 0.0% 0.0% 0.0% 0.0%
1 0.00 0.2% 0.0% 0.0% 99.8% 0.0% 0.0% 0.0% 0.0%
2 0.00 0.2% 0.6% 2.8% 96.4% 0.0% 0.0% 0.0% 0.0%
3 0.01 0.6% 0.4% 5.4% 93.6% 0.0% 0.0% 0.0% 0.0%
--- ---- ----- ----- ----- ----- ----- ----- ----- -----
avg 0.01 0.2% 0.2% 2.2% 97.4% 0.0% 0.0% 0.0% 0.0%


Now in this output, how do they calculate the CPU utilization. Further, what is NICE and LOAD. I think USER gives the % utilization of the user processes which are currently running and SYS gives the % utilization of the System processes and system calls made by the user processes in the currently running proceses. I hope this is right. Please provide some information about the calcuation of cpu utilization. If no one has any info regarding this then we cld discuss it.

Thanks & Regards.
14 REPLIES 14
Geoff Wild
Honored Contributor

Re: Regarding Cpu Utilization in Top output

How about using vmstat?

This will get you idle cpu:

idle=`/usr/bin/vmstat 1 2 | tail -1 | awk '{print $NF}'`

user plus system will be:

usersys=`expr 100 - $idle`

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Scot Bean
Honored Contributor

Re: Regarding Cpu Utilization in Top output

Try "man top" for details.

LOAD is the average load on the CPU

NICE is a priority queue, indicates how much CPU time went to NICEd processes.

You are right on USER and SYS.
doug mielke
Respected Contributor

Re: Regarding Cpu Utilization in Top output

I've found the man page on TOP to be too vague to be useful.

I too would like to know how the 'load' value is determined. I've read that it's a combination of multiple factors, including length of run queue, % idle, etc., but I've never seen any great detail.

re: usr and sys % I assume these are straight sar -u numbers, and there is much documentation on the details and caveats of sar ( not man sar, though. Try sar in your web browser for details)
Mark Greene_1
Honored Contributor

Re: Regarding Cpu Utilization in Top output

Load is an exponential number, similar to the riechter scale used to measure earthquakes; e.g., 2 is twice as busy as 1, 3 is twice as busy at 2, etc.

The number itself isn't a quantification of any one thing, it's an index value, similar to the Dow Jones New York Stock Exchange index of 30 companies. You can probably derive the formula from any linux or freebsd source code for uptime, but I'm not aware of it actually being published anywhere.

mark
the future will be a lot like now, only later
Sridhar Bhaskarla
Honored Contributor

Re: Regarding Cpu Utilization in Top output

Hi Sunil,

Nice is nothing but CPU utilization that was spent running 'niced' processes. The default priority is 20. For the processes that were started with a non-default priority or that started in background will have a high priority value. To find out such processes do

UNIX95= ps -e -o "nice pid args" |sort -n

The ones with more than 20 in the first column are niced processes.

Load is the average number of threads/processes that were being processed + waiting in queue on that CPU during that interval.

Your assumption of USER is right but SYSTEM is the time spent by the CPU in SYSTEM mode such as disk IO, network IO etc.,For ex., if a user process requests an IO from the disk, fetching of IO by the kernel is shown as system CPU.

-Sri



You may be disappointed if you fail, but you are doomed if you don't try
Steven E. Protter
Exalted Contributor

Re: Regarding Cpu Utilization in Top output

I think you need better data.

See attached data gathering scripts.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Bill Hassell
Honored Contributor

Re: Regarding Cpu Utilization in Top output

The actual details of how CPU utilization is calculated are quite involved, especially in a multi-CPU system. Simply put, during the measurement period, structures in the kernel are read repeatedly to determine usage (SYS, USER, NICE, etc) but since some processes may use 100% of the CPU for a fraction of a second, this calculation is quite involved. If a process consumes 100% of a CPU, then on your 4 processor system, one CPU=100%, the rest almost zero, system usage is 25% overall.

The system load is much simpler than described but hard to quantify. The system load (also seen in the uptime command) is the average size of the RUNQUEUE in the kernel for the last 1,5,15 minutes. Now the RUNQUEUE is the number of processes that are ready to run (no waiting on I/O, exec calls, signals, etc). In a single processor system, a single process performing on compute-intensive task generates a RUNQUEUE=1. Run the program 4 times all at once and the RUNQUEUE=4. But since there is only 1 processor, each job is timesliced and the elapsed time will be 4x the length of a single job.

Move the 4 jobs to run on a 4 processor system and RUNQUEUE=4, but on this machine, RUNQUEUE=4 means all jobs finish in the same time as one job. So the RUNQUEUE (load average) is a long average of the number of running and ready-to-run jobs. So it isn't really a workload in the classic sense.

For instance, a workload of 50 or 100 may not be too high if the jobs are all short lived or they perform some polling functions (low compute time, large system overhead). So the load average divided by the number of processors gives you a rough idea if you have more processes than processors.


Bill Hassell, sysadmin
Sunil Surve
Advisor

Re: Regarding Cpu Utilization in Top output

Hello everybody,

thanks to all for the information given.
I have a couple more queries considering the reply given by Sridhar Bhaskarla.

Now, NICE is CPU utilization that was spent running 'niced' processes. What i gather from this is, in case of system having all the proccesses running at default priority this will be zero. Is it like if the system has many processes running at higher processes the NICE value would be higher.

Further, in the top output i consider the average cpu utilization. The total of load,nice,sys,user and idle comes out to 100%. Now while calcualting the average cpu utilization (user+sys) , are the individual %CPU of all the processes (given below in the same top output) considered or only those processes which are in run state.

Thanks & regards
Sridhar Bhaskarla
Honored Contributor

Re: Regarding Cpu Utilization in Top output

Hi Sunil,

Higher nice value means lower the priority. You are right. When all the processes are running at default nice value, NICE column in your top output would be zero. IF any of the processes are started through background, then their nice values will be higher.

Load is the average number of jobs that are in run queue. It's not the cpu utilization. It tells you how many jobs the particularly CPU ran on the average during that interval. It shouldn't be added to the CPU utilzation.

So, leaving it aside, your CPU utilization will be USER+NICE+SYS. Rest of it is IDLE.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sunil Surve
Advisor

Re: Regarding Cpu Utilization in Top output

Hello Sri,

I wanted to know tat how the average cpu utilization values of (user + sys) are calculated. I guess they have to be calculated from addition of %CPU all the processes running on the machine. Now in tat case, only those processes who are in the running state shld be considered or processes in both run+sleep states shld be considered. Actually, at a particular time, i wanted to verify the average cpu utilization reported. I have all the processes listed in the top output and i have taken the output in a file.

Thanks & Rgds,
Sridhar Bhaskarla
Honored Contributor

Re: Regarding Cpu Utilization in Top output

Hi,

CPU utilization is calculated based on the number of CPU cycles that were consumed during that interval. It means, it was only calculated for the processes that were in the running state. The CPU required to manage sleep states, waiting for queue etc., is part of kernel's scheduling usage.

You may not get accurate results if you try to account for the usage as it is done based on the intervals, samples and the averages. Any tool will only give you averages over a certain interval. There is no 100% real time monitoring tool available.

I would suggest you to try 'glance+' pack. You will find an evaluation copy in your application CDs. You can get quite a bit of information from it.


-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Mark Greene_1
Honored Contributor

Re: Regarding Cpu Utilization in Top output

"Further, in the top output i consider the average cpu utilization. The total of load,nice,sys,user and idle comes out to 100%. Now while calcualting the average cpu utilization (user+sys) , are the individual %CPU of all the processes (given below in the same top output) considered or only those processes which are in run state.
"

They are not considered directly, because if you have a multiple CPU system, the %CPU of all the process listed, when totaled, will equal 100 * number of CPUs. So only a 3 CPU system, the total individual processes can be as much as 300%.

mark
the future will be a lot like now, only later
Sunil Surve
Advisor

Re: Regarding Cpu Utilization in Top output

hello mark,

quoting you,
"They are not considered directly, because if you have a multiple CPU system, the %CPU of all the process listed, when totaled, will equal 100 * number of CPUs. So only a 3 CPU system, the total individual processes can be as much as 300%."

you are absolutely right... in that case we can just divide the total %CPU calcluated for all the processes by the no. of CPUs/ Or we can also calcualte the %CPU of all the processes running on a particular CPU and then check that particular CPU's utilization. I tried that but i was not able to match the output...

thnks & rgds,
Bill Hassell
Honored Contributor

Re: Regarding Cpu Utilization in Top output

top is an old program that does not have the code to accurately sort out multiple processors, context switches at 10 times per second, or complex threads, so the numbers will not generally add up exactly. top must wait along with all other processes to get it's information and as suych, is just a rough idea. Loading on individual CPUs is of no interest since trying to force processor affinity or association virtually never gives better performance.

For accurate and extensive kernel performance numbers, you need to purchase GlancePlus with the Measureware package. The program midaemon runs in realtime and collects data from proprietary kernel structures and measurement points that top cannot access.


Bill Hassell, sysadmin