分类: LINUX
2008-08-20 18:17:44
//kernel/timer.c 1254active_tasks=count_active_tasks(); 1256CALC_LOAD(avenrun[0],EXP_1,active_tasks); 1257CALC_LOAD(avenrun[1],EXP_5,active_tasks); 1258CALC_LOAD(avenrun[2],EXP_15,active_tasks); //include/linux/sched.h 110#defineFSHIFT11/*nrofbitsofprecision*/ 111#defineFIXED_1(1< 112#defineLOAD_FREQ(5*HZ)/*5secintervals*/ 113#defineEXP_11884/*1/exp(5sec/1min)asfixed-point*/ 114#defineEXP_52014/*1/exp(5sec/5min)*/ 115#defineEXP_152037/*1/exp(5sec/15min)*/ 117#defineCALC_LOAD(load,exp,n)\ 118load*=exp;\ 119load =n*(FIXED_1-exp);\ 120load>>=FSHIFT; load(t)=(load(t-1)*exp(i) n(t)*(2048-exp(i)))/2048 load(t-1)为上次计算出的结果 n(t)为t时刻的活动进程数 计算方式是累加各个CPU的运行队列中running和uninterruptible的值 再乘以2048 计算方式如下: 1946unsignedlongnr_active(void) 1947{ 1948unsignedlongi,running=0,uninterruptible=0; 1949 1950for_each_online_cpu(i){ 1951running =cpu_rq(i)->nr_running; 1952uninterruptible =cpu_rq(i)->nr_uninterruptible; 1953} 1954 1955if(unlikely((long)uninterruptible<0)) 1956uninterruptible=0; 1957 1958returnrunning uninterruptible; 1959} 1226staticunsignedlongcount_active_tasks(void) 1227{ 1228returnnr_active()*FIXED_1; 1229} exp(1)=1884 exp(5)=2014 exp(15)=2037 exp(i)=2048*e^(-1/12/i)