From 816277335aed745e24f3f072f0e3d5b0780bcc35 Mon Sep 17 00:00:00 2001 From: gatieme Date: Mon, 20 Jun 2016 11:53:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E7=A8=8B=E8=B0=83=E5=BA=A6=E4=B9=8B?= =?UTF-8?q?=E4=BC=98=E5=85=88=E7=BA=A7=E8=AF=A6=E8=A7=A3...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../05-schedule/04-priority/README.md | 21 ++++++++++++++++--- .../05-schedule/06-load_weight/README.md | 2 -- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/study/kernel/01-process/05-schedule/04-priority/README.md b/study/kernel/01-process/05-schedule/04-priority/README.md index e4b1800..d92535b 100644 --- a/study/kernel/01-process/05-schedule/04-priority/README.md +++ b/study/kernel/01-process/05-schedule/04-priority/README.md @@ -124,6 +124,9 @@ linux把进程区分为实时进程和非实时进程, 其中非实时进程进 这需要与CPU的紧密交互. 每个进程刚好属于某一调度类, 各个调度类负责管理所属的进程. 通用调度器自身不涉及进程管理, 其工作都委托给调度器类. +#linux优先级的表示 +------- + ##优先级的内核表示 ------- @@ -256,10 +259,10 @@ static inline bool dl_time_before(u64 a, u64 b) { return (s64)(a - b) < 0; } -```` +``` -#进程的优先级表示 +##进程的优先级表示 ------- @@ -300,9 +303,11 @@ struct task_struct 实时进程的优先级用实时优先级rt_priority来表示 + #进程优先级的计算 ------- + 前面说了task_struct中的几个优先级的字段 | 静态优先级 | 普通优先级 | 动态优先级 | 实时优先级 | @@ -368,6 +373,7 @@ static inline int normal_prio(struct task_struct *p) 定义在[kernel/sched/sched.h#L117](http://lxr.free-electrons.com/source/kernel/sched/sched.h?v=4.6#L117) 中 其本质其实就是传入task->policy调度策略字段看其值等于SCHED_NORMAL, SCHED_BATCH, SCHED_IDLE, SCHED_FIFO, SCHED_RR, SCHED_DEADLINE中的哪个, 从而确定其所属的调度类, 进一步就确定了其进程类型 + ```c static inline int idle_policy(int policy) { @@ -432,7 +438,7 @@ MAX_RT_PRIO = 100, ;这样意味着rt_priority值越大,优先级越高; ##effective_prio设置动态优先级prio ------- -可以通过函数effective_prio用静态优先级static_prio计算动态优先级, 即· +可以通过函数effective_prio用静态优先级static_prio计算动态优先级prio, 即· ```c p->prio = effective_prio(p); @@ -591,6 +597,10 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p) #总结 ------- +task_struct采用了四个成员表示进程的优先级:prio和normal_prio表示动态优先级, static_prio表示进程的静态优先级. 同时还用了rt_priority表示实时进程的优先级 + + + | 字段 | 描述 | | ------------- |:-------------:| @@ -600,6 +610,11 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p) | rt_priority | 实时进程的静态优先级 | +调度器会考虑的优先级则保存在prio. 由于在某些情况下内核需要暂时提高进程的优先级, 因此需要用prio表示. 由于这些改变不是持久的, 因此静态优先级static_prio和普通优先级normal_prio不受影响. +此外还用了一个字段rt_priority保存了实时进程的优先级静态优先级static_prio(普通进程)和实时优先级rt_priority(实时进程)是计算的起点, 通过他们计算进程的普通优先级normal_prio和动态优先级prio. + +内核通过normal_prIo函数计算普通优先级normal_prio +通过effective_prio函数计算动态优先级prio >参考 > diff --git a/study/kernel/01-process/05-schedule/06-load_weight/README.md b/study/kernel/01-process/05-schedule/06-load_weight/README.md index 87816c3..fb5b05d 100644 --- a/study/kernel/01-process/05-schedule/06-load_weight/README.md +++ b/study/kernel/01-process/05-schedule/06-load_weight/README.md @@ -35,8 +35,6 @@ linux把进程区分为实时进程和非实时进程, 其中非实时进程进 | 批处理进程(batch process) | 此类进程不必与用户交互, 因此经常在后台运行. 因为这样的进程不必很快相应, 因此常受到调度程序的怠慢 | 程序语言的编译程序, 数据库搜索引擎以及科学计算 | | 实时进程(real-time process) | 这些进程由很强的调度需要, 这样的进程绝不会被低优先级的进程阻塞. 并且他们的响应时间要尽可能的短 | 视频音频应用程序, 机器人控制程序以及从物理传感器上收集数据的程序| -在linux中, 调度算法可以明确的确认所有实时进程的身份, 但是没办法区分交互式程序和批处理程序, linux2.6的调度程序实现了基于进程过去行为的启发式算法, 以确定进程应该被当做交互式进程还是批处理进程. 当然与批处理进程相比, 调度程序有偏爱交互式进程的倾向 - ##不同进程采用不同的调度策略 -------