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



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

Embedded Systems. 6. Real-Time Operating Systems

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

Lecture 3 Theoretical Foundations of RTOS

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

Tasks Schedule Analysis in RTAI/Linux-GPL

Comparison between scheduling algorithms in RTLinux and VxWorks

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

Développement d'une application en temps réel pour le contrôle d'une carte CANPCI INDEX

Performance Comparison of RTOS

REAL TIME OPERATING SYSTEMS. Lesson-10:

Linux 2.4. Linux. Windows

Enhancing the Monitoring of Real-Time Performance in Linux

Red Hat Linux Internals

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

A Predictable and IO Bandwidth Reservation Task Scheduler

Embedded & Real-time Operating Systems

Real-Time Operating Systems.

CPU SCHEDULING (CONT D) NESTED SCHEDULING FUNCTIONS

SYSTEM ecos Embedded Configurable Operating System

Hard Real-Time Linux

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

RTAI API Inter Process Communication

Quality of Service su Linux: Passato Presente e Futuro

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

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

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

Chapter 3 Operating-System Structures

Design and Implementation of a POSIX Compliant Sporadic Server for the Linux Kernel

Real Time Programming: Concepts

Linux for Embedded and Real-Time Systems

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

Operating Systems Concepts: Chapter 7: Scheduling Strategies

Real Time Operating System for Embedded DSP Applications

Jorix kernel: real-time scheduling

Operating Systems. Lecture 03. February 11, 2013

Chapter 2 System Structures

Operating System Structure

COS 318: Operating Systems

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

OPERATING SYSTEMS SCHEDULING

Predictable response times in event-driven real-time systems

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

Threads Scheduling on Linux Operating Systems

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

Framework for Validation, Test and Analysis of Real-time Scheduling Algorithms and Scheduler Implementations

Middleware. Peter Marwedel TU Dortmund, Informatik 12 Germany. technische universität dortmund. fakultät für informatik informatik 12

Chapter 13 Embedded Operating Systems

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

Mutual Exclusion using Monitors

The Real-Time Operating System ucos-ii

System Software Integration: An Expansive View. Overview

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

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

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Thread-based analysis of embedded applications with real-time and non real-time processing on a single-processor platform

CS161: Operating Systems

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

Embedded & Real-time Operating Systems Communication Libraries

How To Write A Windows Operating System (Windows) (For Linux) (Windows 2) (Programming) (Operating System) (Permanent) (Powerbook) (Unix) (Amd64) (Win2) (X

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

Operating System Components and Services

Monitors, Java, Threads and Processes

Lecture 5. User-Mode Linux. Jeff Dike. November 7, Operating Systems Practical. OSP Lecture 5, UML 1/33

First-class User Level Threads

CPU Scheduling Outline

Scaling Networking Applications to Multiple Cores

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

Process Description and Control william stallings, maurizio pizzonia - sistemi operativi

Encryption Wrapper. on OSX

Linux Kernel Networking. Raoul Rivas

Improvement of Scheduling Granularity for Deadline Scheduler

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

High-performance vnic framework for hypervisor-based NFV with userspace vswitch Yoshihiro Nakajima, Hitoshi Masutani, Hirokazu Takahashi NTT Labs.

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

Operating System Manual. Realtime Communication System for netx. Kernel API Function Reference.

Real- Time Scheduling

Kernel Types System Calls. Operating Systems. Autumn 2013 CS4023

x86 ISA Modifications to support Virtual Machines

Overview of the Linux Scheduler Framework

CPU Scheduling. CPU Scheduling

Operating Systems. III. Scheduling.

Virtual Machine Security

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

Real-Time Scheduling 1 / 39

Priority Based Implementation in Pintos

MQX Lite Real-Time Operating System User Guide

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

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

Chapter 11 I/O Management and Disk Scheduling

KVM: A Hypervisor for All Seasons. Avi Kivity avi@qumranet.com

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

Architecture of the Kernel-based Virtual Machine (KVM)

Application of RT-Preempt Linux and Sercos III for Real-time Simulation

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

ELEC 377. Operating Systems. Week 1 Class 3

Binary Device Driver Reuse. Bernhard Poess. Diplomarbeit

Lecture 6: Interrupts. CSC 469H1F Fall 2006 Angela Demke Brown

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

Operating Systems 4 th Class

Transcription:

Introduction to Real-Time Operating Systems Mahesh Balasubramaniam What is an RTOS? An RTOS is a class of operating systems that are intended for real time-applications What is a real time application? A real time application is an application that guarantees both correctness of result and the added constraint of meeting a deadline So what is an RTOS? An operating system which follows the Real Time criteria. ² Efficiency, Predictability and Timeliness important All components of an RTOS must have these properties. Some tasks which may delay things: Interrupt Processing, Context Switching, Inter-task communication, So what is an RTOS?(contd) IO To cut back on (variable) overhead for these tasks: Multiprogramming, Memory Management, File (and other) IO, IPC, etc. So what makes an RTOS special? An RTOS will provide facilities to guarantee deadlines will be met An RTOS will provide scheduling algorithms in order to enable deterministic behavior in the system An RTOS is valued more for predictability than throughput Design Philosophies Some of the design philosophies of an RTOS are with respect to: Scheduling Memory allocation Inter task communication Interrupt handlers 1

Tasks Task States: Running Ready (possibly: suspended, pended) Blocked (possibly: waiting, dormant, delayed) Scheduler schedules/shuffles tasks between Running and Ready states Blocking is self-blocking by tasks, and moved to Running state via other tasks interrupt signaling (when block-factor is removed/satisfied) When a task is unblocked with a higher priority over the running task, the scheduler switches context immediately Scheduling The data structure of the ready list in the scheduler is designed so as to minimize the worst-case length of time spent in the scheduler's critical section The critical response time, sometimes called the flyback time, is the time it takes to queue a new ready task and restore the state of the highest priority task. In a well-designed RTOS, readying a new task will take 3-20 instructions per ready queue entry, and restoration of the highestpriority ready task will take 5-30 instructions. Intertask Comm. & resource sharing It is "unsafe" for two tasks to access the same specific data or hardware resource simultaneously. 3 Ways to resolve this: Temporarily masking/disabling interrupts Binary Semaphores Message passing Memory Allocation Speed of allocation Memory can become fragmented Interrupt Handling Interrupts usually block the highest priority tasks Need to minimize the unpredictability caused 2

Linux as an RTOS Is Linux an RTOS? Linux provides a few basic features to support real-time applications Provides soft-real time guarantees SCHED_FF and SCHED_RR are 2 scheduling policies provided Problems with Linux Use of Virtual Memory Use of shared memory Does not support priority inheritance and RTAI Variants of Linux with support for real-time applications They both use a real-time kernel which interacts with the main Kernel They treat the Linux OS as the lowest running task : Mechanics behind the Kernel Sudhanshu Sharma Outline Real time Linux The various forms Architecture - Kernel (Wikipedia) : As a basic component of an operating system, a kernel provides the lowest level of abstraction layer for the resources (especially memory, processors and I/O devices ) that applications must control to perform their function -Process Management -Memory Management -Device Management -System Calls 3

Why Real Time Linux? Reuse!!! Most of the standard problems in Systems already solvable through Linux Any RT system application can be divided into 2 parts -Real Time task/process ( Temporal properties Imp.) -Non Real Time task/process (Temporal properties not as Imp.) Ideology behind : Extend the existing source to provide the standard functionalities at the same time provide a framework that can guarantee Hard Real Time requirements to be fulfilled. Linux an obvious choice --- - Open source - Vast User/Developer base of Linux Outline Real Time Linux Approaches Real Time Linux Approaches Architecture - 3 broader paradigms to solve RTOS problem : 1) Providing Non real time Services to the basic real time kernel (eg. VxWorks) 2) Preemption Improvement in Standard kernel (preempt patch for Linux kernel) 3) Virtual Machine Layer to make standard kernel Pre-emptable ( /RTAI) Real Time Linux Approaches Outline RTAI & comparisons -In essence both RTAI and execute Real Time tasks in the kernel memory space preventing RT threads to be swapped out - Dynamic Memory allocation in RTAI while RTlinux still uses static allocation - Shared Memory (Linux <-> ) provided by both - IPC functions in RTAI are more extensive FIFO, Mailboxes, Messg. Q s,net_rpc - POSIX Mutex, Conditional Variables, Semaphores provided in both - User space real time (Protection) Provided only in RTAI called LXRT services - only provides user space real time signals. No interaction with RTservices or Linux System Calls possible in those handlers. Real time Linux The various forms Architecture - 4

Architecture Architecture Bash Emacs gcc - Standard time sharing OS and hard real time executive running on same machine I / O System Calls Drivers Linux kernel Kernel Interrupts RT task Scheduler RT task I / O Interrupt - Kernel provided with the emulation of Interrupt control H/W -RT tasks run at kernel privilege level to provide direct H/W access - runs Linux kernel for booting, device drivers,networking, FS, process control and loadable kernel modules Hardware - Linux kernel runs as a low priority task on the RT kernel hence making sure it cannot preempt any RT task Architecture Architecture -RT task allocated fixed memory for data and code (Pain Sounds Familiar!!!!) -RT tasks cannot use Linux system calls, directly call routines or access ordinary data structures in Linux Kernel -RTProcesses without memory protection features ( Pro has some PSDD now ) - The RT kernel is actually patched over the Linux kernel and then recompiled to work as a system - Completely configurable kernel VM layer only emulates the Interrupt Control The 0 level OS does not provide any basic services that can be provided by Linux - Only RT services - No primitives for process creation, switching or MM Uses software stack for switching and not the expensive H/W switching RT KERNEL IS NOT PREEMPTABLE Outline Real time Linux The various forms Architecture - Here comes the nuts and bolts of implementation We will cover 4 important aspects of the internals 1) Interrupt Handling 2) IPC toolsets RT- FIFO & Shared Memory 3) Clock and Timers 4) Scheduling 5

Interrupt Handling Interrupt Handling - Traditional calls (PSW) of sti() and cli() are modified to use the Software interrupts - Wrapper routines written to save and restore state at return from software Interrupt - Interrupt Handlers in RT executive perform whatever functions are required and passes interrupts to Linux - In Most I/O, RT device interrupts simply notify Linux - Timer interrupt increments timer variable and determines whether RT task needs to run and passes interrupts to Linux at appropriate intervals - All Linux wrappers modified to fix stacks to cheat Linux to believe H/W interrupt and hence kernel mode execution ensured - S_IRET is used to save minimal state and look for pending interrupts (call other wrappers) otherwise restore registers and return from Interrupt Interrupt Handling APIs rtl_request_irq() - Add RT Interrupt Handler RT- FIFO This provides the primary mechanism through which the RT processes interact with the Linux processes rtl_free_irq () Remove RT Interrupt Handler RT tasks should pre allocate the default size of FIFO and the number rtl_get_soft_irq ()- Install Software interrupt Handler RTKernel Config has options for > rtl_free_soft_irq ()- Remove Software interrupt Handler rtl_global_pend_irq ()- Schedule a Linux Interrupt - Pre Allocated FIFO Buffer - Max number of FIFO RT- FIFO - Asynchronous I/O Example Linux process producing data and RT process is the consumer tht writes nothing back void fifo_handler (int sig,rtl_siginfo_t *sig,void *v) char msg[64]; read(sig->si_fd,&msg,64); void fifo(void) int fd; struct rtl_sigaction sigaction; RT- FIFO - Asynchronous I/O... //create FIFO mkfifo( /myfifo,0755); //if 2 arg. 0 then Linux cant see it // open FIFO for read fd = open( /myfifo,0_rdonly 0_NONBLOCK); // register a SIGPOLL handler for FIFO sigaction.sa_sigaction = fifo_handler; //file that we want signal for sigaction.sa_fd =fd; //write event notification sigaction.sa_flags = RTL_SA_RDONLY RTL_SA_SIGINFO; //install handlers rtl_sigaction(sigpoll,&sigaction,null); unlink( /myfifo ); 6

RT- FIFO Shared Memory Only one SIGPOLL handler installed at a given time Many fd share the same FIFO but only one SIGPOLL handler Almost the same principle it uses POSIX RT extensions - shm_open( file,0_create,0) // 0755 to allow Linux to use it - shm_unlink() - mmap() //Area created needs to be mapped Reference Count - Maintained so that shm_unlink() / unlink() don t wipe out the resource in use across Linux or processes Clocks & Timers - Clocks used to manage time in computers Clocks control API s - Timers is H/w or S/w allow functions to be evoked at specified time in future Schedulers RM Scheduler provided EDF Scheduler provided - Multi task systems need timers for each one of them hence S/w timers used Also the Scheduler can be loaded at run time hence more complex extensions are possible - Timer Interrupt will trigger task schedule at specified moments (One shit timers) Timer management API support // Program in Linux writing to FIFO //rtf3 for Sound #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #define DELAY 30000 void make_tone1(int fd) static char buf = 0; write (fd, &buf, 1); void make_tone2(int fd) static char buf = 0xff; write (fd, &buf, 1);.... main() int i, fd = open ("/dev/rtf3", O_WRONLY); while (1) for (i=0;i<delay;i++); make_tone1(fd); for (i=0;i<delay;i++); make_tone2(fd); // RT process doing the same work #include <rtl.h> #include <pthread.h> #include <rtl_fifo.h> #include <time.h> #define FIFO_NO 3 #define DELAY 30000 pthread_t thread; void * sound_thread(int fd) int i; static char buf = 0; while (1) for(i=0; i<delay; i++); buf = 0xff; rtf_put(fifo_no, &buf, 1); for(i=0;i<delay;i++); buf = 0x0; rtf_put(fifo_no, &buf, 1); return 0; int init_module(void) return pthread_create(&thread, NULL, sound_thread, NULL); void cleanup_module(void) pthread_delete_np(thread); // Finally a kernel module that will be a RT thread and // will read the char device //rtf3 to produce sound 7

References Yodaiken, Victor. An Introduction to [www] <http://www.linuxdevices.com/articles/at3694406595.html> Dougan,Court and Matt Sherer. POSIX API for IO on Real Time FIFOs and Shared Memory Yodaiken, Victor and Barabanov, Michael.A Real-Time Linux V. Esteve, I. Ripoll and A. Crespo. Stand-Alone -GPL She Kairui, Bai Shuwei, Zhou Qingguo, Nicholas Mc Guire, and Li Lian. Analyzing /GPL Source Code for Education Ismael Ripoll (2002). versus RTAI Yodaiken, Victor and Barabanov, Michael.FSMLabs PSDD: Hard Realtime with Memory Protection Michael Pettersson,Markus Svensson.Memory Management in VxWorks compared to 8