W4118 Operating Systems. Instructor: Junfeng Yang



Similar documents
Linux scheduler history. We will be talking about the O(1) scheduler

Process Scheduling II

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

Linux Scheduler. Linux Scheduler

Scheduling policy. ULK3e 7.1. Operating Systems: Scheduling in Linux p. 1

Linux O(1) CPU Scheduler. Amit Gud amit (dot) gud (at) veritas (dot) com

ò Paper reading assigned for next Thursday ò Lab 2 due next Friday ò What is cooperative multitasking? ò What is preemptive multitasking?

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

W4118 Operating Systems. Instructor: Junfeng Yang

Linux Process Scheduling. sched.c. schedule() scheduler_tick() hooks. try_to_wake_up() ... CFS CPU 0 CPU 1 CPU 2 CPU 3

CPU Scheduling Outline

Linux Process Scheduling Policy

CPU Scheduling. Basic Concepts. Basic Concepts (2) Basic Concepts Scheduling Criteria Scheduling Algorithms Batch systems Interactive systems

Chapter 5 Process Scheduling

Process Scheduling in Linux

Objectives. Chapter 5: Process Scheduling. Chapter 5: Process Scheduling. 5.1 Basic Concepts. To introduce CPU scheduling

Deciding which process to run. (Deciding which thread to run) Deciding how long the chosen process can run

CPU SCHEDULING (CONT D) NESTED SCHEDULING FUNCTIONS

Comp 204: Computer Systems and Their Implementation. Lecture 12: Scheduling Algorithms cont d

Operating Systems Concepts: Chapter 7: Scheduling Strategies

2. is the number of processes that are completed per time unit. A) CPU utilization B) Response time C) Turnaround time D) Throughput

CPU Scheduling. CSC 256/456 - Operating Systems Fall TA: Mohammad Hedayati

Scheduling. Scheduling. Scheduling levels. Decision to switch the running process can take place under the following circumstances:

Chapter 5 Linux Load Balancing Mechanisms

Processor Scheduling. Queues Recall OS maintains various queues

Real-Time Scheduling 1 / 39

Operating Systems. III. Scheduling.

Objectives. Chapter 5: CPU Scheduling. CPU Scheduler. Non-preemptive and preemptive. Dispatcher. Alternating Sequence of CPU And I/O Bursts

Process Scheduling CS 241. February 24, Copyright University of Illinois CS 241 Staff

CPU Scheduling. Core Definitions

Process Scheduling in Linux

Scheduling. Yücel Saygın. These slides are based on your text book and on the slides prepared by Andrew S. Tanenbaum

Job Scheduling Model

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

ICS Principles of Operating Systems

Announcements. Basic Concepts. Histogram of Typical CPU- Burst Times. Dispatcher. CPU Scheduler. Burst Cycle. Reading

OPERATING SYSTEMS SCHEDULING

Operatin g Systems: Internals and Design Principle s. Chapter 10 Multiprocessor and Real-Time Scheduling Seventh Edition By William Stallings

/ Operating Systems I. Process Scheduling. Warren R. Carithers Rob Duncan

Completely Fair Scheduler and its tuning 1

CPU Scheduling. CPU Scheduling

Road Map. Scheduling. Types of Scheduling. Scheduling. CPU Scheduling. Job Scheduling. Dickinson College Computer Science 354 Spring 2010.

Overview of the Linux Scheduler Framework

Konzepte von Betriebssystem-Komponenten. Linux Scheduler. Valderine Kom Kenmegne Proseminar KVBK Linux Scheduler Valderine Kom

Introduction. Scheduling. Types of scheduling. The basics

Task Scheduling for Multicore Embedded Devices

Operating System: Scheduling

Multilevel Load Balancing in NUMA Computers

ò Scheduling overview, key trade-offs, etc. ò O(1) scheduler older Linux scheduler ò Today: Completely Fair Scheduler (CFS) new hotness

Lecture Outline Overview of real-time scheduling algorithms Outline relative strengths, weaknesses

Understanding the Linux CPU Scheduler

Understanding the Linux CPU Scheduler

Thomas Fahrig Senior Developer Hypervisor Team. Hypervisor Architecture Terminology Goals Basics Details

CPU Scheduling. Multitasking operating systems come in two flavours: cooperative multitasking and preemptive multitasking.

Improvement of Scheduling Granularity for Deadline Scheduler

Main Points. Scheduling policy: what to do next, when there are multiple threads ready to run. Definitions. Uniprocessor policies

Linux process scheduling

Mitigating Starvation of Linux CPU-bound Processes in the Presence of Network I/O

A Survey of Parallel Processing in Linux

CHAPTER 1 INTRODUCTION

Scheduling Algorithms

EECS 750: Advanced Operating Systems. 01/28 /2015 Heechul Yun

Real-time KVM from the ground up

Lecture 3 Theoretical Foundations of RTOS

Scheduling algorithms for Linux

CPU Scheduling 101. The CPU scheduler makes a sequence of moves that determines the interleaving of threads.

OS OBJECTIVE QUESTIONS

REAL TIME OPERATING SYSTEMS. Lesson-10:

Chapter 19: Real-Time Systems. Overview of Real-Time Systems. Objectives. System Characteristics. Features of Real-Time Systems

Operating Systems, 6 th ed. Test Bank Chapter 7

Project No. 2: Process Scheduling in Linux Submission due: April 28, 2014, 11:59pm

Linux Scheduler Analysis and Tuning for Parallel Processing on the Raspberry PI Platform. Ed Spetka Mike Kohler

Process Scheduling. Process Scheduler. Chapter 7. Context Switch. Scheduler. Selection Strategies

Linux Load Balancing

SYSTEM ecos Embedded Configurable Operating System

PROCESS SCHEDULING ALGORITHMS: A REVIEW

Effective Computing with SMP Linux

An Implementation Of Multiprocessor Linux

Hard Real-Time Linux

Why Relative Share Does Not Work

Readings for this topic: Silberschatz/Galvin/Gagne Chapter 5

Tasks Schedule Analysis in RTAI/Linux-GPL

4. Fixed-Priority Scheduling

A Group based Time Quantum Round Robin Algorithm using Min-Max Spread Measure

Real-Time Scheduling (Part 1) (Working Draft) Real-Time System Example

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

Understanding the Linux CPU Scheduler

An Adaptive Task-Core Ratio Load Balancing Strategy for Multi-core Processors

Exercises : Real-time Scheduling analysis

Kernel Optimizations for KVM. Rik van Riel Senior Software Engineer, Red Hat June

Operating Systems Lecture #6: Process Management

On Linux Starvation of CPU-bound Processes in the Presence of Network I/O

Transcription:

W4118 Operating Systems Instructor: Junfeng Yang

Outline Advanced scheduling issues Multilevel queue scheduling Multiprocessor scheduling issues Real-time scheduling Scheduling in Linux Scheduling algorithm Setting priorities and time slices Other implementation issues 1

Motivation No one-size-fits-all scheduler Different workloads Different environment Building a general scheduler that works well for all is difficult! Real scheduling algorithms are often more complex than the simple scheduling algorithms we ve seen

Combining scheduling algorithms Multilevel queue scheduling: ready queue is partitioned into multiple queues Each queue has its own scheduling algorithm Foreground processes: RR Background processes: FCFS Must choose scheduling algorithm to schedule between queues. Possible algorithms RR between queues Fixed priority for each queue

Outline Advanced scheduling issues Multilevel queue scheduling Multiprocessor scheduling issues Real-time scheduling Scheduling in Linux Scheduling algorithm Setting priorities and time slices Other implementation issues 4

Multiprocessor scheduling issues Shared-memory Multiprocessor processes CPU0 CPU1 CPU2 CPU3 How to allocate processes to CPU? 5

Symmetric multiprocessor Architecture Shared Memory $ $ $ $ CPU0 CPU1 CPU2 CPU3 Small number of CPUs Same access time to main memory Private cache 6

Global queue of processes One ready queue shared across all CPUs CPU0 CPU1 CPU2 CPU3 Advantages Good CPU utilization Fair to all processes Disadvantages Not scalable (contention for global queue lock) Poor cache locality Linux 2.4 uses global queue 7

Per-CPU queue of processes Static partition of processes to CPUs CPU0 CPU1 CPU2 CPU3 Advantages Easy to implement Scalable (no contention on ready queue) Better cache locality Disadvantages Load-imbalance (some CPUs have more processes) Unfair to processes and lower CPU utilization 8

Hybrid approach Use both global and per-cpu queues Balance jobs across queues CPU0 CPU1 CPU2 CPU3 Processor Affinity Add process to a CPU s queue if recently run on the CPU Cache state may still present Linux 2.6 uses a very similar approach 9

SMP: gang scheduling Multiple processes need coordination Should be scheduled simultaneously CPU0 CPU1 CPU2 CPU3 Scheduler on each CPU does not act independently Coscheduling (gang scheduling): run a set of processes simultaneously Global context-switch across all CPUs 10

Outline Advanced scheduling issues Multilevel queue scheduling Multiprocessor scheduling issues Real-time scheduling Scheduling in Linux Scheduling algorithm Setting priorities and time slices Other implementation issues 11

Real-time scheduling Real-time processes have timing constraints Expressed as deadlines or rate requirements E.g. gaming, video/music player, autopilot Hard real-time systems required to complete a critical task within a guaranteed amount of time Soft real-time computing requires that critical processes receive priority over less fortunate ones Linux supports soft real-time 12

Outline Advanced scheduling issues Multilevel queue scheduling Multiprocessor scheduling issues Real-time scheduling Scheduling in Linux Scheduling algorithm Setting priorities and time slices Other implementation issues 13

Linux scheduling goals Avoid starvation Boost interactivity Fast response to user despite high load Achieved by inferring interactive processes and dynamically increasing their priorities Scale well with number of processes O(1) scheduling overhead SMP goals Scale well with number of processors Load balance: no CPU should be idle if there is work CPU affinity: no random bouncing of processes Reference: Documentation/sched-design.txt 14

Algorithm overview Multilevel Queue Scheduler Each queue associated with a priority A process s priority may be adjusted dynamically Two classes of processes Real-time processes: always schedule highest priority processes FCFS (SCHED_FIFO) or RR (SCHED_RR) for processes with same priority Normal processes: priority with aging RR for processes with same priority (SCHED_NORMAL) Aging is implemented efficiently 15

Priority partition Total 140 priorities [0, 140) Smaller integer = higher priority Real-time: [0,100) Normal: [100, 140) MAX_PRIO and MAX_RT_PRIO include/linux/sched.h 16

runqueue data structure kernel/sched.c struct prio_array Array of priority queues struct runqueue Two arrays, active and expired 17

Scheduling algorithm 1. Find highest priority non-empty queue in rq- >active; if none, simulate aging by swapping active and expired 2. next = first process on that queue 3. Adjust next s priority 4. Context switch to next 5. When next used up its time slice, insert next to the right queue and call schedule again schedule() in kernel/sched.c 18

Aging: the traditional algorithm for(pp = proc; pp < proc+nproc; pp++) { } if (pp->prio!= MAX) pp->prio++; if (pp->prio > curproc->prio) reschedule(); Problem: O(N). Every process is examined on each schedule() call! This code is taken almost verbatim from 6 th Edition Unix, circa 1976.) 19

Simulate aging Swapping active and expired gives low priority processes a chance to run Advantage: O(1) Processes are touched only when they start or stop running schedule() in kernel/sched.c 20

Find highest priority non-empty queue Use the bitmap field of struct runqueue 140 queues 5 integers Time complexity: O(1) depends on the number of priority levels, not the number of processes Implementation: only a few compares to find the first that is non-zero Hardware instruction to find the first 1-bit bsfl on Intel sched_find_first_bit() in include/asmi386/bitops.h 21

Outline Advanced scheduling issues Multilevel queue scheduling Multiprocessor scheduling issues Real-time scheduling Scheduling in Linux Scheduling algorithm Setting priorities and time slices Other implementation issues 22

Priority related fields in struct task_struct static_prio: static priority set by administrator/users Default: 120 (even for realtime processes) Set use sys_nice() or sys_setpriority() Both call set_user_nice() prio: dynamic priority Index to prio_array rt_priority: real time priority prio = 99 rt_priority include/linux/sched.h 23

Adjusting priority Goal: dynamically increase priority of interactive process How to determine interactive? Sleep ratio Mostly sleeping: I/O bound Mostly running: CPU bound Implementation: sleep_avg in struct task_struct Before switching out a process, subtract from sleep_avg how many ticks a task ran, in schedule() Before switching in a process, add to sleep_avg how many ticks it was blocked up to MAX_SLEEP_AVG (10 ms), in schedule() recalc_task_prio() effective_prio() 24

Calculating time slices Stored in field time_slice in struct task_struct Higher priority processes also get bigger time-slice task_timeslice() in sched.c If (static_priority < 120) time_slice = (140-static_priority) * 20 If (static_priority >= 120) time_slice = (140-static_priority) * 5 25

Example time slices Priority: Static Pri Niceness Quantum Highest 100-20 800 ms High 110-10 600 ms Normal 120 0 100 ms Low 130 10 50 ms Lowest 139 20 5 ms 26

Outline Advanced scheduling issues Multilevel queue scheduling Multiprocessor scheduling issues Real-time scheduling Scheduling in Linux Scheduling algorithm Setting priorities and time slices Other implementation issues 27

Bookkeeping on each timer interrupt scheduler_tick() Called on each tick timer_interrupt do_timer_interrupt do_timer_interrupt_hook update_process_times If realtime and SCHED_FIFO, do nothing SCHED_FIFO is non-preemptive If realtime and SCHED_RR and used up time slice, move to end of rq->active[prio] If SCHED_NORMAL and used up time slice If not interactive or starving expired queue, move to end of rq- >expired[prio] Otherwise, move to end of rq->active[prio] Boost interactive Else // SCHED_NORMAL, and not used up time slice Break large time slice into pieces TIMESLICE_GRANULARITY

Real-time scheduling Linux has soft real-time scheduling No hard real-time guarantees All real-time processes are higher priority than any conventional processes Processes with priorities [0, 99] are real-time saved in rt_priority in the task_struct scheduling priority of a real time task is: 99 - rt_priority Process can be converted to real-time via sched_setscheduler system call 29

Real-time policies First-in, first-out: SCHED_FIFO Static priority Process is only preempted for a higher-priority process No time quanta; it runs until it blocks or yields voluntarily RR within same priority level Round-robin: SCHED_RR As above but with a time quanta Normal processes have SCHED_NORMAL scheduling policy 30

Multiprocessor scheduling Per-CPU runqueue Possible for one processor to be idle while others have jobs waiting in their run queues Periodically, rebalance runqueues Migration threads move processes from one runque to another The kernel always locks runqueues in the same order for deadlock prevention 31

Processor affinity Each process has a bitmask saying what CPUs it can run on By default, all CPUs Processes can change the mask Inherited by child processes (and threads), thus tending to keep them on the same CPU Rebalancing does not override affinity 32