asjo@koldfront.dk (Adam Sjøgren) writes:
>> Den formulering er dog ikke helt korrekt. Det er faktisk ikke
>> gennemsnittet for et specifikt interval, men derimod et expontential
>> fading average. Hvad de 1, 5 og 15 minutter så helt præcist dækker
>> over ved jeg ikke, måske er det halveringstiden.
>
> Kan I ikke være rare at give referencer til de definitioner I giver?
Det kan godt være at jeg leder de forkerte steder, men jeg *kan* ikke
lige finde dokumentation. Så er det godt vi har sourcen. De tre
load-tal findes i et array der hedder avenrun[3] som er defineret i
<linux/sched.h>:
/*
* These are the constant used to fake the fixed-point load-average
* counting. Some notes:
* - 11 bit fractions expand to 22 bits by the multiplies: this gives
* a load-average precision of 10 bits integer + 11 bits fractional
* - if you want to count load-averages more often, you need more
* precision, or rounding will get you. With 2-second counting freq,
* the EXP_n values would be 1981, 2034 and 2043 if still using only
* 11 bit fractions.
*/
extern unsigned long avenrun[]; /* Load averages */
#define FSHIFT 11 /* nr of bits of precision */
#define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
#define LOAD_FREQ (5*HZ) /* 5 sec intervals */
#define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */
#define EXP_5 2014 /* 1/exp(5sec/5min) */
#define EXP_15 2037 /* 1/exp(5sec/15min) */
#define CALC_LOAD(load,exp,n) \
load *= exp; \
load += n*(FIXED_1-exp); \
load >>= FSHIFT;
Her er den eksponentielt aftagende gennemsnit. Selve udregningen af
load foregår i kernel/timer.c hvor man primært kan se at det er tasks
der er markeret running eller uninterruptible der tælles:
/*
* Nr of active tasks - counted in fixed-point numbers
*/
static unsigned long count_active_tasks(void)
{
struct task_struct *p;
unsigned long nr = 0;
read_lock(&tasklist_lock);
for_each_task(p) {
if ((p->state == TASK_RUNNING ||
(p->state & TASK_UNINTERRUPTIBLE)))
nr += FIXED_1;
}
read_unlock(&tasklist_lock);
return nr;
}
/*
* Hmm.. Changed this, as the GNU make sources (load.c) seems to
* imply that avenrun[] is the standard name for this kind of thing.
* Nothing else seems to be standardized: the fractional size etc
* all seem to differ on different machines.
*/
unsigned long avenrun[3];
static inline void calc_load(unsigned long ticks)
{
unsigned long active_tasks; /* fixed-point */
static int count = LOAD_FREQ;
count -= ticks;
if (count < 0) {
count += LOAD_FREQ;
active_tasks = count_active_tasks();
CALC_LOAD(avenrun[0], EXP_1, active_tasks);
CALC_LOAD(avenrun[1], EXP_5, active_tasks);
CALC_LOAD(avenrun[2], EXP_15, active_tasks);
}
}
--
Peter Makholm | What if:
peter@makholm.net | IBM bought Xenix from Microsoft instead of buying
http://hacking.dk | DOS?