Chinaunix首页 | 论坛 | 博客
  • 博客访问: 303154
  • 博文数量: 94
  • 博客积分: 2163
  • 博客等级: 大尉
  • 技术积分: 932
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-20 09:23
文章存档

2012年(2)

2011年(92)

分类: LINUX

2011-10-08 19:52:34

  进程运行一个quantum(量子),quantum由进程的static priority决定的,公式如下:
 每个进程运行一个quantum,这个quantum是由进程的static priority决定的,计算公式如下:
base time quantum=
(140-static priority)*20 if static priority<120
(140-static priority)*5  if static priority>=120
conventional process's static priority位于(100,139)
real-time process's static priority位于(0,100)
处于TASK_RUNNING的进程被sheduler分为两类:
当进程未运行完quantum,则属于active process,否则属于expired process;
一般地说只有当active process都运行完后,才会调度expired process,但事实上没这么简单:
However, the general schema is slightly more complicated than this, because the scheduler tries to boost the performance of interactive processes. An
active batch process that finishes its time quantum always becomes expired. An active interactive process that finishes its time quantum usually remains
active: the scheduler refills its time quantum and leaves it in the set of active processes. However, the scheduler moves an interactive process that
finished its time quantum into the set of expired processes if the eldest expired process has already waited for a long time, or if an expired process
has higher static priority (lower value) than the interactive process. As a consequence, the set of active processes will eventually become empty and the
expired processes will have a chance to run.
scheduler在判断进程的优先级时,是看dynamic priority而不是static priority,process's dynamic priority由下面的公式进行计算:
dynamic priority=max(100,min(static priority-bonus)+5,139)
其中的bonus是跟进程的执行历史有关的,准确地说是跟进程的average sleep time有关,average sleep time越长,bonus就越大;btw,average sleep time还是linux判断一个进程是
interactive,还是batch。real-time process需要显示进行说明,其它进程则由下面的公式来进行分类:
dynamic priority<=3*static priority/4+28
或者
bonus-5>=static priority/4-28
其中static priority/4-28被称为interactive delta
scheduler选中哪个进程来运行是由进程的dynamic priority来决定的
补充:
nice() and setpriority()不会修改实时进程的优先级,但是会改变进程的base quantum time。
阅读(1283) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~