*BSD News Article 78383


Return to BSD News archive

Newsgroups: comp.unix.programmer,comp.os.linux.development.apps,comp.unix.bsd.freebsd.misc
Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!news.ecn.uoknor.edu!news.wildstar.net!news.ececs.uc.edu!news.kei.com!newsfeed.internetmci.com!news.sgi.com!spool.mu.edu!newspump.sol.net!news.mindspring.com!uunet!in2.uu.net!EU.net!sun4nl!rnzll3!sys3.pe1chl!rob
From: rob@pe1chl.ampr.org (Rob Janssen)
Subject: Re: System call for querying system load?
X-Newsreader: NN version 6.5.0 (NOV)
Reply-To: pe1chl@amsat.org
Organization: PE1CHL
Message-ID: <DxrMGE.59t@pe1chl.ampr.org>
References: <51cjj1$1k7@news.cyberenet.net>
Date: Sun, 15 Sep 1996 08:33:49 GMT
Lines: 53
Xref: euryale.cc.adfa.oz.au comp.unix.programmer:43255 comp.os.linux.development.apps:21850 comp.unix.bsd.freebsd.misc:27313

In <51cjj1$1k7@news.cyberenet.net> harry@cyberenet.net (Harry Hochheiser) writes:


>I'm looking for a system call/subroutine that will let me query the system 
>load.  This call would return information similar to that found in uptime(1), 
>and should be roughly portable across BSD-like Unixes (i.e, Linux's sysinfo() 
>won't work, even though that's my primary environment.

There isn't any.  Retrieving the load average is a very non-portable
operation, apparently nobody in the standards committees thought about
a system call for this.
Look in the get_load.c file in the sources for xload (it is distributed
as a part of procps).  There you can find a #ifdef-saturated list of
different methods to get the load average.

>While I'm at it, can anyone clue me in to a source describing proper 
>interpretation of the load averages returned by uptime?

The load average is the number of processes that are ready-to-run (i.e.
that would get the processor if it is available), averaged over some
different periods of time.  The first number is a short-term average,
the others are longer-term.

So, the load average could be used as an estimate of the number of
processors required in a multi-processor system to keep the processes
from being blocked waiting for a processor (rather than for input/output).

Unfortunately there is a bug in the load average calculation in Linux,
that causes the load average to go up when a process is in an uninterruptible
sleep (while in that case it usually is blocked waiting on disk, rather
than processor).  The following patch can be used to solve that:

*** linux/kernel/sched.c~	Fri Dec 10 00:38:26 1993
--- linux/kernel/sched.c	Fri Dec 10 01:10:50 1993
***************
*** 441,447 ****
  
  	for(p = &LAST_TASK; p > &FIRST_TASK; --p)
  		if (*p && ((*p)->state == TASK_RUNNING ||
- 			   (*p)->state == TASK_UNINTERRUPTIBLE ||
  			   (*p)->state == TASK_SWAPPING))
  			nr += FIXED_1;
  	return nr;
--- 441,446 ----

As you can see in the headers, the problem has been there for a long
time...  Unfortunately Linus considers it a feature, so he won't fix it.

Rob
-- 
+------------------------------------+--------------------------------------+
| Rob Janssen       pe1chl@amsat.org | WWW: http://www.knoware.nl/users/rob |
| AMPRnet:       rob@pe1chl.ampr.org | AX.25 BBS: PE1CHL@PI8WNO.#UTR.NLD.EU |
+------------------------------------+--------------------------------------+