使用uptime或者top命令,都可以看到一个负载的输出,形如load average: 0.00, 0.03, 0.00,这个负载到底是什么东西呢,man文档里只是一笔带过,没有具体的给出负载的定义。
负载的统计,必然是由内核完成的,因此在内核源码中找答案是再好不过的事情了,找来2.6.21的内核源码,开始探索。
节选部分源码:
//kernel/timer.c
1254 active_tasks = count_active_tasks();
1256 CALC_LOAD(avenrun[0], EXP_1, active_tasks);
1257 CALC_LOAD(avenrun[1], EXP_5, active_tasks);
1258 CALC_LOAD(avenrun[2], EXP_15, active_tasks);
//include/linux/sched.h
110 #define FSHIFT 11 /* nr of bits of precision */
111 #define ...[ 查看全文 ]