Ingo Molnar | badaff8 | 2017-02-08 08:45:17 +0100 | [diff] [blame] | 1 | #ifndef _LINUX_SCHED_LOADAVG_H |
| 2 | #define _LINUX_SCHED_LOADAVG_H |
| 3 | |
Ingo Molnar | 06455d7 | 2017-02-01 18:25:37 +0100 | [diff] [blame] | 4 | /* |
| 5 | * These are the constant used to fake the fixed-point load-average |
| 6 | * counting. Some notes: |
| 7 | * - 11 bit fractions expand to 22 bits by the multiplies: this gives |
| 8 | * a load-average precision of 10 bits integer + 11 bits fractional |
| 9 | * - if you want to count load-averages more often, you need more |
| 10 | * precision, or rounding will get you. With 2-second counting freq, |
| 11 | * the EXP_n values would be 1981, 2034 and 2043 if still using only |
| 12 | * 11 bit fractions. |
| 13 | */ |
| 14 | extern unsigned long avenrun[]; /* Load averages */ |
| 15 | extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift); |
| 16 | |
| 17 | #define FSHIFT 11 /* nr of bits of precision */ |
| 18 | #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */ |
| 19 | #define LOAD_FREQ (5*HZ+1) /* 5 sec intervals */ |
| 20 | #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */ |
| 21 | #define EXP_5 2014 /* 1/exp(5sec/5min) */ |
| 22 | #define EXP_15 2037 /* 1/exp(5sec/15min) */ |
| 23 | |
Johannes Weiner | f1675aa | 2018-10-26 15:06:11 -0700 | [diff] [blame] | 24 | /* |
| 25 | * a1 = a0 * e + a * (1 - e) |
| 26 | */ |
| 27 | static inline unsigned long |
| 28 | calc_load(unsigned long load, unsigned long exp, unsigned long active) |
| 29 | { |
| 30 | unsigned long newload; |
| 31 | |
| 32 | newload = load * exp + active * (FIXED_1 - exp); |
| 33 | if (active >= load) |
| 34 | newload += FIXED_1-1; |
| 35 | |
| 36 | return newload / FIXED_1; |
| 37 | } |
| 38 | |
Johannes Weiner | 3cd62fc | 2018-10-26 15:06:16 -0700 | [diff] [blame] | 39 | extern unsigned long calc_load_n(unsigned long load, unsigned long exp, |
| 40 | unsigned long active, unsigned int n); |
| 41 | |
Johannes Weiner | f1675aa | 2018-10-26 15:06:11 -0700 | [diff] [blame] | 42 | #define LOAD_INT(x) ((x) >> FSHIFT) |
| 43 | #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) |
Ingo Molnar | 06455d7 | 2017-02-01 18:25:37 +0100 | [diff] [blame] | 44 | |
| 45 | extern void calc_global_load(unsigned long ticks); |
| 46 | |
Ingo Molnar | badaff8 | 2017-02-08 08:45:17 +0100 | [diff] [blame] | 47 | #endif /* _LINUX_SCHED_LOADAVG_H */ |