load average
生活随笔
收集整理的這篇文章主要介紹了
load average
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
\linux\include\linux\sched.h中定義的有關頻率,load average的相關常數與變量 #define HZ 100 //定義時鐘頻率,兩個時鐘間隔時間為10ms /** These are the constant used to fake the fixed-point load-average* counting. Some notes: * - 11 bit fractions expand to 22 bits by the multiplies: this gives 11bit* a load-average precision of 10 bits integer + 11 bits fractional* - if you want to count load-averages more often, you need more* precision, or rounding will get you. With 2-second 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 */#define FSHIFT 11 /* nr of bits of precision */ #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */ #define LOAD_FREQ (5*HZ) /* 5 sec intervals */ #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */ #define EXP_5 2014 /* 1/exp(5sec/5min) */ #define EXP_15 2037 /* 1/exp(5sec/15min) */ #define CALC_LOAD(load,exp,n) \ //n=active_tasks活動進程數 ,load各個exp計算得到的average loadload *= exp; \load += n*(FIXED_1-exp); \load >>= FSHIFT; load=(exp*load+n*(2048-exp))>>11。由這個式子來看,所謂的load只與當前活躍進程數有關。 \linux-2.4.x\kernel\timer.c中定義load average的計算函數。 unsigned long avenrun[3];static inline void calc_load(unsigned long ticks) {unsigned long active_tasks; /* fixed-point */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);} } \linux-2.4.x\fs\proc\proc_misc.c中定義使用uptime命令時調用load average顯示函數的實現方式 static int loadavg_read_proc(char *page, char **start, off_t off,int count, int *eof, void *data) {int a, b, c;int len;a = avenrun[0] + (FIXED_1/200);b = avenrun[1] + (FIXED_1/200);c = avenrun[2] + (FIXED_1/200);len = sprintf(page,"%d.%02d %d.%02d %d.%02d %d/%d %d\n",LOAD_INT(a), LOAD_FRAC(a),LOAD_INT(b), LOAD_FRAC(b),LOAD_INT(c), LOAD_FRAC(c),nr_running, nr_threads, last_pid);return proc_calc_metrics(page, start, off, count, eof, len); }?http://www.yeeyan.org/articles/view/79184/37314
?
?
轉載于:https://my.oschina.net/u/138195/blog/91490
總結
以上是生活随笔為你收集整理的load average的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux使用dd命令快速生成大文件
- 下一篇: zipimport.ZipImportE