14.3.1 Units of Concurrency
It is important to encapsulate concurrency within an application into manageable units. A
14.3.2 Pseudo versus True Concurrent Execution
Concurrent tasks in a real-time application can be scheduled to run on a single processor or multiple processors. Single-processor systems can achieve pseudo concurrent execution, in which an application is decomposed into multiple tasks maximizing the use of a single CPU. It is important to note that on a single-CPU system, only one
In contrast, true concurrent execution can be achieved when multiple CPUs are used in the designs of real-time embedded systems. For example, if two CPUs are used in a system, two concurrent tasks can execute in parallel at one time, as shown in Figure 14.3. This parallelism is possible because two program counters (one for each CPU) are used, which allows for two different instructions to execute simultaneously.
Figure 14.3: Pseudo and true concurrent (parallel) execution.
In the case of multiple CPU systems, the underlying RTOS typically is
Unless explicitly stated, this book refers to both pseudo and true parallel execution as concurrent execution for the sake of simplicity.
Following the outside-in approach, certain types of tasks can be identified near the application edge (i.e., where an application needs to create an interface with an I/O device), whereas other tasks can be internal to the application. From the mobile handheld example, if a design team were to further decompose the application, these internal tasks would be identified. Applications, such as calculator or calendar programs, are some examples of internal tasks or groupings of tasks that can exist within the overall handheld mobile application. These internal tasks are decoupled from the I/O devices; they need no device-specific information in order to run
14.3.3 Some Guidelines
Guideline 1: Identify Device Dependencies
· Guideline 1a: Identify Active I/O Devices
· Guideline 1b: Identify Passive I/O Devices
Guideline 2: Identify Event Dependencies
Guideline 3: Identify Time Dependencies
· Guideline 3a: Identify Critical and Urgent Activities
· Guideline 3b: Identify Different Periodic Execution Rates
· Guideline 3c: Identify Temporal Cohesion
Guideline 4: Identify Computationally Bound Activities
Guideline 5: Identify Functional Cohesion
Guideline 6: Identify Tasks that Serve Specific Purposes
Guideline 7: Identify Sequential Cohesion
All real-time systems interface with the physical world through some devices, such as sensors, actuators, keyboards, or displays. An application can have a number of I/O devices interfacing to it. Not all devices, however, act as both input and output devices. Some devices can act just as inputs or just as outputs. Other devices can act as both. The discussions in this book refer to all of these devices as I/O devices.
The outside-in approach focuses on looking at the I/O devices in a system and assigning a task to each device. The basic concept is that unsynchronized devices need separate handling. For simple device interactions, processing within an ISR may suffice; however, for additional device processing, a separate task or set of tasks may be assigned. Both active and passive I/O devices should be considered for identifying potential areas of an application that can be decomposed into concurrent tasks.
As shown in Figure 14.4, hardware I/O devices can be categorized as two types:
· Active I/O devices
· Passive I/O devices
Figure 14.4: Some general properties of active and passive devices.
Active devices generate interrupts whether they are sending input to or receiving output from the CPU. Active input devices send an interrupt to the CPU when the device has new input ready to be processed. The new input can be a large buffer of data, a small unit of data, or even no data at all. An example of the latter is a sensor that generates an interrupt every time it detects some event. On the other hand, an active output device sends an interrupt to the CPU when the device has finished delivering the previous output from the CPU to the physical world. This interrupt announces to the CPU and the application that the output device has completed the last request and is ready to handle the next request.
Passive input or output devices require the application to generate the necessary requests in order to interact with them. Passive input devices produce an input only when the application requests. The application can make these requests either periodically or aperiodically. In the case of the former, the application runs in a periodic loop and makes a request every time through the loop, called
Special care must be taken when polling a passive input device, especially when sampling a signal that has sharp valleys or peaks. If the polling frequency is too low, a chance exists that a valley or peak might be missed. If the polling frequency is too high, extra performance overhead might be incurred that uses unnecessary CPU