Transcript
  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    1/22

    Real-Time and EmbeddedSystems

    Nam Ho

    Dr. Anh-Vu Dinh-Duc

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    2/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 2

    Module Outline

    Introduction to Real-Time Systems

    Real-Time Task Scheduling

    Real-Time Operating Systems (RTOS)

    Measuring Execution Time and Real-TimePerformance

    Development of Embedded Systems Our Research Results in Embedded

    Systems

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    3/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 3

    What is a Real-Time

    Operating Systems (RTOS)?

    OS provides Task management (scheduling, communication, synchronization) Hardware abstract (device drivers) Resource allocation (memory management)

    Time control Error control

    RTOS Provides some basic functionalities like regular OS But, involves real-time task scheduling The need for "deterministic" timing behavior A ideal platform for developing applications that require precise

    timing (time bonded) Allows the designer to manage both soft and/or hard real time

    requirements

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    4/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 4

    Components in RTOS

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    5/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 5

    RTOS supports Multitasking

    CodeData

    Stack

    Heap

    Shared Data

    Shared Code

    TASK1s

    Segments

    FLASH

    SRAM

    kernelCodeData

    Stack

    Heap

    Shared Data

    Shared Code

    TASK2s

    Segments

    kernel

    system call

    Memory Map

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    6/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 6

    RTOS supports Multitasking

    Task uses Task ControlBlock (TCB) to remember itscontext Task ID Task Name Status Priority (if part of a preemptive

    scheduling plan)

    Task Stack

    Task Program Counter

    RTOS updates TCB whentask is switched

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    7/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 7

    RTOS supports MultitaskingStack

    status

    pc

    sp

    priority

    TCBTask_Rountine()

    {

    while(1)

    {

    ..

    }

    }

    sp

    pc

    CPU register

    Context

    Stack

    status

    pc

    sp

    priority

    TCBTask_Rountine()

    {

    while(1)

    {

    ..

    }

    }

    Memory

    CPU

    TASK 1 TASK n

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    8/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 8

    Task Context Switch

    ( 2. )max min . / 1,1{1 } { }

    where S { . | 1, ..., ; 1, ..., / }i

    The entire task set is feasible by RMS if and only if

    ejiL t pjji n t Si t

    k p j i k p pj i j

    Affect the schedulability test

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    9/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 9

    Non preemptive RTOS

    Higher prioritytasks only gaincontrol of the CPUwhen the currenttasks gives upcontrol of the CPU

    Most importantdrawback is lowresponsiveness

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    10/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 10

    Preemptive RTOS

    Used when systemresponsiveness isimportant

    The highest priority taskready to run is alwaysgiven control of theCPU. The lower prioritytask is suspended

    Most commercial real-time kernels arepreemptive

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    11/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 11

    Task State Clock-Driven

    Based

    k Task(T(tk))

    Start time(tk)

    0 T1 1

    1 T2 2

    2 T1 4

    3 I 5

    4 T2 6

    5 T1 7

    6 T2 8

    9 I 9

    10 T1 10

    11 T2 11

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    12/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 12

    Task State Event-Driven

    Based

    Blocked state: The task is waiting for an event to occur. A semaphore/mutex token for which a task is waiting is released An Arriving message from message queue A time delay imposed on the task expires

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    13/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 13

    Scheduler Implementation Table-driven scheduler

    Input: stored schedule (tk, T(tk)) for k= 0, 1, n 1.Task SCHEDULER:

    set the next scheduling point i= 0 and table entry k= 0;set the timer to expire at tk;do forever:

    accept timer interrupt;if an aperiodic task is executing, preempt the task;current task T= T(tk);increment iby 1;compute the next table entry k= imod n;set the timer to expire at [i/n] * M + tk;if the current task Tis I,

    let the task at the head of the aperiodic queueexecute;

    elselet the task Texecute;

    sleep;end do.

    End SCHEDULER.

    k Task(T(tk))

    Start time(tk)

    0 T1 1

    1 T2 2

    2 T1 4

    3 I 5

    4 T2 6

    5 T1 7

    6 T2 8

    9 I 9

    10 T1 10

    11 T2 11

    pre-computed schedule

    IdleTimer

    interrupt

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    14/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 14

    Scheduler Implementation

    Cyclic Scheduler ?

    The concept implementation is the same

    as table-driven schedulers

    Priority-Based Scheduler ?

    Complex

    Using several queues or link lists in eachof task states

    Case study: cOS-II

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    15/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 15

    Scheduler Implementation

    Priority Scheduler

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    16/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 16

    Inter-Task Communication and

    Synchronization

    Semaphore Controls access to a

    shared resource

    Signal the occurrence ofan event

    Allows two tasks tosynchronize their

    activities Mutex

    Event

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    17/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 17

    Inter-Task Communication and

    Synchronization

    Message Queue A message queue is

    used to send one or

    more messages to atask

    Reader getsmessage in FIFO or

    LIFO order Mailbox

    Pipe

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    18/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 18

    Interrupt Timing Issues

    Interrupt An interrupt is a hardware mechanism used to inform the

    CPU that an asynchronous event has occurred. ISR involve in disabling interruptsand enabling interrupts.

    In a real-time environment, interrupts should be disabledas little as possible

    Interrupt Latency Maximum amount of time interrupts are disabled + time to

    start executing the first instruction in the ISR

    Lower latency is desired Interrupt Response Interrupt Recovery ISR Processing Time

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    19/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 19

    Interrupt Timing Issues

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    20/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 20

    Timer Services

    In developing real-time applications, clearly it is desirable to havefacilities to set and get the time

    Time services are among some of the basic facilities provided toprogrammers by every RTOS

    Embedded processors are usually equipped with a timer circuit (on-chip timer)

    RTOS maintains a number of ticks or system clocks based on theinterrupt received from hardware timers

    The finer the resolution of the clock, the more frequent need to be thetime service interrupts and larger is the amount of processor time thekernel spends in responding to these interrupts (low performance)

    Timer services supported by cOS-II OSTimeDly() OSTimeDlyHMSM() OSTimeDlyResume() OSTimeGet() OSTimeSet()

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    21/22

    8/20/2010 Embedded Systems Course: Real-Time Operating Systems - 2010 21

    Requirement for a good RTOS

    Short Interrupt Latency

    Fast Context Switch

    Proper scheduling Fine granularity Timer Services

    Rich set of Inter-Task Communication

    Mechanism Small size (Footprint)

  • 8/8/2019 RealTimeAndEmbeddedSystems_Part3 mathhoang vietnam_hoangminhnguyen

    22/22


Top Related