Chapter 2 Process, Thread and Scheduling



Similar documents
SYSTEM ecos Embedded Configurable Operating System

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

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

Real-Time Scheduling 1 / 39

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

Operating Systems Concepts: Chapter 7: Scheduling Strategies

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

A Survey of Parallel Processing in Linux

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

Linux Scheduler. Linux Scheduler

CPU Scheduling Outline

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

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

W4118 Operating Systems. Instructor: Junfeng Yang

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

First-class User Level Threads

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

Linux Process Scheduling Policy

Chapter 5 Process Scheduling

CPU SCHEDULING (CONT D) NESTED SCHEDULING FUNCTIONS

CS414 SP 2007 Assignment 1

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

CPU Scheduling. CPU Scheduling

Completely Fair Scheduler and its tuning 1

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

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

An Implementation Of Multiprocessor Linux

OPERATING SYSTEMS SCHEDULING

Processor Scheduling. Queues Recall OS maintains various queues

REAL TIME OPERATING SYSTEMS. Lesson-10:

Process Scheduling in Linux

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

W4118 Operating Systems. Instructor: Junfeng Yang

Chapter 2: OS Overview

A Study of Performance Monitoring Unit, perf and perf_events subsystem

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

Introduction to Operating Systems. Perspective of the Computer. System Software. Indiana University Chen Yu

Tasks Schedule Analysis in RTAI/Linux-GPL

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

Operating Systems 4 th Class

Embedded Systems. 6. Real-Time Operating Systems

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

Operating Systems, 6 th ed. Test Bank Chapter 7

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

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

Chapter 13 Embedded Operating Systems

RTOS Debugger for ecos

Threads Scheduling on Linux Operating Systems

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

Chapter 5 Linux Load Balancing Mechanisms

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. Core Definitions

Long-term monitoring of apparent latency in PREEMPT RT Linux real-time systems

Outline of this lecture G52CON: Concepts of Concurrency

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

Multiprogramming. IT 3123 Hardware and Software Concepts. Program Dispatching. Multiprogramming. Program Dispatching. Program Dispatching

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

These sub-systems are all highly dependent on each other. Any one of them with high utilization can easily cause problems in the other.

OS OBJECTIVE QUESTIONS

Process Scheduling II

Operating System: Scheduling

A Comparative Study on Vega-HTTP & Popular Open-source Web-servers

ICS Principles of Operating Systems

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

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

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

Operating Systems. 05. Threads. Paul Krzyzanowski. Rutgers University. Spring 2015

Improvement of Scheduling Granularity for Deadline Scheduler

Kernel comparison of OpenSolaris, Windows Vista and. Linux 2.6

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

Jorix kernel: real-time scheduling

Operating Systems Lecture #6: Process Management

Real-time KVM from the ground up

Scheduling and Thread Management with RTEMS

Operating Systems. III. Scheduling.

ELEC 377. Operating Systems. Week 1 Class 3

Performance Comparison of RTOS

Effective Computing with SMP Linux

Priority Based Implementation in Pintos

Module 8. Industrial Embedded and Communication Systems. Version 2 EE IIT, Kharagpur 1

Lecture 6: Semaphores and Monitors

Scheduling in Distributed Systems

EE8205: Embedded Computer System Electrical and Computer Engineering, Ryerson University. Multitasking ARM-Applications with uvision and RTX

Introduction. Scheduling. Types of scheduling. The basics

Concurrent programming in Java

Ready Time Observations

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

Job Scheduling Model

Operating System Tutorial

Process Scheduling in Linux

VIRTUALIZATION AND CPU WAIT TIMES IN A LINUX GUEST ENVIRONMENT

Virtual Private Systems for FreeBSD

Transcription:

Chapter 2 Process, Thread and Scheduling Scheduler Class and Priority XIANG Yong xyong@tsinghua.edu.cn

Outline Scheduling Class and Priority Dispatch Queues & Dispatch Tables Thread Priorities & Scheduling Turnstiles & Priority Inheritance 2

Scheduling Class and Priority Solaris supports multiple scheduling classes Allows for the co-existence of different priority schemes andscheduling algorithms (policies) within the kernel Each scheduling class provides a class-specific function to manage thread priorities, administration, creation, termination, etc. The dispatcher is the kernel subsystem Manages the dispatch queues (run queues), handles thread selection, context switching, preemption, etc 3

Scheduling Classes Traditional Timeshare (TS) class attempt to give every thread a fair shot at execution time Interactive (IA) class Desktop only Boost priority of active (current focus) window Same dispatch table as TS System (SYS) Only available to the kernel, for OS kernel threads Realtime (RT) Highest priority scheduling class Will preempt kernel (SYS) class threads Intended for realtime applications 4

Scheduling Classes (Con d) Fair Share Scheduler (FSS) Class Same priority range as TS/IA class CPU resources are divided into shares Shares are allocated (projects/tasks) by administrator Scheduling decisions made based on shares allocated and used, not dynamic priority changes Fixed Priority (FX) Class The kernel will not change the thread's priority A batch scheduling class 5

Priorities 6

Scheduling Class Structures The kernel maintains an array of sclass structures for each loaded scheduling class Thread pointer to the class functions array, and perthread class-specific data structure Scheduling class operations vectors and CL_XXX macros allow a single, central dispatcher to invoke scheduling-class specific functions 7

8

Scheduling Class Specific Functions Implemented via macros #define CL_ENTERCLASS(t, cid, clparmsp, credp, bufp) \ (sclass[cid].cl_funcs->thread.cl_enterclass) (t, cid, \ (void *)clparmsp, credp, bufp) Class management and priority manipulation functions xx_admin, xx_getclinfo, xx_parmsin, xx_parmsout, xx_getclpri, xx_enterclass, xx_exitclass, xx_preempt, xx_sleep, xx_tick, xx_trapret, xx_fork, xx_parms[get set], xx_donice, xx_yield, xx_wakeup 9

Outline Scheduling Class and Priority Dispatch Queues & Dispatch Tables Thread Priorities & Scheduling Turnstiles & Priority Inheritance 10

Dispatcher The kernel subsystem that manages the dispatch queues (run queues), handles preemption, finding the next runnable thread, the idle loop, initiating context switching, etc Solaris implements per-processor dispatch queues - actually a queue of queues Several dispatcher-related variables maintained in the CPU structure as well cpu_runrun - preemption flag - do it soon cpu_kprunrun - kernel preemption flag - do it now! cpu_disp - dispatcher data and root of queues cpu_chosen_level - priority of next selected thread cpu_dispthread - kthread pointer A system-wide (or per-processor set) queue exists for realtime threads 11

Dispatch Queues Per-CPU run queues Actually, a queue of queues Ordered by thread priority Queue occupation represented via a bitmap For Realtime threads, a system-wide kernel preempt queue is maintained Realtime threads are placed on this queue, not the per-cpu queues If processor sets are configured, a kernel preempt queue exists for each processor set 12

Per-CPU Dispatch Queues 13

Dispatch Tables Per-scheduling class parameter tables Time quantums and priorities tuneable via dispadmin(1m) 14

TS Dispatch Table TS and IA class share the same dispatch table RES. Defines the granularity of ts_quantum ts_quantum. CPU time for next ONPROC state ts_tqexp. New priority if time quantum expires ts_slpret. New priority when state change from TS_SLEEP to TS_RUN ts_maxwait. waited too long ticks ts_lwait. New priority if waited too long 15

RT, FX & FSS Dispatch Tables RT Time quantum only For each possible priority FX Time quantum only For each possible priority FSS Time quantum only Just one, not defined for each priority level Because FSS is share based, not priority based SYS No dispatch table Not needed, no rules apply INT Not really a scheduling class 16

Setting A RT Thread s Priority 17

Dispatch Queue Placement Queue placement is based a few simple parameters The thread priority Processor binding/processor set Processor thread last ran on: Warm affinity Depth and priority of existing runnable threads Memory Placement Optimization (MPO) enabled will keep thread in defined locality group (lgroup) 18

Dispatch Queue Manipulation setfrontdq(), setbackdq() A thread will be placed on either the front of back of the appropriate dispatch queue depending on 19

Outline Scheduling Class and Priority Dispatch Queues & Dispatch Tables Thread Priorities & Scheduling Turnstiles & Priority Inheritance 20

Thread Priorities & Scheduling Every thread has 2 priorities; a global priority, derived based on its scheduling class, and (potentially) and inherited priority Priority inherited from parent, alterable via priocntl(1) command or system call Typically, threads run as either TS or IA threads IA threads created when thread is associated with a windowing system RT threads are explicitly created SYS class used by kernel threads, and for TS/IA threads when a higher priority is warranted A temporary boost when an important resource is being held Interrupts run at interrupt priority 21

Thread Selection The kernel dispatcher implements a select-and-ratify thread selection algorithm disp_getbest(). Go find the highest priority runnable thread, and select it for execution disp_ratify(). Commit to the selection. Clear the CPU preempt flags, and make sure another thread of higher priority did not become runnable > If one did, place selected thread back on a queue, and try again Warm affinity is implemented Put the thread back on the same CPU it executed on last > Try to get a warm cache rechoose_interval kernel parameter > Default is 3 clock ticks 22

Thread Preemption Two classes of preemption User preemption > A higher priority thread became runnable, but it's not a realtime thread > Flagged via cpu_runrun in CPU structure > Next clock tick, you're outta here Kernel preemption > A realtime thread became runnable. Even OS kernel threads will get preempted > Poke the CPU (cross-call) and preempt the running thread now 23

Thread Execution Run until A preemption occurs > Transition from S_ONPROC to S_RUN > placed back on a run queue A blocking system call is issued > e.g. read(2) > Transition from S_ONPROC to S_SLEEP > Placed on a sleep queue Done and exit > Clean up Interrupt to the CPU you're running on > pinned for interrupt thread to run > unpinned to continue 24

Sleep & Wakeup Condition variables used to synchronize thread sleep/wakeup A block condition (waiting for a resource or an event) enters the kernel cv_xxx() functions The condition variable is set, and the thread is placed on a sleep queue Wakeup may be directed to a specific thread, or all threads waiting on the same event or resource > One or more threads moved from sleep queue, to run queue 25

Sleep/Wakeup Kernel Subsystem 26

Outline Scheduling Class and Priority Dispatch Queues & Dispatch Tables Thread Priorities & Scheduling Turnstiles & Priority Inheritance 27

Turnstiles & Priority Inheritance Turnstile - A special set of sleep queues for kernel threads blocking on mutex or R/W locks Priority inversion - a scenerio where a thread holding a lock is preventing a higher priority thread from running, because the higher priority thread needs the lock. Priority inheritance - a mechanism whereby a kernel thread may inherit the priority of the higher priority kernel thread Turnstiles provide sleep/wakeup, with priority inheritance, for synchronization primitives 28

Priority Inversion 29

Turnstiles All active turnstiles reside in turnstile_table[], index via a hash function on the address of the synchronization object Each hash chain protected by a dispatcher lock, acquired by turnstile_lookup() Each kernel thread is created with a turnstile, in case it needs to block on a lock turnstile_block() - put the thread to sleep on the appropriate hash chain, and walk the chain, applying PI where needed 30

Turnstiles (con d) turnstile_wakeup() - waive an inherited priority, and wakeup the specific kernel threads For mutex locks, wakeup is called to wake all kernel threads blocking on the mutex For R/W locks; If no waiters, just release the lock If a writer is releasing the lock, and there are waiting readers and writers, waiting readers get the lock if they are of the same or higher priority than the waiting writer A reader releasing the lock gives priority to waiting writers 31

Turnstiles (con d) 32

Reference Richard McDougall, James Mauro, "SOLARIS Kernel Performance, Observability & Debugging", USENIX'05, 2005, t2-solaris-slides.pdf Solaris internals and performance management, Richard McDougall, 2002, class0802.pdf 33

End 2006-02-19 34