Article Title: definitions of loads in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Using the uptime or top command, you can see the output of a load, such as load average: 0.00, 0.03, 0.00. What is this load? man's document is just a document, there is no specific definition of the load.
Load statistics must be completed by the kernel. Therefore, it is better to find the answer in the kernel source code. Find the kernel source code 2.6.21 and start exploring.
Source code excerpt:
// Kernel/timer. c
1254 active_tasks = count_active_tasks();
1256 CALC_LOAD(avenrun[0], EXP_1, active_tasks); 1257 CALC_LOAD(avenrun[1], EXP_5, active_tasks); 1258 CALC_LOAD(avenrun[2], EXP_15, active_tasks);
//include/linux/sched.h
110 #define FSHIFT 11 /* nr of bits of precision */ 111 #define FIXED_1 (1< 112 #define LOAD_FREQ (5*HZ) /* 5 sec intervals */ 113 #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */ 114 #define EXP_5 2014 /* 1/exp(5sec/5min) */ 115 #define EXP_15 2037 /* 1/exp(5sec/15min) */ 117 #define CALC_LOAD(load,exp,n) \ 118 load *= exp; \ 119 load += n*(FIXED_1-exp); \ 120 load >>= FSHIFT;
|
Load (t) = (load (t-1) * exp (I) + n (t) * (2048-exp (I)/2048
Load (t-1) is the result of the last Calculation
N (t) indicates the number of active processes at t time.
The calculation method is to accumulate the running and uninterruptible values in the running queue of each CPU and multiply them by 2048.
The calculation method is as follows:
1946 unsigned long nr_active (void) 1947 {1948 unsigned long I, running = 0, uninterruptible = 0; 1949 1950 for_each_online_cpu (I) {1951 running + = cpu_rq (I) -> nr_running; 1952 uninterruptible + = cpu_rq (I)-> nr_uninterruptible; 1953} 1954 1955 if (unlikely (long) uninterruptible <0) 1956 uninterruptible = 0; 1957 1958 return running + uninterruptible; 1959}
1226 static unsigned long count_active_tasks (void) 1227 {1228 return nr_active () * FIXED_1; 1229}
Exp (1) = 1884 exp (5) = 2014 exp (15) = 2037 exp (I) = 2048 * e ^ (-1/12/I)
In essence, the load is determined by the number of active processes on each CPU in the past period of time, but it is not equivalent to the number of processes to be scheduled per second, the specific computing process is a complicated process.