Lecture Note #6: More on Task Scheduling EECS 571 Principles of Real-Time Embedded Systems Kang G. Shin EECS Department University of Michigan

Similar documents
Shared resources. Sistemi in tempo reale. Giuseppe Lipari. Scuola Superiore Sant Anna Pisa -Italy

CIS 4930/6930: Principles of Cyber-Physical Systems

Real Time Operating Systems

Real Time Operating Systems

Periodic scheduling 05/06/

Real-Time Scheduling and Resource Management

Lec. 7: Real-Time Scheduling

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

Non-preemptive Fixed Priority Scheduling of Hard Real-Time Periodic Tasks

CSE 380 Computer Operating Systems

Simulation of Process Scheduling Algorithms

Scheduling Slack Time in Fixed Priority Pre-emptive Systems

Module 5: CPU Scheduling

Chapter 6: CPU Scheduling

An Improved Schedulability Test for Uniprocessor. Periodic Task Systems

CPU scheduling. CPU Scheduling

Rate Monotonic Analysis (RMA)

Resource Sharing in an Enhanced Rate-Based Execution Model

Clock-driven scheduling

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

An Improved Schedulability Test for Uniprocessor Periodic Task Systems

Lecture 13. Real-Time Scheduling. Daniel Kästner AbsInt GmbH 2013

TDDB68 Concurrent programming and operating systems. Lecture: CPU Scheduling II

Embedded Systems Development

Improved Priority Assignment for the Abort-and-Restart (AR) Model

Global Real-Time Semaphore Protocols: A Survey, Unified Analysis, and Comparison

Resource Sharing Protocols for Real-Time Task Graph Systems

Non-Preemptive and Limited Preemptive Scheduling. LS 12, TU Dortmund

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

Real-Time and Embedded Systems (M) Lecture 5

Dependency Graph Approach for Multiprocessor Real-Time Synchronization. TU Dortmund, Germany

Networked Embedded Systems WS 2016/17

2/5/07 CSE 30341: Operating Systems Principles

CPU Scheduling. Heechul Yun

CPU Scheduling. CPU Scheduler

Embedded Systems 15. REVIEW: Aperiodic scheduling. C i J i 0 a i s i f i d i

CS 550 Operating Systems Spring CPU scheduling I

Real-time operating systems course. 6 Definitions Non real-time scheduling algorithms Real-time scheduling algorithm

Priority-driven Scheduling of Periodic Tasks (1) Advanced Operating Systems (M) Lecture 4

Aperiodic Task Scheduling

Deadlock Ezio Bartocci Institute for Computer Engineering

Probabilistic Preemption Control using Frequency Scaling for Sporadic Real-time Tasks

CPU SCHEDULING RONG ZHENG

CSC501 Operating Systems Principles. Deadlock

TDDI04, K. Arvidsson, IDA, Linköpings universitet CPU Scheduling. Overview: CPU Scheduling. [SGG7] Chapter 5. Basic Concepts.

UC Santa Barbara. Operating Systems. Christopher Kruegel Department of Computer Science UC Santa Barbara

Improved Analysis and Evaluation of Real-Time Semaphore Protocols for P-FP Scheduling (extended version)

The FMLP + : An Asymptotically Optimal Real-Time Locking Protocol for Suspension-Aware Analysis

Online Energy-Aware I/O Device Scheduling for Hard Real-Time Systems with Shared Resources

Selected solutions for. TDDD07 Real-time Systems

LSN 15 Processor Scheduling

Schedulability Analysis for the Abort-and-Restart Model

Real-Time Systems. Event-Driven Scheduling

Bounding the Maximum Length of Non-Preemptive Regions Under Fixed Priority Scheduling

Resource-locking durations in EDF-scheduled systems

Real-time Scheduling of Periodic Tasks (1) Advanced Operating Systems Lecture 2

Process Scheduling. Process Scheduling. CPU and I/O Bursts. CPU - I/O Burst Cycle. Variations in Bursts. Histogram of CPU Burst Times

Real-Time Scheduling. Real Time Operating Systems and Middleware. Luca Abeni

Worst-case response time analysis of real-time tasks under fixed-priority scheduling with deferred preemption revisited

Real-time Scheduling of Periodic Tasks (2) Advanced Operating Systems Lecture 3

Scheduling I. Today Introduction to scheduling Classical algorithms. Next Time Advanced topics on scheduling

Optimality Results for Multiprocessor Real-Time Locking

Operating Systems. VII. Synchronization

Cyclic Schedules: General Structure. Frame Size Constraints

Last class: Today: Synchronization. Deadlocks

Last class: Today: Threads. CPU Scheduling

NATCOR: Stochastic Modelling

Lecture 6. Real-Time Systems. Dynamic Priority Scheduling

Scheduling I. Today. Next Time. ! Introduction to scheduling! Classical algorithms. ! Advanced topics on scheduling

EECS 571 Principles of Real-Time Embedded Systems. Lecture Note #7: More on Uniprocessor Scheduling

There are three priority driven approaches that we will look at

Static priority scheduling

A Note on Modeling Self-Suspending Time as Blocking Time in Real-Time Systems

CycleTandem: Energy-Saving Scheduling for Real-Time Systems with Hardware Accelerators

Schedulability Analysis for the Abort-and-Restart (AR) Model

Andrew Morton University of Waterloo Canada

Design and Performance Evaluation of a New Proposed Shortest Remaining Burst Round Robin (SRBRR) Scheduling Algorithm

Real-Time Systems. Lecture #14. Risat Pathan. Department of Computer Science and Engineering Chalmers University of Technology

EDF Feasibility and Hardware Accelerators

Embedded Systems 14. Overview of embedded systems design

An Optimal k-exclusion Real-Time Locking Protocol Motivated by Multi-GPU Systems

A Dynamic Real-time Scheduling Algorithm for Reduced Energy Consumption

Response Time Analysis for Tasks Scheduled under EDF within Fixed Priorities

Optimal Utilization Bounds for the Fixed-priority Scheduling of Periodic Task Systems on Identical Multiprocessors. Sanjoy K.

Controlling Preemption for Better Schedulability in Multi-Core Systems

CHAPTER 5 - PROCESS SCHEDULING

Reducing Tardiness Under Global Scheduling by Splitting Jobs

3. Scheduling issues. Common approaches 3. Common approaches 1. Preemption vs. non preemption. Common approaches 2. Further definitions

COMPARATIVE PERFORMANCE ANALYSIS OF MULTI-DYNAMIC TIME QUANTUM ROUND ROBIN (MDTQRR) ALGORITHM WITH ARRIVAL TIME

Lightweight Real-Time Synchronization under P-EDF on Symmetric and Asymmetric Multiprocessors

CS 453 Operating Systems. Lecture 7 : Deadlock

Exploiting Precedence Relations in the Schedulability Analysis of Distributed Real-Time Systems

Real-Time Systems. Event-Driven Scheduling

Lightweight Real-Time Synchronization under P-EDF on Symmetric and Asymmetric Multiprocessors

Uniprocessor real-time scheduling

Journal of Global Research in Computer Science

Blocking time under basic priority inheritance: Polynomial bound and exact computation

Real-time Systems: Scheduling Periodic Tasks

arxiv: v1 [cs.os] 6 Jun 2013

Online Scheduling Switch for Maintaining Data Freshness in Flexible Real-Time Systems

Transcription:

Lecture Note #6: More on Task Scheduling EECS 571 Principles of Real-Time Embedded Systems Kang G. Shin EECS Department University of Michigan Note 6-1

Mars Pathfinder Timing Hiccups? When: landed on the Mar on July 4, 1997 Mission: gathering and sending back voluminous data to Earth. Problem: resetting the entire computer system, each reset resulting in data loss (``software glitches?'') System Used and Cause Found: Wind River System's VxWorks that supports preemptive priority scheduling. ``Information bus' ( shared memory) accessed via mutexes. The bus management task T 1 ran frequently with high priority Meteorological data collection task T 3 is an infrequent, low-priority task, and uses the info bus to publish its data. (It acquires mutex, writes data to the bus, then releases the mutex.) a medium-priority, long commercial task T 2. Scenario: T 1 blocks on the mutex held by T 3 and in the meantime T 2 preempts T 3 ; not executing T 1 for certain time triggers a watchdog timer resetting the system. How was the problem solved: A short C program was uploaded to the spacecraft which changed parameter initialization. Note 6-2

Synchronization Protocols Non-preemption Basic priority inheritance Highest locker s priority Priority ceiling All of these prevent unbounded priority inversion. Note 6-3

Non-preemption Protocol τ 2 :{ P(S1) V(S1) } τ 4 :{ P(S1) V(S1) } τ 1 (H) ready blocked ready τ 2 ready τ 3 S1 locked S1 unlocked τ 4 (L) Time Note 6-4

Advantages and Disadvantages Advantages: Simplicity Use with fixed-priority and dynamic-priority systems No prior knowledge about resource requirement by each task Good when all critical sections are short Disadvantages: Every task can be blocked by every lower priority task, even when there is no resource sharing between the tasks. Blocking time: max(cs i ) Note 6-5

Basic Inheritance Protocol (BIP) ready τ 2 :{ P(S1) V(S1) } τ 4 :{ P(S1) V(S1) } τ 1 (H) ready attempts to lock S1 S1 locked S1 unlocked τ 2 blocked ready τ 3 S1 locked S1 unlocked τ 4 (L) inherits the priority of τ 2 after τ 2 is blocked Note 6-6

Some Notations J i is the i-th job of periodic task T. π i = job J i s assigned priority π i (t) = current (at time t) priority of J i If the decision to change the priority of J i is made at t = t 1 then π i (t 1- ) = priority at and immediately before t 1, π i (t 1+ ) = priority immediately after the priority change Ω = nonexistent priority, lower than the lowest priority Note 6-7

Terminology and Rules At time t 1, job J i requests resource R k. R k J l : Resource R k is held by job J l J i R k : Job J i is blocked waiting for resource R k to be released (J i R k J l ) Scheduling Rules: Ready jobs are scheduled on processors preemptively according to their current priorities, π i (t). Upon release of a job, its priority is equal to its assigned priority if J i is released at t = t, then π i (t ) = π i Resource allocation: If a resource is free, then it is allocated when it is requested if not free, then the request is denied and the requesting job is blocked Note 6-8

Priority Inheritance Rules Scheduling Rule: same as the assumptions Allocation Rule: same as the assumptions Priority-Inheritance Rule: if J i R k J l and π l (t 1- ) = priority of J l at t = t 1 then π l (t 1+ ) = π i (t 1 ) until J l releases R k at t 2 when π l (t 2+ ) = π l (t 1- ) L. Sha, R. Rajkumar, J. Lehoczky, Priority Inheritance Protocols: An Approach to Real-Time Synchronization, IEEE Transactions on Computers, Vol. 39, No. 9, pp. 1175-1185, 1990 Note 6-9

Properties of Priority Inheritance For each resource (semaphore), a list of blocked tasks must be stored in a priority queue. A task (job) τ i uses its assigned priority, and inherits the highest dynamic priority of all the tasks it blocks when it is in its critical section and blocks some higher priority tasks. Priority inheritance is transitive; that is, if taskτ i blocks τ j and τ j blocks τ k, then τ i can inherit the priority of τ k. Whenτ i releases a resource, which priority should it use? Chained/nested blocking if requesting multiple resources (nested mutex requests) Direct blocking and indirect (inheritance) blocking (when the lower priority task inherits the higher priority task s priority). Note 6-10

Example of Chained/nested Blocking (BIP) τ 1 :{ P(S1) P(S2) V(S2) V(S1) } τ 2 :{ P(S1) V(S1) } τ 3 :{ P(S2) V(S2) } Attempts to lock S1(blocked) Attempts to lock S2(blocked) τ 1 (H) B B B S1 locked S1 unlocked τ 2 (M) S2 locked S2 unlocked τ 3 (L) Note 6-11

Deadlock: Using BIP τ 1 :{ P(S1) P(S2) V(S2) V(S1)..} τ 2 :{ P(S2) P(S1) V(S1) V(S2)..} Locks S1 Attempts to lock S2 (blocked) τ 1 (H) B S2 locked Attempts to lock S1 (blocked) => deadlock! τ 2 (M) Note 6-12

Blocking Time Under BIP Example T1 = {.. P(A).3. P(B).2. V(B).1. V(A)..} T2 = {.. P(C).2. V(C)..} T3 = {.. P(A).1. P(B).2. V(B).2. V(A).. } T4 = {.. P(A).1. P(C).1. P(B).3. V(B).1. V(C).1. V(A).. } direct blocking by indirect blocking by blocking time T2 T3 T4 T2 T3 T4 T2 T3 T4 T1 N Y Y 5 7 T2 N Y Y Y 5 7 T3 Y Y 7 Note 6-13

Priority Ceiling Protocol (PCP) τ 1 (H) ready τ 2 :{ P(S1) V(S1) } τ 3 : { P(S2) V(S2) } τ 4 : { P(S1) V(S1) } attempts to lock S1 S1 locked S1 unlocked B τ 2 ready attempts to lock S2 S2 locked τ 3 S1 locked blocked by ceiling S1 unlocked τ 4 (L) Note 6-14

Basic Priority Ceiling Rules (1) Π(R) = priority ceiling of resource R the highest priority of the tasks that request R Π S (t) = system priority ceiling the highest priority ceiling of all resources that are in use at time t Scheduling Rule: same as the assumptions Allocation Rule: if J i R k J l at t t 1 then block J i (no change) if R k becomes free at t 1, if π i (t 1 ) > Π S (t 1 ), then R k J i else (i.e., π i (t 1 ) Π S (t 1 ) ) if for some R x J i and Π(R x ) = Π S (t 1 ), then R k J i [J i holds resource R x whose priority ceiling is Π S (t 1 ) ] else deny and block (J i R k ) Note 6-15

Basic Priority Ceiling Rules (2) Priority-Inheritance Rule: if J i R k at t = t 1 and is blocked by J l (and π l (t 1- ) = priority of J l ) either R k J l, (J l holds the resource R k ) or J l R x and Π(R x ) = Π S (t 1 ) π i (t 1 ) then π l (t 1+ ) = π i (t 1 ) (inherited priority) until J l releases all R x with Π(R x ) π i (t 1 ), π l (t 2+ ) = π l (t 1- ) at t = t 2. Note 6-16

Blocking in PCP A task T H can be blocked by a lower-priority task T L in three ways: directly, i.e., T H X T L request for allocated to when T L inherits a priority higher than the priority π H of T H. T T H X T L (π > π H ) When T H requests a resource and the priority ceiling of all resources held by T L is equal to or higher than π H : T H Y X T L (π H Π X ) Note 6-17

Blocked At Most Once (PCP) τ 1 :{ P(S1) P(S2) V(S2) V(S1) } τ 2 :{ P(S1) V(S1) } τ 3 :{ P(S2) V(S2) } τ 1 (H) S2 locked S1 locked attempts to lock S1(blocked) B S2 unlocked S1 unlocked τ 2 (M) attempts to lock S1(blocked) S1 locked S1 unlocked S2 locked S2 unlocked τ 3 (L) Note 6-18

Deadlock Avoidance: Using PCP τ 1 :{ P(S1) P(S2) V(S2) V(S1)..} τ 2 :{ P(S2) P(S1) V(S1) V(S2)..} Attempts to lock S1 (blocked) Locks S1 Locks S2 Unlocks S2 Unlocks S1 τ 1 (H) C Locks S2 Locks S1 Unlocks S1 Unlocks S2 τ 2 (M) Note 6-19

Stack Sharing Sharing a stack among multiple tasks eliminates stack space fragmentation, making memory savings: T 1 T 1 T i T i T n T n no stack sharing stack sharing However: Once job is preempted, it can only resume when it returns to be on top of stack. Otherwise, it may cause a deadlock. Stack becomes a resource that allows for one-way preemption. Note 6-20

Stack-Based Priority Ceiling Protocol To avoid deadlocks: Once execution begins, make sure that job is not blocked due to resource access allow preemption only if the priority is higher than the ceiling of all resources in use Update Current Ceiling in the usual manner If no resource allocated, Π S (t) = Ω Scheduling Rule: J i released and blocked until π i (t) > Π S (t) When not blocked, jobs are scheduled in the usual manner. Allocation Rule: Allocate when requested Note 6-21

Stack-Based PCP, cont d The Stack-Based Priority-Ceiling Protocol is deadlock-free: When a job begins to execute, all the resources it will ever need are free. Otherwise, Π S (t) would be higher or equal to the priority of the job. Whenever a job is preempted, all the resources needed by the preempting job are free. The preempting job can complete, and then the preempted job can resume. Worst-case blocking time of Stack-Based Protocol is the same as for Basic Priority Ceiling Protocol. Stack-Based Protocol smaller context-switch overhead 2 context switches since once execution starts, job cannot be blocked (may be preempted) 4 context switches for PCP since a job may be blocked at most once Note 6-22

Ceiling-Priority Protocol Re-formulation of stack-based priority ceiling protocol for multiple stacks (w/o stack-sharing) Update Current Ceiling in the usual manner Scheduling Rule: No resources held by J i, π i (t) = π i Resource held by J i,π i (t) = max(π(r x )) for all resources R x held by J i FIFO scheduling among jobs with equal priority Allocation Rule: Allocate when requested Note 6-23

Comparison Worst-case performance of stack-based and basic ceiling protocols are the same Stack-based version supported by the Real-Time systems Annex of Ada95 Jobs must not self-suspend When jobs do not self-suspend, stack-based and ceiling-priority protocols yield the same schedules. Stack-based and ceiling-priority have the same worst-case blocking time. Note 6-24

Highest Locker s Priority Protocol τ 2 :{ P(S1) V(S1) } τ 4 :{ P(S1) V(S1) } τ 1 (H) τ 2 ready B ready B τ 3 S1 locked S1 unlocked τ 4 (L) run with the priority of τ 2 Note 6-25

Summary of Synchronization Protocols Protocol Nonpreemptible critical sections Highest locker's priority Bounded Priority Inversion Blocked at Most Once Deadlock Avoidance Yes Yes 1 Yes 1 Yes Yes 1 Yes 1 Basic inheritance Yes No No Priority Ceiling Yes Yes 2 Yes 1 Only if tasks do not suspend within critical sections 2 PCP is not affected if tasks suspend within critical sections. Note 6-26