Scheduling. Today. Next Time Process interaction & communication

Similar documents
Scheduling. Today. Next Time. ! Introduction to scheduling! Classical algorithms. ! Process interaction & communication

Chapter 5: CPU Scheduling. Operating System Concepts 8 th Edition,

Chapter 5: Process Scheduling

Chapter 5 CPU scheduling

Chapter 5: CPU Scheduling

CPU Scheduling. Basic Concepts. Histogram of CPU-burst Times. Dispatcher. CPU Scheduler. Alternating Sequence of CPU and I/O Bursts

Chapter 5 Process Scheduling

Chapter 5: CPU Scheduling. Operating System Concepts Essentials 8 th Edition

Chapter 5: CPU Scheduling

CS307: Operating Systems

Operating Systems CS 323 Ms. Ines Abbes

Chapter 5 Scheduling

Job Scheduling. CS170 Fall 2018

Chapter 6: CPU Scheduling

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Chapter 6: CPU Scheduling

CPU Scheduling. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Chapter 6: CPU Scheduling

Round Robin (RR) ACSC 271 Operating Systems. RR Example. RR Scheduling. Lecture 9: Scheduling Algorithms

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

CSE 4/521 Introduction to Operating Systems

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Chapter 5: Process Scheduling

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Properties of Processes

LECTURE 3:CPU SCHEDULING

Scheduling II. Today. Next Time. ! Proportional-share scheduling! Multilevel-feedback queue! Multiprocessor scheduling. !

CPU Scheduling: Objectives

CS370 Operating Systems

CS370 Operating Systems

CPU Scheduling. Daniel Mosse. (Most slides are from Sherif Khattab and Silberschatz, Galvin and Gagne 2013)

Announcements. Program #1. Program #0. Reading. Is due at 9:00 AM on Thursday. Re-grade requests are due by Monday at 11:59:59 PM.

Chapter 5: CPU Scheduling

Chapter 5: CPU Scheduling. Operating System Concepts 9 th Edit9on

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

CISC 7310X. C05: CPU Scheduling. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/1/2018 CUNY Brooklyn College

CPU Scheduling (Part II)

Chapter 6: CPU Scheduling

Operating Systems. Scheduling

Operating Systems. Lecture Process Scheduling. Golestan University. Hossein Momeni

CS3733: Operating Systems

Last Class: Processes

CPU Scheduling. CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections )

Course Syllabus. Operating Systems

8: Scheduling. Scheduling. Mark Handley

Practice Exercises 305

Lecture 5 / Chapter 6 (CPU Scheduling) Basic Concepts. Scheduling Criteria Scheduling Algorithms

CHAPTER 2: PROCESS MANAGEMENT

Uniprocessor Scheduling. Basic Concepts Scheduling Criteria Scheduling Algorithms. Three level scheduling

Scheduling II. q q q q. Proportional-share scheduling Multilevel-feedback queue Multiprocessor scheduling Next Time: Memory management

ALL the assignments (A1, A2, A3) and Projects (P0, P1, P2) we have done so far.

Operating Systems Unit 3

CS370 Operating Systems

CPU Scheduling. Rab Nawaz Jadoon. Assistant Professor DCS. Pakistan. COMSATS, Lahore. Department of Computer Science

Scheduling in the Supermarket

CPU Scheduling Algorithms

Process Concept Process in Memory Process State new running waiting ready terminated Diagram of Process State

CS 326: Operating Systems. CPU Scheduling. Lecture 6

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

COSC243 Part 2: Operating Systems

Scheduling of processes

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s)

Ch 4 : CPU scheduling

Uniprocessor Scheduling

Example: CPU-bound process that would run for 100 quanta continuously 1, 2, 4, 8, 16, 32, 64 (only 37 required for last run) Needs only 7 swaps

Scheduling Mar. 19, 2018

Last class: Today: CPU Scheduling. CPU Scheduling Algorithms and Systems

CPU Scheduling (1) CPU Scheduling (Topic 3) CPU Scheduling (2) CPU Scheduling (3) Resources fall into two classes:

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Scheduling

Process- Concept &Process Scheduling OPERATING SYSTEMS

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s)

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

Preview. Process Scheduler. Process Scheduling Algorithms for Batch System. Process Scheduling Algorithms for Interactive System

CS370 Operating Systems

Announcements. Program #1. Reading. Due 2/15 at 5:00 pm. Finish scheduling Process Synchronization: Chapter 6 (8 th Ed) or Chapter 7 (6 th Ed)

Titolo presentazione. Scheduling. sottotitolo A.Y Milano, XX mese 20XX ACSO Tutoring MSc Eng. Michele Zanella

Uniprocessor Scheduling. Aim of Scheduling

Uniprocessor Scheduling. Aim of Scheduling. Types of Scheduling. Long-Term Scheduling. Chapter 9. Response time Throughput Processor efficiency

Operating System Concepts Ch. 5: Scheduling

Advanced Operating Systems (CS 202) Scheduling (1)

Processes and Threads

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Process Scheduling. Copyright : University of Illinois CS 241 Staff

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

Start of Lecture: February 10, Chapter 6: Scheduling

CSCI-GA Operating Systems Lecture 3: Processes and Threads -Part 2 Scheduling Hubertus Franke

Subject Name: OPERATING SYSTEMS. Subject Code: 10EC65. Prepared By: Kala H S and Remya R. Department: ECE. Date:

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

Chap 7, 8: Scheduling. Dongkun Shin, SKKU

Assignment 3 (Due date: Thursday, 10/15/2009, in class) Part One: Provide brief answers to the following Chapter Exercises questions:

Unit 3 : Process Management

Operating Systems. Process scheduling. Thomas Ropars.

Lecture 2 Process Management

Chapter 9. Uniprocessor Scheduling

Chapter 9 Uniprocessor Scheduling

CS Computer Systems. Lecture 6: Process Scheduling

Scheduling. Multi-processing. Process Characterization. time. ...makes use of idle. COS450-F18-05-Scheduling - October 8, 2018

Scheduling. CSC400 - Operating Systems. 7: Scheduling. J. Sumey. one of the main tasks of an OS. the scheduler / dispatcher

Review. Preview. Three Level Scheduler. Scheduler. Process behavior. Effective CPU Scheduler is essential. Process Scheduling

Transcription:

Scheduling Today Introduction to scheduling Classical algorithms Thread scheduling Evaluating scheduling OS example Next Time Process interaction & communication

Scheduling Problem Several ready processes & much fewer CPUs A choice has to be made By the scheduler, using a scheduling algorithm Scheduling through time Early batch systems Just run the next job in the tape Early timesharing systems Scarce CPU time so scheduling is critical PCs Commonly one active process so scheduling is easy; with fast & per-user CPU scheduling is not critical Networked workstations & servers All back again, multiple ready processes & expensive CS, scheduling is critical 2

Process behavior Bursts of CPU usage alternate with periods of I/O wait A property key to scheduling CPU-bound & I/O bound process As CPU gets faster more I/O bound processes Histogram of CPU-burst times Long CPU burst Waiting for I/O Large number of short CPU bursts Short CPU burst Small number of long CPU bursts 3

Multilevel scheduling Batch systems allow scheduling at 3 levels (3) Select a ready process and allocate the CPU to it (1) (2) Look for mix of CPU- & I/O-bound jobs or Shortest job first (Job Scheduler) These two determine the degree of multiprogramming Too many processes & not enough memory swap somebody out; when there s room: which one to bring in? 4

When to schedule? When? 1. At process creation 2. When a process exits 3. When a process blocks on I/O, a semaphore, etc 4. When an I/O interrupts occurs 5. A fix periods of time Need a HW clock interrupting Preemptive and non-preemptive No-preemptive: An allocated CPU is not release until the process terminates or switches to waiting new (1) (2) admitted ready interrupt (4) exit running terminated I/O or event completion (4) dispatched waiting (3) I/O or event wait 5

Dispatcher Dispatcher module gives control of CPU to process selected by short-term scheduler Switching context Switching to user mode Jumping to proper location in user program to restart it Dispatch latency time for the dispatcher to stop one process & start another running 6

Environments and goals Different scheduling algorithms for different application areas Worth distinguishing Batch Interactive Real-time All systems Fairness comparable processes getting comparable service Policy enforcement seeing that stated policy is carried out Balance keeping all parts of the system busy (mix pool of processes) 7

Environments and goals Batch systems Throughput max. jobs per hour Turnaround time min. time bet/ submission & termination Waiting time sum of periods spent waiting in ready queue CPU utilization keep the CPU busy all time Interactive systems Response time respond to requests quickly (time to start responding) Proportionality meet users expectations Real-time system Meeting deadlines avoid losing data Predictability avoid quality degradation in multimedia systems Average, maximum, minimum or variance? 8

First-Come First-Served scheduling First-Come First-Served Simplest, easy to implement, non-preemptive Problem: 1 CPU-bound process (burst of 1 sec.) Many I/O-bound ones (needing to read 1000 records to complete) Each I/O-bound process reads one block per sec! CPU I/O 9

FCFS scheduling Order of arrival: P1, P2, P3 Gantt Chart for schedule 0 P 1 P 2 P 3 24 27 30 Waiting times: P1 = 0; P2 = 24; P3 = 27 Average waiting time: (0 + 24 + 27)/3 = 17 Process Burst Time P1 24 P2 3 P3 3 Order of arrival: P 2, P 3, P 1 Gantt chart for schedule is P 1 0 P 2 P 3 3 6 30 Waiting times: P1 = 6; P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Preemptive or not? 10

Shortest Job/Remaining Time First sched. Shortest-Job First Assumption total time needed (or length of next CPU burst) is known Provably optimal First job finishes at time a Second job at time a + b Mean turnaround time (4a + 3 b + 2c + d)/4 Biggest contributor Preempetive or not? Job # Finish time 1 a 2 b 3 c 4 d A preemptive variation Shortest Remaining Time (or SRPT) 11

SJF and SRT SJF Non-preemptive P 1 P 3 P 2 P 4 0 3 7 8 12 16 avg. waiting time = (0 + 6 + 3 + 7)/4 = 4 SRT Preemptive P 1 P 2 P 3 P 2 P 1 0 2 4 5 7 11 16 P 4 avg. waiting time = (9 + 1 + 0 +2)/4 = 3 Process Arrival Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 12

- Determining length of next CPU burst Can only estimate length Can be done using length of previous CPU bursts and exponential averaging - t n actual lenght of n n 1 -, 0 1 - Define : CPU burst predicted value for the next CPU th Weight of history 1. n 1 tn n burst Most recent information Past history 13

Examples of Exponential Averaging =0 1. n 1 tn n n+1 = n Recent history does not count =1 n+1 = t n Only the actual last CPU burst counts If we expand the formula, we get: n+1 = t n +(1 - ) t n -1 + +(1 - ) j t n -j + +(1 - ) n +1 0 Since both and (1 - ) are less than or equal to 1, each successive term has less weight than its predecessor 14

Priority scheduling SJF is a special case of priority-based scheduling Priority = reverse of predicted next CPU burst Pick process with highest priority (lowest number) Problem Starvation low priority processes may never execute Solution: Aging increases priority (Unix s nice) Assigned maximum quantum Process Burst time Priority P1 10 3 P2 1 1 P3 2 4 P4 P5 1 5 5 2 P 2 P 5 P 1 P 3 P 4 0 1 6 16 18 avg. waiting time = (6 + 0 + 16 +18 + 1)/5 = 8.2 15

Round-robin scheduling Simple, fair, easy to implement, & widely-used Each process gets a fix quantum or time slice When quantum expires, if running preempt CPU With n processes & quantum q, each one gets 1/n of the CPU time, no-one waits more than (n-1) q P 1 P 2 P 3 P 1 P 1 P 1 P 1 P 1 0 4 7 10 14 18 22 26 30 avg. waiting time = (6 + 4 +7)/3 = 5.66 q = 4 Process Burst Time P1 24 P2 3 P3 3 Preempetive or not? 16

Quantum & Turnaround time Length of quantum Too short low CPU efficiency (why?) Too long low response time (really long, what do you get?) Commonly ~ 50-100 msec. Largest quantums don t imply shortest turnaround times 17

Combining algorithms In practice, any real system uses some hybrid approach, with elements of each algorithm Multilevel queue Ready queue partitioned into separate queues Each queue has its own scheduling algorithm Scheduling must be done between the queues Fixed priority scheduling; (i.e., foreground first); starvation? Time slice each queue gets a certain amount of CPU time which it can schedule amongst its processes Highest priority System processes Lowest priority Interactive processes Interactive editing processes Batch processes 18

Multiple (feedback) queues Multiple queues, allow processes to move bet/ queues Example CTSS Idea: separate processes based on CPU bursts 7094 had only space for 1 process in memory (switch = swap) Goals: low context switching cost & good response time Priority classes: class i gets 2 i quantas (i: 0 ) Scheduler executes first all processes in queue 0; if empty, all in queue 1, If process uses all its quanta move to next lower queue (leave I/O-bound & interact. processes in high-priority queue) What about process with long start but interactive after that? Carriage-return hit promote process to top class 19

Some other algorithms Guaranteed sched. - e.g. proportional to # processes Priority = amount used / amount promised Lower ratio higher priority Lottery scheduling simple & predictable Each process gets lottery tickets for resources (CPU time) Scheduling lottery, i.e. randomly pick a ticket Priority more tickets means higher chance Processes may exchange tickets Fair-Share scheduling Schedule aware of ownership Owners get a % of CPU, processes are picked to enforce it 20

Real-time scheduling Different categories Hard RT not on time ~ not at all Soft RT important to meet guarantees but not critical Scheduling can be static or dynamic Schedulable real-time system m periodic events event i occurs within period P i and requires C i seconds Then the load can only be handled if m i 1 Ci P i 1 P1: C = 50 msec, P = 100msec (.5) P2: C = 30 msec, P = 200msec (.15) P3: C = 100 msec, P = 500msec (.2) P4: C = 200 msec, P= 1000msec (.2) 21

Multiple-processor scheduling Scheduling more complex w/ multiple CPUs Asymmetric/symmetric (SMP) multiprocessing Supported by most OSs (common or independent ready queues) Processor affinity benefits of past history in a processor Load balancing keep workload evenly distributed Push migration specific task periodically checks load in processors & pushes processes for balance Pull migration idle processor pulls processes from busy one Symmetric multithreading (hyperthreading or SMT) Multiple logical processors on a physical one Each w/ own architecture state, supported by hardware Shouldn t require OS to know about it (but could benefit from) 22

Scheduling the server-side of P2P systems Response time experienced by users of P2P services is dominated by downloading process. >80% of all download requests in Kazaa are rejected due to capacity saturation at server peers >50% of all requests for large objects (>100MB) take more than one day & ~20% take over one week to complete Most implementations use FCFS or PS Apply SRPT! Work by Qiao et al. @ Nortwestern PS Process Sharing FCFS First-Come First-Serve SRPT Shortest-Remaining Processing-Time Mean response time of object download as a function of system load. 23

Thread scheduling Now add threads user or kernel level? User-level (process-contention scope) Context switch is cheaper You can have an application-specific scheduler at user level Kernel doesn t know of your threads Kernel-level (system-contention scope) Any scheduling of threads is possible (since the kernel knows of all) Switching threads inside same process is cheaper than switching processes 24

Pthread scheduling API #include <pthread.h> #include <stdio.h> #define NUM THREADS 5 /* Each thread begin control in this function */ void *runner(void *param) { printf("i am a thread\n"); pthread exit(0); } int main(int argc, char *argv[]) { int i; pthread_t tid[num THREADS]; pthread_attr_t attr; pthread_attr_init(&attr); /* get the default attributes */ pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); /* set the sched algo */ pthread_attr_setschedpolicy(&attr, SCHED_OTHER); /* set the sched policy */ for (i = 0; i < NUM_THREADS; i++) /* create the threads */ pthread_create(&tid[i],&attr,runner,null); } for (i = 0; i < NUM_THREADS; i++) /* now join on each thread */ pthread_join(tid[i], NULL); 25

Policy vs. mechanism Separate what is done from how it is done Think of parent process with multiple children Parent process may knows relative importance of children (if, for example, each one has a different task) None of the algorithms presented takes the parent process input for scheduling Scheduling algorithm parameterized Mechanism in the kernel Parameters filled in by user processes Policy set by user process Parent controls scheduling w/o doing it 26

Algorithm evaluation First problem: criteria to be used in selection E.g. Max CPU usage, but w/ max. response time of 1 sec. Evaluation forms Analytic evaluation - deterministic modeling: Given workload & algorithm number or formula Simple & fast, but workload specific Queueing models Computer system described as a network of servers Load characterized by distributions Applicable to limited number of algorithms complicated math & questionable assumptions Simulations Distribution-driven or trace-based Implementation Highly accurate & equally expensive 27

Next time Process synchronization Race condition & critical regions Software and hardware solutions Review of classical synchronization problems What really happened in Mars? http://research.microsoft.com/~mbj/mars_pathfinder/mars_pathfinder.html 28

OS examples Linux Preemptive, priority-based scheduling Two separate priority ranges mapping to a global priority scheme Real-time [0,99] & nice [100,140] Two algorithms Time-sharing Prioritized credit-based process w/ most credits is scheduled next Credit subtracted when timer interrupt occurs When credit = 0, another process chosen When all processes have credit = 0, re-crediting occurs Based on factors including priority and history (Soft) Real-time Static priority for RT tasks Two classes FCFS (2+ task w/ = priority RR) and RR (FCFS w/ quantum) Highest priority process always runs first 29

OS examples Linux (Ingo Molnar s O(1)) Perfect SMP scalability & improved SMP affinity O(1) scheduling constant-time, regardless of # of running processes One run queue per processor Two priority arrays: Active (tasks w/ remaining quantum) & Expired Each array includes 1 queue of runable processes per priority level Recalculation of task s dynamic priority done when task has exhausted its time quantum & moved to expired When active is empty swap 30