
Average load? That the system in a period of time the average number of processes, which means that the system is busy. Average load and CPU utilization is not the same, more able to express the system's busy, the following will be the system's average load calculation and related to a brief introduction.
View method
Linux system using the uptime command, or view / proc / loadavg can see the system load average load. Use the uptime command to display the average load for the system in the last 1 minute, 5 minutes, and 10 minutes, respectively.
[Root @ localhost ~] # uptime
19:32:09 up 5 days, 8:53, 5 users, load average: 0.05, 0.04, 0.05
[Root @ localhost ~] # cat / proc / loadavg
0.04 0.04 0.05 1/394 23203
Then uptime command to calculate the load average of the working principle of what is it?
Calculation method
For a single cpu and multicpu situation, the system's average load situation is slightly different. Single cpu is the simplest case, such as the average of the past one minute inside to determine the system is running or waiting for the number of processes that the average load of the system, but slightly different in the linux system, those in io wait state of the process Will be incorporated into the calculation. This can lead to CPU utilization and the average load is very different in most of the processes are doing IO, even if the average load is great, there will be no great CPU utilization. In addition, some systems for the process and the thread is also very different, some for each thread will be calculated, some only concerned about the process, for HyperThreading Technology thread, it may be another way. For multiCPU average load calculation, in the case of singleCPU divided by the number of CPU.
File: kernel / timer.c:
Unsigned long avenrun [3];
Static inline void calc_load (unsigned long ticks)
{
Unsigned long active_tasks; / * fixedpoint * /
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);
}}
}}
The function sched.h in the kernel
/ *
* These are the constant used to fake the fixedpoint loadaverage
* Counting. Some notes:
*  11 bit fractions expand to 22 bits by the multiplies: this gives
* A loadaverage precision of 10 bits integer + 11 bits fractional
*  if you want to count loadaverages more often, you need more
* Precision, or rounding will get you. With 2second 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 * /
Extern void get_avenrun (unsigned long * loads, unsigned long offset, int shift);
#define FSHIFT 11 / * nr of bits of precision * /
#define FIXED_1 (1 < < FSHIFT) / * 1.0 as fixedpoint * /
#define LOAD_FREQ (5 * HZ + 1) / * 5 sec intervals * /
#define EXP_1 1884 / * 1 / exp (5sec / 1min) as fixedpoint * /
#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_1exp); \
Load >> = FSHIFT;
Extern unsigned long total_forks;
Extern int nr_threads;
DECLARE_PER_CPU (unsigned long, process_counts);
Extern int nr_processes (void);
Extern unsigned long nr_running (void);
Extern unsigned long nr_uninterruptible (void);
Extern unsigned long nr_iowait (void);
Extern unsigned long nr_iowait_cpu (int cpu);
Extern unsigned long this_cpu_load (void);
Ewma algorithm
Linux system in many ways the use of this algorithm, such as TC system in addition to this there is the CBQ algorithm, which is an algorithm of statistics 


