Linux Scheduling CS 4510. Scheduling Policy ► The scheduling algorithm of traditional Unix systems must fulfill several conflicting objectives  Fast.

Slides:



Advertisements
Similar presentations
CS 149: Operating Systems February 3 Class Meeting
Advertisements

Operating Systems Process Scheduling (Ch 3.2, )
Linux Scheduling Algorithm -Ashish Singh. Introduction History and Background Linux Scheduling Modification in Linux Scheduling Results Conclusion References.
Linux Scheduler. Linux is a multitasking OS Deciding what process runs next, given a set of runnable processes, is a fundamental decision a scheduler.
Process Scheduling in Linux (Chap.7 in Understanding the Linux Kernel) J. H. Wang Oct. 1, 2009.
Operating Systems, fall 2002 SCHEDULING in Linux Lior Amar, David Breitgand (recitation)
Sogang University Advanced Operating Systems (Process Scheduling - Linux) Advanced Operating Systems (Process Scheduling - Linux) Sang Gue Oh, Ph.D. .
Chapter 5 CPU Scheduling. CPU Scheduling Topics: Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Operating Systems 1 K. Salah Module 2.1: CPU Scheduling Scheduling Types Scheduling Criteria Scheduling Algorithms Performance Evaluation.
© Ibrahim Korpeoglu Bilkent University
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 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.
Scheduling in Linux COMS W4118 Spring Scheduling Goals O(1) scheduling; 2.4 scheduler iterated through Run queue on each invocation Task queue.
1 Scheduling in Representative Operating Systems.
Wk 2 – Scheduling 1 CS502 Spring 2006 Scheduling The art and science of allocating the CPU and other resources to processes.
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?
Process Description and Control A process is sometimes called a task, it is a program in execution.
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.
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.
Scheduling in Linux and Windows 2000
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 6 CPU SCHEDULING.
More Scheduling cs550 Operating Systems David Monismith.
Operating System Examples - Scheduling
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.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Scheduling. Alternating Sequence of CPU And I/O Bursts.
Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.
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.
Process Scheduling in Linux (Chap. 11, Understanding the Linux Kernel) J. H. Wang Sep. 26, 2008.
What Every Developer Should Know about the Kernel Dr. Michael L. Collard 1.
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
Chapter 5: Process Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Basic Concepts Maximum CPU utilization can be obtained.
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
1 Review of Process Mechanisms. 2 Scheduling: Policy and Mechanism Scheduling policy answers the question: Which process/thread, among all those ready.
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.
4300 Lines Added 1800 Lines Removed 1500 Lines Modified PER DAY DURING SUSE Lab.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 3.
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.
CPU Scheduling CS Introduction to Operating Systems.
Process Scheduling. Scheduling Strategies Scheduling strategies can broadly fall into two categories  Co-operative scheduling is where the currently.
Process Scheduling 國立中正大學 資訊工程研究所 羅習五 老師 1. Outline OS schedulers Unix scheduling Linux scheduling Linux 2.4 scheduler Linux 2.6 scheduler – O(1) scheduler.
UNIT–II: Process Management
PROCESS MANAGEMENT IN MACH
EEE Embedded Systems Design Process in Operating Systems 서강대학교 전자공학과
Chapter 5a: CPU Scheduling
Operating Systems Processes Scheduling.
Lecture 23: Process Scheduling for Interactive Systems
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Operating System Concepts
Chapter 2: The Linux System Part 3
Process Scheduling Decide which process should run and for how long
Linux Scheduling CSE 2431: Introduction to Operating Systems
Presentation transcript:

Linux Scheduling CS 4510

Scheduling Policy ► The scheduling algorithm of traditional Unix systems must fulfill several conflicting objectives  Fast process response time  Good throughput for background jobs  Avoidance of process starvation  Etc. ► The set of rules used to determine when and how to select a new process to run is called the scheduling policy

Scheduling Policy ► Linux scheduling is based on time sharing ► CPU time is divided into slices, one for each runnable process ► If a currently running process is not terminated when its quantum expires, a process switch may take place

Scheduling Policy ► The scheduling policy ranks processes according to their priority ► In Linux, process priority is dynamic.  Processes that have been denied the use of the CPU for a long time are boosted by dynamically increasing their priority  Long running processes have their priority lowered.

Classes of Processes ► Interactive Processes  Must respond quickly ► Typically between 50 and 150 ms ► Variance must also be bounded  Includes: ► Command Shells ► Text editors ► Graphical applications

Classes of Processes ► Batch processes  Do not need user interaction  Often penalized by the Scheduler  Includes: ► Compilers ► Database Search Engines ► Scientific Computations

Classes of Processes ► Real-time processes  Have very stringent scheduling requirements  Should never be blocked by lower-priority processes  Needs ► Short guaranteed response time ► Minimum variance  Includes ► Video and sound applications ► Robot controllers ► Data Collectors from physical sensors

Process Preemption ► If a process enters the TASK_RUNNING state, the kernel checks whether its dynamic priority is greater than the priority of the currently running process. ► If so, the current process is interrupted and the scheduler is invoked to select another process to run. ► A preempted process is not suspended it remains in the TASK_RUNNING state; it simply no longer uses the CPU

How Long Should a Quantum Last? ► If its too short, system overhead is high ► If too long, processes no longer appear to be responsive ► Long quantum durations do not usually degrade response time  Higher priority process, such as interactive process, will quickly interrupt lower priority processes like batch processes ► The choice of quantum duration is always a compromise  Choose a duration as long as possible while keeping good system response time.

The Scheduling Algorithm ► CPU time is divided into epochs.  Every process has a time quantum whose duration is computed when the epoch begins  The quantum is the maximum CPU time assigned to the process in that epoch  A process can be selected several times from the scheduler in the same epoch, as long as its quantum is not exhausted

The Scheduling Algorithm ► Base Time Quantum  Assigned by the scheduler if a process has exhausted its time quantum in the previous epoch  Users can change the base time quantum by using the system calls nice( ) and setPriority( )  A new process inherits the base time quantum of its parent

The Scheduling Algorithm ► Process Priorities  Static priority ► Assigned by the users to real-time process ► Ranges from 1 to 99 ► Never changed by the scheduler  Dynamic priority ► Applies only to conventional processes ► Sum of  Base time quantum  Ticks of CPU time left to the process before its quantum expires

CPU’s Data Structures ► nice  Determines the length of the process time quantum when a new epoch begins. Ranges between -20 and +19 ► Negative values correspond to high priority processes ► counter  Number of ticks of CPU time left to the process before its quantum expires ► need_resched  A flag checked by ret_from_sys_call( ) to decide whether to invoke the schedule( ) function ► counter  Number of ticks of CPU time left to the process before its quantum expires ► cpus_allowed  A bitmask specifying the CPU on which the process is allowed to run ► cpus_runnable  A bit mask specifying the CPU that is executing the process, if any.

CPU’s Data Structures ► nice  Determines the length of the process time quantum when a new epoch begins. Ranges between -20 and +19 ► Negative values correspond to high priority processes ► counter  Number of ticks of CPU time left to the process before its quantum expires ► need_resched  A flag checked by ret_from_sys_call( ) to decide whether to invoke the schedule( ) function

The schedule( ) function ► Direct Invocation  The scheduler is invoked directly when the current process must be blocked right away ► Steps 1.Inserts current in the proper wait queue 2.Changes state to TASK_INTERRUPTIBLE or TASK_UNINTERRUPTIBLE 3.Invokes schedule( ) 4.Goto step 2 unless resource is available 5.Once resource is available, removes current from wait queue

The schedule( ) Function ► Lazy Invocation  The scheduler can also be invoked in a lazy way by setting the “need_resched” field of current to 1  A check on this value is always made before resuming execution of a User Mode process  Schedule will be invoked at some time in the near future ► Lazy invocation is performed in the following cases  When current has used up its time quantum  When a process is woken up and its priority is higher than the current process  When a sched_yield( ) system call is issued

Actions Performed Before a Process Switch ► The key outcome of the function is to set a local variable ‘next’ so that it points to the PCB of the process selected to replace current

Actions Performed Before a Process Switch ► The schedule function starts with the following code prev = current; this_cpu = prev->processor; sched_data = &aligned_data[this_cpu]

Actions Performed Before a Process Switch ► Before starting to look at the runnable processes, schedule( ) must disable the local interrupts and acquire the spin lock that protects the run queue. ► spin_lock_irq(&runqueue_lock)

Actions Performed Before a Process Switch ► If prev is not in the TASK_RUNNING state, schedule( ) was directly invoked by the process itself because it had to wait on some external resource; therefore, prev must be removed from the runqueue ► if (prev->state != TASK_RUNNING) del_from_runqueue(prev); ► The function also resets the need_resched field of current, just in case the scheduler was activated in the lazy way: ► prev->need_resched = 0;

Actions Performed Before a Process Switch ► Now schedule scans the runqueue to find the process to be executed in the next quantum. repeat_schedule: next = init_tasks[this_cpu]; c = -1000; list_for_each(tmp, &runqueue_head) P = list_entry(tmp, struct task_struct, runlist); int weight = goodness(p, this_cpu, prev->active_mm); If (weight > c) c = weight, next = p; ► The goodness( ) function returns an integer that denotes the priority of the process passed as a parameter

Actions Performed Before a Process Switch ► While scanning processes in the runqueue, schedule( ) considers only those that are  Runnable on the executing CPU ► (cpus_allowed & 1<<this_cpu)  Not alreading on some other CPU ► (cpus_runnable & 1<<this_cpu)

Actions Performed Before a Process Switch ► If the run-queue is empty, next points to the swapper kernel thread associated with the executing CPU. ► It is also possible that the best candidate turns out to be the old current process -- prev

Actions Performed Before a Process Switch ► If C is set to 0, then all processes have exhausted their time quantum. When this happens a new epoch begins, and all processes are assigned a fresh quantum (if !c) for_each_task(p) p->counter = (p->counter >> 1) + (20 – p->nice) / (20 – p->nice) / goto repeat_schedule ► Suspended or stopped process have their dynamic priorities periodically increased. This gives a higher priority to interactive processes

Actions Performed Before a Process Switch ► The last thing that is done before the process switch is to be sure that the processes memory is set up properly

Actions Performed after a Context Switch ► Schedule( ) invokes _schedule_tail() ► This function checks whether some other process has set the need_resched field of prev while it was not running. In this case, the whole schedule function is reexecuted from the beginning.

Actions Performed After a Process Switch ► Most of the functions performed by schedule( ) after the context switch are primarily important for multi-processor systems.

Goodness Values ► weight == -1  p is the previous process, and its SCHED_YIELD flag is set. The process will be selected only if no other runnable processes are in the runqueue ► weight == 0  p is a conventional process that has exhausted its quantum ► 2 <= weight <= 77  p is a conventional process that has not exhausted its quantum ► weight >= 1000  p is a real-time process

Goodness Values ► The goodness value is computed as follows ► weight = p->counter p->nice ; ► A bonus is also given to process running on the same CPU and those which share the same memory space as the kernel