Download presentation
Presentation is loading. Please wait.
1
Laboratory for Perceptual Robotics – Department of Computer Science Embedded Systems Introduction to Real-Time Systems
2
2 Laboratory for Perceptual Robotics – Department of Computer Science Real-Time Systems Definition: Real-time systems are those in which the correctness of the system depends not only on the logical results of the computation but also on the time at which the results are produced. Hard real-time systems: time critical - it is imperative that the system respond within a specified time period. Soft real-time systems: the system will function correctly, although at a lower overall utility if deadline are occasionally missed.
3
3 Laboratory for Perceptual Robotics – Department of Computer Science Real-Time Systems timing constraints: periodic --- once per period T, precisely T units apart aperiodic --- start time, finish time, or both
4
4 Laboratory for Perceptual Robotics – Department of Computer Science Real-Time Programming Concurrent, task-based approach multi-tasking RTOS (VxWorks) scheduling theory industrial state-of-the-art Synchronous approach reactive kernel represented as an automata formal properties special-purpose programming languages - Esterel Discrete-Event Dynamic Systems
5
5 Laboratory for Perceptual Robotics – Department of Computer Science Logical Concurrency A concurrent program can be viewed as a collection of autonomous sequential processes executing (logically) in parallel. Each process has a single thread of control. multiplex on a single processor; multiplex on a multi-processor with shared memory; or multiplex on several processors without share memory (distributed systems)
6
6 Laboratory for Perceptual Robotics – Department of Computer Science Processes A process (task) can be in one of the following process states: Ready: Processes that are ready to execute. Stored in a ReadyQueue (a linked list) Running: The currently executing process (the first process in the ReadyQueue) Blocked: Processes waiting for an event, e.g., an external event (Temp < T min ) The switch from one running process to another is called a context switch The process state consists of: program counter, process status information (priority, enabled interrupts), and the contents of the programmable registers. Process administration is handled by the RT kernel
7
7 Laboratory for Perceptual Robotics – Department of Computer Science Interactive C - Multitasking process - a function with a unique pid, local program stack (256 bytes default) for return addresses, local variables, arguments, etc, and a processor allocation in milliseconds--- processes communicate via global variables process table - a set of processes that are logically concurrent
8
8 Laboratory for Perceptual Robotics – Department of Computer Science HandyBoard Process Control int start_process(function-call(…), [TICKS],[STACK-SIZE]) returns the process id int kill_process(int pid) returns 0 if successfully killed, 1 otherwise (process not found) kill_all() stops all running processes ps processor status void hog_processor() allocates an additional 256 msec to the function currently running-called repeatedly, system will wedge requiring reset void defer() Forces a context shift
9
9 Laboratory for Perceptual Robotics – Department of Computer Science Example: Multitasking void check_sensor(int n) { while(1) printf(“sensor %d is %d\n”, n, digital(n)); } void main() { int pid; pid = start_process(check_sensor(2)); sleep(1.0); kill_process(pid); } starts check_sensor() and then kills it 1 second later Q: how often does check_sensor() actually run?
10
10 Laboratory for Perceptual Robotics – Department of Computer Science Example: Multitasking void check_sensor(int n) { while(1) printf(“sensor %d is %d\n”, n, digital(n)); } void main() { int pid; pid = start_process(check_sensor(2)); sleep(1.0); kill_process(pid); } starts check_sensor() and then kills it 1 second later Q: how often does check_sensor() actually run? A: assuming nothing else is in the process table, this process runs ~continuously in about 200 consecutive 5 msec chunks.
11
11 Laboratory for Perceptual Robotics – Department of Computer Science Scheduling...to ensure that the run-time scheduler dispatches the runnable processes in an order that will result in all deadlines being met… orders the ReadyQueue allocates priorities BOTH STATIC AND DYNAMIC PRIORITY ALLOCATIONS ARE POSSIBLE
12
12 Laboratory for Perceptual Robotics – Department of Computer Science Scheduling Operations Research job shop scheduling and shop-flow problems schedule physical devices and processes - machines, workcells, maintenance, orders, batches, projects mostly (not exclusively) static schedules Computer Science schedule tasks in a uni- or multiprocessor environment mostly (not exclusively) dynamic schedules
13
13 Laboratory for Perceptual Robotics – Department of Computer Science Scheduling-Problem Formulation Events - anything that requires a response in the system---computation, work, communication periodic, aperiodic, sporadic, and stochastic events interrupts Time - execution times for event handling---how much time will it take to handle an event? How much CPU time does a periodic process require? How much time will it take to change a bearing on the milling machine? Deadline upper bound on the time required to service an event Scheduling reflects decisions about which event to process at a given time
14
14 Laboratory for Perceptual Robotics – Department of Computer Science Priority-Based Preemptive Scheduling How should processes be scheduled in order to maximize the utilization of the system while guaranteeing deadlines? priority reflects the severity of the time demands high low 0 255 The ReadyQueue is sorted by priority: A blocked process that becomes ready and has higher priority than the currently running process causes a context shift. This task preempts the running task.
15
15 Laboratory for Perceptual Robotics – Department of Computer Science Priorities and Scheduling Priority Inversion Consider tasks T 1, T 2, and T 3 with corresponding priorities P 1 >P 2 >P 3 (that is, task T 1 has the highest priority). If task T 1 depends on task T 3, it may be suspended in order to wait for a result from T 3. However, a priority-based preemptive scheduler will choose to run task T 2, thus further blocking task T 1 indirectly by way of task T 3 even though P 1 >P 2.
16
16 Laboratory for Perceptual Robotics – Department of Computer Science Priorities and Scheduling Priority Inheritance The priority of a process is the max of its priority and the priorities of all other processes that depend on it. therefore: task T 3 inherits priority P 1 while T 1 is waiting for a T 3 event T 3 will run in preference to T 2. For example, a synchronous communication protocol (rendezvous) requires the sender to wait until contact is established and the receiver is verified before the message is sent. In ADA, the priority of the rendezvous itself is the highest priority of the two participating processes.
17
17 Laboratory for Perceptual Robotics – Department of Computer Science Schedulability Given a single processor, a set of n-independent, periodic processes with only execution time deadlines (no start/stop constraints) are schedulable if the overall processor utilization is less than n(2 1/n -1) For large n this function approaches a utilization of 0.693. This is a very conservative estimate, based on worst-case relationships between the periods of the processes. Liu and Layland (1973)
18
18 Laboratory for Perceptual Robotics – Department of Computer Science Schedulability Given a single processor, a set of n-independent, periodic processes with only execution time deadlines (no start/stop constraints) are schedulable if the overall processor utilization is less than n(2 1/n -1) For large n this function approaches a utilization of 0.693. This is a very conservative estimate, based on worst-case relationships between the periods of the processes. Liu and Layland (1973) non-repeating prime # periods in n processes
19
19 Laboratory for Perceptual Robotics – Department of Computer Science Consider two tasks, T 1 and T 2, with P 1 >P 2 (T 1 is more “important”). T 1 has a period of 50 units of time and requires 10 units of time to run. Task T 2 has a period of 10 units of time and requires 2 units of time to run. Under a priority-based preemptive schedule, T 1 will execute first and when it completes, T 2 will have already missed its first deadline! The problem is related to the use of “preference” priorities. Schedulability
20
20 Laboratory for Perceptual Robotics – Department of Computer Science Consider two tasks, T 1 and T 2, with P 1 >P 2 (T 1 is more “important”). T 1 has a period of 50 units of time and requires 10 units of time to run. Task T 2 has a period of 10 units of time and requires 2 units of time to run. Under a priority-based preemptive schedule, T 1 will execute first and when it completes, T 2 will have already missed its first deadline! The problem is related to the use of “preference” priorities. Schedulability schedulability n(2 1/n -1) 2(2 1/n -1) = 0.818
21
21 Laboratory for Perceptual Robotics – Department of Computer Science Consider two tasks, T 1 and T 2, with P 1 >P 2 (T 1 is more “important”). T 1 has a period of 50 units of time and requires 10 units of time to run. Task T 2 has a period of 10 units of time and requires 2 units of time to run. Under a priority-based preemptive schedule, T 1 will execute first and when it completes, T 2 will have already missed its first deadline! The problem is related to the use of “preference” priorities. Schedulability schedulability n(2 1/n -1) 2(2 1/n -1) = 0.818 utilization P1 P2 10 + (5x2) 50 =40%
22
22 Laboratory for Perceptual Robotics – Department of Computer Science Consider two tasks, T 1 and T 2, with P 1 >P 2 (T 1 is more “important”). T 1 has a period of 50 units of time and requires 10 units of time to run. Task T 2 has a period of 10 units of time and requires 2 units of time to run. Schedulability schedulability n(2 1/n -1) 2(2 1/n -1) = 0.818 utilization P1 P2 10 + (5x2) 50 =40% Threshold utilization for worst case schedulability 0.818 > 0.40 actual utilization …so we know it’s schedulable…
23
23 Laboratory for Perceptual Robotics – Department of Computer Science Rate Monotonic Scheduling Assign fixed priorities inversely proportional to the period for the tasks P i ~ , so that the shorter the period, the higher the priority. optimal static schedule for independent periodic processes: if a process can be scheduled by any static scheduling algorithm, then it can also be scheduled by the rate monotonic algorithm.
24
24 Laboratory for Perceptual Robotics – Department of Computer Science Extensions to Rate Monotonic Scheduling Soft RT Systems - if all deadlines cannot be met, the most “important” processes must be run first. If the ReadyQueue is schedulable, then the process with the shortest period should be first. “Specification Aliases” - transforming specifications for the most important tasks. If T 1 ( =50, and execution time=10) were respecified e.g., T 1 '( =5, and execution time=1), then relative preference is consistent with its rate-based priority. …the details are non-trivial… Periodic Servers - incorporate aperiodic, interupts, and important soft-deadline tasks into the rate monotonic schedule. reserve time in the periodic server to handle worst-case arrival rates global schedule---even for tasks with random arrival rates! at the expense of utilization
25
25 Laboratory for Perceptual Robotics – Department of Computer Science Other Scheduling Algorithms Earliest Deadline - need to know about deadlines Least Slack Time - need deadlines and complete times when deadlines can be met, ED and LST are equivalent to Rate Monotonic
26
26 Laboratory for Perceptual Robotics – Department of Computer Science Other Scheduling Algorithms Earliest Deadline --- need to know about deadlines Least Slack Time --- needs deadlines and the amount of execution time needed to complete......scheduler allocates resources to the task with the least “free time” When all deadlines can be met, Earliest Deadline and Least Slack Time are equivalent to Rate Monotonic --- every periodic task load schedulable by one is schedulable by all. These alternatives are designed to do the best they can with instantaneous and aperiodic task loads.
27
27 Laboratory for Perceptual Robotics – Department of Computer Science Periodic Tasks Revisited A feedback control process is the canonical periodic task with a fixed period---the sampling rate. between sampling intervals, the system is ballistic
28
28 Laboratory for Perceptual Robotics – Department of Computer Science Periodic Tasks Revisited in practice, the control delay is not constant--- variations are due to: preemptions from higher priority tasks variation in the execution times (branching, data dependencies) communication delays in distributed controllers jitter can result from: preemptions from higher priority tasks improper useage of timing primitives in the RT kernel
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.