CS 3204 Operating Systems Lecture 14 Godmar Back.

Slides:



Advertisements
Similar presentations
CPU Scheduling Tanenbaum Ch 2.4 Silberchatz and Galvin Ch 5.
Advertisements

Sogang University Advanced Operating Systems (Process Scheduling - Linux) Advanced Operating Systems (Process Scheduling - Linux) Sang Gue Oh, Ph.D. .
1 ECE7995 Computer Storage and Operating System Design Lecture 3: Processes and threads (I)
Project 2 – solution code
CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.
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.
The Linux Scheduler 2.4 vs 2.6 Michael McCabe Michael McCabe
CS 4284 Systems Capstone Godmar Back Resource Allocation & Scheduling.
Process Scheduling in Windows XP, Linux, and UNIX By Sarah G. Levinson CSC 4320.
Scheduling in Linux and Windows 2000
Operating System Concepts and Techniques Lecture 5 Scheduling-1 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First.
More Scheduling cs550 Operating Systems David Monismith.
MM Process Management Karrie Karahalios Spring 2007 (based off slides created by Brian Bailey)
Operating System Examples - Scheduling
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.
CPU Scheduling Thomas Plagemann (with slides from Otto J. Anshus, Kai Li, Pål Halvorsen and Andrew S. Tanenbaum)
CS 3204 Operating Systems Godmar Back Lecture 13.
CPU Scheduling CSCI 444/544 Operating Systems Fall 2008.
CPU Scheduling Presentation by Colin McCarthy. Runqueues Foundation of Linux scheduler algorithm Keeps track of all runnable tasks assigned to CPU One.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
Real-Time Scheduling CS 3204 – Operating Systems Lecture 20 3/3/2006 Shahrooz Feizabadi.
Lec 3aOperating Systems1 Operating Systems Lecture 3a: Linux Schedulers William M. Mongan Material drawn in part from
2.5 Scheduling Given a multiprogramming system. Given a multiprogramming system. Many times when more than 1 process is waiting for the CPU (in the ready.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Scheduling II: priority scheduling.
Traditional UNIX Scheduling Scheduling algorithm objectives Provide good response time for interactive users Ensure that low-priority background jobs do.
Cpr E 308 Spring 2005 Process Scheduling Basic Question: Which process goes next? Personal Computers –Few processes, interactive, low response time Batch.
Periodic scheduler for Linux OS
Real-Time Scheduling CS 3204 – Operating Systems Lecture 13 10/3/2006 Shahrooz Feizabadi.
2.5 Scheduling. Given a multiprogramming system, there are many times when more than 1 process is waiting for the CPU (in the ready queue). Given a multiprogramming.
CS 4284 Systems Capstone Godmar Back Resource Allocation & Scheduling.
CSC 322 Operating Systems Concepts Lecture - 10: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
CS Spring 2009 CS 414 – Multimedia Systems Design Lecture 31 – Process Management (Part 1) Klara Nahrstedt Spring 2009.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
Scheduling Algorithms : Important Aspects Minimize Response Time –Elapsed time to do an operation (job) –Response time is what the user sees Time to echo.
CS333 Intro to Operating Systems Jonathan Walpole.
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-
Lecture 12 Scheduling Models for Computer Networks Dr. Adil Yousif.
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.
Scheduling.
Real-Time Operating Systems RTOS For Embedded systems.
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
Scheduling of Non-Real-Time Tasks in Linux (SCHED_NORMAL/SCHED_OTHER)
Linux Scheduler.
Linux Scheduling.
Networks and Operating Systems: Exercise Session 2
Resource Allocation & Scheduling
Chapter 2 Scheduling.
Chapter 8 – Processor Scheduling
Lecture 24: Process Scheduling Examples and for Real-time Systems
Process management Information maintained by OS for process management
Andy Wang Operating Systems COP 4610 / CGS 5765
Scheduling Adapted from:
Scheduling.
Process Scheduling Decide which process should run and for how long
CS703 – Advanced Operating Systems
CSE 451: Operating Systems Winter 2003 Lecture 6 Scheduling
Scheduling of Regular Tasks in Linux
Uniprocessor scheduling
Scheduling Classes and Real-Time Scheduling in Linux
Linux Scheduler © DJ Foreman 3/8/2009.
Scheduling 21 May 2019.
Linux Scheduling CSE 2431: Introduction to Operating Systems
CSE 451: Operating Systems Winter 2001 Lecture 6 Scheduling
Scheduling of Regular Tasks in Linux
Presentation transcript:

CS 3204 Operating Systems Lecture 14 Godmar Back

CPU Scheduling Part II

Case Study: 2.6 Linux Scheduler (pre 2.6.23) nice=19 140 Variant of MLFQS 140 priorities 0-99 “realtime” 100-140 nonrealtime Dynamic priority computed from static priority (nice) plus “interactivity bonus” Processes scheduled based on dynamic priority SCHED_OTHER nice=0 120 nice=-20 100 “Realtime” processes scheduled based on static priority SCHED_FIFO SCHED_RR CS 3204 Fall 2008

Linux Scheduler (2) Instead of recomputation loop, recompute priority at end of each timeslice dyn_prio = nice + interactivity bonus (-5…5) Interactivity bonus depends on sleep_avg measures time a process was blocked 2 priority arrays (“active” & “expired”) in each runqueue (Linux calls ready queues “runqueue”) CS 3204 Fall 2008

Linux Scheduler (3) Finds highest-priority ready thread quickly struct prio_array { unsigned int nr_active; unsigned long bitmap[BITMAP_SIZE]; struct list_head queue[MAX_PRIO]; }; typedef struct prio_array prio_array_t; /* find the highest-priority ready thread */ idx = sched_find_first_bit(array->bitmap); queue = array->queue + idx; next = list_entry(queue->next, task_t, run_list); /* Per CPU runqueue */ struct runqueue { prio_array_t *active; prio_array_t *expired; prio_array_t arrays[2]; … } Finds highest-priority ready thread quickly Switching active & expired arrays at end of epoch is simple pointer swap (“O(1)” claim) CS 3204 Fall 2008

Linux Timeslice Computation Linux scales static priority to timeslice Nice [ -20 … 0 … 19 ] maps to [800ms … 100 ms … 5ms] Various tweaks: “interactive processes” are reinserted into active array even after timeslice expires Unless processes in expired array are starving processes with long timeslices are round-robin’d with other of equal priority at sub-timeslice granularity CS 3204 Fall 2008

Proportional Share Scheduling Aka “Fair-Share” Scheduling None of algorithms discussed so far provide a direct way of assigning CPU shares E.g., give 30% of CPU to process A, 70% to process B Proportional Share algorithms do by assigning “tickets” or “shares” to processes Process get to use resource in proportion of their shares to total number of shares Lottery Scheduling, Weighted Fair Queuing/Stride Scheduling [Waldspurger 1995] CS 3204 Fall 2008

Lottery Scheduling Idea: number tickets between 1…N every process gets pi tickets according to importance process 1 gets tickets [1… p1-1] process 2 gets tickets [p1… p1+p2-1] and so on. Scheduling decision: Hold a lottery and draw ticket, holder gets to run for next time slice Nondeterministic algorithm Q.: how to implement priority donation? CS 3204 Fall 2008

Weighted Fair Queuing Uses ‘per process’ virtual time Increments process’s virtual time by a “stride” after each quantum, which is defined as (process_share)-1 Choose process with lowest virtual finishing time ‘virtual finishing time’ is virtual time + stride Also known as stride scheduling Linux now implements a variant of WFQ/Stride Scheduling as its “CFS” completely fair scheduler CS 3204 Fall 2008

WFQ Example (A=3, B=2, C=1) Ready Queue is sorted by Virtual Finish Time (Virtual Time at end of quantum if a process were scheduled) Time Task A Task B Task C Ready Queue Who Runs One scheduling epoch. A ran 3 out of 6 quanta, B 2 out of 6, C 1 out of 6. This process will repeat, yielding proportional fairness. 1/3 1/2 1 A (1/3) B (1/2) C (1) A 2/3 B (1/2) A (2/3) C (1) B 2 A (2/3) C(1) B(1) 3 C(1) B(1) A(1)  C 4 B(1) A(1) C(2) 5 3/2 A(1) B(3/2) C(2) A  6 4/3 A (4/3) B(3/2) C(2)   CS 3204 Fall 2008

WFQ (cont’d) WFQ requires a sorted ready queue Linux now uses R/B tree Higher complexity than O(1) linked lists, but appears manageable for real-world ready queue sizes Unblocked processes that reenter the ready queue are assigned a virtual time reflecting the value that their virtual time counter would have if they’d received CPU time proportionally Accommodating I/O bound processes still requires fudging In strict WFQ, only way to improve latency is to set number of shares high – but this is disastrous if process is not truly I/O bound Linux uses “sleeper fairness,” to identify when to boost virtual time; similar to the sleep average in old scheduler CS 3204 Fall 2008

Linux SMP Load Balancing static void double_rq_lock( runqueue_t *rq1, runqueue_t *rq2) { if (rq1 == rq2) { spin_lock(&rq1->lock); } else { if (rq1 < rq2) { spin_lock(&rq2->lock); } Runqueue is per CPU Periodically, lengths of runqueues on different CPU is compared Processes are migrated to balance load Aside: Migrating requires locks on both runqueues CS 3204 Fall 2008

Real-time Scheduling Real-time systems must observe not only execution time, but a deadline as well Jobs must finish by deadline But turn-around time is usually less important Common scenario are recurring jobs E.g., need 3 ms every 10 ms (here, 10ms is the recurrence period T, 3 ms is the cost C) Possible strategies RMA (Rate Monotonic) Map periods to priorities, fixed, static EDF (Earliest Deadline First) Always run what’s due next, dynamic CS 3204 Fall 2008

EDF – Example Assume deadline equals period (T). A B C Hyper-period Task T C A 4 1 B 8 12 3 Assume deadline equals period (T). A B C 5 10 15 20 25 Hyper-period CS 3204 Fall 2008

EDF – Example Assume deadline equals period (T). A B C Task T C A 4 1 8 12 3 Assume deadline equals period (T). A B C 5 10 15 20 25 CS 3204 Fall 2008

EDF – Example Assume deadline equals period (T). A B C Task T C A 4 1 8 12 3 Assume deadline equals period (T). A B C 5 10 15 20 25 CS 3204 Fall 2008

EDF – Example Assume deadline equals period (T). A B C Task T C A 4 1 8 12 3 Assume deadline equals period (T). Lexical order tie breaker (C > B > A) A B C 5 10 15 20 25 CS 3204 Fall 2008

EDF – Example Assume deadline equals period (T). A B C Task T C A 4 1 8 12 3 Assume deadline equals period (T). A B C 5 10 15 20 25 CS 3204 Fall 2008

EDF – Example Assume deadline equals period (T). A B C Task T C A 4 1 8 12 3 Assume deadline equals period (T). A B C 5 10 15 20 25 CS 3204 Fall 2008

EDF – Example Assume deadline equals period (T). A B C Task T C A 4 1 8 12 3 Assume deadline equals period (T). A B C 5 10 15 20 25 CS 3204 Fall 2008

EDF – Example Assume deadline equals period (T). A B C Task T C A 4 1 8 12 3 Assume deadline equals period (T). A B C 5 10 15 20 25 CS 3204 Fall 2008

EDF – Example Assume deadline equals period (T). A B C Pattern repeats Task T C A 4 1 B 8 12 3 Assume deadline equals period (T). A B C 5 10 15 20 25 Pattern repeats CS 3204 Fall 2008

EDF Properties Feasibility test: U = 100% in example Bound theoretical Sufficient and necessary Optimal CS 3204 Fall 2008

Scheduling Summary OS must schedule all resources in a system CPU, Disk, Network, etc. CPU Scheduling affects indirectly scheduling of other devices Goals for general purpose schedulers: Minimizing latency (avg. completion or waiting time) Maximing throughput Provide fairness In Practice: some theory, lots of tweaking CS 3204 Fall 2008