linux 负载的定义,Linux操作系统中关于负载的定义

引用:

//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 FIXED_1 (1<

112 #define LOAD_FREQ (5*HZ) /* 5 sec intervals */

113 #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */

114 #define EXP_5 2014 /* 1/exp(5sec/5min) */

115 #define EXP_15 2037 /* 1/exp(5sec/15min) */

117 #define CALC_LOAD(load,exp,n) \

118 load *= exp; \

119 load += n*(FIXED_1-exp); \

120 load >>= FSHIFT;

load(t) = ( load(t-1)*exp(i) + n(t)*(2048-exp(i)) ) / 2048

load(t-1)为上次计算出的结果

n(t)为t时刻的活动进程数

计算方式是累加各个CPU的运行队列中running和uninterruptible的值 再乘以2048

计算方式如下:

1946 unsigned long nr_active(void)

1947 {

1948 unsigned long i, running = 0, uninterruptible = 0;

1949

1950 for_each_online_cpu(i) {

1951 running += cpu_rq(i)->nr_running;

1952 uninterruptible += cpu_rq(i)->nr_uninterruptible;

1953 }

1954

1955 if (unlikely((long)uninterruptible < 0))

1956 uninterruptible = 0;

1957

1958 return running + uninterruptible;

1959 }

1226 static unsigned long count_active_tasks(void)

1227 {

1228 return nr_active() * FIXED_1;

1229 }

exp(1) = 1884

exp(5) = 2014

exp(15) = 2037

exp(i) = 2048 * e^(-1/12/i)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值