NuttX Realtime Programming

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

Chapter 19: Real-Time Systems. Operating System Concepts 8 th Edition,


Multiprocessor and Real-Time Scheduling. Chapter 10

SMD149 - Operating Systems

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

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

Timers 1 / 46. Jiffies. Potent and Evil Magic

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

10 th AUTOSAR Open Conference

Systemy RT i embedded Wykład 11 Systemy RTOS

Operating system concepts. Task scheduling

REAL-TIME OPERATING SYSTEMS SHORT OVERVIEW

Real-Time Systems. Real-Time Operating Systems

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

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

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

Multiprocessor and Real- Time Scheduling. Chapter 10

CEC 450 Real-Time Systems

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

OPERATING SYSTEM CONCEPTS UNDERSTAND!!! IMPLEMENT!!! ANALYZE!!!

Scheduling Mar. 19, 2018

Task Scheduling of Real- Time Media Processing with Hardware-Assisted Virtualization Heikki Holopainen

Multimedia Systems 2011/2012

Real-Time Programming

Recap. Run to completion in order of arrival Pros: simple, low overhead, good for batch jobs Cons: short jobs can stuck behind the long ones

Lecture notes Lectures 1 through 5 (up through lecture 5 slide 63) Book Chapters 1-4

8: Scheduling. Scheduling. Mark Handley

CS 326: Operating Systems. CPU Scheduling. Lecture 6

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

Micrium µc/os II RTOS Introduction EE J. E. Lumpp

238P: Operating Systems. Lecture 14: Process scheduling

Embedded Systems: OS. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

CPU Scheduling. CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections )

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

Real-time operating systems and scheduling

Embedded Systems: OS

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

Implementation Alternatives. Lecture 2: Implementation Alternatives & Concurrent Programming. Current Implementation Alternatives

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

CEC 450 Real-Time Systems

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

Concurrent Programming Synchronisation. CISTER Summer Internship 2017

REAL-TIME MULTITASKING KERNEL FOR IBM-BASED MICROCOMPUTERS

Chapter 5: CPU Scheduling. Operating System Concepts 9 th Edit9on

Process Description and Control

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

EMERALDS: a small-memory real-time microkernel

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

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

CEC 450 Real-Time Systems

Deadline Miss Detection with SCHED_DEADLINE

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

CS 4284 Systems Capstone. Resource Allocation & Scheduling Godmar Back

Implementing Task Schedulers (1) Real-Time and Embedded Systems (M) Lecture 10

EECS 482 Introduction to Operating Systems

Enriching Enea OSE for Better Predictability Support

Agenda. Threads. Single and Multi-threaded Processes. What is Thread. CSCI 444/544 Operating Systems Fall 2008

EECS 482 Introduction to Operating Systems

Motivation. Threads. Multithreaded Server Architecture. Thread of execution. Chapter 4

INF1060: Introduction to Operating Systems and Data Communication. Pål Halvorsen. Wednesday, September 29, 2010

Comparison of scheduling in RTLinux and RT-Mach Fredrik Löfgren frelo305 Dan Persson danpe454

How Linux RT_PREEMPT Works

Concurrent Programming. Implementation Alternatives. Content. Real-Time Systems, Lecture 2. Historical Implementation Alternatives.

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

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

Concurrent Programming

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

Tasks. Task Implementation and management

CEC 450 Real-Time Systems

CPU Scheduling. Daniel Mosse. (Most slides are from Sherif Khattab and Silberschatz, Galvin and Gagne 2013)

Comparison of soft real-time CPU scheduling in Linux kernel 2.6 series with Solaris 10

CS4514 Real Time Scheduling

PROCESS SCHEDULING Operating Systems Design Euiseong Seo

The University of Missouri - Columbia Electrical & Computer Engineering Department ECE4220 Real-Time Embedded Computing

Process- Concept &Process Scheduling OPERATING SYSTEMS

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

Operating System Concepts Ch. 5: Scheduling

True/False: In Signal and Wait, the signaller finishes execution while the signalled process waits for its turn

Practice Exercises 305

Reference Model and Scheduling Policies for Real-Time Systems

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

8th Slide Set Operating Systems

Operating Systems ECE344. Ding Yuan

Linux - Not real-time!

RT extensions/applications of general-purpose OSs

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

Operating Systems, Fall

LINUX AND REALTIME 1

Real-Time Operating Systems

Tuned Pipes: End-to-end Throughput and Delay Guarantees for USB Devices. Ahmad Golchin, Zhuoqun Cheng and Richard West Boston University

CS A320 Operating Systems for Engineers

Operating Systems. CPU Scheduling ENCE 360

RT3 - FreeRTOS Real Time Programming

CS A331 Programming Language Concepts

Dynamic Resource Allocation for Priority Processing

Last Class: Processes

SIDDHARTH GROUP OF INSTITUTIONS :: PUTTUR Siddharth Nagar, Narayanavanam Road QUESTION BANK (DESCRIPTIVE) UNIT I OPERATING SYSTEMS

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

Transcription:

NuttX RTOS NuttX Realtime Programming Gregory Nutt

Overview Interrupts Cooperative Scheduling Tasks Work Queues Realtime Schedulers

Real Time == == Deterministic Response Latency Stimulus Response Deadline Real time does not mean fast Real time systems have Deadlines

Bare Metal / No-OS Single Interrupt External Stimulus generates Hardware Interrupt Request (IRQ) Response Latency Hardware Response from Software Processing Hardware Interrupt Vector Software Processing Interrupt Handler Hardware Interrupt Return Hardware Interrupt Processing may may be be delayed if if interrupts disabled. Very Simple! Deterministic if if interrupts never disabled.

Bare Metal / No-OS Nested Interrupts Response Latency Single Interrupt Handler High Priority Deterministic? No Meet Deadlines? Maybe Medium Priority Low Priority Response Latency No OS way: Extensive interrupt processing, prioritized interrupts and, maybe, a main loop.

Bare Metal / No-OS Cooperative Scheduling Task A Task G Task B Task C Main, Background Loop Task F Task E Round-Robin Non-premptive Cooperative Scheduling State State machines ad hoc strategies Non-deterministic! ad hoc strategies Non-deterministic! Task D

RTOS Interrupts No OS way: Extensive interrupt processing, prioritized interrupts and, maybe, a main loop. Interrupt Interrupt Interrupt Interrupt Interrupt Signal Task Task A Signal Task Task B Signal Signal Task Task C Signal Task Task D Signal Task Task E RTOS way: Minimal work performed in in interrupt handlers Interrupt handlers only signal events to to tasks RTOS scheduler manages realtime behavior Prioritized interrupts replaced with prioritized tasks No benefit in in nesting interrupts

Properties of of NuttX Tasks Task = A thread within an an environment (like a Linux process) Thread = Normal sequence of of instruction execution Each thread has its its own stack Each thread has an an execution priority managed by by the OS Each thread is is a member of of a task group Share resources (like a Linux process) Can wait for events or or resource availability Threads communicate via Interprocess Communications (IPC): POSIX Message Queues, Signals, Counting semaphores, etc. Standard / / Linux compatible NuttX supports use of of standard IPCs from interrupt handlers

RTOS Interrupt Processing Stimulus Response Interrupt Handler Signals thread via IPC RTOS Scheduler Reassess next next ready-to-run thread Resumes thread if highest priority, ready-to-run Task Suspended, Waiting for event Thread awakened, Processes interrupt related event Task Suspended, Waiting for Next event

Work Queues Interrupt Handler Top Half Defer more extended interrupt processing to Worker Thread Prioritized Work Queue Worker Thread Bottom half Priority Qeue Non-premptive Qeue Very Very high high priority Inappropriate for for extended processing Non-deterministic! Use with care!

Multiple Work Queues P R I O R I T Y High Priority Work Queue Multiple Low Priority Work High Queues Priority Work High Queue Priority Work Queue Single high priority work queue Intended for interrupt bottom half Should be be highest priority Multiple low priority work queues Support priority inheritance Use to to implement asynchronous I/O (AIO) Thread pool

Components of of Response Latency Stimulus Event Hardware interrupt processing. Delay may be be extended if if interrupts disabled Software interrupt processing Thread state save (for Context Switch) Interrupt handler processing IPC Task execution may delayed if if it it does not have priority Interrupt return State restore OR Interrupt Context Switch Thread processing Output response

Synchronous vs vs Asynchronous Context Switch Asynchronous Context Switch == Interrupt Context Switch Critical part of of realtime response VERY efficient in in NuttX Near zero additional overhead Synchronous Context Switch Thread relinquishes CPU by by waiting for event NOT a critical part of of realtime response But may be be important to to overall performance and throughput

High Priority, Zero Latency Interrupts Software interrupt processing overhead Thread state save and restore (for interrupt Context Switch) ARM Cortex-M* Can support direct vector to to C-code Zero (software) latency NuttX implements with: Higher interrupt priority Direct vector to to C code Indirect interrupt context switches via PENDSV Important to to support: Very high rate interrupts Interrupts with very low latency requirements

Realtime Schedulers Realtime behavior realized via OS scheduler RTOS provides tools only enable realtime designs But a bad application design may still not be be realtime Scheduling Disciplines: Traditional // POSIX Schedulers Deadline Scheduler (and other modern schedulers) Rate Monotonic Scheduling (RMS)

Deadline Schedulers Example: Linux SCHED_DEADLINE Earliest Deadline First (EDF) Highly managed High processing overhead Complex Difficult to to configure correctly Non-standard Not commonly used in in a small RTOS Not currently supported by by NuttX

Standard / POSIX Schedulers Primary NuttX Specification: OpenGroup.org Standard Schedulers specified at at OpenGroup.org: SCHED_FIFO For Managed latency Supports Rate Monotonic Scheduling (RMS) SCHED_RR Not realtime Time-slicing Balanced throughput SCHED_SPORADIC Dynamic prioritization to to achieve processing budget For background tasks with guaranteed bandwidth Response latency vs. Throughput trade-offs

Rate Monotonic Scheduling Can achieve realtime behavior under certain circumstances: Strict priority scheduling Static priorities Priorities assigned according to to the rate monotonic conventions And this unrealistic assumption: Threads with shorter periods/deadlines are given higher priorities No resource sharing No waiting for resources Example: hardware, queue, etc. No semaphores or or locks. No disabling pre-emption No disabling interrupts No critical sections Priority Inversion / Priority Inheritance

Priority Inversion No Locks Event 1 Event 2 Event 3 Low Priority Task High PriorityTask Medium PriorityTask High High Priority Task Task has has to to wait wait at at the the priority of of the the low low priority task! task! High PriorityTask Medium PriorityTask With Lock Low Priority Task Low Priority Task Takes Lock High Priority Task Waits for Lock Low Priority Task Releases Lock

With Lock Event 1 Event 2 Event 3 Low Priority Task Priority Inheritance Medium Priority Task High PriorityTask Low Priority Task High PriorityTask Medium PriorityTask Low Priority Task Lock With Priority Inheritance Low Priority Task Takes Lock Priority Boosted Low Priority Task Releases Lock High High Priority Task Task now now Waits Waits at at the the High High priority

Effect of Violations of Assumptions Average Response Latency Increased Variability in Response Latency Deadline Missed Deadlines Stimulus Can be managed with good designs Response

Mixing Real-Time and non-real-time Tasks Real Time Priority Domain High Priority Work Queue Work Work Queue should be be highest priority because it it services the the interrupt bottom half half P R I O R I T Y Real-Time Tasks Non-Real-Time Tasks Real Real Time Time tasks tasks need need to to be be higher priority than than any any non-real-time task task Non-real-time tasks tasks must must be be lower lower priority than than all all Real Real time time tasks tasks so so that that they they cannot interfere with with Real-time behavior Non-Real-Time PriorityDomain