680 likes | 2.19k Views
Process Scheduling. 2010. 04. 17 Byoung Kwi, Lee GNU OS Lab. Contents. Basic Concept Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling Operating Systems Examples Algorithm Evaluation Summary. Objectives.
E N D
Process Scheduling 2010. 04. 17 Byoung Kwi, Lee GNU OS Lab.
Contents • Basic Concept • Scheduling Criteria • Scheduling Algorithms • Thread Scheduling • Multiple-Processor Scheduling • Operating Systems Examples • Algorithm Evaluation • Summary Operating System Concepts 8th - Process Scheduling
Objectives • To introduce CPU scheduling, which is the basis for multi-programmed Operating Systems. • To describe various CPU-scheduling algorithms. • To discuss evaluation criteria for selecting a CPU-scheduling algorithm for a particular system. Operating System Concepts 8th - Process Scheduling
Basic Concepts • CPU-I/O Burst Cycle • Processes alternate between CPU cycle and I/O wait Operating System Concepts 8th - Process Scheduling
Basic Concepts • CPU Scheduler • Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them • CPU scheduling decisions may take place when a process: • Switches from running to waiting state • Switches from running to ready state • Switches from waiting to ready • Terminates Operating System Concepts 8th - Process Scheduling
Basic Concepts • Dispatcher • Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: • switching context • switching to user mode • jumping to the proper location in the user program to restart that program • Dispatch latency • time it takes for the dispatcher to stop one process and start another running Operating System Concepts 8th - Process Scheduling
Scheduling Criteria • CPU utilization • keep the CPU as busy as possible • Throughput • # of processes that complete their execution per time unit • Turnaround time • amount of time to execute a particular process • Waiting time • amount of time a process has been waiting in the ready queue • Response time • amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment) Operating System Concepts 8th - Process Scheduling
Scheduling Algorithms • FCFS (First-Come, First-Served) Scheduling • The process that requests the CPU first is allocated the CPU first. • Can be implemented with a FIFO queue. • Non preemptive algorithm. • Disadvantage : the average waiting time can be long. Small processes can wait for long time a big process to finish Operating System Concepts 8th - Process Scheduling
Scheduling Algorithms • SJF (Shortest-Job-First) Scheduling • Associate with each process the length of its next CPU burst. • CPU is assigned to the process with the smallest next CPU burst. FCFS is used for processes with same CPU bursts. • SJF is optimal – gives minimum average waiting time for a given set of processes • The difficulty is knowing the length of the next CPU request. • Can be either preemptive or non preemptive Operating System Concepts 8th - Process Scheduling
Scheduling Algorithms • Priority Scheduling • A priority number (integer) is associated with each process • The CPU is allocated to the process with the highest priority (smallest integer highest priority) • Preemptive • Nonpreemptive • SJF is a priority scheduling where priority is the predicted next CPU burst time • Problem Starvation • low priority processes may never execute • Solution Aging • as time progresses increase the priority of the process Operating System Concepts 8th - Process Scheduling
Scheduling Algorithms • RR (Round-Robin) Scheduling • Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. • After this time has elapsed, the process is preempted and added to the end of the ready queue. How a smaller time quantum increases context switches Operating System Concepts 8th - Process Scheduling
Scheduling Algorithms • Multilevel Queue Scheduling • Ready queue is partitioned into separate queues: • foreground (interactive) • background (batch) • Each queue has its own scheduling algorithm: • foreground – RR • background – FCFS • Scheduling must be done between the queues: • Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation. • Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes i.e., 80% to foreground in RR, 20% to background in FCFS Operating System Concepts 8th - Process Scheduling
Scheduling Algorithms • Multilevel Queue Scheduling Operating System Concepts 8th - Process Scheduling
Scheduling Algorithms • Multilevel Feedback Queue Scheduling • A process can move between the various queues • Aging prevents starvation • Multilevel-feedback-queue scheduler defined by the following parameters: • number of queues • scheduling algorithms for each queue • method used to determine when to upgrade a process • method used to determine when to demote a process • method used to determine which queue a process will enter when that process needs service Operating System Concepts 8th - Process Scheduling
Scheduling Algorithms • Multilevel Feedback Queue Scheduling Operating System Concepts 8th - Process Scheduling
Thread Scheduling • Contention Scope • Distinction between user-level and kernel-level threads • Many-to-one and many-to-many models, thread library schedules user-level threads to run on LWP • Known as process-contention scope (PCS) since scheduling competition is within the process • Kernel thread scheduled onto available CPU is system-contention scope (SCS) – competition among all threads in system Operating System Concepts 8th - Process Scheduling
Multiple-Processor Scheduling • Approaches to Multiple-Processor Scheduling • CPU scheduling more complex when multiple CPUs are available • Asymmetric multiprocessing • only one processor accesses the system data structures, alleviating the need for data sharing • Symmetric multiprocessing (SMP) • each processor is self-scheduling, all processes in common ready queue, or each has its own private queue of ready processes Operating System Concepts 8th - Process Scheduling
Multiple-Processor Scheduling • Processor Affinity • process has affinity for processor on which it is currently running • soft affinity • when an operating system has a policy of attempting to keep a process running on the same processor • hard affinity • process to specify that It is not to migration to other processors Operating System Concepts 8th - Process Scheduling
Multiple-Processor Scheduling • Load Balancing • Keep the workload balanced among all processors • Each processor should have its own private queue • Two approaches: • Push migration: a specific task periodically checks the load on each processor and distributes the load by pushing processes from overloaded to idle or less-busy processors. • Pull migration: an idle processor pulls a waiting task from a busy processor Operating System Concepts 8th - Process Scheduling
Multiple-Processor Scheduling • Multicore Processors • Memory stall • processors accessing the memory spent significant amount of time waiting for data to become available • Implementation of multithreaded processor cores in which two or more hardware threads are assigned to each core. • Two ways to multithread a processor • Corse-grained multithreading • Fine-grained multithreading Operating System Concepts 8th - Process Scheduling
Multiple-Processor Scheduling • Virtualization and Scheduling • System with virtualization act like multiprocessor • One or more virtual CPU are presented to each of the running virtual machines. • The host OS creates and manages VMs that run guest operating system. • Virtualization will negatively impact any guest OS scheduler that assumes a certain amount of progress in a given amount of time. • Delays are introduced in the scheduling results • Delays can be more catastrophic for real-time guest OS Operating System Concepts 8th - Process Scheduling
Operating System Examples • Solaris Scheduling • Uses priority-based thread scheduling • Each thread belongs to one of six classes • Time sharing(TS) • Interactive(IA) • Real time(RT) • System (SYS) • Fair share(FSS) • Fixed priority(FP) • Each class there are different priorities and different scheduling algorithm • The default scheduling class for a process is time sharing Operating System Concepts 8th - Process Scheduling
Operating System Examples • Windows XP Scheduling • Priority-based, preemptive scheduling algorithm • The highest-priority thread will always run • The dispatcher is the portion of the kernel that handles scheduling • The dispatcher user a 32-level priority scheme • Variable class : priorities form 1 to 15 • Real-time class : priorities from 16 to 31 Priority 0 is used for memory management • Idle thread • If no ready thread is found, the dispatcher will execute a special thread Operating System Concepts 8th - Process Scheduling
Operating System Examples • Linux Scheduling • Preemptive, priority-based algorithm with two separate priority ranges • Real-time : range from 0 to 99, static priorities • Nice value : range from 100 to 140, dynamic priorities • Higher-priority tasks longer time quanta and lower-priority tasks shorter time quanta • Each Processor maintains its own runqueue and schedules itself independently • The kernel maintains a list of all runnable tasks in a runqueue data structure • Each runqueue contains two priority arrays • Active : tasks with time remaining in their time slices • Expired : expired tasks Operating System Concepts 8th - Process Scheduling
Algorithm Evaluation • Deterministic Modeling • Type of analytic evaluation: • Uses the given algorithm and the system workload to produce a formula or number that evaluates the performance of the algorithm for that workload • Takes a predetermined workload and defines the performances of each algorithm for that workload. • Simple and fast, produces numbers permitting to easily compare algorithms. • Results are applied only to the analyzed cases Operating System Concepts 8th - Process Scheduling
Algorithm Evaluation • Queueing Models • Just the distribution of CPU and I/O burst can be determined • Little’s formula: n = λ x W • n is the average queue length, W average waiting time in a queue, and λ average arrival rate for new processes in the queue • Particularly useful because it is valid for any scheduling algorithm and arrival distribution • Difficult to apply on complicated algorithms Operating System Concepts 8th - Process Scheduling
Algorithm Evaluation • Simulations • Evaluate the scheduling algorithms using simulators. • Trace tapes : monitor the real system and record the sequence of actual events. • Simulations are expensive and trace tapes require more storage space. Operating System Concepts 8th - Process Scheduling
Algorithm Evaluation • Implementation • All the previous method are of limited accuracy • The completely accurate way to evaluate a scheduling algorithm is to code it, put it in the operating system, and see how it works • Difficulties • The real problem here is the high cost • The environment can change Operating System Concepts 8th - Process Scheduling
Summary • CPU Scheduling is the task of selecting a waiting process from the ready queue and allocating the CPU to it. The CPU is allocated to the selected process by the dispatcher. • Many algorithms are proposed: FCFS, SJF, RR… • Scheduler can be preemptive or non-preemptive • Multiprocessor scheduling must consider processor affinity, load balancing, multicore processing scheduling in virtualization systems. • Some OS provide threads at the kernel level and mechanisms to schedule them. • The wide variety of scheduling algorithms demands that we have methods to select among algorithms. Operating System Concepts 8th - Process Scheduling