Linux O(1) CPU Scheduler. Amit Gud amit (dot) gud (at) veritas (dot) com http://amitgud.tk



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

W4118 Operating Systems. Instructor: Junfeng Yang

Process Scheduling II

Understanding the Linux CPU Scheduler

Understanding the Linux CPU Scheduler

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

CPU Scheduling Outline

Understanding the Linux CPU Scheduler

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

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

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

Linux Scheduler. Linux Scheduler

Linux Load Balancing

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

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

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

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

CPU Scheduling. Core Definitions

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 Linux Load Balancing Mechanisms

Chapter 5 Process Scheduling

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

CPU SCHEDULING (CONT D) NESTED SCHEDULING FUNCTIONS

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

OPERATING SYSTEMS SCHEDULING

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

Operating Systems Concepts: Chapter 7: Scheduling Strategies

Operating System: Scheduling

Process Scheduling in Linux

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

Operating Systems. III. Scheduling.

Overview of the Linux Scheduler Framework

Process Scheduling in Linux

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

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

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

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

Scheduling Algorithms

CPU Scheduling. CPU 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

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

Tasks Schedule Analysis in RTAI/Linux-GPL

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

ICS Principles of Operating Systems

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

Linux process scheduling

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

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

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

Completely Fair Scheduler and its tuning 1

Real-Time Scheduling 1 / 39

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

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

Threads Scheduling on Linux Operating Systems

Process Scheduling in Linux

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

W4118 Operating Systems. Instructor: Junfeng Yang

Task Scheduling for Multicore Embedded Devices

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

Linux Process Scheduling Policy

Introduction. Scheduling. Types of scheduling. The basics

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

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

Operating Systems Lecture #6: Process Management

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

A Survey of Parallel Processing in Linux

Improvement of Scheduling Granularity for Deadline Scheduler

A complete guide to Linux process scheduling. Nikita Ishkov

Operating System Multilevel Load Balancing

An Implementation Of Multiprocessor Linux

Modular Real-Time Linux

Operating Systems, 6 th ed. Test Bank Chapter 7

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

Hard Real-Time Linux

CFS-v: I/O Demand-driven VM Scheduler in KVM

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

Operating System Tutorial

REAL TIME OPERATING SYSTEMS. Lesson-10:

OS OBJECTIVE QUESTIONS

CS Fall 2008 Homework 2 Solution Due September 23, 11:59PM

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

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

Load-Balancing for a Real-Time System Based on Asymmetric Multi-Processing

Update on big.little scheduling experiments. Morten Rasmussen Technology Researcher

LAB 5: Scheduling Algorithms for Embedded Systems

Effective Computing with SMP Linux

Resource Reservation & Resource Servers. Problems to solve

Lecture 3 Theoretical Foundations of RTOS

Processor Scheduling. Queues Recall OS maintains various queues

Transcription:

Linux O(1) CPU Scheduler Amit Gud amit (dot) gud (at) veritas (dot) com http://amitgud.tk April 27, 2005

Agenda CPU scheduler basics CPU scheduler algorithms overview Linux CPU scheduler goals What is O(1)? Data structures of O(1) CPU scheduler Quick run through the task execution process Calculation of priorities Calculation of timeslices NUMA / SMP support Load Balancing 2 Amit Gud

CPU Scheduler Basics Programs and processes Threads CPU timeslices Multiprogramming and preemption I/O bound and CPU bound processes Context switching 3 Amit Gud

CPU Scheduler Algorithms Overview First Come First Server (FCFS) Shortest Job First (SJF) Priority scheduling Round robin Multilevel queue Multilevel feedback queue 4 Amit Gud

Linux CPU Scheduler Goals Efficiency Interactivity Fairness SMT / SMP scheduling NUMA scheduling Soft real-time scheduling 5 Amit Gud

What is O(1)? /* O(n) algorithm */ Time complexity Big-O notation O(n 2 ) > O(n) O(n) > O(1) for (i = 0; i < n; i++) { printf( i: 5d\n, i); } /* O(n*m) = O(n*n) algorithm */ for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { } printf( i: %d, j: %d\n, i, j); } 6 Amit Gud

Data Structures - runqueue kernel/sched.c: For tracking all runnable processes Maintained per CPU struct runqueue { spinlock_t lock; /* lock for this q */ task_t *curr; /* current task */ task_t *idle; /* the idle task */ prio_array_t *active; /* active array */ prio_array_t *expired; /* expired array */ struct sched_domain *sd;/* for SMP/NUMA */ task_t *migration_thread; /*migration task*/...... }; 7 Amit Gud

Data Structures priority arrays kernel/sched.c: Forms the basis of O(1) nature of the scheduler 140 priority levels 2 priority arrays per runqueue struct prio_array { unsigned int nr_active; unsigned long bitmap[bitmap_size]; struct list_head queue[max_prio]; }; include/linux/sched.h: typedef struct prio_array prio_array_t; #define MAX_PRIO 140 8 Amit Gud

Priority arrays contd... Two priority arrays per runqueue active array inactive array Tasks are scheduled from active array When active array is empty, active array and expired arrays are swapped. 9 Amit Gud

When task becomes runnable... Priority calculation Addition of the task to the priority queue of the active runqueue of some CPU (selection depends on the load balancing and cache warmth exploit) Setting the bit in the bitmask of the active priority queue 10 Amit Gud

When a running task becomes unschedulable... Priority calculation Moving the task from active priority queue to inactive one Resetting the bit in the bitmask of the active priority queue 11 Amit Gud

Selecting a task for scheduling Find first set bit in the bitmask of the active array (using ffs() - O(1), length of bitmask is constant) Schedule the task of that priority from the linked list If more than one task of that priority, round robin is applied 12 Amit Gud

Priority Calculation <-- user tasks --> Static priority nice value [-20, 19] by default 0 used for timeslice calculation Dynamic priority [0, 139] signifies the type of the task I/O bound or CPU bound 0 100 140 MAX_RT_PRIO <-- kernel threads & RT tasks --> lower the priority value higher the priority MAX_PRI O 13 May 4, 2005

Dynamic Priority Calculation Penalty (addition) for CPU bound tasks and reward (subtraction) for I/O bound tasks [-5, 5] p >sleep_avg : average amount of time a task sleeps vs. average amount of time task uses CPU p >sleep_avg += sleep_time p >sleep_avg = run_time Higher sleep_avg > more I/O bound the task -> more reward. And vice versa. 14 Amit Gud

Dynamic Priority Calculation contd... Mapping sleep_avg to range 0 MAX_BONUS, i.e. 0-10 MAX_SLEEP_AVG : MAX_BONUS SLEEP_AVG : X (unknown) bonus = X MAX_BONUS / 2; p >prio = p >static_prio bonus; 15 Amit Gud

Timeslice Calculation Mapping of static_prio (nice value) onto MIN_TIMESLICE MAX_TIMESLICE Directly proportional to static_prio i.e. MIN_TIMESLICE + static_prio scaled onto possible timeslice ranges 16 Amit Gud

Interactive Credit Earned when a task sleeps for a 'long' time Spent when a task runs for a 'long' time IC is used to avoid loosing interactivity of the task very soon or vice versa CPU hog sleeping occasionally for a long time I/O bound task occasionally utilizing CPU for a long time 17 Amit Gud

Real-Time Tasks Have priority between 0 99, so always preempt non- RT tasks No penalties or bonuses Scheduling schemes SCHED_FIFO preempts any other task, no timeslice limit, obeys priorities amongst other SCHED_FIFO tasks SCHED_RR preempts SCHED_NORMAL tasks, round robin scheduling amongst same priority SCHED_RR tasks 18 Amit Gud

SMP / NUMA Support Virtual hierarchy sched_domain sched_group 19 Amit Gud

Load Balancing Balancing attempted after certain time interval rq > cpu_load : represents load on the CPU calculated every timer interrupt calculated as average of previous load and current load #define SCHED_LOAD_SCALE 128 current_load = rq >nr_running * SCHED_LOAD_SCALE; Bottom up load balancing Pulling of tasks instead of pushing 20 Amit Gud

References Understanding the Linux 2.6.8.1 CPU Scheduler Josh Aas. http://josh.trancesoftware.com/linux/ Linux on NUMA Systems Bligh, Dobson, Hart, Huizenga. Proceedings of the Linux Symposium 2004 Linux Kernel Source Code http://lxr.linux.no/source 21 Amit Gud