Slide 1Cyclic Executive Design 1 (pages 81-87)Cyclic executiveRT Cyclic Executive ProgramTask Specification to Cyclic ExecutiveImplementation of a cyclic executiveImplementation (contd.)Implementation (contd.)Implementation (contd.)SummaryImplementation of Cyclic Executive B. RamamurthyCyclic Executive Design 1 (pages 81-87)•Base tasks, clock tasks, interrupt tasks•Base: no strict requirements, background activity•Clock: periodic with fixed runtime•Interrupt: event-driven preemption, rapid response but little processing•Design the slots•Table-driven cyclic executive01/13/2019CE321-fa ll20142Cyclic executive•Each task implemented as a function•All tasks see global data and share them•Cyclic executive for three priority level•The execution sequence of tasks within a cyclic executive will NOT vary in any unpredictable manner (such as in a regular fully featured Operating Systems)•Clock tasks, clock sched, base tasks, base sched, interrupt tasks •Each clock slot executes, clock tasks, at the end a burn task that is usually the base task•Study the figures in pages 83-86 of your text01/13/2019CE321-fa ll20143RT Cyclic Executive Program•Lets examine the code:•Identify the tasks•Identify the cyclic schedule specified in the form of a table•Observe how the functions are specified as table entry•Understand the scheduler is built-in•Learn how the function in the table are dispatched01/13/2019CE321-fa ll20144Task Specification to Cyclic ExecutiveTransform into hyperperiod, frame, slotsDesign the cyclic executiveThen cyclic executive can be implemented by a table-drivenOr function-driven (simply a series of function calls).We will look at a table-driven implementation.Implementation of a cyclic executive#include <stdio.h>#include <ctype.h>#include <unistd.h>#include <sys/times.h>#define SLOTX 4#define CYCLEX 5#define SLOT_T 5000int tps,cycle=0,slot=0;clock_t now, then;struct tms n;void one() { printf("Task 1 running\n"); sleep(1);}void two() { printf("Task 2 running\n"); sleep(1); }01/13/2019CE321-fa ll20146Implementation (contd.)void three() { printf("Task 3 running\n"); sleep(1);}void four() { printf("Task 4 running\n"); sleep(1);}void five() { printf("Task 5 running\n"); sleep(1);}01/13/2019CE321-fa ll20147Implementation (contd.)void burn() { clock_t bstart = times(&n); while ((( now = times(&n)) - then) < SLOT_T * tps / 1000) { } printf (" brn time = %2.2dms\n\n", (times(&n)-bstart)*1000/tps); then = now; cycle = CYCLEX;}01/13/2019CE321-fa ll20148Implementation (contd.)void (*ttable[SLOTX][CYCLEX])() = {{one, two, burn, burn, burn},{one, three, four, burn, burn},{one, two, burn, burn, burn},{one, five, four, burn, burn}};main() { tps = sysconf(_SC_CLK_TCK); printf("clock ticks/sec = %d\n\n", tps); then = times(&n); while (1) { for (slot=0; slot <SLOTX; slot++) for (cycle=0; cycle<CYCLEX; cycle++) (*ttable[slot][cycle])(); }}01/13/2019CE321-fa ll20149Summary•The cyclic executive discussed the scheduler is built-in. You can also use clock ticks RTC etc to schedule the tasks•In order use the cyclic executive discussed here in other applications simply change table configuration, and rewrite the dummy functions we used.01/13/2019CE321-fa
View Full Document