Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_SCHED_LOADAVG_H
0003 #define _LINUX_SCHED_LOADAVG_H
0004 
0005 /*
0006  * These are the constant used to fake the fixed-point load-average
0007  * counting. Some notes:
0008  *  - 11 bit fractions expand to 22 bits by the multiplies: this gives
0009  *    a load-average precision of 10 bits integer + 11 bits fractional
0010  *  - if you want to count load-averages more often, you need more
0011  *    precision, or rounding will get you. With 2-second counting freq,
0012  *    the EXP_n values would be 1981, 2034 and 2043 if still using only
0013  *    11 bit fractions.
0014  */
0015 extern unsigned long avenrun[];     /* Load averages */
0016 extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift);
0017 
0018 #define FSHIFT      11      /* nr of bits of precision */
0019 #define FIXED_1     (1<<FSHIFT) /* 1.0 as fixed-point */
0020 #define LOAD_FREQ   (5*HZ+1)    /* 5 sec intervals */
0021 #define EXP_1       1884        /* 1/exp(5sec/1min) as fixed-point */
0022 #define EXP_5       2014        /* 1/exp(5sec/5min) */
0023 #define EXP_15      2037        /* 1/exp(5sec/15min) */
0024 
0025 /*
0026  * a1 = a0 * e + a * (1 - e)
0027  */
0028 static inline unsigned long
0029 calc_load(unsigned long load, unsigned long exp, unsigned long active)
0030 {
0031     unsigned long newload;
0032 
0033     newload = load * exp + active * (FIXED_1 - exp);
0034     if (active >= load)
0035         newload += FIXED_1-1;
0036 
0037     return newload / FIXED_1;
0038 }
0039 
0040 extern unsigned long calc_load_n(unsigned long load, unsigned long exp,
0041                  unsigned long active, unsigned int n);
0042 
0043 #define LOAD_INT(x) ((x) >> FSHIFT)
0044 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
0045 
0046 extern void calc_global_load(void);
0047 
0048 #endif /* _LINUX_SCHED_LOADAVG_H */