自适应分区 Adaptive Partitioning

有个朋友问到QNX的自适应分区(adaptive partitioning),手头没有现成的资料.于是决定简单的写一个.

首先,我们需要了解一下QNX的SCHEDULING(简单起见,只讨论一个CPU的情况):
QNX每个线程都有一个指定的优先级(0~255). 同时中断也有256个优先级,并比线程优先级高.如下图.
线程有两种基本的状态(可使用pidin来查看你系统的每个线程的当前状态):
BLOCKED
REPLY, MUTEX, RECEIVE…
READY
RUNNING, READY
*DEAD
*STOPPED




状态为READY的线程,按优先级等待调度.

同一优先级的线程,如Thread A/B/C,则有三种调度方式可选择,Round-robin, FIFO or Sporadic.
时间片轮询

先进先出.

Sporadic(不知道中文应该叫什么) 如图,你可以指定此线程的预算.当它用时超过预算时,它的优先级会被降低.等再有预算时再恢复高的优先级.





QNX的调度方式已经很丰富了,为什么还需要分区?
案例一: 分布在几个国家的开发部门共同开发某一系统. 各自开发系统中的某一子系统. 各自使用了优先级来让子系统按设计的要求来运行. 各自测试的时候没有问题. 但系统集成的时候却发现系统不能正常运行. 原因是各优先级线程之间的影响,有的低优先级的进程可能根本没有时间运行. 就算之前有考虑优先级的问题,当一个系统很大的时候, 如何安排几十上百个线程之间的优先级也是一场恶梦.

案例二: 当一个连接在网络上的服务器受到DOS攻击的时候,管理员可能发现了攻击行为却无能为力.因为饱和攻击已经把服务器资源耗尽.你不能登陆你的服务器.除非亲自跑到电信机房拔掉网线…!!

通过分区,我们可以指定某一或某些进程的CPU使用预算. 从此,你不必担心你的程序会因为其它高优先级的程序把资源耗尽而得不到时间运行. 如上面提到的管理员,他尽可telnet到他的服务器,做一些设置来避免攻击.因为分区可以保证,当telnet程序需要运行时,它可以得到设定好的CPU时间.

为什么需要自适应分区?
分区的概念并不是QNX提出的.其它操作系统已经实际分区的功能,如linux. 但之前的分区是一种静态的分区. 举例说明:如上面的管理员给他的telnet程序分配了10%的CPU预算.那么,就算此管理员并没有使用telnet服务.其它进程也只能/最多使用90%的CPU.有10%浪费掉.

所谓自适应分区,很简单. 如果我不用这10%, 而其它程序又需要的时候, 可以拿去用. 只是当我需要的时候,系统会保证你的10%的可利用率.

这样,在一个以优先级为主宰的实时操作系统中,我们就有了既可以保证低优先级进程生存权利,又不浪费资源的手段!

目前自适应分区只能指定CPU资源,将来会有更多的选择.内存?!还是什么.让QNX的人去想好了

Adaptive partitioning offers several innovations, including the ability to:

*use real-time, priority-based scheduling when the system is lightly loaded — this allows systems to use the same scheduling behavior that they do today
*provide CPU time guarantees when the system is heavily loaded — this ensures that all partitions receive their fair budget of CPU time
*“borrow” any unused CPU time from partitions that have free time, giving other partitions the extra processing time they need to handle peak demands
*“repay” borrowed time to ensure scheduling fairness
*overlay the adaptive partitioning scheduler onto existing systems — applications and system services can simply be launched in a partition, and the scheduler will ensure that partitions receive their allocated budget
*dynamically add and configure partitions at runtime, enabling the system to adjust processor consumption in response to fault conditions or other scenarios
*guarantee that recovery operations have the CPU cycles they need to repair system faults, enabling improved mean-time-to-repair for high availability systems
*stop malicious code from stealing all the CPU time and launching a denial of service attack

先写这么多吧.如果还不清楚.自己看E文去.
更多资料: http://www.qnx.com/innovation/adaptive_partitioning/
[/img]

写的不错,多多学习