1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _LINUX_SCHED_LOADAVG_H 2 #ifndef _LINUX_SCHED_LOADAVG_H 3 #define _LINUX_SCHED_LOADAVG_H 3 #define _LINUX_SCHED_LOADAVG_H 4 4 5 /* 5 /* 6 * These are the constant used to fake the fix 6 * These are the constant used to fake the fixed-point load-average 7 * counting. Some notes: 7 * counting. Some notes: 8 * - 11 bit fractions expand to 22 bits by th 8 * - 11 bit fractions expand to 22 bits by the multiplies: this gives 9 * a load-average precision of 10 bits inte 9 * a load-average precision of 10 bits integer + 11 bits fractional 10 * - if you want to count load-averages more 10 * - if you want to count load-averages more often, you need more 11 * precision, or rounding will get you. Wit 11 * precision, or rounding will get you. With 2-second counting freq, 12 * the EXP_n values would be 1981, 2034 and 12 * the EXP_n values would be 1981, 2034 and 2043 if still using only 13 * 11 bit fractions. 13 * 11 bit fractions. 14 */ 14 */ 15 extern unsigned long avenrun[]; /* Loa 15 extern unsigned long avenrun[]; /* Load averages */ 16 extern void get_avenrun(unsigned long *loads, 16 extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift); 17 17 18 #define FSHIFT 11 /* nr 18 #define FSHIFT 11 /* nr of bits of precision */ 19 #define FIXED_1 (1<<FSHIFT) /* 1.0 19 #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */ 20 #define LOAD_FREQ (5*HZ+1) /* 5 s 20 #define LOAD_FREQ (5*HZ+1) /* 5 sec intervals */ 21 #define EXP_1 1884 /* 1/e 21 #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */ 22 #define EXP_5 2014 /* 1/e 22 #define EXP_5 2014 /* 1/exp(5sec/5min) */ 23 #define EXP_15 2037 /* 1/e 23 #define EXP_15 2037 /* 1/exp(5sec/15min) */ 24 24 25 /* 25 /* 26 * a1 = a0 * e + a * (1 - e) 26 * a1 = a0 * e + a * (1 - e) 27 */ 27 */ 28 static inline unsigned long 28 static inline unsigned long 29 calc_load(unsigned long load, unsigned long ex 29 calc_load(unsigned long load, unsigned long exp, unsigned long active) 30 { 30 { 31 unsigned long newload; 31 unsigned long newload; 32 32 33 newload = load * exp + active * (FIXED 33 newload = load * exp + active * (FIXED_1 - exp); 34 if (active >= load) 34 if (active >= load) 35 newload += FIXED_1-1; 35 newload += FIXED_1-1; 36 36 37 return newload / FIXED_1; 37 return newload / FIXED_1; 38 } 38 } 39 39 40 extern unsigned long calc_load_n(unsigned long 40 extern unsigned long calc_load_n(unsigned long load, unsigned long exp, 41 unsigned long 41 unsigned long active, unsigned int n); 42 42 43 #define LOAD_INT(x) ((x) >> FSHIFT) 43 #define LOAD_INT(x) ((x) >> FSHIFT) 44 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1- 44 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) 45 45 46 extern void calc_global_load(void); 46 extern void calc_global_load(void); 47 47 48 #endif /* _LINUX_SCHED_LOADAVG_H */ 48 #endif /* _LINUX_SCHED_LOADAVG_H */ 49 49
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.