Presentation is loading. Please wait.

Presentation is loading. Please wait.

EEE 243B Applied Computer Programming Timing considerations.

Similar presentations


Presentation on theme: "EEE 243B Applied Computer Programming Timing considerations."— Presentation transcript:

1 EEE 243B Applied Computer Programming Timing considerations

2 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Review What benefits does reuse have? What is the definition of a component?

3 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Outline Normal flow Periodic tasks Cyclic executives Aperiodic tasks Scheduling

4 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Normal flow So far in this course, we have studied programs that are controlled through programming language structures Our programs follow a structure that is dictated through if-else, while,do- while, switch,… statements But is this all there is to controlling the behaviour of programs?

5 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Normal flow Each instruction or set of instruction takes some time to execute; even if it is only microseconds There may be some programs for which we may want to control the elapsed time between various instructions (functions or tasks) This control of time is common among applied programs (robotics, process control, sampling,…)

6 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Normal flow The first time we played God with our robots (and face it, we are Gods to our Bots) is when we delayed their activities We used the sleep() or msleep functions to enlist the help of the brickOS operating system to impose a timeout to our programs

7 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Normal flow So if we do not impose some form of time control, our programs will execute following the control flow logic; in this case, the only time limitation is the execution time of the instructions Most applications that we use from day to day follow this kind of “static” scheduling of tasks where no timing behaviour is specified

8 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Periodic tasks Closely related to static task execution, is the concept of periodic tasks Some systems require some tasks (functions) to execute at given intervals to ensure that the system behaves in a specific manner Most control systems include periodic tasks Periodic tasks are “clockwork” maintenance events

9 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Periodic tasks The period of a task is dictated by control requirements and stability concerns Systems with periodic tasks can be implemented in several ways Some operating systems allow programmers to specify the periodicity of tasks. This spec may be: Actual period that the task will take (run every 10 msecs) Priority of a task is determined by its required frequency (period). A task with high frequency requirement will have a high priority so that it executes often Release time, execution time and deadline

10 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Cyclic executives Perhaps the easiest way to implement periodic tasks is the cyclic executive In the implementation of a cyclic executive, the programmer specifically directs or “hand controls” the timing behaviour of every task At the base of the cyclic executive is a loop with counters (or a set of loops) that execute “tasks” at given frequencies Cyclic executives do not require much support from the operating system; the entire schedule is embedded in the program itself

11 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Cyclic executives Cyclic executives mean that the programmer knows the hardware intimately The programmer must know how long each instruction takes to execute in order to tweak the cycles or loops that contain each tasks Most of the time, the programmer will measure the execution times empirically with tests Delays are used to tweak loop frequencies

12 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage A Cyclic executives ABBCBBCAA Period of A Period of B Period of C Delay/idle time time 0

13 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Cyclic executives … while (1) { //tasks at high frequency each time the loop executes if (!(count%2)) { //tasks at half frequency every second loop //some delay } if (!(count%4)) { //tasks at quarter freq and delay} count++; sleep(x); //idle time that regulates the //highest frequency loop } …

14 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Aperiodic tasks Very few systems operate on a set of “pure” periodic tasks In order to be responsive, most applied systems allow for tasks to occur at unknown times; hence the tasks are aperiodic Aperiodic tasks occur in a spontaneous fashion through a computer’s interrupt facilities The operating system must have a mechanism to handle interrupts

15 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Aperiodic tasks Timing behaviour for aperiodic tasks is, in general, unpredictable, because you cannot know “when” an event will occur: When a temperature will be reached Data comes on a port Robot hits an obstacle…

16 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Aperiodic tasks Aperiodic tasks can, however, be modelled as pseudo periodic tasks In many systems, it is possible to estimate the frequency of aperiodic events When you model aperiodic tasks, you goal is only to see if you will have “enough room” in your schedule so that the system can respond to a maximum number of events

17 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Scheduling Scheduling is a software engineering discipline that deals with several problems: Efficiency: maximises system resources Throughput: execute as many tasks as possible for a given time Fairness: ensure that users on a multi-user system get their fair share of system resources Safety: ensures that all tasks in a real-time system meet their deadlines Response time: ensures that the system is responsive to requests

18 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Scheduling All the programs that we have written so far run in a single task and have a single thread In some systems, it is possible for a program to have several tasks that can execute in parallel These tasks can be full processes or execution threads; where the processor is shared in some fashion (round-robin, priority based, …)

19 Winter 2005Maj JGA Beaulieu & Capt MWP LeSauvage Quiz Time How would you implement a cyclic executive?


Download ppt "EEE 243B Applied Computer Programming Timing considerations."

Similar presentations


Ads by Google