- 论坛徽章:
- 0
|
我们在top查看系统负载情况,1,5,15分钟的负载情况,查看top代码,知道其是读取proc下的/proc/loadavg文件
而又知道内核中设置loadavg文件的代码是(版本2.6.12):
- 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 %ld/%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);
- }
复制代码
另外找到了:
- unsigned long avenrun[3];
- EXPORT_SYMBOL(avenrun);
- /*
- * calc_load - given tick count, update the avenrun load estimates.
- * This is called while holding a write_lock on xtime_lock.
- */
- 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);
- }
- }
复制代码
哪位大侠能帮忙讲解下,这个负载具体是如何计算出来的吗?
谢谢! |
|