In the tradition of UTSL, I've pasted in the code that runs the calculation. Here,
nrun=sched_load() is the total "ready to run" processes this instant and avg is pointing to a structure with 3 fixed point numbers (1,5,15 minutes). cexp are magic numbers to decay the values for 1,5 and 15 minutes. For reference, this is in
/usr/src/sys/kern/kern_synch.c ... which I might recommend as a fascinating read.
In FreeBSD, what most surprises people about responsive machines with high load averages is that a spot awakening of a large number of processes can inflate the numbers greatly. IE: if 400-ish processes all awake together (web servers or database servers sometimes do this.)
* Compute a tenex style load average of a quantity on
* 1, 5 and 15 minute intervals.
int i, nrun;
struct loadavg *avg;
nrun = sched_load();
avg = &averunnable;
for (i = 0; i < 3; i++)
avg->ldavg[i] = (cexp[i] * avg->ldavg[i] +
nrun * FSCALE * (FSCALE - cexp[i])) >> FSHIFT;
* Schedule the next update to occur after 5 seconds, but add a
* random variation to avoid synchronisation with processes that
* run at regular intervals.
SBT_1US * (4000000 + (int)(random() % 2000001)), SBT_1US,
loadav, NULL, C_DIRECT_EXEC | C_PREL(32));