Real-Time Operating Systems Lecture for the Embedded Systems Course CSD, University of Crete (May 23, 2014)

Similar documents
Linux 2.4. Linux. Windows

CPU SCHEDULING (CONT D) NESTED SCHEDULING FUNCTIONS

Chapter 19: Real-Time Systems. Overview of Real-Time Systems. Objectives. System Characteristics. Features of Real-Time Systems

Embedded Systems. 6. Real-Time Operating Systems

Lecture 3 Theoretical Foundations of RTOS

Performance Comparison of RTOS

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

Operating Systems. III. Scheduling.

W4118 Operating Systems. Instructor: Junfeng Yang

Predictable response times in event-driven real-time systems

Comparison between scheduling algorithms in RTLinux and VxWorks

ICS Principles of Operating Systems

OPERATING SYSTEMS SCHEDULING

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

CPU Scheduling. CPU Scheduling

REAL TIME OPERATING SYSTEMS. Lesson-10:

Real-Time Operating Systems.

CPU Scheduling Outline

Exercises : Real-time Scheduling analysis

Processor Scheduling. Queues Recall OS maintains various queues

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

Linux Process Scheduling Policy

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

Real- Time Scheduling

Operating Systems Concepts: Chapter 7: Scheduling Strategies

What is best for embedded development? Do most embedded projects still need an RTOS?

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

POSIX. RTOSes Part I. POSIX Versions. POSIX Versions (2)

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

Real-Time Scheduling 1 / 39

Real-Time Systems Prof. Dr. Rajib Mall Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

2. is the number of processes that are completed per time unit. A) CPU utilization B) Response time C) Turnaround time D) Throughput

Chapter 5 Process Scheduling

Enhancing the Monitoring of Real-Time Performance in Linux

Hard Real-Time Linux

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

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

Real Time Programming: Concepts

CHAPTER 15: Operating Systems: An Overview

Operating Systems, 6 th ed. Test Bank Chapter 7

CPU Scheduling. Core Definitions

Operating Systems Lecture #6: Process Management

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

What is an RTOS? Introduction to Real-Time Operating Systems. So what is an RTOS?(contd)

CPU Scheduling. Multitasking operating systems come in two flavours: cooperative multitasking and preemptive multitasking.

Real-time Operating Systems. VO Embedded Systems Engineering Armin Wasicek

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

SYSTEM ecos Embedded Configurable Operating System

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

The Design and Implementation of Real-Time Schedulers in RED-Linux

Real-Time Software. Basic Scheduling and Response-Time Analysis. René Rydhof Hansen. 21. september 2010

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

Real Time Operating Systems. Tajana Simunic Rosing Department of Computer Science and Engineering University of California, San Diego.

/ Operating Systems I. Process Scheduling. Warren R. Carithers Rob Duncan

Tasks Schedule Analysis in RTAI/Linux-GPL

Linux A multi-purpose executive support for civil avionics applications?

Kernel Types System Calls. Operating Systems. Autumn 2013 CS4023

Chapter 2: OS Overview

Programming real-time systems with C/C++ and POSIX

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

Lecture Outline Overview of real-time scheduling algorithms Outline relative strengths, weaknesses

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

ELEC 377. Operating Systems. Week 1 Class 3

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

Embedded & Real-time Operating Systems

White Paper. Real-time Capabilities for Linux SGI REACT Real-Time for Linux

Module 6. Embedded System Software. Version 2 EE IIT, Kharagpur 1

Chapter 2 System Structures

A Survey of Fitting Device-Driver Implementations into Real-Time Theoretical Schedulability Analysis

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

Real-Time Operating Systems With Example PICOS18. What is an Operating System?

Page 1 of 5. IS 335: Information Technology in Business Lecture Outline Operating Systems

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

Lecture 25 Symbian OS

A LECTURE NOTE ON CSC 322 OPERATING SYSTEM I DR. S. A. SODIYA

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

Operating System Aspects. Real-Time Systems. Resource Management Tasks

Have both hardware and software. Want to hide the details from the programmer (user).

Real Time Operating System for Embedded DSP Applications

CS0206 OPERATING SYSTEMS Prerequisite CS0201, CS0203

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

LAB 5: Scheduling Algorithms for Embedded Systems

Introduction. Scheduling. Types of scheduling. The basics

Implementing and Using Execution Time Clocks in Ada Hard Real-Time Applications

CS161: Operating Systems

Operating System: Scheduling

COS 318: Operating Systems. Virtual Machine Monitors

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

Real Time Operating Systems. Tajana Simunic Rosing Department of Computer Science and Engineering University of California, San Diego.

Chapter 1: Introduction. What is an Operating System?

RTAI. Antonio Barbalace (modified by M.Moro 2011) RTAI

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

This tutorial will take you through step by step approach while learning Operating System concepts.

Chapter 3 Operating-System Structures

Transcription:

Real-Time Operating Systems Lecture for the Embedded Systems Course CSD, University of Crete (May 23, 2014) ManolisMarazakis (maraz@ics.forth.gr) Institute of Computer Science (ICS) Foundation for Research and Technology Hellas (FORTH)

Real-Time OS =? Real-Time Control External Events Synchronous, Asynchronous, Independent Speed Fast response, Low overheads Deterministic A late answer is a wrong answer Multi-Tasking Sequence: One task controlling all events in an infinite loop Multi-tasking: Task Waiting on Event, Task becomes Ready upon Event Priority Scheduling Preemptive Scheduling on Task Priority No delay on Context Switch to the next Tick Equal Priority tasks won t preempt each other Scheduling due to synchronous or asynchronous event Round-Robin Scheduling All tasks in the same priority share the CPU Context Switch in each (predefined) time slice period 2 Real-Time Operating Systems

Need for Synchronization? Reentrancy & SharedResources Co-ordination between tasks Asynchronous events Interrupts & Exceptions Interrupts allow devices to notify the CPU on events Interrupt Levels Exceptions Unplanned event generated by the CPU (e.g. divide-by-0) Exceptions will generate an internal interrupt ISR (Interrupt Service Routines) Not a task (has no task control block ) Timers Synchronous events 3 Real-Time Operating Systems

RTOS vs General-Purpose OS General-purpose OS: Key criteria: Task throughput, fairness average case optimizations Real-Time OS: Deterministic timing behavior worst-case guarantees Processing must be done within a time constraint or the system will fail. All delays in the system will be bounded; from the retrieval of stored data to the time RTOS finishes the request. 4 Real-Time Operating Systems

Can Linux provide real-time guarantees? (NO) (usually) Non-preemptive kernel A system call may sometimes take a long time to complete Coarse timer resolution Tasks can be released with millisecond precision (1/10/100) Virtual memory Unpredictable delay Variable task priority Task priority varies with time, to achieve fairness Batching and possible re-ordering of storage & network operations (for efficient use of H/W) High-priority task may queue behind a low-priority task that has issued a system call High-priority tasks may have to wait for lower priority tasks to release resources 5 Real-Time Operating Systems

Can Linux provide real-time guarantees? (YES) Provides RT-POSIX interface Fixed priority real-time scheduling classes SCHED_FIFO SCHED_RR Timesharing in SCHED_OTHER Preemptive Linux kernel Concerns: Real-time? Footprint? 6 Real-Time Operating Systems

Outline RTOS theory LynxOS QNX Wind River VxWorks RTLinux TimeSysLinux POSIX 1003.1b standard Asynchronous I/O Semaphores Message queues Queued signals Scheduling Clocks &timers Memory Management 7 Real-Time Operating Systems

Three Models of Kernel Kernel =? Process Management Memory Management I/O System Management Three models of kernel : Monolithic Layered Microkernel (client-server) 8 Real-Time Operating Systems

Monolithic Kernel In a monolithic-modularized OS, the functionality is integrated into a single executable file that is made up of modules, separate pieces of code reflecting various OS functionality. 9 Real-Time Operating Systems

Layered Kernel In the layered design, the OS is divided into hierarchical layers (0...N), where upper layers are dependent on the functionality provided by the lower layers (via APIs). Like the monolithic design, layered OSesare a single large file that includes device driversand middleware 10 Real-Time Operating Systems

Microkernel (Client-server) OS An OS that is stripped down to minimal functionality, commonly only process and memory management subunits is called a client-server OS, or a microkernel. The remaining functionality typical of other kernel algorithms is abstracted out of the kernel, while device drivers, for instance, are usually abstracted out of a microkernel entirely 11 Real-Time Operating Systems

Non-preemptiveScheduling Tasks are given control of the master CPU until they have finished execution, regardless of the length of time or the importance of the other tasks that are waiting. First-Come-First-Serve (FCFS)/ Run-To-Completion The response time of a FCFS algorithm is typically slower than other algorithms Shortest Process Next (SPN)/Run-To-Completion SPN algorithm has faster response times for shorter processes. However, then the longer processes are penalized by having to wait until all the shorter processes in the queue have run. In this scenario, starvation can occur to longer processes if the ready queue is continually filled with shorter processes. The overhead is higher than that of FCFS, since the calculation and storing of run times for the processes in the ready queue must occur. Co-operative: the tasks themselves run until they tell the OS when they can be context switched (i.e., for I/O, etc.). This algorithm can be implemented with the FCFS or SPN algorithms, rather than the run-to-completion scenario, but starvation could still occur with SPN if shorter processes were designed not to cooperate, for example. 12 Real-Time Operating Systems

Preemptive Scheduling Round Robin/FIFO (First In, First Out) Scheduling Each process in the FIFO queue is allocated an equal time slice (the duration each process has to run). An interrupt is generated at the end of each of these intervals to start the pre-emption process. Priority (Preemptive) Scheduling Every process is assigned a priority The processes with the highest priority always preempt lower priority processes when they want to run Problems: Process starvation, Priority inversion, how to determine the priorities of various processes, i.e. same priority vs how often the process(es) are run 13 Real-Time Operating Systems

Preemptive Scheduling (cont.) Rate Monotonic Scheduling (RMS) scheme, in which tasks are assigned a priority based upon how often they execute within the system. EDF (Earliest Deadline First)/Clock Driven Scheduling The EDF/Clock Driven algorithm schedules priorities to processes according to three parameters: frequency (number of times process is run) deadline (when processes execution needs to be completed) duration (time it takes to execute the process) 14 Real-Time Operating Systems

Preemptive Scheduling & RTOS Tasks with real-time requirements have to be allowed to preempt other tasks Preemptive scheduling must be one of the algorithms implemented within RTOS schedulers RTOS schedulers also make use of their own array of timers, ultimately based upon the system clock, to manage and meet their hard deadlines. Whether an RTOS or a non real-time OS in terms of scheduling, all will vary in their implemented scheduling schemes. E.g: vxworks(wind River) : priority-based + round-robin Jbed(Esmertec) : EDF Linux (Timesys) : priority-based 15 Real-Time Operating Systems

LynxOS(1/2) Microkernel design Small kernel footprint : ~28 KB in size The microkernel provides essential services in scheduling, interrupt dispatching and synchronization The other services are provided by kernel lightweight service modules Kernel Plug-Ins (KPIs) New KPIs can be added to the microkernel to support I/O, file systems, TCP/IP, streams and sockets Can function as a multipurpose UNIX OS LynxOSoffers memory protection through hardware MMUs Applications make I/O requests to I/O system through system calls Kernel directs I/O request to the device driver 16 Real-Time Operating Systems

LynxOS(2/2) Each device driver has an interrupt handler and kernel thread The interrupt handler carries the 1 st step of interrupt handling If it does not complete the processing, it sets an asynchronous trap to the kernel Later, when kernel can respond to the software interrupt, it schedules an instance of the kernel thread to complete the interrupt processing 17 Real-Time Operating Systems

QNX Neutrino (1/2) Microkernel design kernel provides essential threads and realtime services Microkernel footprint: ~12 KB Other services are considered as resource managers and can be added or removed at run-time SMP RTOS requires high end, networked SMP machines with GBs of physical memory Message passing: Messages are the basic means of inter-process communication among all threads Message-based priority tracking Messages are delivered at the priority order and the service provider executes at the priority of the highest priority clients waiting for service So, if the highest priority task wants to do read some data from file, the file system resource manager will execute at this task s priority 18 Real-Time Operating Systems

QNX Neutrino (2/2) When a service provider thread wants to provide service, then it creates a channel (for exchanging messages) with its service identifier for identification To get a service from a provider, the client thread attaches it to the provider s channel Within the client, this connection is directly mapped to the file descriptor (so RFS can be sent directly to the file descriptor) QNX messages are blocking (unlike POSIX standards) 19 Real-Time Operating Systems

VxWorks(1/4) Microkernel Monolithic Kernel (CoreOS+ Wind microkernel) Provides interfaces specified by RT-POSIX standards in addition to its own APIs Shared-memory objects: shared binary and counting semaphores Standard MMU (as in modern OS) Provides basic virtual-to-physical memory mapping Allows to add new mappings and make portions of memory non cacheable When memory boards are added dynamically, to increase the address space for inter-process communication The data is made non cacheable, to ensure cache consistency 20 Real-Time Operating Systems

VxWorks(2/4) Reduced Context Switch time Saves only those register windows that are actually in use (e.g. applicable on SPARC) When a task s context is restored, only the relevant register window is restored To improve response time, it saves the register windows in a register cache useful for recurring tasks 21 Real-Time Operating Systems

VxWorks(3/4) Real-Time Embedded Application Graphics Multiprocessing Internet Java Support POSIX Library File System WindNet Networking Core OS: Wind Microkernel 22 22 Real-Time Operating Systems

VxWorks(4/4) 23 Real-Time Operating Systems

RTLinux(1/3) Patch-set for Linux kernel + RT API Runs Linux kernel as lowest-priority task (pre-emptible) User Processes Device drivers System libraries Linux kernel I/O Hardware Interrupts Hardware 24 Real-Time Operating Systems 24

RTLinux(2/3) Linux is executed in the background User Processes Real Time Tasks Device drivers System libraries Linux kernel Direct h/w access RT-Scheduler RTLinux Plug-in I/O I/O Software Interrupts Hardware Interrupts Hardware 25 Real-Time Operating Systems 25

RTLinux(3/3) Development flow for RT-application program: 1. Develop RT-application program : Linux kernel module 2. Load RT-Core / RT-Scheduler/ RT-FIFOs transit to RTLinux 3. Load RT-application module Interrupt control H/W Real-Time Kernel Linux Linux Processes Real-Time FIFOs Real-Time Tasks 26 Real-Time Operating Systems

Linux/RK A Kernel that provides to applications Timely, Guaranteed, and Enforced access to System Resources Allows Applications to specify only their Resource Demands User-Level leaving the Kernel to satisfy Demands using hidden management schemes Linux Process Kernel Resource Kernel Kernel Loadable Kernel Module Linux Process Hardware Linux Kernel Linux Process 27 Real-Time Operating Systems Reservation Parameters T : Period (1/f) C : Execution time within period D : Deadline within period

Hard Reservation 28 Real-Time Operating Systems

Firm Reservation 29 Real-Time Operating Systems

Soft Reservation 30 Real-Time Operating Systems

Commercialized Linux/RK: TimeSys Linux Resource kerneland QoSSupport guaranteed, timelyand enforced access to CPU cycles and network bandwidth SMP support with QoSReservations Fully preemptive kernel Fixed-priority scheduling (POSIX-compliant) High-resolution timer and clock support (microsecond resolution) Periodic processes Message queues Priority inheritanceand priority ceiling protocol emulation support to avoid unbounded priority inversion TimeSysLinux/GPL Basic TimeSysLinux kernel Full preemption at the kernel level, prioritized interrupt handlers, unlimited priorities,... TimeSysLinux/Real-time Support priority inheritance and a POSIXbased high-resolution timer API TimeSysLinux/CPU Support CPU reservation, which gives a thread, process, or process group exclusive use of the CPU. TimeSysLinux/Net Support network bandwidth reservation to guarantee that your thread or process will get the bandwidth it requires, regardless of network activity in other processes TimeSysLinux GPL: Downloadable from sourceforge.net/projects/timesysgpl 31 Real-Time Operating Systems

Sources Victor Yodaiken, The RTLinuxManifesto, In Proceedings of the 5 th Linux Expo, 1999 Victor Yodaiken, CortDougan, Michael Barabanov, RTLinux/RTCoredual kernel real-time operating system, FSM Labs White Paper, 2004 [ available from http://vyodaiken.com/papers-and-talks/] QNX Neutrino RTOS System Architecture [ available from qnx.com/download/ ] http://www.lynx.com/products/real-time-operatingsystems/lynxos-rtos/ http://www.vxworks.com/collateral Raj Rajkumar, Kanaka Juvva, AnastasioMolanoand ShuiOikawa, Resource Kernels: A Resource-Centric Approach to Real-Time Systems, In Proceedings of the SPIE/ACM Conference on Multimedia Computing and Networking, January 1998. 32 Real-Time Operating Systems