minix/servers/procfs/util.c
Gianluca Guida cc17b27a2b Build NetBSD libc library in world in ELF mode.
3 sets of libraries are built now:
  . ack: all libraries that ack can compile (/usr/lib/i386/)
  . clang+elf: all libraries with minix headers (/usr/lib/)
  . clang+elf: all libraries with netbsd headers (/usr/netbsd/)

Once everything can be compiled with netbsd libraries and headers, the
/usr/netbsd hierarchy will be obsolete and its libraries compiled with
netbsd headers will be installed in /usr/lib, and its headers
in /usr/include. (i.e. minix libc and current minix headers set
will be gone.)

To use the NetBSD libc system (libraries + headers) before
it is the default libc, see:
   http://wiki.minix3.org/en/DevelopersGuide/UsingNetBSDCode
This wiki page also documents the maintenance of the patch
files of minix-specific changes to imported NetBSD code.

Changes in this commit:
  . libsys: Add NBSD compilation and create a safe NBSD-based libc.
  . Port rest of libraries (except libddekit) to new header system.
  . Enable compilation of libddekit with new headers.
  . Enable kernel compilation with new headers.
  . Enable drivers compilation with new headers.
  . Port legacy commands to new headers and libc.
  . Port servers to new headers.
  . Add <sys/sigcontext.h> in compat library.
  . Remove dependency file in tree.
  . Enable compilation of common/lib/libc/atomic in libsys
  . Do not generate RCSID strings in libc.
  . Temporarily disable zoneinfo as they are incompatible with NetBSD format
  . obj-nbsd for .gitignore
  . Procfs: use only integer arithmetic. (Antoine Leca)
  . Increase ramdisk size to create NBSD-based images.
  . Remove INCSYMLINKS handling hack.
  . Add nbsd_include/sys/exec_elf.h
  . Enable ELF compilation with NBSD libc.
  . Add 'make nbsdsrc' in tools to download reference NetBSD sources.
  . Automate minix-port.patch creation.
  . Avoid using fstavfs() as it is *extremely* slow and unneeded.
  . Set err() as PRIVATE to avoid name clash with libc.
  . [NBSD] servers/vm: remove compilation warnings.
  . u32 is not a long in NBSD headers.
  . UPDATING info on netbsd hierarchy
  . commands fixes for netbsd libc
2011-06-24 11:46:30 +02:00

65 lines
1.9 KiB
C

/* ProcFS - util.c - by Alen Stojanov and David van Moolenbroek */
#include "inc.h"
/*===========================================================================*
* procfs_getloadavg *
*===========================================================================*/
PUBLIC int procfs_getloadavg(struct load *loadavg, int nelem)
{
/* Retrieve system load average information.
*/
struct loadinfo loadinfo;
u32_t system_hz, ticks_per_slot;
int p, unfilled_ticks;
int minutes[3] = { 1, 5, 15 };
ssize_t l;
if(nelem < 1) {
errno = ENOSPC;
return -1;
}
system_hz = sys_hz();
if((l=sys_getloadinfo(&loadinfo)) != OK)
return -1;
if(nelem > 3)
nelem = 3;
/* How many ticks are missing from the newest-filled slot? */
ticks_per_slot = _LOAD_UNIT_SECS * system_hz;
unfilled_ticks =
ticks_per_slot - (loadinfo.last_clock % ticks_per_slot);
for(p = 0; p < nelem; p++) {
int h, slots;
int latest = loadinfo.proc_last_slot;
slots = minutes[p] * 60 / _LOAD_UNIT_SECS;
loadavg[p].proc_load = 0;
/* Add up the total number of process ticks for this number
* of minutes (minutes[p]). Start with the newest slot, which
* is latest, and count back for the number of slots that
* correspond to the right number of minutes. Take wraparound
* into account by calculating the index modulo _LOAD_HISTORY,
* which is the number of slots of history kept.
*/
for(h = 0; h < slots; h++) {
int slot;
slot = (latest - h + _LOAD_HISTORY) % _LOAD_HISTORY;
loadavg[p].proc_load +=
loadinfo.proc_load_history[slot];
l += (double) loadinfo.proc_load_history[slot];
}
/* The load average over this number of minutes is the number
* of process-ticks divided by the number of ticks, not
* counting the number of ticks the last slot hasn't been
* around yet.
*/
loadavg[p].ticks = slots * ticks_per_slot - unfilled_ticks;
}
return nelem;
}