Real time systems RTS Engineering.

Slides:



Advertisements
Similar presentations
Real-Time Kernels and Operating Systems Basic Issue - Purchase commercial “off-the- shelf” system or custom build one Basic Functions –Task scheduling.
Advertisements

CENG 324 Embedded Computer Systems Lecture 3 General Concepts of RTOS (Real-Time Operating System) Asst. Prof. Tolga Ayav, Ph.D. Department of Computer.
RTOS Concepts and Defn From Pseudokernels to Operating Systems
ECE 526 – Network Processing Systems Design Software-based Protocol Processing Chapter 7: D. E. Comer.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.
© Copyright 2004 Dr. Phillip A. Laplante 1 Real-time operating systems: I  Operating systems taxonomy  Pseudo-kernels  Interrupt driven systems  Preemptive.
MicroC/OS-II Embedded Systems Design and Implementation.
Exceptions, Interrupts & Traps
Performance Evaluation of Real-Time Operating Systems
Advanced Embedded Systems Design Pre-emptive scheduler BAE 5030 Fall 2004 Roshani Jayasekara Biosystems and Agricultural Engineering Oklahoma State University.
Introduction to Embedded Systems
CHAPTER 3 TOP LEVEL VIEW OF COMPUTER FUNCTION AND INTERCONNECTION
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
Processes and Process Control 1. Processes and Process Control 2. Definitions of a Process 3. Systems state vs. Process State 4. A 2 State Process Model.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
ECGR-6185 µC/OS II Nayana Rao University of North Carolina at Charlotte.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
1 VxWorks 5.4 Group A3: Wafa’ Jaffal Kathryn Bean.
Embedded Computer - Definition When a microcomputer is part of a larger product, it is said to be an embedded computer. The embedded computer retrieves.
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
Real-Time Operating Systems RTOS For Embedded systems.
SE3910 Week 8, Class 3 Week 4 Lab: Please return your graded Lab 4 to me so I can enter it in my gradebook Week 9 Lab: Individual demos of working sub-modules.
Introduction to Operating Systems Concepts
Input / Output Chapter 9.
Computer System Structures Interrupts
Chapter 13: I/O Systems.
REAL-TIME OPERATING SYSTEMS
Module 12: I/O Systems I/O hardware Application I/O Interface
Process Management Process Concept Why only the global variables?
CS 6560: Operating Systems Design
Topics Covered What is Real Time Operating System (RTOS)
RTS: Kernel Design and Cyclic Executives
Lesson Objectives Aims Key Words Interrupt, Buffer, Priority, Stack
OPERATING SYSTEMS CS3502 Fall 2017
Computer Architecture
Intro to Processes CSSE 332 Operating Systems
Real-time Software Design
Chapter 8 Input/Output I/O basics Keyboard input Monitor output
RTS: Kernel Design and Cyclic Executives
Process management Information maintained by OS for process management
Structure of Processes
Computer System Overview
RTS: Kernel Design 11/30/2018.
Processor Fundamentals
Operating System Concepts
Chapter 2: The Linux System Part 3
Process Description and Control
RTS: Kernel Design and Cyclic Executives
RTS: Kernel Design 1/2/2019.
Architectural Support for OS
Threads Chapter 4.
RTS: Kernel Design and Cyclic Executives
Multiprocessor and Real-Time Scheduling
RTS: Kernel Design and Cyclic Executives
EE 472 – Embedded Systems Dr. Shwetak Patel.
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
COMP3221: Microprocessors and Embedded Systems
Module 12: I/O Systems I/O hardwared Application I/O Interface
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

Real time systems RTS Engineering

RTSs Engineering Two dimensions: Designing, coding and analyzing RT code such it executes in the required interval Threads usage Memory management Synchronization Events and Interrupts Clock and time management Ensuring that resurces such as CPU are allocated so RT activities get enough time and resources to meet their deadlines Scheduling

RT Operating Systems Slides below based on Laplante (chapter 3) RT Kernels Scheduling Intertask Communication and Synchronization Memory Management

RT Kernels Process or Task: Thread: Abstraction of a running program Logical unit of work scheduled by the operating system Represented as a data structure: state of execution, identity, attributes, associated resources Thread: Lightweight process Shares resources with other processes or threads Reside within some process and make use of the resources of that process

RT Kernels Kernels functions related to tasks: Scheduling: which task to run next in a multitasking environment Dispatching: switches the tasks contexts Intercommunication and Synchronization: ensures that the tasks can cooperate

Taxonomy of RT OS layers

Pseudo-kernels Obtain multitasking even if: Techniques: Do not use interrupts No operating system around Techniques: Polled Loops Synchronized Pooled Loops Cyclic Executives State Driven Code Coroutines

Polled Loops Used for fast response to events coming from a single device Repetitive loop testing a flag indicating if the event occurred: while(true){ if (eventOccured){ processData(); eventOccured = false; } Works well when: A single processor is dedicated to handling IO fro some fast device The overlapping of events is not allowed or is minimized

Synchronized polled loops Uses a fixed clock interrupt to pause between the time the event was triggered and the event processing while(true){ if (eventOccured){ pause(20); //wait 20 ms processData(); eventOccured = false; } Ex: switch bounce

Advantages/Disadvantages Pooled loops are simple to develop and analyze, thus easy to guarantee response time Good at handling high speed data channels when the events occur at widely dispersed intervals and the processor is dedicated to the data channel Fails on bursts Not sufficient to handle complex systems Waste CPU

Cyclic Executives A list of tasks called in a continuous loop: while(true){ Process1(); Process2(); … ProcessN(); } Round robin fashion The same process may appear multiple times in the list Intertask communication and synchronization can be implemented through global variables or task parameters Variations in the list of tasks are possible by maintaining the task list as a list of pointers to tasks. Ineffective for more complex RT systems as the duration of tasks is hard to control

State Driven Code Allows for suspending the execution of a task by using nested if-then statements, case structures or finite automata. The task will stay into a stable state until restarted. Work well in conjunction with cyclic executives and coroutines. Not all processes are naturally expressed as finite state automata.

Coroutines Also called cooperative multitasking Requires usage of the state driven code in a task in order for the task to be split in phases; After each phase a central dispatcher is called which switches to the next task in a round robin fashion. Communication is done through global variables

void process_a(void) { for(;;) { switch(state_a) case 1: phase_a1(); break; case 2: phase_a2(); case 3: phase_a3(); case 4: phase_a4(); case 5: phase_a5(); } void process_b(void) { for(;;) { switch(state_b) case 1: phase_b1(); break; case 2: phase_b2(); case 3: phase_b3(); case 4: phase_b4(); case 5: phase_b5(); }

Advantages/Disadvantages No hardware interrupts Requires programmers giving control to the dispatcher at known intervals in order for the fairness scheduling to happen Communication through global variables is not desirable Processes cannot be always decomposed uniformly

Interrupt Driven Systems Tasks scheduled through hardware/software interrupts Dispatching performed by the interrupt handling routines Techniques: Interrupt service routines Context switching Preemptive priority systems Hybrid Systems The task control block model

Interrupt Service Routines Hardware Interrupt: A signal generated by a peripheral device and sent to the CPU. CPU executes an Interrupt Service Routine (ISR) to perform appropriate actions Software Interrupt: similar to the hardware interrupt but comes from the running code Exception: internal interrupt triggered by a program performing an unexpected or an illegal operation

Processing Interrupts Asynchronous, can happen at any time The program is suspended while CPU invokes ISR The application developer is often required to write the ISR for a specific type of hardware interrupt The developer has to understand the CPU state and to preserve everything needed in addition to the general registers Access to the shared resources within an ISR is usually controlled by disabling/enabling interrupts around any code accessing that resource

Processing Interrupts Synchronization is not possible inside an ISR as it cannot wait indefinitely for a resource It is important to minimize the time the interrupts are disabled Reentrant code: code which is safe to be executed simultaneously from two contexts ISR is reentrant if the same interrupt can occur while still processing a previous occurrence The machine context prior to ISR has to be restored after ISR completion.

Context Switching The process of saving and restoring sufficient information for a RT task so that it can be resumed after it is interrupted Usually saved on the stack Context switching time is important when evaluating the response time Contexts include: General registers The program counter Coprocessor registers (if available) Memory page register Images of the memory-mapped I/O locations

Context Switching Interrupts has to be disabled during the critical context switching period The stack model for context switching: Mostly used in embedded systems Each interrupt handler is associated with a hardware interrupt invoked by the CPU based on a stored interrupt vectors table The context is saved to a memory area (single interrupt systems) or to the stack.

void int2(void) /. interrupt handler 2. / { save(context); / void int2(void) /* interrupt handler 2 */ { save(context); /* save context on stack */ task2(); /* execute task 2 */ restore(context); /* restore context from stack */ } void int3(void) /* interrupt handler 3 */ task3(); /* execute task 3 */ restore(context); /* restore context from stack */ void main(void) /*initialize system, load interrupt handlers */ { init(); while(TRUE); /* infinite wait loop */ } void intl (void) /* interrupt handler 1 */ save(context); /* save context on stack */ task1(); /* execute task 1 */ restore(context); /* restore context from stack */

Preemptive-Priority Systems A higher-priority task is said to preempt a lower-priority task if it interrupts the lower-priority task Preemptive-priority systems: Systems that use preemption schemes instead of round-robin or first-come-first-served scheduling Fixed priority vs. dynamic priority Starvation: lower priority tasks do not run Rate monotonic systems: special class of fixed-rate preemptive-priority interrupt-driven systems where priorities are assigned so that the higher the execution frequency, the higher the priority

Hybrid Systems Systems processing interrupts occurring both at fixed rate and sporadically Common in embedded applications when sporadic interrupts handle critical errors requiring immediate attention Also found as combinations of round robin scheduling (tasks with the same priority) and preemption (higher priority tasks) Types: Foreground/background systems Background processing Initialization Real-time operation Full-featured real-time operating systems Task Control Block Model

Foreground/Background Systems Adds some processing in the polled loop which is the main program: background work The most common architecture for embedded applications Involve a set of interrupt driven or RT processes called the foreground and a collection of noninterrupt-driven processes called the background. The foreground tasks run in round-robin, preemptive priority, or hybrid fashion. The background task is fully preemptable by any foreground task (the lowest priority task in the system)

FgBg Systems Architecture

RT Solutions vs FgBg Systems All real-time solutions are just special cases of the foreground/background systems: The polled loop is simply a foreground/background system with no foreground, and a polled loop as a background. State-driven code is a foreground/background system with no foreground and phase-driven code for a background. Coroutine systems are a more complicated background process. Interrupt-only systems are foreground/background systems without background processing.

Background processing tasks Count statistics for the foreground processes Monitor the foreground processes Testing the CPU instruction set (robust systems) Updates the display, log to printers or other interfaces

Initialization First part of the background process: Disable interrupts Set up interrupt vectors and stacks Perform self-test Perform system initialization Enable interrupts

Real Time Operation Foreground/background systems typically have good response times, since they rely on hardware to perform scheduling. Drawbacks: interfaces to complicated devices and networks must be written. This procedure can be tedious and error-prone. best implemented when the number of foreground tasks is fixed and known a priori. Although languages that support dynamic allocation of memory could handle a variable number of tasks, this can be tricky. the foreground/background system is vulnerable to timing variations, unanticipated race conditions, hardware failures, and so on (similar to the interrupt only systems).

Full Featured RT Operating Systems The foreground/background solution can be extended into an operating system by adding additional functions such as network interfaces, device drivers, and complex debugging tools Rely on a complex operating system using round-robin, preemptive priority, or a combination of both schemes to provide scheduling; The operating system represents the highest priority task: kernel or supervisor

The Task-Control Block Model The ISR model allows for a determined number of tasks to exists. TCB Model allows for variable number of tasks Used in interactive on-line systems where tasks associated with users manifest a great dynamism Added overhead to the scheduler Each task is associated with a data structure called the Task Control Block TCBs are placed in a linked list in order to be managed by the scheduler

Task Control Block

Task states

Task management RT OS: highest priority task Each hardware interrupt invokes the RT OS OS maintains a linked list of TCBs for Ready tasks and another list for the tasks in the Suspended state OS maintains a list with the resources and a table with resources requests OS checks the ready list to see if the next task is eligible for execution If eligible, the TCB of the currently executing task is placed at the end of the ready list The TCB of the eligible task is removed from the list and its execution begins The updates on the “status” of a TCB drive the way the tasks are managed