Misreporting cpu - linux+smp

From: Dancer <dancer@dont-contact.us>
Date: Mon, 15 Feb 1999 12:19:05 +1100

Here's a bit of fun, kids.

Assume you have a linux box, with multiple CPU's. (For the sake of
argument, a twin xeon 450)

Now, calculation of CPU usage is an inexact science. Occasionally the
operating system may report _slightly_ more than 100%. (Say, 100.01%)
This can happen even on single processor systems, but happens much more
commonly on SMP boxen.

Squid (like most tools that access CPU statistics) sees numbers like
101% as 4294967294 (4294967295 is the maximum value of a UINT for
reference). This isn't squid's fault...but it throws the numbers way out
of whack. Since squid keeps an _average_ CPU load, once the damage is
done, you're stuck with impossible load figures until your next squid
shutdown.

There _is_ a simple alogorithm to avoid this, that seems to work. It's
ugly and quite Not Nice(tm), but it does work:

if(load>4290000000) load=4294967295-load;

That _should_ give you a true figure (up to 400%, say, if you have four
CPU's). I figure it's better to have a number that resolves to
100%*number_of_cpus than to try to make the application aware of how
many CPUs there actually are.

D
Received on Sun Feb 14 1999 - 18:00:26 MST

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:44:33 MST