Operating Systems, fall 2002 SCHEDULING in Linux Lior Amar, David Breitgand (recitation) www.cs.huji.ac.il/~os.

Slides:



Advertisements
Similar presentations
Operating Systems Process Scheduling (Ch 3.2, )
Advertisements

Process Scheduling in Linux (Chap.7 in Understanding the Linux Kernel) J. H. Wang Oct. 1, 2009.
Sogang University Advanced Operating Systems (Process Scheduling - Linux) Advanced Operating Systems (Process Scheduling - Linux) Sang Gue Oh, Ph.D. .
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
Chapter 5 CPU Scheduling. CPU Scheduling Topics: Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
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.
Scheduling in Batch Systems
CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.
Chapter 6: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Chapter 6: CPU Scheduling Basic.
Uniprocessor Scheduling Chapter 9. Aim of Scheduling The key to multiprogramming is scheduling Scheduling is done to meet the goals of –Response time.
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.
What we will cover…  CPU Scheduling  Basic Concepts  Scheduling Criteria  Scheduling Algorithms  Evaluations 1-1 Lecture 4.
CS 104 Introduction to Computer Science and Graphics Problems Operating Systems (2) Process Management 10/03/2008 Yang Song (Prepared by Yang Song and.
5: CPU-Scheduling1 Jerry Breecher OPERATING SYSTEMS SCHEDULING.
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 Lecture 10: Uniprocessor Scheduling. 2 CPU Scheduling n The problem: scheduling the usage of a single processor among all the existing processes in.
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.
 Scheduling  Linux Scheduling  Linux Scheduling Policy  Classification Of Processes In Linux  Linux Scheduling Classes  Process States In Linux.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
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.
Linux Scheduling CS Scheduling Policy ► The scheduling algorithm of traditional Unix systems must fulfill several conflicting objectives  Fast.
Uniprocessor Scheduling
OPERATING SYSTEMS CPU SCHEDULING.  Introduction to CPU scheduling Introduction to CPU scheduling  Dispatcher Dispatcher  Terms used in CPU scheduling.
Chapter 6 CPU SCHEDULING.
More Scheduling cs550 Operating Systems David Monismith.
Operating System Examples - Scheduling
1 Scheduling Processes. 2 Processes Each process has state, that includes its text and data, procedure call stack, etc. This state resides in memory.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Scheduling. Alternating Sequence of CPU And I/O Bursts.
Operating Systems 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.
Silberschatz and Galvin  Operating System Concepts Module 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor.
CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling Operating Systems Examples Algorithm.
Process Scheduling in Linux (Chap. 11, Understanding the Linux Kernel) J. H. Wang Sep. 26, 2008.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
Chapter 5: Process Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Basic Concepts Maximum CPU utilization can be obtained.
1 11/29/2015 Chapter 6: CPU Scheduling l Basic Concepts l Scheduling Criteria l Scheduling Algorithms l Multiple-Processor Scheduling l Real-Time Scheduling.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Scheduling II: priority scheduling.
Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Operating Systems Scheduling. Scheduling Short term scheduler (CPU Scheduler) –Whenever the CPU becomes idle, a process must be selected for execution.
1 Uniprocessor Scheduling Chapter 3. 2 Alternating Sequence of CPU And I/O Bursts.
Chapter 4 CPU Scheduling. 2 Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation.
Process Scheduling. Scheduling Strategies Scheduling strategies can broadly fall into two categories  Co-operative scheduling is where the currently.
Basic Concepts Maximum CPU utilization obtained with multiprogramming
1 Lecture 5: CPU Scheduling Operating System Fall 2006.
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
Chapter 5a: CPU Scheduling
Chapter 2 Scheduling.
Chapter 5: CPU Scheduling
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Chapter5: CPU Scheduling
Process Scheduling Decide which process should run and for how long
CPU Scheduling: Basic Concepts
Presentation transcript:

Operating Systems, fall 2002 SCHEDULING in Linux Lior Amar, David Breitgand (recitation)

Scheduling in Unix The scheduling algorithm must fulfill several conflicting objectives: –fast process response time; –good throughput for background jobs; –avoidance of process starvation; –Preferential treatment of low- and high-priority processes. The set of rules used to determine when and how selecting a new process to run is called scheduling policy.

Linux Unix clone for PC by Tornvald Linus; –Originally for x386 family; Scheduling is based on the time-sharing: –Several processes are allowed to run "concurrently“; –Which means that the CPU time is roughly divided into "slices“, one for each runnable process; –If a currently running process is not terminated when its time slice (quantum) expires, a process switch may take place; –Time-sharing relies on timer interrupts and is transparent to processes; –No additional code needs to be inserted in the programs in order to ensure CPU time-sharing. –CPU sharing policies can be controlled to a certain extent.

Process Classification I/O-bound: make heavy use of I/O devices and spend much time waiting for I/O operations to complete. CPU-bound: number-crunching applications that require a lot of CPU time.

Alternative Process Classification Interactive processes : interact constantly with their users; spend a lot of time waiting for key presses and mouse operations; when input is received, the process must be woken up quickly, or the user will find the system to be unresponsive; typically, the average delay must fall between 50 and 150 ms. the variance of such delay must also be bounded, or the user will find the system to be erratic; typical interactive programs are command shells, text editors, and graphical applications.

Alternative Process Classification Batch processes : Do not need user interaction; Often run in the background; Do not need to be very responsive; Typical batch programs data-mining engines, file transfers, compilers Real-time processes: Have very strong scheduling requirements; Should have a short response time and a minimum variance; Often require a guaranteed sequence of execution; Often require a guaranteed timing (deadlines).

Real Time Processes Hard real time processes: –Nuclear power plant control; –Airplane control. Soft real time processes: –Video/audio streaming; –On-line gaming/conferencing.

Classifications are largely independent Batch programs may be I/O bound and CPU bound Real Time programs maybe I/O bound and CPU bound. Can interactive programs be CPU bound?

…and in Linux Soft real-time processes are explicitly recognized: –There are two types of user processes in Linux: real time, and conventional. No way explicitly to distinguish among conventional batch and interactive processes: –Linux (as all UNIXs) prefers I/O processes –Is this always OK?

Linux Scheduling Policy Based on priorities; Priority is a measure of worthiness of choosing a certain process to run among the processes being ready to run; In Linux there are two types of priorities: –Static : stay fixed throughout the process life for soft real time processes –Dynamic : for conventional processes (adjusted by the scheduler based on process history)

Why not Hard Real Time? Two reasons: –Linux kernel is non-preemptive (as in classic Unix), you will appreciate why in this week lecture. –Linux user-level process is preemptive.

Preempted vs Suspended Preempted process is logically in the READY state, it just does not use CPU Suspended process waits for some event completion (e.g., I/O completion, timer event, other event – can you give an example?), thus it is not runnable.

Quantum Time sharing is possible since each process occupies CPU for a finite time slice aka quantum; How long should it be? –If too long - FCFS –If too short – switching overhead is too high –Question: if switching takes up 10 ms, and quantum is 10 ms, what is switching overhead? Statement: long quantum always degrades response time of interactive applications. –Is this false or true?

Quantum (II) The statement from the previous slide is FALSE in general; In particular, this is not true in Linux; This actually depends on whether the scheduler gives higher priority to the I/O bound process (interactive programs are always I/O bound); In Linux previously suspended I/O process will very quickly preempt currently running CPU-bound process upon wakeup when SUSPENDED ->READY state transition takes place

Quantum (III) However, in some cases when quantum is too long responsiveness may be degraded Example: –Two commands are invoked simultaneously by two users. One is CPU bound, another one is interactive –Shells of users fork two process. If initially these two have the same dynamic priority, and the CPU bound is selected first, then the I/O bound suffers. The rule of thumb adopted by Linux is: choose quantum duration as long as possible, while keeping good system response time. The actual value is 210 ms.

Linux Scheduling Algorithm Linux uses a variant of multilevel queue with feedback; CPU time is divided into epochs; –In a single epoch, every process has a specified quantum whose duration is computed when the epoch begins; Different processes may have different quanta; Quantum value is the maximum CPU time portion assigned to the process in that epoch; Process is preempted when: –it finishes up its quantum; –a previously suspended process with higher priority is awaken; –process voluntarily relinquish CPU either by calling a blocking system call, or by calling sched_yeild() syscall; –process voluntarily decreases/increases its priority through calling setpriority() –Real time process is ready to run.

Linux Scheduling Algorithm (continued) Priority of a conventional process in Linux equals unused time from the process’s quantum; –The more time left, the higher priority; Static priorities: 1-99 are never changed by the scheduler Different priority queues can be handled through two policies: FCFS and RR. An epoch terminates when all runnable processes exhaust their quantum. When a new epoch begin each runnable process is assigned a new quantum: base priority + time left from the last epoch

More on priorities (I) When a process forks a child process the priority for the child is set as follows: current->counter >>= 1; //counter counts ticks left p->counter = current->counter; What is the effect of this? Why this is needed? In PC one clock tick usually happens every 0.01 sec. Base quantum (=base priority) is 20 ticks (defined in /usr/include/sched.h)

More on Priorities (II) When a new epoch begins every process (i.e., also the suspended ones) obtain new priorities: p->priority += p->counter >> 1; Thus suspended processes (I/O bound) increase their priority; What is the maximum priority a process may get ever? Why is it good to recalculate all priorities once per epoch, and not all the time?

Let’s check ourselves What type of processes will be favored by Linux scheduler? Can starvation occur if only conventional processes execute? Can starvation occur if both real time and conventional processes execute? Can starvation occur if only real time processes execute? Why relatively long quantum does not hurt interactive processes in Linux? Can a single epoch be infinite?

System CallDescription nice( ) Change the priority of a conventional process. getpriority( ) Get the maximum priority of a group of conventional processes. setpriority( ) Set the priority of a group of conventional processes. sched_getscheduler( ) Get the scheduling policy of a process. sched_setscheduler( ) Set the scheduling policy and priority of a process. sched_getparam( ) Get the scheduling priority of a process. sched_setparam( ) Set the priority of a process. sched_yield( ) Relinquish the processor voluntarily without blocking. sched_get_ priority_min( ) Get the minimum priority value for a policy. sched_get_ priority_max( ) Get the maximum priority value for a policy. sched_rr_get_interval( ) Get the time quantum value for the Round Robin policy.