Content deleted Content added
m →Reckoning CPU load: Typo fixing, replaced: refereshes → refreshes |
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags |
||
Line 5:
== Unix-style load calculation ==
All Unix and Unix-like systems generate a dimensionless [[Software metric|metric]] of three "load average" numbers in the [[kernel (computer science)|kernel]]. Users can easily query the current result from a [[Unix shell]] by running the <code>[[uptime]]</code> command:
<
$ uptime
14:34:03 up 10:43, 4 users, load average: 0.06, 0.11, 0.09
</syntaxhighlight>
The [[W (Unix)|<code>w</code>]] and [[Top (Unix)|<code>top</code>]] commands show the same three load average numbers, as do a range of [[graphical user interface]] utilities. In [[Linux]], they can also be accessed by reading the [[procfs|<code>/proc/loadavg</code>]] file.
Line 38:
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. This setting defines the kernel clock tick rate in [[Hertz]] (times per second), and it defaults to 100 for 10ms ticks. Kernel activities use this number of ticks to time themselves. Specifically, the timer.c::calc_load() function, which calculates the load average, runs every {{tt|1=LOAD_FREQ = (5*HZ+1)}} ticks, or about every five seconds:
<
unsigned long avenrun[3];
Line 55:
}
}
</syntaxhighlight>
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:
<
#define FSHIFT 11 /* nr of bits of precision */
#define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
Line 71:
load += n*(FIXED_1-exp); \
load >>= FSHIFT;
</syntaxhighlight>
The "sampled" calculation of load averages is a somewhat common behavior; FreeBSD, too, only refreshes 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>
|