cec 450 real-time systems - embry–riddle aeronautical

24
September 4, 2018 Sam Siewert CEC 450 Real - Time Systems Lecture 2 Introduction to Scheduling of RT Services Part 1

Upload: others

Post on 05-Dec-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

September 4, 2018 Sam Siewert

CEC 450Real-Time Systems

Lecture 2 – Introduction to Scheduling of RT Services

Part 1

Page 2: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

So Why SW for HRT Systems?ASIC and FPGA State-Machine Solutions Offer Hardware Clocked Deterministic Solutions

FPGAs Can be Updated with New Bit-streams (Synthesized HDL to Reconfigurable Logic Elements)

Software (Firmware) Remains Simplest for Field Upgrade (Reconfigurable at Run-time)

FPGAs Can be Costly Per Unit

Cost of Software Engineering vs. Hardware Engineering

Sam Siewert 2

Page 3: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

What History Teaches UsApollo 11, Launched July 16, 1969– On descent, Lunar Module experienced a computer overload– Alarm 1201, 1202 (CPU overload s.t. Sum(Ci/Ti) > 1.0)– Landed July 10, 1969 [By ignoring alarms - lucky?]

Rate Monotonic Theory - Not yet formalized (math model)

Sam Siewert 3

https://www.space.com/26593-apollo-11-moon-landing-scariest-moments.html

Apollo 11's Scariest Moments: Perils of the 1st Manned ...

www.space.com

NASA's Apollo 11 moon landing was a human spaceflight feat, but also a dangerous journey. See some of the scariest moments of first manned moon landing.

“Scheduling Algorithmsfor MultiprogrammingIn a Hard-Real-TimeEnvironment”, C.L. Liu[MIT], James W. Layland[NASA JPL], Jan 1, 1973

Page 4: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Sam Siewert 4

Outline - Learning ObjectivesCPU Scheduling Overview– Linux CFS [Completely Fair Scheduler]– Linux CFQ [Completely Fair Queue for I/O]– We really want an “unfair” scheduler for Real-Time

RTOS Schedulers and POSIX RT – Linux, FreeRTOS, VxWorks

RT Services – How to Define?

Linux POSIX RT Thread Analysis and Debug– SCHED_FIFO– Synchronization– Issues from “Fair” Operating Systems vs. Same in “Unfair” RTOS

Page 5: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Key Terminology - See GlossaryKernel Task - a thread with normal thread state including stack, registers, PC, but also including signal handlers, task variables, task ID and name, priority, entry point, and a number of state and inter-task communication data contained in a TCB.

RTP or Process - a thread of execution with stack, register state, and PC state along with significant additional software state such as copies of all I/O descriptors (much more than a task TCB for example) including a protected memory data segment (protected from writes by other processes).

Context Switch - When a CPU is multiplexed (shared) by more than one threadof execution and the scheduler provides preemption, when the scheduler does preempt a thread in order to dispatch another, it must save state information associated with the currently executing thread (e.g. register values including PC) so that this thread can later be dispatched again to restore its thread of execution without a state error. …

Preemption - when the current thread executing on a CPU is placed back on the ready queue by the scheduler and state information saved so that a different thread can be allocated the CPU.

Dispatch - when an RTOS scheduler selects a thread ready to run, restores state associated with the thread, and transfers execution control back to the thread’s last PC if it was preempted earlier (or to its entry point if the thread is ready to run for the first time). Sam Siewert 5

Page 6: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Key Terminology - See GlossaryAMP – Asymmetric Multi-Processing – Multiple CPU Cores with Local memory and message passing interconnection network with application specific task workloads running on Multiple OS Instances or SMP Thread Affinity so Threads are “assigned” to core, disabling load balancing for those threads

SMP – Symmetric Multi-Processing – Multiple CPU Cores with common shared memory (uniform access) and One OS level interrupt handler mapping and task load balancing.

NUMA – Non-Uniform Memory Access - Each CPU has local and non-local memory with different access latencies (e.g. Intel Nehalem-Tylersburg with QPI).

SMT – Simultaneous Multi-threading – Super-scalar CPU micro-parallelism designed to support threads of execution.

Flynn’s Taxonomy – {Single Instruction, Multi-Instruction} x {Single Data, Multi-Data}

Sam Siewert 6

Page 7: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Fair vs. Unfair SchedulingCFS (Completely Fair Scheduler) in Linux – Fair!– Linux 2.6.23 Introduction of CFS– Fundamental Concepts of Fair Schedulers – “Everyone Get’s a

Slice of Pie (Time), Some Just Get Slices More Often”– Requires PIT (Programmable Interval Timer) to Raise Time Based

Interrupts – The Quantum– Scheduling Changes Can Be Made at Each Quantum “Tick”– All Tasks (Threads) Should Make Progress – Fair– Does Not Provide Predictable Response

Priority Preemptive Run-to-Completion RTOS – Unfair!– Tasks (Threads) Run at Priority Until:

Complete and ExitYield, Sleep, Activate Higher Priority Task or Block on Secondary Resource (System Call)Interrupt Raised

Sam Siewert 7

Page 8: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Flynn’s Computer Architecture Taxonomy

Single Instruction Multiple InstructionSingle Data SISD (Traditional Uni-

processor)MISD (Voting schemes and active-active controllers)

Multiple Data SIMD (e.g. SSE 4.2, GP-GPU, Vector Processing)

MIMD (Distributed systems (MPMD), Clusters with MPI/PVM (SPMD), AMP/SMP)

Sam Siewert 8

GPC has gone MIMD with SIMD Instruction Sets and SIMD Offload (GP-GPU)NUMA vs. UMA (Trend away from UMA to NUMA or MCH vs. IOH)SMP with One OS (Shared Memory, CPU-balanced Interrupt Handling, Process Load Balancing, Mutli-User, Multi-Application, CPU Affinity Possible)MIMD - Single Program Multi-Data vs. Multi-Program Multi-Data

Embedded has traditionally been SISD or MIMD AMPNeed for SMP in Embedded?SIMD Offload and Acceleration Quite Useful (DSP, Image Processing, Error Correction Codes, Encryption, etc.)

Page 9: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Sam Siewert 9

CPU Scheduling TaxonomyExecution Scheduling

Global-Multi-core Local-Uniprocessor

DistributedAsymmetric(AMP )

Symmetric(SMP OS)

Preemptive Non-Preemptive

Fixed-Priority

Hybrid

Dynamic-PriorityCooperative

Batch

FCFS SJN

Co-Routine ContinuationFunction

Heuristic EDF/LLF RR Timeslice(desktop)

Multi-FrequencyExecutives

StaticDynamic

RateMonotonic

DeadlineMonotonic

Dataflow

(Preemptive, Non-Preemptive SubtreeUnder Each Global-MP Leaf)

SMT(Micro-Paralell)

Linux Default -SMP “Fair”

HRT - AMP RMSRT - SMP EDF

Page 10: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Sam Siewert 10

Elements of a Scheduling ClassScheduling Policy

– How is Dispatch Decision Made?– Non-Preemptive, Cooperative or Batch (Hard Coded)

Main Loop ExecutivesDataflow ScheduleCooperative Sequential Processes, Co-Routines

– PreemptiveFixed Priority Encoding - RTOSDynamic Priority - RTOS with Programmed PrioritiesHeuristic (Fuzzy Logic Scheduler, Heuristically Guided Iterative Repair)

Scheduling Feasibility Determination– Will Schedule Work?– Can a Set of Services Be Scheduled Given:

CPU Resources AvailableI/O Resources AvailableMemory Resources Available

Ability to Tune Schedule– If Actuals Differ From Expected

WCET Expected vs. ObservedMaximum Release Frequency for a Service – Expected vs. Observed

Page 11: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Sam Siewert 11

Typical RTOS Scheduling PoliciesFixed Priority Preemptive– Tasks State Based on Resources Required

Needs CPU Only = ReadyNon-CPU Resource Required = Pending

– Task Context Switch on System Call or Interrupt – Dispatch from Ready Queue

– Dispatch with Rate Monotonic Priority– RM LUB Feasibility– Feasibility Tests

Scheduling Point AlgorithmCompletion Test AlgorithmOver LCM of Periods

Dynamic Priority Premptive– Earliest Deadline First– Least Laxity First

delayedreadypending

Suspended,+Delayed,+Pending

executing

Dispatch

Yield(taskDelay())

Wait onResource

(semTake(),pause())

Interference(preemption)

Suspend(unhandled exception,

taskSuspend())

Note: Different from Chapter 7In VxWorks Kernel

Programmer’s Guide

Presenter
Presentation Notes
Altenatives to Typical RTOS Scheduling Local, Non-Preemptive, Cooperative Systems Best for A Few Simple Services Hybrid Multi-Frequency Executive Multi-Frequency Executive (i.e. Multiple Dispatch Queues) High Frequency (100 x Low @ 100 Hz) Med Frequency (10 x Low @ 10 Hz) Low Frequency (1 Hz) State Machines Yield and Place Continuation on Queue Global-MP, Static, Asymmetric with Local, Non-Preemptive Cooperative Pipelined Dataflow Systems Credit-Based Dataflow for CPU to CPU Message Queues Credits Provide Flow Control Can Enqueue Messages Until Credit Runs Out, Then Stall Continuation-Passing-Style for Cooperative
Page 12: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Sam Siewert 12

RTOS Kernel Tasking / Linux NPTLAn RTOS task or Linux NPTL thread is an Implementation of a Service– E.g. Anti-Lock Braking Digital Control– Created and Put Into Service, Awaits Event (Data Ready) For a Release– Memory Resident (TCB / Process descriptor (container), stack, code, data,

semaphores, message queues)

RTOS or Linux Kernel Dispatcher Runs…– On Entry Point into Kernel Following Initialization– Loops (Idle) Until Task(s) in Ready Queue

Dispatches Highest Priority Task from Ready QueueIdle is NOT a Task Context (Kernel Context)

– Tasks or Threads become Ready and Are Dispatched When …Sequencer or Interrupt Service Routines Release (E.g. semGive(), sem_post())As a Result of a System Call (E.g. mq_send(), taskActivate(), pthread_create())Following Return from an Interrupt Service Routine

Dispatch Forces a Context Switch– Task/Thread State of Preempted is Saved (RTOS VX_FP_TASK for floats)

Coming from Idle, No Preemption, Simply DispatchRegisters, Stack, PC (Program Counter or Instruction Pointer) Saved

– Task State of Dispatched Task is Restored– PC Set to Last Text Address of Dispatched Task

NPTL Documentaiton - manpage, NPTL paper (Red Hat - out of date)

Page 13: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Sam Siewert 13

RTOS Local PreemptiveFixed Priority RTOS/NPTL RMAdvantages…

– Deterministic Latency Control (Deadline = Period)

– Well Established Theory, Tools, and Resources

– Predictable Overload Deadline Failures

– By Lehoczky, Shah, Ding Theorem Can Schedule up to 100%, By RM LUB to 70%

– Known Latency/Throughput Tuning Methods (e.g. Period Transform, Sporadic Servers, Slack Stealers)

Disadvantages…– RM LUB is Pessimistic– Sacrifices Throughput for Margin– Requires Overhead of Preemption– Context Switch and ISRs– Can Be Complex for Global-MP Architectures

No Load BalancingAsymmetric Service Allocation to CPUsMessage Passing vs. Shared Memory

Execution Scheduling

Global-MP Local-Uniprocessor

Asymmetric(AMP )

Preemptive

Fixed-Priority

Static

RateMonotonic

Assign Threads (Services) to Cores

Each awaits service requestRuns to completionAwaits next request

Priority is RM Policy

Presenter
Presentation Notes
Alternatives – Advantages and Disadvantages Multi-Frequency Executive - Polling Advantages… Simple and Low Overhead (no ISRs and Minimal Context Changes) Disadvantages… Hard to Tune – Restructure Code Data-Available/Work-Available Queue Latency Hard to Control Multi-Frequency Executive - ISR Advantages… Immediate Maintenance of Data-Available Queues Simple Cooperative Data Processing Disadvantages… ISR Overhead No Possibility of Tuning Data Processing with Prio Preemption Fixed Asymetric MP Load Assignment for Dataflow with Continuation-Passing-Style Advantages… Simple to Analyze and Design for Throughput – Natural Pipelining No Load Balancing Required Disadvantages… Schedule Generation Provides Sub-Optimal Latency Control Difficult to Modify Requires Signficant HW Support for Message Passing between CPUs and CPU Synchronization
Page 14: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Sam Siewert 14

Local Preemptive with Dynamic Priorities

Dynamic Priority RTOS (EDF, LLF)Advantages…

– 100% Utilization and High Throughput

Disadvantages…– Hard to Implement – LLF is Easier than EDF, Catastrophic

failure modes

Linux/Unix “Fair” RR/Time SliceAdvantages…

– Best Effort Fair - Everyone Gets a Slice Eventually

Disadvantages…– Huge Overhead on Quantum Preemption and Context

Switch

– Complex Scheduler - Do we really care about fairness anyway?

Liu and Layland Paper

Liu, Chung Laung, and James W. Layland. "Scheduling algorithms for multiprogramming in a hard-real-time environment." Journal of the ACM (JACM) 20.1 (1973): 46-61.

11,711 citations

Describes RM fixed priority

Describes RT Dynamic priority as “Deadline Driven” scheduling

Both are still used today

RM fixed - HRTRT Dynamic priority - SRT

Page 15: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Sam Siewert 15

Why Use an RTOS? POSIX RT Threads?

RTOS / NPTL Provides Common Scheduling Framework for:– Fixed Priority Preemptive

Rate MonotonicDeadline Montonic

– Dynamic Priority PreemptiveEDFLLF

– Non-Preemptive CooperativeMulti-Frequency ExecutiveDataflow

Page 16: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Sam Siewert 16

Real-Time Service TypesTypes of Services– Hard Real-Time (Flight Software, Anti-Lock Braking)– Soft Real-Time (Multi-media, Audio, Video, Virtual Reality)– Best Effort (E.g. Desktop Applications)– Isochronal Hard Real-Time (Digital Feedback Control

Systems) – Isochronal Soft Real-Time (Continuous Media, Video,

Audio)

Real-Time Service Types in Terms of Utility– Utility Curve Shows Value/Harm of Response Over Time

From ReleaseBoth Before and After Deadline Relative to Release

– Full Utility - Service Performs as Required– Zero Utility- Service is Not Provided

Drop-out Causes No Harm– Negative Utility

Harm to System and/or User and Significant Loss of Assets

Page 17: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Sam Siewert 17

Hard Real-Time Service Utility

Deadline

Utility

Time

Release

100%

0%

After Deadline, Utility is Negative

Page 18: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Sam Siewert 18

Soft Real-Time Service Utility

Deadline

Utility

Time

Release

100%

0%

F(t)

After Deadline, Utility DiminishesAccording to Some Function F(t)

Page 19: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Sam Siewert 19

Best Effort Service Utility

Deadline Does Not ExistUtility

Time

Release

100%

0%

Page 20: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Sam Siewert 20

Isochronal Hard Real-Time UtilityDeadline

Utility

Time

Release

100%

0%

After Deadline, Utility is NegativeBefore Deadline, Utility is Negative

Page 21: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Sam Siewert 21

Isochronal Soft Real-Time UtilityDeadline

Utility

Time

Release

100%

0%

After Deadline, Utility is < 100%Before Deadline, Utility is < 100%

F(t)F(t)

Page 22: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Sam Siewert 22

Anytime Utility Curve

DeadlineUtility

Time

Release

100%

0%

After Deadline,Utility is Negative or Zero

Before Deadline,Utility is </= 100%

F(t)

Page 23: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Sam Siewert 23

Issues Beyond Policy and FeasibilityLatency Control– Do We Allow Deadline Over-runs?

Over-runs Use Resources That Could Be Used By Services On Time So FarDo We Need to Execute a Missed Deadline Call-back Handler?Should We Just Immediately Terminate a Service Release That Misses its Deadline?

Dealing with Non-Determinism– Do We Always Have to Assume Worst Case?

WCETShortest Period (Worst Case Release Frequency)

– When Have We Tested Long Enough to Have Verified Worst Case Assumptions?

Overhead– Lump it Into Worst Case?, Ignore it?

Page 24: CEC 450 Real-Time Systems - Embry–Riddle Aeronautical

Next Time …Linux POSIX SCHED_FIFO Overview

Synch Examples -http://mercury.pr.erau.edu/~siewerts/cec450/code/example-sync/

What is Priority Inversion?

Why is Unbounded Priority Inversion an Issue?

Why Do Fair OS Schedulers Claim to Have No Such Issue?

Sam Siewert 24