Embedded Operating Systems

Similar documents
Zilog Real-Time Kernel

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

Tasks. Task Implementation and management

Real-Time Programming

Introduction to Real-Time Operating Systems

RTOS Real T i Time me Operating System System Concepts Part 2

Embedded Systems. 5. Operating Systems. Lothar Thiele. Computer Engineering and Networks Laboratory

ZiLOG Real-Time Kernel Version 1.2.0

Operating System Concepts Ch. 5: Scheduling

6/17/2011. Real-time Operating Systems

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

Midterm Exam. October 20th, Thursday NSC

Midterm Exam Amy Murphy 6 March 2002

Microcomputer Architecture..Second Year (Sem.2).Lecture(2) مدرس المادة : م. سندس العزاوي... قسم / الحاسبات


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

Lecture 3. Introduction to Real-Time kernels. Real-Time Systems

Scheduling Mar. 19, 2018

Lecture 9: Midterm Review

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Main Points of the Computer Organization and System Software Module

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Computer Systems Assignment 4: Scheduling and I/O

Back to RTOS. CSE466 Autumn 00-1

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

Chapter 5: CPU Scheduling

MARUTHI SCHOOL OF BANKING (MSB)

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

AC OB S. Multi-threaded FW framework (OS) for embedded ARM systems Torsten Jaekel, June 2014

Lecture 3: Concurrency & Tasking

CSE 153 Design of Operating Systems

Lesson 5: Software for embedding in System- Part 2

Bringing Organization to our Code (the shared-data problem)

Exam TI2720-C/TI2725-C Embedded Software

Multiprocessor and Real- Time Scheduling. Chapter 10

GLOSSARY. VisualDSP++ Kernel (VDK) User s Guide B-1

The components in the middle are core and the components on the outside are optional.

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

CSE306 - Homework2 and Solutions

Embedded Systems. 6. Real-Time Operating Systems

CS/ECE 6780/5780. Al Davis

Page 1. Lab 5 Logistics. Implicit Threads. Explicit Thread Semantics. Problem not enough interrupt pins CS/ECE 6780/5780. Al Davis

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Timers 1 / 46. Jiffies. Potent and Evil Magic

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document C28X CCS

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

Frequently asked questions from the previous class survey

Process- Concept &Process Scheduling OPERATING SYSTEMS

Chapter 2 Processes and Threads. Interprocess Communication Race Conditions

Copyright 2000 by Barry B. Brey The CPU Scheduling Processes

Review. Preview. Three Level Scheduler. Scheduler. Process behavior. Effective CPU Scheduler is essential. Process Scheduling

In Class Assignment 2

Systemy RT i embedded Wykład 11 Systemy RTOS

AC59/AT59/AC110/AT110 OPERATING SYSTEMS & SYSTEMS SOFTWARE DEC 2015

DSP/BIOS Kernel Scalable, Real-Time Kernel TM. for TMS320 DSPs. Product Bulletin

CS-537: Midterm Exam (Spring 2001)

Virtual Machine Design

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

Putting it All Together

16-Bit Intel Processor Architecture

Multitasking and scheduling

Embedded Software TI2726 B. 7. Embedded software design. Koen Langendoen. Embedded Software Group

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

Embedded System Curriculum

ECE 462 Object-Oriented Programming using C++ and Java. Scheduling and Critical Section

Operating Systems: Quiz2 December 15, Class: No. Name:

Techno India Batanagar Department of Computer Science & Engineering. Model Questions. Multiple Choice Questions:

Context Switch DAVID KALINSKY

CS 326: Operating Systems. CPU Scheduling. Lecture 6

OPERATING SYSTEMS. COMS W1001 Introduction to Information Science. Boyi Xie

2 Introduction to Processes

Embedded Software TI2725 C. 5. Software architectures. Koen Langendoen. Embedded Software Group

Chapter 2 Processes and Threads

Processes, Context Switching, and Scheduling. Kevin Webb Swarthmore College January 30, 2018

CSE 120. Fall Lecture 8: Scheduling and Deadlock. Keith Marzullo

Part B Questions. Unit I

PROCESSES & THREADS. Charles Abzug, Ph.D. Department of Computer Science James Madison University Harrisonburg, VA Charles Abzug

SMD149 - Operating Systems

CODE TIME TECHNOLOGIES. Abassi RTOS. Porting Document. ARM Cortex-M3 CCS

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

Threads. Threads The Thread Model (1) CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5

Process Synchronization and Communication

CPU Scheduling. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

Multitasking. Embedded Systems

CSE 120 Principles of Operating Systems

2. Introduction to Software for Embedded Systems

Process Scheduling Part 2

CS370 Operating Systems

REAL TIME OPERATING SYSTEMS: A COMPLETE OVERVIEW

Verification of Real-Time Systems Resource Sharing

Course Syllabus. Operating Systems

Lesson FreeRTOS + LPC17xx. FreeRTOS & Tasks LPC17xx Memory Map Lab Assignment: FreeRTOS Tasks

Processes The Process Model. Chapter 2 Processes and Threads. Process Termination. Process States (1) Process Hierarchies

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

CMPS 111 Spring 2013 Prof. Scott A. Brandt Midterm Examination May 6, Name: ID:

Process Coordination and Shared Data

CS 4410 Operating Systems. Review 1. Summer 2016 Cornell University

Operating System Study Notes Department of Computer science and Engineering Prepared by TKG, SM and MS

3.1 (a) The Main Features of Operating Systems

CPSC/ECE 3220 Summer 2018 Exam 2 No Electronics.

Transcription:

Embedded Operating Systems Embedded Software Design 熊博安國立中正大學資訊工程研究所 pahsiung@cs.ccu.edu.tw Textbook: Programming Embedded Systems in C and C++, Michael Barr, O Reilly 1

Contents History and Purpose A Decent Embedded Operating System Real-Time Characteristics Selection Process 2

History and Purpose Originally, no operating system (OS) Users controlled everything Later, a loose collection of routines (like modern software library) resetting hardware to a known state reading state of inputs changing state of outputs Finally, modern OS set of tasks 3

Tasks Task: a piece of software that can be separated from and run independently of the rest A set of embedded software requirements can be DECOMPOSED into a small number of independent pieces (tasks). Example: Printer-sharing device Task 1: receive data from serial port A Task 2: receive data from serial port B Task 3: format & send waiting data to printer 4

Tasks Software abstraction Software design easier Software implementation easier Designer can concentrate on unique features of system under development Need an OS 5

Embedded OS Small No need of filesystem No need of GUI Single user No need of security features of multiuser OS 6

ADEOS (A Decent Embedded OS) Developed by Michael Barr Less than 1000 lines of source code ¾ platform independent, in C++ ¼ platform dependent, in assembly For learning embedded OS 7

Tasks Pseudoparallel: take turns using processor Processor decides: which task gets the processor context of a task (like a bookmark for a book reader) Instruction Pointer: Pointer to next instruction (80x86 Eg: CS and IP) Stack Pointer: Address of current top of stack (80x86 Eg: SS and SP) Process flag and general-purpose register contents (80x86 Eg: Flags, DS, ES, SI, DI, AX, BX, CX, DX) 8

Task Class in ADEOS class Task { public: Task( void (*function)(), Priority p, int stacksize ); TaskID id; Context context; TaskState state; Priority priority; int * pstack; Task * pnext; void (*entrypoint)(); private: static TaskId nextid; }; 9

Task States enum TaskState { Ready, Running, Waiting }; 10

Task Mechanics How to create a task for OS to run? How to use tasks? How to assign priority? How to assign stack size? etc. 11

Task Constructor 12

Task Constructor 13

Scheduler Decides which ready task gets to execute on the processor Common scheduling algorithms for nonembedded systems: First-In-First-Out (FIFO) Shortest Job First (SJF) Round Robin (RR): preemptive Not suitable for real-time embedded systems requires task priorities 14

Scheduler Priority-based scheduling needs a backup policy required when tasks have equal priorities Mostly, round-robin In ADEOS: FIFO ADEOS supports: 255 tasks, and 255 levels of priorities 15

Scheduler in ADEOS extern Sched os; 16

Scheduling Points Set of operating system events that result in scheduler invocation (os.schedule()) Task Creation (see constructor) Task Deletion Clock Tick (awakes tasks waiting on timers) (Timer class from Chapter 7 Peripherals: disable entercs, enable exitcs, 1 ms 10 ms ) 17

Ready List Fast dispatching Slow insertion 18

Idle Task An infinite loop Lowest priority At the end of ready list When no task is ready for execution, scheduler runs the idle task Other tasks are called user tasks 19

Scheduler 20

Scheduler 21

Scheduler 2 situations when context switch is not done: Multitasking not enabled (state!= Started) to create all tasks first and then start scheduler During interrupt processing (interruptlevel!= 0) to speed up interrupt response time 22

Create all tasks first 23

then, start scheduler! 24

Context Switch Hardware specific, in assembly contextswitch() executed twice! Returns non-zero when going to sleep Returns zero when awaking 25

Context Switch 26

Task Synchronization Tasks are not necessarily independent Tasks must communicate for solving a larger problem To coordinate access to shared data: variables, buffers, device registers, OS must provide one of the following: mutex or semaphore, message queues, monitors 27

Task Synchronization Mutex a multitasking-aware binary flag grants exclusive access to shared data! setting / clearing are ATOMIC! (guaranteed by OS by disabling interrupts) 28

Mutex Class wait for mutex to be cleared and set it clear a previously set mutex list of tasks waiting to take mutex 29

Mutex Constructor 30

Mutex::take() 31

Mutex::take() continued 32

Mutex:: release() 33

Mutex:: release() continued 34

Critical Section Mutexes can be used to access shared data without disabling interrupts Thus, to enter critical sections we do not need to disable interrupts Just use mutexes!!! 35

Dangers of using Mutex: Deadlock 2 Tasks, each of which require two mutexes: A and B Task 1 has mutex A and requires mutex B, Task 2 has mutex B and requires mutex A, Both will wait for each other and a deadlock occurs! System will crawl to a standstill Need reboot! 36

Dangers of using Mutex: Priority Inversion Low priority task is running and holds a shared resource High priority task need that shared resource High priority task waits for low priority task to release resource Middle priority task activates, preempts low priority task, and runs!!! High priority task is waiting for a long time, even forever! Space shuttle sent to Mars was lost like this! 37

38

Priority Inversion t 0 t 1 t 2 t 3 t 4 t 5 t 6 39

Real-Time Characteristics A late answer is as bad as a wrong one! A missed ABS deadline you are in an accident OR you are in a coffin! For an embedded OS to be a RTOS (Real- Time OS), it must satisfy 3 goals: Deterministic Guaranteed Worst-Case Interrupt Latency Guaranteed Worst-Case Context Switch Times 40

1. Deterministic RTOS Worst-case execution time of each system call is calculable RTOS vendor must publish a data sheet providing minimum, average, & maximum #clock cycles required for each system call Different for different processors Deterministic on 1 processor deterministic on any other processor 41

2. Guaranteed Worst-Case Interrupt Latency in an RTOS Interrupt Latency = from interrupt signal arrival to start of ISR Finish executing current instruction Recognize interrupt type Start interrupt (if enabled) If interrupts are disabled, the duration must also be considered in the interrupt latency 42

3. Guaranteed Worst-Case Context Switch Time in an RTOS Important because it is an overhead of entire system Processor-specific Must be published by RTOS vendor 43

Selection Process Buy a commercial RTOS, if you can afford to! Continuum of functionality, performance, and price! Lower end of spectrum: Accelerated Technology s Nucleus Kadak s AMX scheduler + a few system calls 44

Selection Process Higher end of spectrum: more functionalities stronger guarantees about real-time performance costly: $10,000 ~ $50,000 royalties: on every copy shipped in ROM free technical support, training, development tools Wind River Systems VxWorks Integrated Systems psos Microtec s VRTX 45

Selection Process Between these 2 extremes more functionalities than scheduler reasonable guarantees about real-time performance reasonable costs and royalties no source code extra cost for technical support Examples: all other commercial RTOS 46

Selection Process Processor Real-Time Performance Budget Compatibility with cross-compilers debuggers development tools Main Selection Criteria Differences: processors supported, memory requirements, add-on software modules (network protocol stacks, device drivers, Flash filesystems, ) 47