Load (computing): Difference between revisions

Content deleted Content added
Line 35:
 
== Reckoning CPU load ==
On Linux systems, the load-average is not calculated on each clock tick, but driven by a variable value that is based on the HZ frequency setting and tested on each clock tick. (HZThis variablesetting isdefines the pulse rate of particular Linux kernel activity. 1 HZ is equal to one clock tick; 10ms by default.) Although the HZ value can be configuredrate in some[[Hertz]] versions(times ofper the kernelsecond), and it is normally setdefaults to 100. Thefor calculation10mms codeticks. usesKernel theactivities HZuse valuethis tonumber determineof theticks CPUto Loadtime calculation frequencythemselves. Specifically, the timer.c::calc_load() function, willwhich runcalculates the algorithmload average, runs every 5{{tt|1=LOAD_FREQ = (5*HZ+1)}} HZticks, or roughlyabout every five times per secondseconds:
 
<source lang="c">
Line 55:
}
</source>
 
The countdown is over a {{code|LOAD_FREQ}} of 5&nbsp;HZ.<ref group="note">
<poem>
1 HZ = 100 ticks
5 HZ = 500 ticks
1 tick = 10 milliseconds
500 ticks = 5000 milliseconds (or 5 seconds)
So, 5 HZ means that {{code|CALC_LOAD}} is called every 5 seconds.
</poem>
</ref>
The avenrun array contains 1-minute, 5-minute and 15-minute average. The {{code|CALC_LOAD}} macro and its associated values are defined in sched.h:
 
Line 69 ⟶ 61:
#define FSHIFT 11 /* nr of bits of precision */
#define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
#define LOAD_FREQ (5*HZ+1) /* 5 sec intervals */
#define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */
#define EXP_5 2014 /* 1/exp(5sec/5min) */
Line 79 ⟶ 71:
load >>= FSHIFT;
</source>
 
The "sampled" calculation of load averages is a somewhat common behavior; FreeBSD, too, only refereshes the value every five seconds. The interval is usually taken to not be exact so that they do not collect processes that are scheduled to fire at a certain moment.<ref>{{cite web |title=How is load average calculated on FreeBSD? |url=https://unix.stackexchange.com/a/342778 |website=Unix & Linux Stack Exchange}}</ref> A post on the Linux mailing list considers the {{tt|+1}} tick insufficient to avoid such collection, and suggests an interval of 4.61 seconds instead.<ref>{{cite web |last1=Ripke |first1=Klaus |title=Linux-Kernel Archive: LOAD_FREQ (4*HZ+61) avoids loadavg Moire |url=http://lkml.iu.edu/hypermail/linux/kernel/1111.1/02446.html |website=lkml.iu.edu |date=2011}}</ref>
 
==Other system performance commands==