Scheduling in the Supermarket

Similar documents
Last Class: Processes

Properties of Processes

8: Scheduling. Scheduling. Mark Handley

Chapter 6: CPU Scheduling

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

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

Course Syllabus. Operating Systems

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.

CPU Scheduling. Schedulers. CPSC 313: Intro to Computer Systems. Intro to Scheduling. Schedulers in the OS

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

Chapter 5: CPU Scheduling

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

Chapter 5 CPU scheduling

LECTURE 3:CPU SCHEDULING

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

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

CS370 Operating Systems

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

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

Chapter 5: CPU Scheduling

Chapter 5: CPU Scheduling

Chapter 5 Scheduling

CPU Scheduling: Objectives

1.1 CPU I/O Burst Cycle

CS370 Operating Systems

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

Operating Systems CS 323 Ms. Ines Abbes

Scheduling of processes

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

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

Operating Systems. Scheduling

by Maria Lima Term Paper for Professor Barrymore Warren Mercy College Division of Mathematics and Computer Information Science

CPU Scheduling Algorithms

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)

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

Practice Exercises 305

CS307: Operating Systems

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

Uniprocessor Scheduling. Aim of Scheduling

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

Operating Systems. Process scheduling. Thomas Ropars.

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

Scheduling. The Basics

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

CHAPTER 2: PROCESS MANAGEMENT

CS 326: Operating Systems. CPU Scheduling. Lecture 6

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)

Chapter 5 Process Scheduling

Uniprocessor Scheduling. Chapter 9

Chapter 5: Process Scheduling

Frequently asked questions from the previous class survey

Operating Systems ECE344. Ding Yuan

CS3733: Operating Systems

Scheduling. Today. Next Time Process interaction & communication

Interactive Scheduling

Two Level Scheduling. Interactive Scheduling. Our Earlier Example. Round Robin Scheduling. Round Robin Schedule. Round Robin Schedule

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

Unit 3 : Process Management

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)

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

High level scheduling: Medium level scheduling: Low level scheduling. Scheduling 0 : Levels

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

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

Uniprocessor Scheduling

Operating Systems: Quiz2 December 15, Class: No. Name:

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

Announcements/Reminders

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

Process Scheduling. Copyright : University of Illinois CS 241 Staff

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)

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

Chapter 9. Uniprocessor Scheduling

Operating System Review Part

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Scheduling - Overview

SMD149 - Operating Systems

Operating System Concepts Ch. 5: Scheduling

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

Start of Lecture: February 10, Chapter 6: Scheduling

CS Computer Systems. Lecture 6: Process Scheduling

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

Chapter 5: Process Scheduling

Scheduling Bits & Pieces

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

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

Computer Systems Laboratory Sungkyunkwan University

Job Scheduling. CS170 Fall 2018

CSCE Operating Systems Scheduling. Qiang Zeng, Ph.D. Fall 2018

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

CS 318 Principles of Operating Systems

Mid Term from Feb-2005 to Nov 2012 CS604- Operating System

Scheduling. Scheduling. Scheduling. Scheduling Criteria. Priorities. Scheduling

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

8th Slide Set Operating Systems

Chapter 6: CPU Scheduling

Chapter 6: CPU Scheduling

Today s class. Scheduling. Informationsteknologi. Tuesday, October 9, 2007 Computer Systems/Operating Systems - Class 14 1

CS370 Operating Systems

Chapter 6: CPU Scheduling

Transcription:

Scheduling in the Supermarket Consider a line of people waiting in front of the checkout in the grocery store. In what order should the cashier process their purchases?

Scheduling Criteria CPU utilization Keep the CPU as busy as possible. Throughput Maximize the number of tasks completed per time unit. Response time Minimize the time required to finish a task. Fairness Try to give a similar amount of CPU time to similar tasks; avoid starvation. Here, a task might be a thread, a single CPU burst in a thread, or an application-level service request (e.g., HTTP request).

The Nature of Program Execution A running thread typically alternates between CPU bursts and I/O bursts (or I/O waiting times). During a CPU burst, the thread is executing instructions. During an I/O burst, the thread is waiting for the hardware and not executing any instructions.

Preemptive vs. Non-Preemptive A non-preemptive scheduler only runs when the currently running thread gives up control of the CPU, by terminating; blocking due to I/O activity; performing a Yield system call; performing some other system call and thus transferring control of the CPU to the kernel. A preemptive scheduler may force a running thread to stop temporarily. The most important mechanism in a preemptive scheduler is the timer interrupt. A preempted thread is inserted into the scheduler's ready queue.

FCFS Scheduling First-Come, First-Served (FCFS) scheduling: non-preemptive: each thread runs until it blocks or terminates; scheduler maintains a FIFO ready queue.

Round-Robin Scheduling Round-Robin is a preemptive version of FCFS running thread is preempted after a predefined sched. quantum; preempted thread is appended to the FIFO ready queue.

Shortest Job First The Shortest Job First (SJF) scheduling policy is a non-preemptive scheduling policy. Ready threads are scheduled according to the length of their next CPU burst; the thread with the shortest burst is scheduled first. SJF minimizes mean waiting time, but can lead to starvation. Requires knowledge of the future. Possible solution: Estimate the length of the next burst based on previous bursts. B i+1 := * b i + (1 ) * B i where B i is the estimated length of the i-th burst, and b i is its actual (measured) length. is a dampening factor (0 1).

Shortest Job First

Shortest Remaining Time First Shortest Remaining Time First (SRTF) is a preemptive variant of the SJF scheduling policy. Preemption may occur whenever a new thread enters the system (via Fork or ThreadFork).

Highest Response Ratio Next Highest Response Ratio Next (HRRN) is a non-preemptive scheduling policy that takes the responsiveness of a thread into account. Responsiveness: How often does a thread yield control of the CPU because it is blocked on I/O acitivity? The response ratio of a thread T is defined as: RR(T) = (w + b) / b, where b is T's CPU burst time, and w is its waiting time. The scheduler chooses the thread with highest response ratio. HRRN's goal is to keep the system responsive by picking nice threads. This only makes sense for non-preemptive scheduling.

Probabilistic Scheduling In probabilistic scheduling, CPU time slices are not assigned deterministically, but according to some probability distribution. An example of probabilistic scheduling: Lottery Scheduling. In lottery scheduling, each thread is assigned a certain number of lottery tickets. The scheduling decision is based on the outcome of randomly selecting a ticket. The number of tickets a thread receives depends on certain thread characteristics, such as its interactivity. Probabilistic scheduling can be used to approximate a deterministic scheduling strategy, but avoids starvation (probably...).

Priorities The scheduler might take priorities into account when making a scheduling decision. Priorities can be based on (among other things): user ID (e.g., give higher priority to root); application type (e.g., kernel threads vs. user threads); explicit priority levels (e.g., SetPriority in Nachos). The scheduler will: always prefer higher-priority threads over lower-priority threads; use a scheduling heuristic (e.g., Round-Robin) to schedule threads at the same priority level.

Priorities Priority levels can be: static a thread always has the same priority; dynamic the priority of a thread may change over time. A general problem with priority-based CPU scheduling is that lowpriority threads risk starvation. This can be avoided with dynamic priority levels, where the priority of a thread is changed depending on how long it has been waiting for the CPU.

Multi-Level Feedback Queues One way to change thread priorities dynamically is to use a multilevel feedback queue. Properties of CPU scheduling with feedback queues: Priority is given to interactive threads. The scheduler maintains several ready queues; as long as there are threads in queue i, i j, the scheduler never selects a thread from queue j. When a thread gets unblocked (or created), it is put into ready queue 0. When a thread from queue i gets preempted, it is put into queue i+1.

Multi-Level Feedback Queues State diagram for a 3-level feedback queue

Different Types of Interactivity So far, we have considered blocking as evidence that a thread is interactive (interacting with the hardware or interacting with other threads). Interactive threads ought to receive higher priority. However, there are different types of interaction. In a desktop environment, user interaction is more important than interaction with the hard drive. How can we find out whether a thread is interacting with the user?

Summary of Scheduling Algorithms FCFS + Simple to implement; low overhead; no starvation. - Gives poor response time for interactive processes. Round-Robin + No starvation; reduced waiting time variance; good response time for interactive processes. SJF (Shortest Job First), SRTF (Shortest Resp. Time First) + Optimal average response time. - Effectiveness depends on the accuracy of estimating the burst lengths; starvation is possible. Feedback Queues + Good response time for interactive processes. - CPU-intensive processes might starve.

Multi-Processor Scheduling When a computer has more than 1 CPU, scheduling becomes more complicated. Two different paradigms: Asymmetric multiprocessing Have the different CPUs in the system perform different tasks; e.g., one CPU is responsible for I/O tasks, the other CPU does numerical computations. Symmetric multiprocessing (SMP) All CPUs basically do the same job. Issues in symmetric multiprocessing: Load balancing Keep both CPUs similarly busy (or not!). Differentiate between real CPU cores and virtual cores (hyperthreading).

Multi-Processor Scheduling More issues in symmetric multiprocessing: CPU affinity Let the user (or the operating system) decide which CPU a given thread to run on. This is important because it can lead to better utilization of the CPU cache. If a process consists of more than one thread, should the threads be executed on the same CPU or on different CPUs? In general, everything becomes more complicated, because of true parallelism (as opposed to mere concurrency). Operating system providers/vendors usually supply two different versions of their kernel, one for single-cpu systems, one for SMP.

Scheduling Scopes Covered so far: Short-term scheduling ( What task to run next? ). Medium-term scheduling: Suspension and resumption of processes. Processes are usually suspended because the system is overloaded (typically main memory). Suspended processes may release some resources (e.g., memory, CPU), but not all (e.g., open file descriptors). Sometimes, the operating system allows users to suspend a process (UNIX: Ctrl+Z). Long-term scheduling: Usually happens outside the core operating system.

Scheduling States with Suspend/Resume

CPU Scheduling in Solaris Each task in Solaris can be in one of four classes: 1. Real-time 2. System 3. Time sharing 4. Interactive Real-time tasks have the highest priority, followed by system tasks. Within each class, priority levels can be assigned to different tasks. Priority levels are changed via a multi-level feedback queue. A higher priority results in a shorter time quantum. If there are multiple threads at the same priority level, Solaris uses a Round-Robin scheduling algorithm to dispatch them.

CPU Scheduling in Linux Linux assigns tasks a priority between 0 and 140: 0..99: real-time priority levels 100..140: non-real-time (nice levels) A higher-priority thread is assigned a longer time quantum. Linux maintains a list of all runnable threads (the runqueue, 1 per CPU). A runqueue consists of two arrays: active and expired. The active array contains a tasks with remaining time in their time slices; the expired array contains all tasks with no time left. The scheduler chooses the highest-priority task from the active array until all threads are in expired. Then the arrays are swapped. Thread priorities can be changed (+/- 5) based on interactiveness whenever a thread it is moved from active to expired. Interaction includes keyboard, mouse, hard drive, sound card.

CPU Scheduling in Windows XP Windows XP supports 32 priority levels: 0: special system process 1..15: real-time processes 16..31: variable priority Each priority level has its own ready queue. Real-time processes are always scheduled first. When a task gets preempted, its priority is lowered (numerical priority is increased), but stays within a class-specific limit. When a thread becomes unblocked, its priority is raised; the amount of change depends on what it was waiting for (e.g., keyboard vs. hard drive). Windows running in the foreground receive a higher priority (and approximately 3x the original time slice).