cyclic scheduling

21

Upload: israel

Post on 17-Jan-2016

93 views

Category:

Documents


0 download

DESCRIPTION

Cyclic Scheduling. Advantages Simple implementation (no real-time operating system is required). Low run-time overhead. It allows jitter control. Disadvantages It is not robust during overloads. It is difficult to expand the schedule. It is not easy to handle non periodic activities. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Cyclic Scheduling
Page 2: Cyclic Scheduling

Cyclic Scheduling

– Advantages• Simple implementation (no real-time

operating system is required).• Low run-time overhead.• It allows jitter control.

– Disadvantages• It is not robust during overloads.• It is difficult to expand the schedule. • It is not easy to handle non periodic

activities.

Page 3: Cyclic Scheduling

Other Schedule Algorithms

– Priority Scheduling• Each task is assigned a priority based on its

timing constraints • We verify the feasibility of the schedule

using analytical techniques • Tasks are executed on a priority-based

kernel

– Example: Rate Monotonic (RM)• Each task is assigned a fixed priority

proportional to its rate

Page 4: Cyclic Scheduling

Real Time and Linux

• Linux is a standard time-sharing operating system– Good average performance and highly

sophisticated services– Hardware management layer dealing

with event polling or processor/peripheral interrupts

– Scheduler classes dealing with process activation, priorities, time slice

– Communications between applications.

Page 5: Cyclic Scheduling

Real Time and Linux

• Linux suffers from a lack of real time support

• Changes in the kernel sources, i.e. in the interrupt handling and scheduling policies

• Real time platform, with low latency and high predictability requirements– Full non real time Linux environment (access

to TCP/IP, graphical display and windowing systems, file and data base systems, etc.).

Page 6: Cyclic Scheduling

Timers PC’s

– Specific chip to solve the problem of generating accurate time delays under software control.

– 8254• Programmable interval timer/counter• 4 I/O ports in the system software• Three are independent 16-bit, one is a control

register• We configures the 8254 to match requirements

(select the mode) and program one of the counters for the desired delay.

• After the delay, the 8254 will interrupt the CPU.

Page 7: Cyclic Scheduling

Real Time in Linux, RTAI

• Use low cost general purpose computers and open-free source operating systems

• RTAI means Real Time Application Interface. – Not a real time operating system – Based on the Linux kernel.

• RTAI expands Linux to hard real time

Page 8: Cyclic Scheduling

Real Time in Linux, RTAI

• A patch to the Linux kernel which introduces a hardware abstraction layer

• A broad variety of services which make real-time programmers' life easier

• RTAI offers the same services of the Linux kernel core, adding the features of an industrial real time operating system.

Page 9: Cyclic Scheduling

Real Time in Linux, RTAI

• Is an interrupt dispatcher• RTAI traps the peripherals interrupts and if

necessary re-routes them to Linux• It uses the concept of HAL (hardware

abstraction layer) to get information from Linux and to trap some fundamental functions.

• HAL provides few dependencies to Linux Kernel.

• RTAI considers Linux as a background task running when no real time activity occurs.

Page 10: Cyclic Scheduling

RT Computer Systems RTAI

– Basic task management• time management and conversions• dynamic priority assignment• scheduler policy assignment• scheduling locking/unlocking• counting suspend/resume to avoid trivial

deadlocks

– Memory Management• shared memory for inter tasks• inter-intra user/kernel space data• sharing, dynamic memory allocations

Page 11: Cyclic Scheduling

RT Computer Systems RTAI

– Semaphores• Wait• Send• broadcast on

– counting, binary and resources with full priority

• inheritance to avoid priority inversion.

Page 12: Cyclic Scheduling

RT Computer Systems RTAI

– Conditional variables• wait, signal, broadcast, equivalent to the

related POSIX APIs, but with an RTAI specific implementation.

– Bits synchronization• Multi events/flags/signals synchronization,

i.e. semaphore like operations with different logical masking/unmasking on a set of bits at call and return time.

Page 13: Cyclic Scheduling

RT Computer Systems RTAI

– Mailboxes• send, receive of messages with multi

readers/writers capability• messages queued in either FIFO or priority

order. It is possible to use overwriting and urgent sends, broadcast a single message to all task waiting to receive on a mailbox queue, preview any message before reading it.

Page 14: Cyclic Scheduling

RT Computer Systems RTAI

– Direct Inter-task Messages• Asynchronous: send, receive• Synchronous remote procedures calls

(RPC)– rpc, receive, return.

Page 15: Cyclic Scheduling

RTAI Modules

– To use RTAI, you have to load the modules that implement whatever RTAI capabilities you need.

– Modules: • Rtai, Main module.• rtai_sched. scheduler module, which is in charge of

distributing the CPU to different tasks– Task functions – Timing functions– Semaphore functions – Mailbox functions – Inter-task communication functions

• rtai_fifos.

Page 16: Cyclic Scheduling

RTAI Modules

– Modules• rtai_shm• Lxrt• rtai_pqueue• rtai_pthread• rtai_utils

Page 17: Cyclic Scheduling

RTAI Examples

The program simply generates a sine signal and displays the instant values on the screen.

-------------- RT_PROCESS.C -------------------\#include <linux/module.h>\#include <asm/io.h>\#include <math.h>\#include <rtai.h>\#include <rtai_sched.h>\#include <rtai_fifos.h>

\#define TICK_PERIOD 1000000\#define TASK_PRIORITY 1\#define STACK_SIZE 10000\#define FIFO 0

Page 18: Cyclic Scheduling

RTAI Examples

static RT_TASK rt_task; static void fun(int t){    int counter = 0;    float sin_value;        while (1) {        sin_value = sin(2*M_PI*1*rt_get_cpu_time_ns()/1E9);        rtf_put(FIFO, &counter, sizeof(counter));        rtf_put(FIFO, &sin_value, sizeof(sin_value));        counter++;        rt_task_wait_period();    }}

Page 19: Cyclic Scheduling

RTAI Examples

int init_module(void){    RTIME tick_period;    rt_set_periodic_mode();    rt_task_init(&rt_task, fun, 1, STACK_SIZE, TASK_PRIORITY, 1, 0);    rtf_create(FIFO, 8000);    tick_period = start_rt_timer(nano2count(TICK_PERIOD));    rt_task_make_periodic(&rt_task, rt_get_time() + tick_period,       tick_period);    return 0;}

Page 20: Cyclic Scheduling

RTAI Examples

void cleanup_module(void){    stop_rt_timer();    rtf_destroy(FIFO);    rt_task_delete(&rt_task);    return;}

Page 21: Cyclic Scheduling

RTAI Examples

Scope: int main (void){    int fifo, counter;    float sin_value;    if ((fifo = open("/dev/rtf0", O_RDONLY)) < 0) {        fprintf(stderr, "Error opening /dev/rtf0\n");        exit(1);    }    signal(SIGINT, endme);    while (!end) {        read(fifo, &counter, sizeof(counter));        read(fifo, &sin_value, sizeof(sin_value));        printf(" Counter : %d Seno : %f \n", counter, sin_value);    }    return 0;}