16 - Scheduling (3)OutlinePriority SchedulingAnnouncementsReading:Priority SchedulingProcesses get assigned a priority (weight).Example 1:Multiple QueuesOther AlgorithmsPA 3 instructions are out, a few things are stillmissing that will hopefully be out be end of weekQuiz 2 this Friday1)2)3)MOS 2.4---Always finish highest priority jobs firstEach priority level has an associated queuePriority queue processed Round-RobinPriority 1Priority 2Priority 3Priority 4QueueHeadersRunnableProcesses(Round-Robin)MOS Figure 2-42P1P131012151452PriorityProcessingTimeP2P2P3P3P4P4P5P5higher priority = lower number(Linux convention)Turnaround Time:Waiting Time:queues:1: P22: P53: P14: P35: P4each queue mustfinish processingbefore the nextbegins.t = 0ready:1: P22: P53: P14: P35: P4Quantum = 2Example 2:P131012151332PriorityProcessingTimeP2P3P4P5Quantum = 2queues:1: P22: P53: P1, P3, P4t = 0ready:1: P22: P53: P1, P3, P4P1P2P3P4P5Turnaround Time:Waiting Time:Assigning PrioritiesStatic assignment by system admin:Linux PrioritiesWindows PrioritiesDynamic assignment by kernel algorithm-----------Process typeStarvation possiblePriority inversion possibleUser Rolekernel measures runtime statisticsnumbered 0-139, lower number = higher priorityreal-time class: 0-99; normal class: 100-139kernel assigns default priority of 120priority modified with `nice` modifierprocess list commands show different numbersfor historical reasonsexample: 1/fprocess types defined into priority groupsprocesses assigned default prioritysystem admin can modify individual process prioritypriority assigned based on user id/group ownershipe.g. based on QoS agreements between customer/adminpriority calculated based on process's past behaviorf is proportion of quantum usedlonger a process runs for, the lower its priorityI/O bound tasks tend to higher priority for better interactivitynice = -20 => priority 100 (admin only)nice = +19 => priority 139nice modifier value subject to imposed limits`ps -elf` shows PRI = number - 40 = 80 + nice`top` shows PRI = number - 100 = 20 + niceReal-TimeNormal099100139priorityhigherlower-----32-level priority scheme, 6 different classeshigher number = higher priorityreal-time class: 16-31; other classes 1-15system idle thread priority 0default: normal class, normal priority (8)time-criticalreal-time311515151015151514131212111099877655432466881111111262524232216highabovenormalnormalbelownormalidlehighestabove normalnormalbelow normallowestidleMultiple QueuesSimilar to priority queues, but priority is notassigned to process itself, only to queues.Jobs start in highest priority queue and move tolower queues after getting processing time.Jobs move back to highest priority queue when"interaction" occurs (as defined by kernel)longer running jobs move to lower queues wherefewer interruptions occur, while highly interactiveones stay in higher queues.High responsiveness for I/O-bound jobsCPU-bound processes have fewer interruptionsmultiple queues need to be managedSJF but kernel guesses processing timesN processes get 1/N total processing timeevery process in ready queue given lotterytickets, and kernel picks a ticket at randomstarvation is possible but unlikelygive more tickets to increase priorityRR over users instead of processeslimit processing time per user regardless ofnumber of user processes-----higher queues processed RR before lower oneseach queue is assigned different time quantume.g. moving mouse into windowuser can potentially abuse interactionsguarantees CPU time to all processesProblems:lower priority task blocks higher priority task if it locks a resourceneeded by higher priority taskPriority 1Q = 1Priority 2Q = 2Priority 3Q = 4Priority 4Q = 8QueueHeadersRunnableProcesses(Round-Robin)Example 2:P105021008ReleaseTimeProcessingTimeP2P35 queues with quanta:(1, 2, 4, 8, 16)t = 0queues:1: P1, P22:3:4:5:----------Other AlgorithmsShortest Process NextGuaranteed SchedulingLottery Scheduling (probabilistic scheduling)Fair Share Scheduling