Copyright Notice. COMP9242 Advanced Operating Systems S2/2014 Week 9: Real-Time Systems. Real-Time System: Definition

Similar documents
Department of Computer Science Institute for System Architecture, Operating Systems Group REAL-TIME MICHAEL ROITZSCH OVERVIEW

Exam Review TexPoint fonts used in EMF.

Implementing Scheduling Algorithms. Real-Time and Embedded Systems (M) Lecture 9

Towards Principled OS-Level Temporal Isola?on

Real-Time and Concurrent Programming Lecture 6 (F6): Scheduling and bounded response times

Microkernel/OS and Real-Time Scheduling

Analyzing Real-Time Systems

Real Time Operating Systems and Middleware

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable

Multiprocessor and Real-Time Scheduling. Chapter 10

A Capacity Sharing and Stealing Strategy for Open Real-time Systems

Event-Driven Scheduling. (closely following Jane Liu s Book)

Simplified design flow for embedded systems

Constructing and Verifying Cyber Physical Systems

Introduction to Embedded Systems

REAL-TIME OVERVIEW SO FAR MICHAEL ROITZSCH. talked about in-kernel building blocks:

Overview of Scheduling a Mix of Periodic and Aperiodic Tasks

Commercial Real-time Operating Systems An Introduction. Swaminathan Sivasubramanian Dependable Computing & Networking Laboratory

Ensuring Schedulability of Spacecraft Flight Software

Multiprocessor and Real- Time Scheduling. Chapter 10

Tasks. Task Implementation and management

A Synchronous IPC Protocol for Predictable Access to Shared Resources in Mixed-Criticality Systems

What s an Operating System? Real-Time Operating Systems. Cyclic Executive. Do I Need One? Handling an Interrupt. Interrupts

Overview. Sporadic tasks. Recall. Aperiodic tasks. Real-time Systems D0003E 2/26/2009. Loosening D = T. Aperiodic tasks. Response-time analysis

DISTRIBUTED REAL-TIME SYSTEMS

Aperiodic Servers (Issues)

Introduction to Real-time Systems. Advanced Operating Systems (M) Lecture 2

Concurrent activities in daily life. Real world exposed programs. Scheduling of programs. Tasks in engine system. Engine system

CS4514 Real-Time Systems and Modeling

Time Triggered and Event Triggered; Off-line Scheduling

REAL-TIME OPERATING SYSTEMS SHORT OVERVIEW

Real-time operating systems and scheduling

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

Verification of Real-Time Systems Resource Sharing

A Predictable RTOS. Mantis Cheng Department of Computer Science University of Victoria

Lecture 12: An Overview of Scheduling Theory

NuttX Realtime Programming

6.1 Motivation. Fixed Priorities. 6.2 Context Switch. Real-time is about predictability, i.e. guarantees. Real-Time Systems

PROCESS SCHEDULING II. CS124 Operating Systems Fall , Lecture 13

Embedded Systems. 6. Real-Time Operating Systems

Precedence Graphs Revisited (Again)

Programming Languages for Real-Time Systems. LS 12, TU Dortmund

EECS 571 Principles of Real-Time Embedded Systems. Lecture Note #10: More on Scheduling and Introduction of Real-Time OS

OVERVIEW. Last Week: But if frequency of high priority task increases temporarily, system may encounter overload: Today: Slide 1. Slide 3.

Two Real-Time Operating Systems and Their Scheduling Algorithms: QNX vs. RTLinux

Learning Outcomes. Scheduling. Is scheduling important? What is Scheduling? Application Behaviour. Is scheduling important?

Subject Name: OPERATING SYSTEMS. Subject Code: 10EC65. Prepared By: Kala H S and Remya R. Department: ECE. Date:

Embedded Software Programming

CS4514 Real Time Scheduling

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)

Enriching Enea OSE for Better Predictability Support

Comparison of scheduling in RTLinux and QNX. Andreas Lindqvist, Tommy Persson,

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)

Scheduling Mar. 19, 2018

Real-time Support in Operating Systems

LAST LECTURE ROUND-ROBIN 1 PRIORITIES. Performance of round-robin scheduling: Scheduling Algorithms: Slide 3. Slide 1. quantum=1:

Real-Time Systems Hermann Härtig Real-Time Operating Systems Brief Overview

2. Introduction to Software for Embedded Systems

IN4343 Real-Time Systems

Administrative Stuff. We are now in week 11 No class on Thursday About one month to go. Spend your time wisely Make any major decisions w/ Client

7. Multimedia Operating System. Contents. 7.3 Resource Management. 7.4 Process Management. 7.2 Real Time Systems. 7.5 Prototype Systems. 7.


Scheduling Algorithm and Analysis

Multimedia Systems 2011/2012

Multimedia-Systems. Operating Systems. Prof. Dr.-Ing. Ralf Steinmetz Prof. Dr. rer. nat. Max Mühlhäuser Prof. Dr.-Ing. Wolfgang Effelsberg

Fault tolerant scheduling in real time systems

Reference Model and Scheduling Policies for Real-Time Systems

PROCESS SCHEDULING Operating Systems Design Euiseong Seo

Real-Time Scheduling. Dynamic Priority Servers

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

Computer Science 4500 Operating Systems

Computer Systems Assignment 4: Scheduling and I/O

Operating System Concepts Ch. 5: Scheduling

The sel4 Status Report Security is no excuse for poor performance!

Real-Time Component Software. slide credits: H. Kopetz, P. Puschner

Real-Time Systems. Real-Time Operating Systems

Introduction to Real-Time Communications. Real-Time and Embedded Systems (M) Lecture 15

Operating Systems. Scheduling

Introduction to Real-Time Systems and Multitasking. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Real-Time Systems 1. Basic Concepts

Embedded Systems Dr. Santanu Chaudhury Department of Electrical Engineering Indian Institution of Technology, IIT Delhi

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

3. Quality of Service

Response Time Analysis of Asynchronous Real-Time Systems

A comparison between the scheduling algorithms used in RTLinux and in VxWorks - both from a theoretical and a contextual view

Lecture 3. Introduction to Real-Time kernels. Real-Time Systems

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

Schedulability with resource sharing. Priority inheritance protocol Priority ceiling protocol Stack resource policy

Notes based on prof. Morris's lecture on scheduling (6.824, fall'02).

2. REAL-TIME CONTROL SYSTEM AND REAL-TIME NETWORKS

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

Predictable Interrupt Management and Scheduling in the Composite Component-based System

Scheduling. The Basics

Scheduling. Scheduling 1/51

Real-Time Operating Systems M. 9. Real-Time: Basic Concepts

Processes. Overview. Processes. Process Creation. Process Creation fork() Processes. CPU scheduling. Pål Halvorsen 21/9-2005

CEC 450 Real-Time Systems

TDDD07 Real-time Systems Lecture 10: Wrapping up & Real-time operating systems

CEC 450 Real-Time Systems

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

Transcription:

Copyright Notice These slides are distributed under the Creative Commons Attribution.0 License COMP94 Advanced Operating Systems S/014 Week 9: Real- Systems @GernotHeiser You are free: to share to copy, distribute and transmit the work to remix to adapt the work under the following conditions: Attribution: You must attribute the work (but not in any way that suggests that the author endorses you or your use of the work) as follows: Courtesy of Gernot Heiser, [Institution], where [Institution] is one of UNSW or NICTA The complete license text can be found at http://creativecommons.org/licenses/by/.0/legalcode Note: Substantial re-use of material from Stefan M Petters (ex-nicta) Real- System: Definition Real- Systems A real-time system is any information processing system which has to respond to externally generated input stimuli within a finite and specified period Correctness depends not only on the logical result (function) but also the time it was delivered Failure to respond is as bad as delivering the wrong result! 4

Types of Real- Systems Hard real-time systems Weakly-hard real-time systems Firm real-time systems Soft real-time systems Best-effort systems Hard Real- Systems Deadline miss is catastrophic safety-critical system: failure results in death, severe injury mission-critical system: failure results in massive financial damage Steep and real cost function Real-time systems typically deal with deadlines: A deadline is a time instant by which a response has to be completed A deadline is usually specified as relative to an event The relative deadline is the maximum allowable response time Absolute deadline: event time + relative deadline Cost Triggering Event Deadline 5 6 Soft Real- Systems Deadline miss is undesired but tolerable Frequently results on quality-of-service (QoS) degradation eg audio, video rendering Steep cost function Cost of deadline miss may be abstract Bounded Tardiness Firm Real- Systems Deadline miss makes computation obsolete Typical examples are forecast systems weather forecast trading systems Cost may be loss of revenue (gain) Cost Deadline Cost Deadline Gain Deadline Triggering Event Triggering Event Tardiness 7 8

Weakly-Hard Real- Systems Tolerate a (small) fraction of deadline misses Most feedback control systems (including life-supporting ones!) occasionally missed deadline can be compensated at next event system becomes unstable if too many deadlines are missed Typically integrated with other fault tolerance electro-magnetic interference, other hardware issues Best-Effort Systems No deadlines, timeliness is not part of required operation In reality, there is at least a nuissance factor to excessive duration response time to user input Again, cost may be reduced gain Cost Triggering Event Deadline Cost Triggering Event 9 10 Real- Operating System (RTOS) Designed to support real-time operation Fast context switches, fast interrupt handling? Yes, but predictable response time is more important Real time is not real fast Analysis of worst-case execution time (WCET) Support for scheduling policies appropriate for real time Classical RTOSes very primitive single-mode execution no memory protection essentially a scheduler with a threads package real-time executive inherently cooperative Many modern uses require actual OS technology for isolation generally microkernels Approaches to Real Clock-driven (cyclic) Typical for control loops Fixed order of actions, round-robin execution Statically determined (static schedule) need to know all execution parameters at system configuration time Event-driven Typical for reactive systems (sensors & actuators) Static or dynamic schedules 11 1

Real- System Operation -triggered Pre-defined temporal relation of events event is not serviced until its defined release time has arrived Event-triggered timer interrupt asynchronous events Rate-based activities get assigned CPU shares ( rates ) Real- Task Model Job: unit of work to be executed resulting from an event or time trigger Task: set of related jobs which provide some system function A task is a sequence of jobs (typically executing same function) Job i+1 of of a task cannot start until job i is completed/aborted Periodic tasks -driven and all relevant characteristics known a priori Task t characterized by period T i, deadline, D i and execution time C i Applies to all jobs of task Aperiodic tasks Event driven, characteristics are not known a priori Task t characterized by period T i, deadline D i and arrival distribution Sporadic tasks Aperiodic but with known minimum inter-arrival time T i treated similarly to periodic task with period T i 1 14 Standard Task Model C: Worst-case computation time (WCET) T: Period (periodic) or minimum inter-arrival time (sporadic) D: Deadline (relative, frequently D=T) J: Release jitter P: Priority: higher number means higher priority B: Worst-case blocking time R: Worst-case response time U: Utilisation; U=C/T C D Release OS terminology: task = thread job = event-based activation of thread Task Constraints Deadline constraint: must complete before deadline Resource constraints: Shared (R/O), exclusive (W-X) access Energy Precedence constraints: : execution cannot start until is finished Fault-tolerance requirements eg redundancy Scheduler s job to ensure that constraints are met! T J 15 16

Scheduling Preemptive vs non-preemptive Static (fixed, off-line) vs dynamic (on-line) Clock-driven vs priority-based clock-driven is static, only works for very simple systems priorities can be static (pre-computed and fixed) or dynamic dynamic priority adjustment can be at task-level (each job has fixed prio) or job-level (jobs change prios) Clock-Driven (-Triggered) Scheduling Typically implemented as time frames adding up to base rate Advantages fully deterministic cyclic executive is trivial loop waiting for timer tick, followed by function calls to jobs minimal overhead Disadvantage: Big latencies if event rate doesn t match base rate (hyper-period) Inflexible Hyper-period 17 18 Non-Preemptive Scheduling Minimises context-switching overhead Significant cost on modern processors (pipelinies, caches) Easy to analyse timeliness Drawbacks: Larger response times for important tasks Reduced utilisation, schedulability In many cases cannot produce schedule despite plenty idle time Only used in very simple systems Fixed-Priority Scheduling (FPS) Real-time priorities are absolute: Scheduler always picks highest-priority job Fixed priorities obviously easy to implement, low overhead Drawbacks: inflexible, sub-optimal Cannot schedule some systems which are schedulable preemptively Note: Fixed in the sense that system doesn t change them OS may support dynamic adjustment Requires on-the-fly (re-)admission control 19 0

Rate-Monotonic (RM) Scheduling RM: Standard approach to fixed priority assignment T i <T j P i >P j 1/T is the rate of a task RM is optimal (as far as fixed priorities go) Schedulability test: RM can schedule n tasks with D=T if U C i /T i n( 1/n -1); lim n U = log sufficient but not necessary condition n 1 4 5 10 U [%] 100 8.8 78.0 75.7 74. 71.8 69. If D<T replace by deadline-monotonic (DM): D i <D j P i >P j DM is also optimal (but schedulability bound is more complex) FPS Example Release Deadline P C T D U [%] release 5 0 0 5 5 8 0 0 7 1 1 15 50 50 0 0 8 1 Earliest Deadline First (EDF) Dynamic scheduling policy Job with closest deadline executes Preemptive EDS with D=T is optimal: n jobs can be scheduled iff U C i /T i 1 necessary and sufficient condition no easy test if D T FPS vs EDF 4

FPS vs EDF FPS vs EDF Misses deadline Misses deadline P C T D U [%] release 5 0 0 5 5 8 0 0 7 1 1 15 40 40 7.5 0 89.5 P C T D U [%] release 1 5 0 0 5 5 8 0 0 7 1 15 40 40 7.5 0 EDF 89.5 schedules 5 6 Overload: FPS Overload: FPS Old Old P C T D U [%] 1 5 0 0 5 1 8 0 0 0 7 60 1 1 15 50 50 0 115 8 Old New New 7 8

Overload: FPS vs EDF Overload: EDF FPS EDF 9 0 Overload: FPS vs EDF On overload, (by definition!) lowest-prio jobs miss deadlines Result is well-defined and -understood for FPS Treats highest-prio task as most important but that may not always be appropriate! Under transient overload may miss deadlines of higher-priority tasks Result is unpredictable (apparently random) for EDF May result in all tasks missing deadlines! Under constant overload will scale back all tasks No concept of task importance EDF behaves badly under overload Main reason EDF is unpopular in industry Why Have Overload? Faults (software, EMI, hardware) Incorrect assumptions about environment Optimistic WCET Computing WCET of non-trivial programs is hard, often infeasible! Safe WCET bounds tend to be highly pessimistic (orders of magnitude!) WCET often very unlikely and orders of magnitude worse than normal thanks to caches, pipelines, under-specified hardware requires massive over-provisioning Some systems have effectively unbounded execution time e.g. object tracking 1

WCET Analysis Why Have Overload? Program binary Control Flow Graph System model Analysis tool Accurate & sound model of pipeline, caches Integer linear equations ILP solver WCET Faults (software, EMI, hardware) Incorrect assumptions about environment Optimistic WCET Computing WCET of non-trivial programs is hard, often infeasible! Safe WCET bounds tend to be highly pessimistic (orders of magnitude!) WCET often very unlikely and orders of magnitude worse than normal thanks to caches, pipelines, under-specified hardware requires massive over-provisioning Loop bounds Infeasible path info Scalability! Way out? Need explicit notion of importance: criticality Expresses effect of failure on the system mission Catastrophic, hazardous, major, minor, no effect Orthogonal to scheduling priority Pessimism! 4 Mixed Criticality Mixed Criticality Implementation A mixed-criticality system supports multiple criticalities concurrently Eg in avionics: consolidation of multiple functionalities Higher criticality requires more pessimistic analysis, higher certification Needs more than just scheduling support: strong OS-level isolation In overload scheduler drops lowest criticality Current research issue Must handle Criticality T U worst U expec U average High 10 50% 50% 0.05% Medium 1 (00%) 10%.5% Low 100 (1000%) 0% 10% Not really known over! 80% 1.55% Whenever running low job, ensure no high job misses deadline Switch to critical mode when not assured Various approaches to determine switch eg. zero slack: high job s deadline = its WCET Criticality-mode actions: FP: temporarily drop all low jobs prios below that of critical high! Simply preempting present job won t help! EDF: drop all low deadlines earlier than next high deadline Issues: Treatment of low jobs still rather indiscriminate Need to determine when to switch to normal mode, restore prios Alternative: use reservations 5 6

CPU Bandwidth Reservations Constand Bandwidth Server (CBS) Idea: Utilisation U = C/T can be seen as required CPU bandwidth Account time use against reservation C Not runnable when reservation exhausted Replenish every T Can support over-committing Reduce low reservations if high reservations fully used Advantages: Allows dealing with jobs with unknown (or untrusted) deadlines Allows integrating sporadic, asynchronous and soft tasks Modelled as a server which hands out time to jobs effectively a simple (FIFO) sub-scheduler hard (,) soft CBS (,7) Popular theoretical model suitable for EDF [Abeni & Buttazzo 98] CBS schedules specified bandwidth server has a period, T and a budget, Q = U T generates appropriate absolute EDF deadlines on the fly when executing a job, budget is consumed when budget goes to zero, new deadline is generated with new budget D i+1 = D i + T Schedulability: U i 1 1 1 1 7 8 Message-Based Synchronisation Tasks may communicate via messages blocking IPC Enforces precedence relations Allows sharing resources (services) Tag prios/deadlines onto messages Classical L4 approach: timeslice donation: Receiver continues on sender s time slice (and prio) Avoids scheduler invocation Synchronisation Issues Thread invoked by IPC is essentially a Hoare-style monitor Typical in client-server scenario Blocks other threads IPCing to same thread How long? -slice preemption during monitor? Worse: priority inversion general issue with shared resources 9 40

Shared Resources Priority Inversion Problem is not restricted to synchronous communication 4 Q Q V 4 t_low() {. Async EP wait(sem); /* critical section */ signal(sem); } sel4_notify t_high() {. wait(sem); /* critical section */ signal(sem); } V V Blocked! 1 Q Q 1 Preempted High-priority job is blocked, waiting for low-priority job Priority inversion! Undermines scheduling policy Must limit and control enough to still allow analysis of timeliness High-priority job is blocked for a long time by a low-prio job Long wait chain: Worst-case blocking time of bounded only by WCET of C +C +C 4 Must find a way to do better! 41 4 Priority Inheritance ( Helping ) Priority Inheritance V V 4 Q V 4 If blocks on a resource held by, and P 1 >P, then is temporarily given priority P 1 when t t releases the resource, its priority reverts to P 1 Q Q 1 4 Q V 4 4 Q V 4 V V V V 1 Q 4 1 1 Q 4 1 4 44

Priority Inheritance If blocks on a resource held by, and P 1 >P, then is temporarily given priority P 1 when t t releases the resource, its priority reverts to P Priority Inheritance If blocks on a resource held by, and P 1 >P, then is temporarily given priority P 1 when t t releases the resource, its priority reverts to P t 5 5 V 5 t 5 5 V 5 4 Q 4 4 Q 4 V 5 5 5 V 5 5 5 1 Q 4 5 1 1 Q 4? 5 1 Transitive Inheritance Deadlock! 45 46 Priority Inheritance Protocol (PIP) If blocks on a resource held by, and P 1 >P, then is temporarily given priority P 1 when t t releases the resource, its priority reverts to P Transitive inheritance potentially long blocking chains potential for deadlock Frequently blocks much longer than necessary Priority Inheritance: Easy to use, potential deadlocks Complex to implement Bad worst-case blocking times Priority Ceiling Protocol (PCP) Purpose: ensure job can block at most once on a resource avoid transitivity, potential for deadlocks Idea: associate a ceiling priority with each resource equal to the highest priority of jobs that may use the resource when job accesses its resource, immediately bump prio to ceiling! Also called: immediate ceiling priority protocol (ICPP) ceiling priority protocol (CPP) stack-based priority-ceiling protocol because it allows running all jobs on the same stack Improved version of the original ceiling priority protocol (OCPP) which is also called the basic priority ceiling protocol Requires global tracking of ceiling prios 47 48

(Immediate) Priority Ceiling Protocol PCP Implementation 4 Q V 4 V V PIP Each task must declare all resources at admission time System must maintain list of tasks associated with resource Priority ceiling derived from this list For EDF the ceiling is the floor of relative deadlines 1 Q 4 1 4 4 4 4 4 1 4 1 PCP In sel4: Have the server run at the ceiling prio Ceiling is max prio of threads holding a send cap on server EP Obviously hard to determine automatically at admission time Could use trusted server to hand out caps In any case a user-level (system design) problem Challenge: proper time accounting not supported by present sel4 Work in progress stay tuned! 49 50