Operating System Examples - Scheduling

Slides:



Advertisements
Similar presentations
Scheduling Algorithems
Advertisements

Operating Systems Process Scheduling (Ch 3.2, )
CS4315A. Berrached:CMS:UHD1 CPU Scheduling Chapter 7.
Sogang University Advanced Operating Systems (Process Scheduling - Linux) Advanced Operating Systems (Process Scheduling - Linux) Sang Gue Oh, Ph.D. .
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 17 Scheduling III.
 A quantum is the amount of time a thread gets to run before Windows checks.  Length: Windows 2000 / XP: 2 clock intervals Windows Server systems: 12.
CPU Scheduling Section 2.5.
Day 25 Uniprocessor scheduling. Algorithm: Selection function Selection function – which process among ready processes to select. w – time spent in system,
Chapter 3: CPU Scheduling
Operating System Process Scheduling (Ch 4.2, )
Operating System I Process Scheduling. Schedulers F Short-Term –“Which process gets the CPU?” –Fast, since once per 100 ms F Long-Term (batch) –“Which.
CS 311 – Lecture 23 Outline Kernel – Process subsystem Process scheduling Scheduling algorithms User mode and kernel mode Lecture 231CS Operating.
Chapter 5: CPU Scheduling
Uniprocessor Scheduling Chapter 9. Aim of Scheduling The key to multiprogramming is scheduling Scheduling is done to meet the goals of –Response time.
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
1 Thursday, June 15, 2006 Confucius says: He who play in root, eventually kill tree.
1 Multilevel Feedback Queue Scheduling Another way to put a preference on short-lived processes –Penalize processes that have been running longer. Preemptive.
Scheduling in Linux COMS W4118 Spring Scheduling Goals O(1) scheduling; 2.4 scheduler iterated through Run queue on each invocation Task queue.
Wk 2 – Scheduling 1 CS502 Spring 2006 Scheduling The art and science of allocating the CPU and other resources to processes.
Job scheduling Queue discipline.
Operating Systems Process Scheduling (Ch 4.2, )
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Chapter 5: Process Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Objectives To introduce CPU scheduling To describe.
Operating System Process Scheduling (Ch 4.2, )
1Chapter 05, Fall 2008 CPU Scheduling The CPU scheduler (sometimes called the dispatcher or short-term scheduler): Selects a process from the ready queue.
Process Scheduling in Windows XP, Linux, and UNIX By Sarah G. Levinson CSC 4320.
1 Uniprocessor Scheduling Chapter 9. 2 Aim of Scheduling Main Job: Assign processes to be executed by the processor(s) and processes to be loaded in main.
 Scheduling  Linux Scheduling  Linux Scheduling Policy  Classification Of Processes In Linux  Linux Scheduling Classes  Process States In Linux.
Chapter 5: CPU Scheduling (Continuation). 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Determining Length.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Cosc 4740 Chapter 5 Process Scheduling. CPU Scheduling Short-term Scheduler –Selects a process from the ready queue when current process releases the.
Chapter 6: CPU Scheduling
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-3 CPU Scheduling Department of Computer Science and Software Engineering.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Scheduler What is the job of.
1 Previous lecture review n Out of basic scheduling techniques none is a clear winner: u FCFS - simple but unfair u RR - more overhead than FCFS may not.
Chapter 6 Scheduling. Basic concepts Goal is maximum utilization –what does this mean? –cpu pegged at 100% ?? Most programs are I/O bound Thus some other.
Scheduling Basic scheduling policies, for OS schedulers (threads, tasks, processes) or thread library schedulers Review of Context Switching overheads.
Scheduling. Alternating Sequence of CPU And I/O Bursts.
CE Operating Systems Lecture 11 Windows – Object manager and process management.
CPU Scheduling CSCI 444/544 Operating Systems Fall 2008.
1 Scheduling The part of the OS that makes the choice of which process to run next is called the scheduler and the algorithm it uses is called the scheduling.
CPU Scheduling Presentation by Colin McCarthy. Runqueues Foundation of Linux scheduler algorithm Keeps track of all runnable tasks assigned to CPU One.
What Every Developer Should Know about the Kernel Dr. Michael L. Collard 1.
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
1 Uniprocessor Scheduling Chapter 9. 2 Aim of Scheduling Response time Throughput Processor efficiency.
Uniprocessor Scheduling
Chapter 5: Process Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Basic Concepts Maximum CPU utilization can be obtained.
Traditional UNIX Scheduling Scheduling algorithm objectives Provide good response time for interactive users Ensure that low-priority background jobs do.
Scheuduling.
Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch.
Lecture 6 Page 1 CS 111 Online Preemptive Scheduling Again in the context of CPU scheduling A thread or process is chosen to run It runs until either it.
Uniprocessor Scheduling Chapter 9. Aim of Scheduling Assign processes to be executed by the processor or processors: –Response time –Throughput –Processor.
Operating System Examples - Scheduling. References r Silberschatz et al, Chapter 5.6, Chapter
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 3.
Operating Systems Scheduling. Scheduling Short term scheduler (CPU Scheduler) –Whenever the CPU becomes idle, a process must be selected for execution.
Operating System Examples - Scheduling. References r er/ch10.html r bangalore.org/blug/meetings/200401/scheduler-
Process Scheduling. Scheduling Strategies Scheduling strategies can broadly fall into two categories  Co-operative scheduling is where the currently.
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 6: CPU Scheduling.
CPU Scheduling Scheduling processes (or kernel-level threads) onto the cpu is one of the most important OS functions. The cpu is an expensive resource.
UNIT–II: Process Management
Chapter 5a: CPU Scheduling
Chapter 6: CPU Scheduling
Operating System Concepts
Chapter 5: CPU Scheduling
Chapter 2: The Linux System Part 3
TDC 311 Process Scheduling.
CPU scheduling decisions may take place when a process:
Process Scheduling Decide which process should run and for how long
Presentation transcript:

Operating System Examples - Scheduling

References Silberschatz et al, Chapter 5.6, Chapter 22.3.22 (Windows 7) http://linux-bangalore.org/blug/meetings/200401/scheduler-2.6.pdf

Note: Process/Thread A unit of execution is a process Processes can create a unit of execution called a thread Threads share data with processes Operating systems schedule threads in the same way processes are scheduled We will discuss threads in much greater detail later in the course

Solaris

Solaris Solaris uses priority-based scheduling Each process belongs to one of six classes Time sharing Interactive Real time System File share Fixed priority Default scheduling class time sharing Within each class: Different priorities Different scheduling algorithms Priority levels from 0 to 169

Priorities

Priorities Interrupt Real-time class System class Highest priority Guaranteed response time Kernel processes (very few) assigned this class System class Kernel processes are assigned to this class e.g., scheduler Priorities are static

Priorities Time-sharing Fixed-priority Fair-share Processes can have their priorities adjusted Fixed-priority Introduced in Solaris 9 No dynamic adjustment of priorities Fair-share Uses CPU shares instead of priorities A share is an indicator of entitlement

Real-Time Scheduling Real-time priority queues can be configured to operate with a FIFO-strategy or a Round Robin strategy Real-time processes can preempt running processes that have lower priority Tend to be few real-time processes

Time Sharing Scheduling Algorithm Default priority for a user process is time sharing Priorities are dynamic Use of a multilevel feedback queue Each queue represents a different priority level Time slices (quantum) are associated with a priority queue Higher priorities  smaller time slice

Time Sharing Scheduling Algorithm Solaris uses a dispatch table This is used to assign a new priority to a process. Two cases: Time quantum expired without blocking Could be a CPU intensive process Process blocked before time quantum expired This new priority will be used to determine the process in a priority queue when the process returns to a READY state

Solaris Dispatch Table For time-sharing & Interactive processes

Solaris Dispatch Table Priority: A higher number indicates a higher priority Time quantum: There is an inverse relationship between priorities and time quanta Time quantum expired: The new priority of a process that has used its entire time quantum without blocking Return from sleep: The priority of a process that is returning from the blocked state (such as waiting for I/O)

Scheduling Algorithm Time sharing scheduling algorithm If a priority has used its entire time quantum without blocking its priority is changed (with one exception) The priority of a priority that is returning from sleeping (e.g. waiting for I/O) has its priority increased This allows for better support of interactive processes

Interactive Processes Interactive processes (e.g., window managers) typically have higher priority (good response time) CPU-bound processes have lower priority (good throughput)

Windows 7

Priorities Similar to that used in Windows XP The scheduler is called a dispatcher 32 priorities Priorities are divided into two classes: User class: priorities 1 to 15 Real-time class: priorities 16 to 31 Priority 0 is used for memory management processes There is a queue for each priority

Selecting a Process The dispatcher traverses the set of queues from highest to lowest until it finds a process that is ready to run If there are no processes ready to run the dispatcher executes the idle process Priority of a preempted process may be modified before being returned to a ready state Round robin

Adjusting Priority If process was in user class Time quantum expires: If process is in the user class the priority is lowered Process switches from blocked to running: Priority is increased The amount depends on what the process was doing Keyboard I/O gets a large increase while disk I/O gets a moderate increase Some processes always have a low priority e.g., disk fragmenter

Adjusting Priority The priority of a process cannot be lowered passed the base priority (lower threshold value) of the process Windows 7 distinguishes between the foreground process that is currently selected on the screen and the background processes that are not currently selected Tends to give good response times to interactive processes that are using the mouse and windows

Linux

Linux Used for both servers and workstations Linux provides flexibility so that performance is optimized

Linux Scheduling Goals Implement scheduling algorithms in O(1) time. Provide good interactive performance. Optimize for the common case of only one or two runnable processes, yet scale well to multiple processors, each with many processes. Linux uses the term task to refer to a process/thread Linux priority levels are on the next slide

Priorities and Time-slice length Priority Levels Priorities and Time-slice length

Priorities Priorities 0-99 for real-time processes Priorities 100-139 for normal (user) processes

Linux Scheduling A process is considered for execution on the CPU as long as it has time remaining in its time slice (quantum) When a task has exhausted its time slice, it is considered expired and is not eligible for execution again until all other tasks have all exhausted their time slice

Linux Data Structures The kernel maintains a list of all runnable tasks in a runqueue data structure A runqueue consists of two priority arrays: Active: Contains all tasks with time remaining in their time slices Expired: Contains all expired tasks The active, expired queues are indexed according to priority

Linux Data Structures List of Tasks Indexed According to Priorities

Linux Scheduling How is a process selected for execution? The scheduler finds the highest-priority queue with a runnable process Finds the first process on the queue Determine its quantum size (more later) What happens to a running process that does not complete its time quantum? When that process returns to the ready state it goes into the active array

Linux Scheduling When there are no more processes in the active array, the expired array becomes the active array and the active array becomes the expired array. A process’s priority (queue) is recalculated when the process has exhausted its time quantum and is to be moved to the expired array

To Discuss Linux Efficiency Calculating time quantum using static priorities Determining the queue that a process should be placed using dynamic priority

Linux Efficiency We will now discuss efficiency. Choice of next process to run: Process with the highest priority A bitmap is created such that there is 1 bit for every priority level. 140 priority levels Bitmap size: 140 bits/32 bits per word = 4.375 words = 5 words If a running process exists at a level with quantum left, the corresponding bit is true

Linux Efficiency If a priority N has a process that can be run, bitmap[N] = 1 The first bit position in bitmap that is 1 represents the priority level from which a process is chosen A priority level is a queue Pick the first process

Linux Efficiency Find the first bit with a 1 Hardware instruction to find the first 1-bit bsfl on Intel Time depends on the number of priority levels, not the number of processes

Linux Efficiency There are pointers to the expired and active arrays Making the expired array the active array requires update of the pointers Can be done quickly No need for an explicit aging mechanism

Scheduling Components Scheduler chooses a process based on dynamic priority. Dynamic priority is a function of Static priority and bonus Bonus is derived from sleep average Now to explain this

Static Priorities Each process has a static priority (SP) Value is between 0 and 139 Real-time processes have a static priority between 0 and 99 All other processes (referred to as conventional) are assigned a static priority between 100-139 Static until arrays are changed.

Static Priorities The static priority is set based on the nice value Range of nice values: [-20,20] By default 0 Mapping of nice values to static priorities 0 maps to 120 -20 maps to 100 20 maps to 140 Static until arrays are changed.

Static Priorities Base time quantum: The time quantum assigned by the scheduler to a process if it has exhausted its previous time quantum If (SP < 120):Base time quantum = (140-SP)* 20 If (SP ≥ 120):Base time quantum = (140-SP)*5 If SP = 100 BTQ is (140-100)*20 = 40*20 = 800 If SP = 110 BTQ is (140-110)*20 = 30*20 = 600 If SP = 120 BTQ is (140-120)*5 = 20*5 = 100 If SP=130 BTQ is (140-130)*5 = 10*5 = 50 If SP=139 BTW is (140-139)*5 = 1*5 = 5 l arrays are changed.

Typical Quanta Priority Static Priority Quantum Highest 100 800 ms 110 600 ms Normal 120 100 ms Low 130 50 ms Lowest 139 5 ms

Dynamic Priority Besides a static priority, a user process also has a dynamic priority Ranges from 100 (highest priority) to 139 (lowest priority) The dynamic priority is the number actually used by the scheduler when selecting the new process to run. This number is the queue

Adjusting Priorities Dynamic priority (DP) is calculated from static priority (SP) and bonus value DP = max(100, min(SP-bonus+5,139)) The bonus is based on average sleep time Measure of interactiveness

Calculating Sleep Time The scheduler keeps track of the average amount of time a task sleeps vs average amount of time task uses CPU Use the sleep_avg variable When a process wakes the time spent sleeping is added to its sleep_avg When a process is switched out, the run time is subtracted from sleep_avg

Calculating Sleep Time Sleep ratio Mostly sleeping: I/O bound Mostly running: CPU bound sleep_avg scaled to a bonus value

Sleep Time and Bonus Values >=0 but < 100 ms >= 100 ms but < 200 ms 1 >=200 ms but < 300 ms 2 >=300 ms but < 400 ms 3 >=400 ms but < 500 ms 4 >=500 ms but < 600 ms 5 >=600 ms but < 700 ms 6 >=700 ms but < 800 ms 7 >= 800 ms but < 900 ms 8 >=900 ms but < 1000 ms 9 1 second 10

Bonus and Dynamic Priority Dynamic priority (DP) is calculated from static priority (SP) and bonus DP = max(100, min(SP-bonus+5,139)) Bonus: 0-10 <5: penalty Less sleeping >5: premium More sleeping (highly interactive) The higher the bonus the task is getting and the higher its static priority, the more likely it is to be considered interactive

Using Quanta Assume a process has consumed its quanta (time slice) Check interactive status: If non-interactive, put it aside on the expired array If interactive, put it at the end of the active array

Using Quanta Exceptions to putting on higher-priority array: If higher-priority process is on expired list If expired task has been waiting more than some specified amount of time If there’s nothing else at that priority, it will run again immediately Of course, by running so much, its bonus will go down, and so will its priority and its interactive status

Other

MAC OS X Based on MACH and Unix BSD Priorities are categorized into priority bands Normal: Applications System high priority: Processes with higher priority then Normal Kernel mode: Reserved for kernel processes Real-time: For processes that must be guaranteed a slice of CPU time by a particular deadline

MAC OS X Priorities change dynamically Based on wait time and amount of time that the process has had the processor Stay within the same priority band Reschedules every tenth of a second and recomputes priorities once every second Prrocess will relinquish CPU after time quantum or when it must wait for an I/O completion Feedback prevents starvation

Android For mobile devices Today it is the most commonly used platform Uses Linux for device managers, memory management, process management

Summary We have examined scheduling in several contemporary operating systems