Dealing with Task Overruns



Similar documents
Linux Process Scheduling Policy

Partition Scheduling in APEX Runtime Environment for Embedded Avionics Software

174: Scheduling Systems. Emil Michta University of Zielona Gora, Zielona Gora, Poland 1 TIMING ANALYSIS IN NETWORKED MEASUREMENT CONTROL SYSTEMS

Predictable response times in event-driven real-time systems

REAL TIME OPERATING SYSTEMS. Lesson-10:

Lec. 7: Real-Time Scheduling

Chapter 2: OS Overview

Lecture 3 Theoretical Foundations of RTOS

Performance Comparison of RTOS

Exception and Interrupt Handling in ARM

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

Real-Time Scheduling (Part 1) (Working Draft) Real-Time System Example

Real-Time Scheduling 1 / 39

Real-time Scheduling of Periodic Tasks (1) Advanced Operating Systems Lecture 2

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

Keil C51 Cross Compiler

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

LAB 5: Scheduling Algorithms for Embedded Systems

Processor Capacity Reserves: An Abstraction for Managing Processor Usage

Chapter 1 Computer System Overview

4. Fixed-Priority Scheduling

Grid Computing Approach for Dynamic Load Balancing

REDUCING TIME: SCHEDULING JOB. Nisha Yadav, Nikita Chhillar, Neha jaiswal

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

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

Real Time Programming: Concepts

PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks

LynxOS RTOS (Real-Time Operating System)

Chapter 12. Development Tools for Microcontroller Applications

Java Virtual Machine Locks

Introduction to Embedded Systems. Software Update Problem

Attaining EDF Task Scheduling with O(1) Time Complexity

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

Lesson Objectives. To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization

Experimental implementation of a real-time token-based network protocol on a microcontroller

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

The Real-Time Operating System ucos-ii

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

Windows Server Performance Monitoring

HARD REAL-TIME SCHEDULING: THE DEADLINE-MONOTONIC APPROACH 1. Department of Computer Science, University of York, York, YO1 5DD, England.

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Execution-Time Clocks and Ravenscar Kernels

SYSTEM ecos Embedded Configurable Operating System

The simple case: Cyclic execution

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

Quantum Support for Multiprocessor Pfair Scheduling in Linux

Introduction. Scheduling. Types of scheduling. The basics

Dynamic Scheduling of Object Invocations in Distributed Object Oriented Real-Time Systems Jørgensen, Bo Nørregaard; Joosen, Wouter

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

OPC COMMUNICATION IN REAL TIME

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

How to design and implement firmware for embedded systems

Embedded Systems. 6. Real-Time Operating Systems

Effective Scheduling Algorithm and Scheduler Implementation for use with Time-Triggered Co-operative Architecture

Chapter 2 Basic Structure of Computers. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

Introduction. What is an Operating System?

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

RTOS Debugger for ecos

Performance Evaluation of Software Architectures

RESEARCH PAPER International Journal of Recent Trends in Engineering, Vol 1, No. 1, May 2009

Operating Systems 4 th Class

Asynchronous counters, except for the first block, work independently from a system clock.

Ready Time Observations

OPERATING SYSTEM - VIRTUAL MEMORY

Embedded Software Architecture

Chapter 13 Embedded Operating Systems

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

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

Chapter 11 I/O Management and Disk Scheduling

CS161: Operating Systems

OPERATING SYSTEMS SCHEDULING

Embedded Systems Conference / Boston, MA September 20, ESC-302 Stress Testing Embedded Software Applications

Embedded OS. Product Information

A Clustered Approach for Load Balancing in Distributed Systems

EE8205: Embedded Computer System Electrical and Computer Engineering, Ryerson University. Multitasking ARM-Applications with uvision and RTX

Analysis of Micromouse Maze Solving Algorithms

Computer-System Architecture

Multiprocessor Scheduling and Scheduling in Linux Kernel 2.6

Jorix kernel: real-time scheduling

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

the high-performance embedded kernel User Guide Version 5.0 Express Logic, Inc Toll Free 888.THREADX FAX

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

An Efficient Non-Preemptive Real-Time Scheduling

Transport Layer Protocols

Traditional IBM Mainframe Operating Principles

An Introduction to the ARM 7 Architecture

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

Embedded Software development Process and Tools:

Chapter 6, The Operating System Machine Level

ICS Principles of Operating Systems

PikeOS: Multi-Core RTOS for IMA. Dr. Sergey Tverdyshev SYSGO AG , Moscow

Predictable response times in eventdriven real-time systems

An On-Line Algorithm for Checkpoint Placement

CPU SCHEDULING (CONT D) NESTED SCHEDULING FUNCTIONS

Resource Synchronization in Hierarchically Scheduled Real-Time Systems using Preemptive Critical Sections

CPU Scheduling. Core Definitions

Processes and Non-Preemptive Scheduling. Otto J. Anshus

µtasker Document µtasker Zero-Configuration (Auto-IP)

1. Computer System Structure and Components

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

Transcription:

Dealing with Task Overruns Standard scheduling works well when a processor is moderately loaded but may fail if the processor becomes overloaded. When a task is required to perform extra processing and takes longer than normal to execute, it may be scheduled to execute before a previous instance of the same task has completed. The result is a task overrun. The most recent versions of the Embedded Target for Motorola MPC555 and the Embedded Target for Infineon C166 Microcontrollers include a task scheduler that handles temporary task overruns. You can configure this scheduler to meet applicationspecific requirements. This article explains the basic principles of task scheduling and shows how these apply to the enhanced task scheduler in the Embedded Targets products. The enhanced scheduler can also be applied to any Real-Time Workshop target, including custom targets developed by third parties. Standard Task Scheduling Real-Time Workshop includes three types of task scheduling: single-rate, multirate single tasking, and multirate multitasking. Single-rate In single-rate scheduling, every component in the model runs at a constant sample rate in a single task (Figure 1). As long as all the elements of the model can be executed before the next time step, no scheduling problems occur. Figure 1 -- A single-rate execution scheme. Multirate single tasking When multiple rates are present, different portions of the code must be run at different sample rates. The simplest, but not the most efficient, approach for executing a multirate COPYRIGHT 2004 The MathWorks, Inc. All Rights Reserved. 1

system is to use a single-tasking scheduler. Figure 2, for example, shows a model with three separate sample rates executing in a single task. The process execution associated with the base task rate is executed at every timer interrupt. However, operations scheduled for sub-rates execute every fourth and sixteenth timer interrupt, respectively. For example, the task execution that begins at approximately 0.0075 seconds executes the code associated with all three sample rates, while every other fourth task execution processes the fastest two sample rate calculations. Figure 2 A multirate, single-tasking execution scheme.. In this situation, the multirate single-tasking scheduler executes in the manner illustrated in Figure 1 but enables multiple rates by selective execution, as shown in the following pseudo code example. main_task() { execute fastest blocks if (time == slow rate sample hit) { execute slower blocks } } Multirate multitasking A priority-based multitasking scheduler is the most efficient method for executing a multirate system. A multitasking scheduler may be based on a real-time operating system or implemented directly as a timer interrupt service routine for your target hardware. For optimal execution, the separate tasks are prioritized in rate-monotonic order, from the fastest tasks to the slowest (Figure 3). A multitasking scheduler allows a lower priority (longer sample-period) task to be preempted by a higher priority task. COPYRIGHT 2004 The MathWorks, Inc. All Rights Reserved. 2

The grey areas in Figure 3 correspond to task preemption, meaning that task execution is susped by the interrupt request of a higher priority task. Figure 3 -- A priority-based multirate, multi-tasking execution scheme. This process occurs on multiple levels. Figure 3 shows an instance in which the lowest priority task waits on the mid-priority task, which in turn is waiting on the highest priority task. For more information, consult the Models with Multiple Sample Rates section of the Real-Time Workshop User Guide. The Enhanced Scheduler in Action The standard scheduler just described handles even a single task overrun as an error and terminates the application. The most recent version of the Embedded Target for Motorola MPC555 and the Embedded Target for Infineon C166 Microcontrollers include an improved scheduler designed to allow temporary task overruns. This scheduler allows tasks to occasionally overrun their allotted execution time by delaying the start of the next task. It does not, however, allow the gross overruns that occur when the sample rate is too fast for the average task execution time. In this situation, you must use a longer sample period. The operation of the temporary-overruns scheduler is best described through an example. Figure 4 illustrates a single task that takes longer than expected on a heavily loaded processor. An overload occurs, perhaps owing to an infrequent asynchronous event. The disruption in regularly timed interrupts, denoted by triangles, indicate that the execution during this overload did not complete until after the next scheduled start time of the task. In this case, the task executes immediately after completion in an attempt to catch up with COPYRIGHT 2004 The MathWorks, Inc. All Rights Reserved. 3

the scheduled timer events. The time steps immediately after the overload are affected, but execution has recovered within two time steps. Figure 4 -- An asynchronous single-task overrun. With a multitasking system, the problem is more complicated. Because the scheduler must maintain priority ordering, lower-priority tasks are the first to be delayed. Figure 5 illustrates a situation in which the second-highest priority is taking too long to execute. Figure 5 -- Task overrun occurring on a multitask system. The lower-priority task execution is periodically delayed by the processor loading and by task overruns in the mid-priority task. If overruns are allowed for this priority level, each delayed iteration will be queued and eventually run. Note that this example shows a COPYRIGHT 2004 The MathWorks, Inc. All Rights Reserved. 4

heavily loaded processor. Although the temporary overruns scheduler can accommodate large peak loads well, it cannot compensate for an average load that is too high. Again, in this case a larger sample period is recommed. Behavior of Inter-rate Communications During Overruns Rate-transition blocks that are configured to ensure deterministic data transfer between tasks may be affected by overruns. If overruns occur only in the base-rate task, there is no effect on the deterministic data transfer between tasks. If sub-rate overruns occur, however, deterministic data transfer is not guaranteed. In these circumstances, the behavior of the model in real time may differ from its behavior during simulation. This is because, if task-rate overruns occur, loss of synchronization of data between tasks allows old data to be communicated between tasks. For the Embedded Target products, you can specify whether base rate overruns or sub-rate overruns should be allowed. Non-deterministic data transfer is illustrated by models that are included with Embedded Target product demos, c166_multitasking and mpc555rt_multitasking. To ensure that data transfer between tasks is deterministic, you must allow only base rate overruns. Implementing the Temporary Overruns Scheduler The pseudo code for a temporary overruns scheduler implementation is as follows. COPYRIGHT 2004 The MathWorks, Inc. All Rights Reserved. 5

disable interrupts increment base_rate_overrun_counter if base_overrun_counter > 3 error: too many concurrent base-rate overruns if base_rate_overrun_counter > 1 return while base_rate_overrun_counter!= 0 enable interrupts set event flags for each sub-task that is hit run base-rate task disable interrupts decrement base_rate_overrun_counter for i = 1 to number of sub-tasks if hit for sub-task i increment sub_rate_overrun_counter[i] if sub_rate_overrun_counter[i] > 3 error: too many concurrent sub-rate overruns %% sub-rate tasks for i = 1 to number of sub-tasks if sub_task_running[i] == true return else while sub_rate_overrun_counter[i]!= 0 set running_sub_task[i] = true enable interrupts run the sub-rate task disable interrupts set running_sub_task[i] Listing 2 = false decrement sub_rate_overrun_counter[i] When this algorithm is placed inside an interrupt handler, interrupts are enabled inside the function, which allows it to be pre-empted by new timer interrupts. If another interrupt occurs while the base rate is running, the base count will be incremented and the interrupt handler will return to the interrupted base rate. When this interrupted base rate has completed its run, the scheduler runs the new rate. COPYRIGHT 2004 The MathWorks, Inc. All Rights Reserved. 6

If a base-rate interrupt occurs while a non-base-rate task is running, the function will not return but will run the base rate and then update the task counters to see if any subtasks have been activated. It will then continue to the 'for each task' section of the handler, which will run each sub-task, starting with the highest priority. This process will continue until the priority corresponding to the interrupted rate occurs. The function will then return and continue with the interrupted rate. This behavior preserves monotonicity in all conditions. It also results in the possibility that multiple versions of this pseudo code can be running concurrently, however, and thus the number of stack frames could equal the number of rates plus one. Multiple invocations of a given rate will not occur at the same time, but will be queued. The italicized pseudo code is not represented explicitly in the actual code; it is inherent in the operation of the interrupts used by the functions implementing the scheduler. This algorithm can be implemented in a number of different ways. The Embedded Target for Infineon C166 Microcontrollers implements the algorithm as an autogenerated main, with separate interrupts for each task. These interrupts are actually TRAP instructions issued by a scheduler kernel written in assembler. This means that the implementation for C166 differs somewhat from the pseudo code, but the behavior is the same. The Embedded Target for Motorola MPC555 implements the algorithm as a static main function, which calls the tasks as functions. This implementation requires no assembler and is written entirely in C. Consequently, it is simpler to understand and more appropriate for the timers and interrupts of the MPC555. In this case, the commented code in previous listing is not present. You can obtain code samples for both these targets by building the demo models provided with the Embedded Target products. You can simply generate the code to examine the scheduler, but to accurately assess the scheduler s behavior, it is best to compile and run the code on the processors. References [1] Erkkinen, T. "High-Integrity Production Code Generation," AIAA GN&C, 2002. [2] Janka, R.S., "Specification and Design Methodology for Real-Time Embedded Systems," Springer, 2002, ISBN: 0-7923-7626-9. [3] Balarin, F.; Lavagno, L.; Murthy, P.; Sangiovanni-Vincentelli, A.; Systems, C.D.; Sangiovanni-, A. "Scheduling for embedded real-time systems," IEEE Design & Test of Computers, vol.15, (no.1), IEEE, Jan.-March 1998. p.71-82. [4] Sha, L.; Rajkumar, R.; Sathaye, S.S. "Generalized rate-monotonic scheduling theory: a framework for developing real-time systems," Proceedings of the IEEE, vol.82, (no.1), Jan. 1994. p.68-82. COPYRIGHT 2004 The MathWorks, Inc. All Rights Reserved. 7

[5] Liu, C.L.; Layland, J.W. "Scheduling algorithms for multiprogramming in a hard real-time environment," Journal of the Association for Computing Machinery, vol.20, (no.1), Jan. 1973. Pages 46-61 provide some general RTOS references. NOTE: The plots shown in this paper were generated with the task execution profiling utility that is provided with the Embedded Target for Infineon C166 Microcontrollers and Embedded Target for Motorola MPC555. COPYRIGHT 2004 The MathWorks, Inc. All Rights Reserved. 8