From: Ben Gras Date: Thu, 11 Dec 2008 14:37:18 +0000 (+0000) Subject: dynamic HZ X-Git-Tag: v3.1.4~197 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/Bv9ARM.html?a=commitdiff_plain;h=991000dd70beff287322a3f6113f7f73a9d237d6;p=minix.git dynamic HZ --- diff --git a/lib/posix/getloadavg.c b/lib/posix/getloadavg.c index 82fceba1c..adca7d847 100755 --- a/lib/posix/getloadavg.c +++ b/lib/posix/getloadavg.c @@ -9,16 +9,25 @@ int getloadavg(double *loadavg, int nelem) { struct loadinfo loadinfo; + static u32_t system_hz = 0; int h, p, unfilled_ticks; #define PERIODS 3 int minutes[3] = { 1, 5, 15 }; size_t loadsize; ssize_t l; + if(nelem < 1) { errno = ENOSPC; return -1; } + if(system_hz == 0) { + if((getsysinfo_up(PM_PROC_NR, SIU_SYSTEMHZ, + sizeof(system_hz), &system_hz)) < 0) { + system_hz = DEFAULT_HZ; + } + } + loadsize = sizeof(loadinfo); if((l=getsysinfo_up(PM_PROC_NR, SIU_LOADINFO, loadsize, &loadinfo)) < 0) return -1; @@ -28,7 +37,7 @@ int getloadavg(double *loadavg, int nelem) nelem = PERIODS; /* How many ticks are missing from the newest-filled slot? */ -#define TICKSPERSLOT (_LOAD_UNIT_SECS * sys_hz()) +#define TICKSPERSLOT (_LOAD_UNIT_SECS * system_hz) unfilled_ticks = TICKSPERSLOT - (loadinfo.last_clock % TICKSPERSLOT); for(p = 0; p < nelem; p++) {