56
© Prof. Dr. rer. nat. F. J. Rammig, Heinz Nixdorf Institute, University of Paderborn Slide 1 Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin <[email protected]>

Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

  • Upload
    lynga

  • View
    220

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 1

Introduction to Real-time Operating Systems

An Introduction to ORCOS Daniel Baldin <[email protected]>

Page 2: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 2

ORCOS Organic Re-Configurable Operating System

Source: RAMMIG, 2009

§  ORCOS is a Real-Time Operating System developed by our Workgroup (2008) https://orcos.cs.uni-paderborn.de/

§  Current Operating Systems -  Try to meet the requirements by reducing their size -> Reduction in functionality

§  ORCOS Vision -  Distributed operating system service over many nodes -  Full OS functionality with small scale nodes -  Use biologically inspired algorithms for communication

§  Development Goal -  Develop a new real-time capable, configurable basic operating system with small footprint -  Capability to transparently use services of other ORCOS nodes -  Mainly used for research projects and student education

Page 3: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 3

ORCOS vs. General Purpose OS

§  ORCOS has been designed for use in embedded devices only! §  No rich user runtime environment support! §  No GUI, no interactive Bash Shell, no runtime tools (compiler a.s.o). Just pure OS interface! §  All Tasks + Kernel are loaded onto the device at once!

§  But: reduced functionality leads to smaller footprint and faster execution times! §  Both are very important features for highly embedded systems.

Page 4: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 4

ORCOS Organic Re-Configurable Operating System

Source: RAMMIG, 2009

Commu-nication

RT and Interrupts

HAL

Synchro-nization

Tasks /RT- Scheduling

User API

ORCOS Configuration Base

Architecture

Page 5: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 5

ORCOS Design Approach

§  ORCOS is a completely Object Oriented Operating System §  Most functionality written in C++ §  Hardware relevant parts in Assembler or C

§  Object Oriented Structure allows the System to be designed in a natural fashion §  Interfaces and Inheritance allow easy adaptation of the system §  E.g. Schedulers implement „Scheduler“ Interface and operate on „Schedulable“ Items §  Storable Items inherit the „DatebaseItem“ Class

§  ORCOS needs NO external libraries! All functions are implemented in a smaller and faster way inside the ORCOS build tree

Page 6: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 6

Class Inheritance Overview

Page 7: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 7

ORCOS Architecture

Hardware

Memory Management Transparent Communication

Migration Scheduling Character / Comm Block

Device Drivers

System Call Manager

Basic File System

Service User Space

Kernel Space

Task Task

Interrupts

System Calls

Page 8: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 8

Configuration Operating System Components

Page 9: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 9

ORCOS Configuration System

Application Programmer

Implementation

file

*.cc

SCLConfig.xml

SCL Tool: verify

SCLConfig.hh

Preprocessor : replace Symbols

generate

Compiler

Skeleton Customization Language (SCL)

-  XML based Configuration of the Operating System Members

-  Verification and Validation by XML Schema File to ensure correctness of selected Configuration Members

-  Configuration on Source Code Level by Preprocessor Macros

Page 10: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 10

Skeleton Customization Language 2.0

Example: Changing the Scheduler to a Real-Time Scheduler

<Skeleton> <Name>SingleCPUDispatcher</Name> <Member> <Name>Scheduler</Name> <Class>scheduler/RateMonotonicThreadScheduler</Class> </Member> </Skeleton>

<Skeleton> <Name>SingleCPUDispatcher</Name> <Member> <Name>Scheduler</Name> <Class>scheduler/RoundRobinThreadScheduler</Class> </Member> </Skeleton>

Page 11: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 11

Skeleton Customization Language 2.0

<!-- ************************************ Skeleton Board ************************************ --> <Skeleton> <Name>Board</Name> <Superclass>arch/PPC40x/RAPTOR/RaptorBoard</Superclass> <Member> <Name>Timer</Name> <Class>arch/PPC40x/PPC405ProgrammableIntervalTimer</Class> <None>false</None> </Member> <Member> <Name>Clock</Name> <Class>arch/PPC40x/PPC405Clock</Class> <Device>"clock"</Device> </Member> <Member> <Name>Watchdog</Name> <Class>arch/PPC40x/PPC405Watchdog</Class> <Device>"watchdog"</Device> <None>false</None> </Member> <Member> <Name>UART</Name> <Class>arch/PPC40x/RAPTOR/OPB_UART_Lite</Class> <Device>"serial0"</Device> <Address>0x90210000</Address> <Length>(unint4)16</Length> <None>false</None> </Member>

Page 12: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 12

Skeleton Customization Language

<Skeleton> <Name>SingleCPUDispatcher</Name> <Member> <Name>Scheduler</Name> <Classes> <Class>scheduler/RoundRobinThreadScheduler</Class> <Class>scheduler/PriorityThreadScheduler</Class> <Class>scheduler/RateMonotonicThreadScheduler</Class> <Class>scheduler/EarliestDeadlineFirstThreadScheduler</Class> <Class>scheduler/EarliestDeadlineFirstThreadScheduler_TBS</Class> </Classes> </Member> </Skeleton>

§  SCLDependency.xml file allows the specification of valid classes for each Skeleton §  SCL Tool automatically checks the correctness of the configuration §  XML Schema File ensures the correctness of the SCL Configuration XML file

Page 13: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 13

Skeleton Customization Language 2.0

Page 14: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 14

ORCOS Organic Re-Configurable Operating System

Commu-nication

RT and Interrupts

HAL

Synchro-nisation

Tasks /RT- Scheduling

User API

ORCOS Configuration Base

Architecture

Page 15: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 15

ORCOS HAL

The Hardware Abstraction Layer (HAL) of ORCOS defines a clean interface for hardware dependent implementations: •  Hardware Time (most important and mandatory for Real-Time operation) •  Hardware Clock (mandatory but can be simulated) •  Hardware Address Translation Layer (HAT) •  Device Driver embedded into a basic file system (e.g. „/dev/comm/serial0“ or „/dev/led0“) •  Interrupt Handler are directly implemented in Assembler and C

Page 16: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 16

Hardware Abstraction Layer

Board

Kernel

Timer Interrupt Handler Watchdog Device Drivers

§  ORCOS Kernel uses only abstractions of hardware §  Generic Device Driver Architecture

§  ORCOS is easy to port to other architectures

-  Main parts are hardware independent

Page 17: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 17

HAL Layer

Page 18: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 18

Architecture Dependent Implementations

§  ARM v4

§  Sparc

§  PPC405

Page 19: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 19

ORCOS Organic Re-Configurable Operating System

Commu-nication

RT and Interrupts

HAL

Synchro-nisation

Tasks /RT- Scheduling

User API

ORCOS Configuration Base

Architecture

Page 20: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 20

Execution Spaces

§  ORCOS distinguishes strictly between user and kernel space §  Threads need to call the kernel by System Calls to perform specific functions

§  System Calls for: §  Access to Hardware Devices §  Communication §  Synchronisation §  Memory Management §  Scheduling related features

§  System Call Features: §  Very fast System Call execution as this

can become a bottle neck §  Safe System Calls (no stack sniffing or other attack possibilites)

Page 21: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 21

ORCOS API

§  ORCOS System Call user Library headers in „lib/orcos.hh“

§  Provides all nessecary operations for embedded applications to run §  The ORCOS API is not POSIX conform! However it is very similiar to it! §  There is a POSIX intermediate Wrapper Layer (not part of the open source

available version)

§  Example: Memory related system calls trigger the corresponding MemoryManager operation:

void* operator new( size_t s ); extern "C"void* malloc(size_t s); extern "C"void free(void *s); void operator delete( void* ptr );

Page 22: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 22

ORCOS API Overview int task_stop (int taskid)

Stop the specified task. It could be resumed later on.

int task_resume (int taskid)

resumes the specified task. Resumes execution of a task that is currently not running.

void sleep (int ms)

Sleep method. The calling thread will be blocked for at least 'ms' milliseconds.

int thread_create (int *threadid, thread_attr_t *attr, void *(*start_routine)(void *), void *arg) Create a new thread.

int thread_run (int threadid)

Start the execution of the thread with id 'threadid'.

int thread_self ()

Returns the id of the currently running thread.

void thread_yield ()

Voluntarily yield the cpu to some other thread (if any).

void thread_exit () Terminates the currently executing thread.

Page 23: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 23

ORCOS Organic Re-Configurable Operating System

Source: RAMMIG, 2009

Commu-nication

RT and Interrupts

HAL

Synchro-nisation

Tasks /RT- Scheduling

User API

ORCOS Configuration Base

Architecture

Page 24: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 24

ORCOS Tasks

§  ORCOS Real-Time entities are multi-thread capable tasks §  Different to other Real-Time Systems as e.g. RTAI

§  ORCOS Threads always run in user mode

§  Tasks are defined statically and initialized by the System at Boot Time §  The initial execution entity (Thread) inside a Task is specified by the user at build

time (e.g. Type and Scheduling Parameters) §  Upon BootUp each task is created and the initial thread is created

§  Task Heap, Memory Manager and Thread Stack are created §  Virtual Memory Address Space is initialized

§  Threads can be created at Run-Time

§  Tasks can not be created at Run-Time (only exception is the addition of a migrated task by the MigrationManager)

Page 25: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 25

Task Configuration

Page 26: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 26

Task Control Block

struct RTThreadAttrs { unint4 initialPriority; unint4 phase; unint4 period; unint4 deadline; unint4 executionTime; };

SECTIONS { . = TASK_START; .text TASK_VMA : AT(TASK_START) { LONG(TASK_START); LONG(task_main); LONG(TASK_HEAP); LONG(TASK_END); LONG(TASK_DATA_END); LONG(thread_exit); LONG(INITIAL_PRIORITY); LONG(PHASE); LONG(PERIOD); LONG(DEADLINE); LONG(EXECUTIONTIME); static.o(.text) *(.text) }

typedef struct { long task_start_addr; long task_entry_addr; long task_heap_start; long task_heap_end; long task_data_end; long task_thread_exit_addr; } taskTable;

Part of the Linker Script for an ORCOS Task

Page 27: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 27

§  Same memory layout for every task -  Position and Heap size defined by linker (configured by SCLConfig)

Interrupt Handler

OS .text

Task1

Task2

OS heap

+ stacks

36 KB

3,5 KB

6 KB

> 2 KB

tasktable

.text

memManager Task2

stack thread 1

objects

stack thread 2

2,5 KB

> 1,4 KB

> 1,4 KB

heap

(Example)‏

ORCOS Memory Layout

maintains

Page 28: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 28

ORCOS Process States

§  Dispatcher works on two Queues: §  Ready Queue §  Sleep Queue

§  Scheduler updates the queues according to the scheduler rule

§  ORCOS does not distinguish

between sleeping (sleep(ms)) Threads and Threads waiting for the next Period (this has implementation reasons)

Page 29: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 29

Writing a periodic Task

#include <orcos.hh> extern "C" int thread_main(int instance) {

// Execution Instance starts here

int led_id = fopen("dev/led0"); fputc(instance, led_id); fclose(led_id); // reaching this point results in calling thread_exit() // Execution Instance ends here

}

ORCOS automatically passes the instance number to the application by the instance function parameter

ORCOS periodic task execution is different to other systems like RTAI: RTAI example: while (true) { … waitForPeriod(); } ORCOS:

Page 30: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 30

Periodic Task Execution

thread_main(instance)

thread_main(++instance)

Page 31: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 31

Creating a new Thread at runtime

#include <orcos.hh> void* thread_entry(void* arg) { } extern "C" int thread_main(int instance) {

thread_attr_t attr; attr.deadline = 400000; // deadline in µs attr.period = 400000 ; // period in µs attr.executionTime = 166444; // execution time in µs if known attr.phase = 0; // phase in µs attr.stack_size = 2048; // the stack size for this thread int id; thread_create(&id,&attr,&thread_entry,0); thread_run(id);

}

Creating a new thread is done by using the thread_create system call:

int thread_create (int *threadid, thread_attr_t *attr, void *(*start_routine)(void *), void *arg)

Page 32: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 32

Scheduling

§  ORCOS supports multiple Scheduler Algorithms

§  Implementing a new Scheduler possible by implementing the getNext() and getNextTimerEvent() Methods.

§  ORCOS does not support online schedulability analysis! Thus schedulabilty must be guaranteed by the system designer!

§  ORCOS only announces missded deadlines!

Page 33: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 33

Scheduling

Page 34: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 34

Context Switching Times

ORCOS has a very small Context Switching Overhead. Example Measurements for the PPC405 @ 200MHZ Approx. Cycles to Instructions Ratio : 3 / 1

#Cycles cs

2755 9,183 µSec

622 2,073 µSec

622 2,073 µSec

622 2,073 µSec

Table 1: Context switching times with instruction cache and data cache enabled (32 KB caches each) #Cycles cs

5749 19,08 µSec

4816 16,05 µSec

4908 16,36 µSec

Table 4: Context switching times with instruction cache and data cache enabled (32 KB caches each) using the worst case scenario

Page 35: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 35

ORCOS Organic Re-Configurable Operating System

Source: RAMMIG, 2009 Source: RAMMIG, 2009

Commu-nication

RT and Interrupts

HAL

Synchro-nisation

Tasks /RT- Scheduling

User API

ORCOS Configuration Base

Architecture

Page 36: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 36

Communication

§  ORCOS uses the lwIP TCP/IP Stack §  Supports:

§  TCP §  IPv4 (ICMPv4, ARP) §  IPv6 §  Currently only usable over Ethernet Devices

§  Serial Communication must be done by the Application Level §  e.g.: directly writing to and reading from a serial device

§  Shared Memory Communication §  No protocol provided here. Applications must implement their own protocol! §  ORCOS only provides the memory mapping features!

Page 37: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 37

TCP/IP Example

// first get some buffer the socket can work on (storing messages and so on) char* mysocketbuffer = (char*) malloc(500); // create a socket using the buffer created above int mysock = socket(0x800,SOCK_STREAM,6,mysocketbuffer,500); // bind our socket to some address sockaddr* addr = (sockaddr*) malloc(sizeof(sockaddr)); addr->port_data = 4000; //< our port addr->sa_data = IP4_ADDR(192,168,2,1); //< our address bind(mysock,addr); addr->port_data = 4001; //< destination port addr->sa_data = IP4_ADDR(192,168,2,2); //< destination address connect(mysock,addr);

Page 38: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 38

Socket Syscall

int mysock = socket(0x800,SOCK_STREAM,6,mysocketbuffer,500);

§  Posix like System Call to create a new socket

Domain (0x800 = IPv4)

Connection oriented or Message oriented

Transportprotocol (6 = TCP)

Pointer to a memory region which can be used to store received messages

Size of the buffer

Page 39: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 39

Commu-nication

RT and Interrupts

HAL

Synchro-nisation

Tasks /RT- Scheduling

User API

ORCOS Configuration Base

Architecture

ORCOS Organic Re-Configurable Operating System

Page 40: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 40

Resources

ORCOS uses two levels of exclusive access control. Kernel Level Synchronisation: - All Objects derived from „Resource“are proteced by Mutexes. - Must be aquired first to use them! - Aquisition can be blocking if configured. User Level Synchronisation: Signals for synchronisation

Page 41: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 41

ORCOS Resource Aquisition

§  As Resources are viewed and accessed as Files (UNIX Style) two methods exist for Resource Synchronisation: §  int fopen (const char *filename) §  int fclose (int fileid)

§  fopen() will call the Resource::aquire() Method which ensures exclusive access to the Resource §  Threads who are denied are blocked, PIP will be used if configured

§  fclose() frees the Resource for other Threads

§  fcreate(const char *filename, const char *path) allows creation of new Resources that may be used as Semaphores.

§  User Level synchronization can be done by using: §  void signal_wait (void *sig, bool memAddrAsSig=false)

§  Blocks the calling thread until signal_signal is called on the same *sig §  void signal_signal (void *sig, bool memAddrAsSig=false)

§  Issues a signal on the *sig object deblocking all threads waiting on it

Page 42: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 42

PIP

Problem: Priority Inversion of blocked Threads Solution: Inherit the priority of the higher priority task! Automatically used for Priority enabled Configurations in ORCOS.

J1

J2

J3

J1 blockiert

Priority Inversion

cirtical section

normal execution

Page 43: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 43

Nested Interrupts

§  ORCOS supports Nested Interrupts §  Reduces the Interrupt Latency for e.g. the Timer Interrupt

Syscall Handler

syscall irq timer irq

Timer Handler

Syscall Handler

Timer Handler

syscall irq timer irq

Page 44: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 44

ORCOS Organic Re-Configurable Operating System

Source: RAMMIG, 2009 Source: RAMMIG, 2009

Commu-nication

RT and Interrupts

HAL

Synchro-nisation

Tasks /RT- Scheduling

User API

ORCOS Configuration Base

Architecture

Page 45: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 45

RT and Interrupts

§  Straight Forward implementation of Interrupt Handlers typically run directly inside the Interrupt Handling Context

§  Problem: Interrupt Handling for e.g. Communication Devices may prolong the execution of Real-Time tasks §  Result: Worst Case Interrupt Handler Execution Time needs to be

calculated into the Execution Time of every Task as Interrupts always have the highest priority!

Example: WCET of Task: 100 ms , Deadline 140ms Device Interrupts: Minimal Inter-Arrival Time: 30 ms, 10 ms Packet Handling

30ms 30ms 30ms 30ms 30ms

150

Interrupt Handler

RT-Task

0 30 60 90 120

Page 46: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 46

Idea: ORCOS uses Workerthreads -  Workerthread activated and scheduled for different jobs:

§  Asynchronous External I/O interrupts §  Timed/Periodic Function Calls §  Allows all kind of Activities to be scheduled

§  Result: Higher Priority Tasks may only be interrupted once for each lower priority interrupt

Activation of

Workerthread

Interrupt- Handling

By Workerthread IO Interrupt

Thread 3

Thread 2

Highest Priority

Lowest Priority

scheduling Workerthread

Thread 1

ORCOS Workerthreads

Page 47: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 47

RT and Interrupts

if (!eth->hasAssignedWorkerThread) { if (theOS->getWorkerTask()->addJob( ExternalDeviceJob, // This is a Device Driver Job 0, // Execution Mode ID (void*) eth, // Pointer to the Device WORKERTHREAD_ETH_PRIORITY_PARAM // Priority /

Deadline )) eth->hasAssignedWorkerThread = true;

}

§  Example Workerthread for a Device Driver Interrupt:

§  Communication Device Driver can just be added to the Workertask as it implements a callable CommDeviceDriver Interface

Page 48: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 48

IRTOS LAB: DigiTrain

IRTOS LAB

An Introduction to the DigiTrain Environment

Page 49: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 49

IRTOS Railway System Architecture

ORCOS Application

ETHLI100

ORCOS

ETH PHY XnTCP

Lenz LI100

User Mode

Kernel Mode

Hardware Level

10 Mbit ETH Phy

XpressNet Serial Bus (62500 baud/s)

Page 50: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 50

RAPTOR 2000

•  Virtex-II Pro FPGA XC2VP20/30 with embedded PowerPC processor

•  128 MB SDRAM •  JTAG Debug Interface •  5x5 LED-matrix

•  Quad Ethernet PHY Module DB-Ethernet

Page 51: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 51

Programming / Debugging Architecture

RS232

USB

Xilinx Interface

JTAG BUS

Linux Host

•  Logging Information can be read over the Serial Console

•  FPGA programming / loading applications done

using the Xilinx Interface

XMD

Serial Console

115200 bit/s

Page 52: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 52

Lenz XpressNet

Source: LENZ ELEKTRONIK GMBH

XpressNet Serial Bus: -  62500 baud/s -  arbitration for each

device (for us 3 devices)

-  every 10th bit is a non-data stop bit

1 Byte 1-15 Bytes 1 Byte Header Data CRC

XpressNet Bus Message:

Page 53: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 53

Railway System

Page 54: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 54

Railway Control System API

API Documentation can be found at: https://orcos.cs.uni-paderborn.de/irtos/html/ ETHLI100 class enables communication with the railway system over the dedicated ethernet line Offers Methods for •  setting the train speed (setTrainSpeed()) •  controlling the switches (setSwitch(), getSwitch()) •  reading block states (getBlockState()) •  a.s.o

Page 55: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 55

Exercises

There will be 4 Lab Sessions for each group. Lab Session will start 2nd week of January! Have a look at the exercises website: http://wwwhni.uni-paderborn.de/eps/lehre/wintersemester-201112/irtos/irtos-exercises/ You will be using ORCOS realtime, communication, scheduling, signalling and resource access features. So read the documentation! Try to solve the exercises at home! Write the program at home and bring them to the Lab Sessions to try out your solution!

Page 56: Introduction to Real-time Operating Systems - Heinz Nixdorf … · 2012-05-31 · Introduction to Real-time Operating Systems An Introduction to ORCOS Daniel Baldin

© P

rof.

Dr.

rer.

nat.

F. J

. Ram

mig

, Hei

nz N

ixdo

rf In

stitu

te, U

nive

rsity

of P

ader

born

Slide 56

Heinz Nixdorf Institute University of Paderborn Design of Distributed Embedded Systems Fuerstenallee 11 33102 Paderborn Phone: +49 5251 606501 Fax.: +49 5251 606502 E-mail: [email protected] www.hni.uni-paderborn.de/en/eps

Thank you for your attention