SchedulingContent of This LectureReview: State Process ModelOS Representation of Process via Process Control Block (PCB)Process SchedulingContext SwitchWhen to schedule?Queuing Diagram for ProcessesPreemptive vs. Non-preemptive schedulingScheduling ObjectivesPerformance CriteriaProcess ProfilesSimple Processor Scheduling AlgorithmsFirst Come First Serve (FCFS)FCFS ExampleProblems with FCFSSummaryCopyright ©: Nahrstedt, Angrave, Abdelzaher 1SchedulingCopyright ©: Nahrstedt, Angrave, Abdelzaher2Content of This LectureWhy CPU scheduling?Basic scheduling algorithmsFIFO (FCFS)Shortest job firstRound RobinPriority SchedulingGoals:Understand how your program is executed on the machine together with other programsCopyright ©: Nahrstedt, Angrave, Abdelzaher3Review: State Process ModelCopyright ©: Nahrstedt, Angrave, Abdelzaher4OS Representation of Process via Process Control Block (PCB)Copyright ©: Nahrstedt, Angrave, Abdelzaher5Process SchedulingDeciding which process/thread should occupy the resource (CPU, disk, etc)CPUProcess 1Process 2 Process 3I want to playWhose turn is it?Copyright ©: Nahrstedt, Angrave, Abdelzaher6Context Switch Switch CPU from one process to anotherPerformed by scheduler It includes: save PCB state of the old process; load PCB state of the new process;Flush memory cache;Change memory mapping (TLB);Context switch is expensive (1-1000 microseconds)No useful work is done (pure overhead)Can become a bottleneckNeed hardware supportCopyright ©: Nahrstedt, Angrave, Abdelzaher7When to schedule?A new process startsThe running process exitsThe running process is blocked I/O interrupt (some processes will be ready)Clock interrupt (every 10 milliseconds)Copyright ©: Nahrstedt, Angrave, Abdelzaher8Queuing Diagram for ProcessesReady QueueReady QueueI/O request inI/O request inDevice QueueDevice QueueTime SliceTime SliceExpiredExpiredFork a ChildFork a ChildWait for an Wait for an InterruptInterruptInterrupt Interrupt OccursOccursCreate Create Child Child CPUCPUI/OI/OUpdateUpdateAccountingAccountingCreate JobCreate JobCopyright ©: Nahrstedt, Angrave, Abdelzaher9Preemptive vs. Non-preemptive schedulingNon-preemptive scheduling:The running process keeps the CPU until it voluntarily gives up the CPU process exitsswitches to blocked state1 and 4 only (no 3)Preemptive scheduling:The running process can be interrupted and must release the CPU (can be forced to give up CPU)RunningTerminatedReady Blocked143Copyright ©: Nahrstedt, Angrave, Abdelzaher10Scheduling ObjectivesFairness (equitable shares of CPU)Priority (most important first)Efficiency (make best use of equipment)Encouraging good behavior (can’t take advantage of the system)Support for heavy loads (degrade gracefully)Adapting to different environments (interactive, real-time, multi-media)Copyright ©: Nahrstedt, Angrave, Abdelzaher11Performance CriteriaFairness Efficiency: keep resources as busy as possible Throughput: # of processes that completes in unit time Turnaround Time (also called elapse time)amount of time to execute a particular process from the time its entered Waiting Time amount of time process has been waiting in ready queue Response Time amount of time from when a request was first submitted until first response is produced. predictability and variance Proportionality: meet users' expectation Meeting Deadlines: avoid losing dataCopyright ©: Nahrstedt, Angrave, Abdelzaher12Process ProfilesI/O – Bound Does too much I/O to keep CPU busyCPU – BoundDoes too much computation to keep I/O busyProcess MixScheduling should load balance between I/O bound and CPU-bound processesIdeal would be to run all equipment at 100% utilization but that would not necessarily be good for response timeCopyright ©: Nahrstedt, Angrave, Abdelzaher13Simple Processor Scheduling AlgorithmsBatch systemsFirst Come First Serve (FCFS)Shortest Job FirstInteractive SystemsRound RobinPriority Scheduling…Copyright ©: Nahrstedt, Angrave, Abdelzaher14First Come First Serve (FCFS)Process that requests the CPU FIRST is allocated the CPU FIRST. Also called FIFOPreemptive or Non-preemptive?Used in Batch Systems ImplementationFIFO queuesA new process enters the tail of the queueThe schedule selects from the head of the queue.Copyright ©: Nahrstedt, Angrave, Abdelzaher15FCFS ExampleProcess Duration Order Arrival TimeP1 24 1 0P2 3 2 0P3 4 3 0The final schedule:0P1 (24)24 27P2 (3) P3 (4)P1 waiting time: 0P2 waiting time: 24P3 waiting time: 27The average waiting time: (0+24+27)/3 = 17What if P1 arrives at time 2Copyright ©: Nahrstedt, Angrave, Abdelzaher16Problems with FCFSNon-preemptiveNot optimal AWTCannot utilize resources in parallel:Assume 1 process CPU bounded and many I/O bounded processes result: Convoy effect, low CPU and I/O Device utilization Why?Copyright ©: Nahrstedt, Angrave, Abdelzaher17Summary Why Scheduling?Scheduling objectivesScheduling AlgorithmsFCFS
View Full Document