1 / 42

CHAPTER 9 UNIPROCESSOR SCHEDULING ( 单处理机调度)

CHAPTER 9 UNIPROCESSOR SCHEDULING ( 单处理机调度). Aim of Scheduling. Processor efficiency (处理机效率) (多进程竞争 CPU ,合理安排调度) Fairness( 公平性,防止进程饥饿 ) (通过调度算法来安排调度次序,满足系统的设计目标). Types of Scheduling (调度类型). 按 OS 的类型划分: 批处理调度、分时调度、实时调度、多处理机调度 按调度的层次划分: Long-term scheduling ( 长程调度)

everly
Download Presentation

CHAPTER 9 UNIPROCESSOR SCHEDULING ( 单处理机调度)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CHAPTER 9UNIPROCESSOR SCHEDULING(单处理机调度)

  2. Aim of Scheduling • Processor efficiency(处理机效率) (多进程竞争CPU,合理安排调度) • Fairness(公平性,防止进程饥饿) (通过调度算法来安排调度次序,满足系统的设计目标)

  3. Types of Scheduling(调度类型) • 按OS的类型划分: 批处理调度、分时调度、实时调度、多处理机调度 • 按调度的层次划分: Long-term scheduling(长程调度) Medium-term scheduling(中程调度) Short-term scheduling(短程调度)

  4. Long-term scheduling 又称为高级调度、作业调度,它为被调度作业或用户程序创建进程、分配必要的系统资源,并将新创建的进程插入就绪队列,等待Short-term scheduling • 采用交换技术的系统将新创建的进程插入(就绪,挂起)队列,等待Medium-term scheduling。 • 批处理系统中,作业进入系统后,先驻留在磁盘上(批处理队列中)。长程调度从该队列中选择作业,为之创建进程。

  5. Long-Term Scheduling • Determines which programs are admitted to the system for processing - 这取决于调度算法,如FCFS、短作业优先、基于优先权、响应比高者优先等调度算法 • How many programs are admitted to the system ? - Controls the degree of multiprogramming • When does the scheduler be invoked? - Each time a job terminates - Processor is idle exceeds a certain threshold

  6. Medium-term scheduling 又称为中级调度,它调度换出到磁盘的进程进入内存,准备执行 • 中程调度配合对换技术使用。 • 其目的是为了提高内存的利用率和系统吞吐量。 • 在多道程序度允许的情况下,从外存选择一个挂起状态的进程调度到内存(换入)

  7. Short-term scheduling • 又称为进程调度、低级调度,调度内存中的就绪进程执行。 • Known as the dispatcher:决定就绪队列Which进程将获得处理机 • Executes most frequently • Invoked when an event occurs • Clock interrupts • I/O interrupts • Operating system calls • Signals(信号)

  8. 9.2 SCHEDULING ALGORITHMS(调度算法) • Scheduling Criteria(调度准则) • The Use of Priorities(优先权的使用) • Scheduling Policies(调度策略)

  9. Scheduling Criteria (调度准则) User-oriented • Response Time(响应时间) - Elapsed time between the submission of a request until there is output. - 常用于评价分时系统的性能。 • Turnaround time(周转时间) - 是指从作业提交给系统开始,到作业完成为止的这段时间间隔(也称为作业周转时间) - 常用于评价批处理系统的性能。

  10. User-oriented • Deadlines(截止时间) - 是指某任务必须开始执行的最迟时间(Starting deadline ),或必须完成的最迟时间(Completion deadline ) - 常用于评价实时系统的性能。

  11. System-oriented • Throughput(吞吐量) - 单位时间内系统所完成的作业数 - 用于评价批处理系统的性能 • Processor Utilization (处理机利用率) - This is the percentage of time that the processor is busy. (处理机忙的时间百分比)

  12. System-oriented • Balancing Resource(资源平衡) - Keep the resources of the system busy - 适用于长程调度和中程调度 • Fairness(公平性) - Process should be treated the same, and no process should suffer starvation.

  13. The Use of Priorities(优先权的使用) • Scheduler will always choose a process of higher priority over one of lower priority (总是调度优先权高的进程) • To provide a set of ready queues, in descending order of priority (提供一组队列,按优先权递减排列) • Lower-priority may suffer starvation (低优先权的进程有可能被饿死) • allow a process to change its priority based on its age (生存期)or execution history

  14. Scheduling Algorithms

  15. Decision Mode • Nonpreemptive(非剥夺方式) • Once a process is in the running state, it will continue until it terminates or blocks itself for I/O. • 主要用于批处理系统。 • Preemptive(剥夺方式) • Currently running process may be interrupted and moved to the Ready state by the operating system

  16. Decision Mode • Preemptive(剥夺方式) • Allows for better service since any one process cannot monopolize the processor for very long • 主要用于实时性要求较高的实时系统及性能要求较高的批处理系统和分时系统。

  17. Process Scheduling Example 例如,有5个进程,描述如下: 进程 到达时间 服务时间 P1 0 3 P2 2 6 P3 4 4 P4 6 5 P5 8 2

  18. 作业周转时间Tq: 作业的完成时间-作业的提交时间 • 作业带权周转时间: 周转时间Tq/作业的服务时间Ts • 根据以上例子用6种不同的短程调度算法调度这5个进程,比较各种调度算法的平均周转时间、平均带权周转时间,参见P390,Table9.4。分析各种调度算法的优缺点。

  19. 5 0 10 15 20 First-Come-First-Served(FCFS) • Each process joins the Ready queue • When the current process ceases to execute, the oldest process in the Ready queue is selected 1 2 3 4 5

  20. First-Come-First-Served(FCFS) • 平均周转时间、带权平均周转时间:Tq / Ts(参见P390,Table9.4) • A short process may have to wait a very long time before it can execute • FCFS可能导致处理机和I/O设备都没有得到充分利用。

  21. FCFS is unfair to short process

  22. FCFS算法的实际应用 • 一般,FCFS与其他调度算法混合使用。 • 系统可以按照不同的优先级维护多个就绪队列,每个队列内部按照FCFS算法调度。

  23. Round Robin(循环法,又称: RR、轮转法、时间片法) • Uses preemption based on a clock (使用基于时钟的剥夺方式) • 进程轮流按时间片( time slicing)运行 • Clock interrupt is generated at periodic intervals(按周期间隔产生时钟中断) • When an interrupt occurs, the currently running process is placed in the read queue,Next ready job is selected

  24. 5 0 10 15 20 Round Robin(循环法,又称:RR、轮转法、时间片法) 1 2 3 4 5 当q=1时,RR调度示意图

  25. RR算法分析 1.RR常用于分时系统及事务处理系统 2.时间片的大小对计算机性能的影响(P392) ①时间片<进程执行时间,进程需交替执行 ②时间片>进程执行时间,退化为FCFS 3.存在的问题:受CPU限制( processor-bound)进程执行完一个时间片后,立即返回就绪队列。充分利用时间片。而受I/O限制( I/O- bound)进程只使用很少的CPU时间(时间片未用完),就被阻塞,等待I/O操作完成,然后加入就绪队列。体现出不公平的使用处理机时间.

  26. Virtual round robin(虚循环法,又称:VRR) • VRR算法的改进:增加一个辅助队列,接收I/O阻塞完成的进程,调度优先于就绪队列,但占用的处理机时间等于基本时间片长减去上次运行的部分时间片。 (P393,图9.7) • 算法分析:VRR算法比RR算法公平。

  27. 5 0 10 15 20 1 2 3 4 5 Shortest Process Next(SPN,短进程优先) • Nonpreemptive policy(非剥夺策略) • Process with shortest expected processing time is selected next(选择处理时间最短的)

  28. Shortest Process Next(SPN,短进程优先) • 实例分析 参见P390,Table9.4 • SPN算法分析: 1.改善了系统的性能,降低了系统的平均等待时间,提高了系统的吞吐量 2.存在的问题: • 很难准确确定进程的执行时间 • 对长进程不公平,Possibility of starvation for longer processes • 未考虑进程的紧迫程度,不适合于分时系统和事务处理系统

  29. 5 0 10 15 20 1 2 3 4 5 Shortest Remaining Time(SRT,剩余时间最短者优先) • SRT policy is a Preemptive version of SPN. (SRT是对SPN增加了剥夺机制的版本) • Elapsed service times must be recorded. (必须记录过去的服务时间)

  30. Shortest Remaining Time(SRT,剩余时间最短者优先) • 实例分析参见P390,Table9.4 • SRT算法分析: 1.与SPN算法一样,很难准确确定进程的剩余执行时间,且对长进程不公平 2.但是,它不象FCFS算法偏袒长进程,也不象RR算法会产生很多中断而增加系统负担。 3.由于短进程提前完成,故其平均周转时间比SPN短。

  31. Highest Response Ratio Next(HRRN,响应比高者优先) • 响应比RR = (time spent waiting + expected service time) / expected service time • Choose the ready process with the greatest value of RR. (选择就绪进程中响应比高者优先)

  32. 5 0 10 15 20 Highest Response Ratio Next(HRRN,响应比高者优先) 1 2 3 4 5

  33. Highest Response Ratio Next(HRRN,响应比高者优先) • 实例分析参见P390,Table9.4 • HRRN算法分析: 1.若进程的等待时间相同,则要求服务时间短的进程优先(SPN); 2.若进程要求的服务时间相同,则等待时间长的进程优先(FCFS); 3.长进程随着等待时间增加,必然会被调度。 4.但是,很难准确确定进程要求的执行时间,且每次调度之前需要计算响应比,增加系统开销。

  34. Feedback(FB,反馈调度法) • 调度方式 1.设置多个就绪队列,各队的优先权不同(从上而下优先级逐级降低); 2.各个队列中进程执行的时间片不同,优先权愈高时间片愈短; 3.新进程首先放入第一队列尾,按FCFS方法调度,若一个时间片未完成,到下一队列排队等待; 4.仅当第一队列空时,调度程序才开始调度第二队列的进程,依次类推。

  35. 5 0 10 15 20 1 2 3 4 5 Feedback(FB,反馈调度法)

  36. Feedback(FB,反馈调度法) • 实例分析参见P390,Table9.4 • FB算法分析: 1.有利于交互型作业 (常为短作业) 2.有利于短批处理作业 3.存在的问题,当不断有新进程到来,则长进程可能饥饿。

More Related