CS 530 - Advanced Software Engineering

Real-time Software Engineering

Reference: Sommerville, Software Engineering, 10 ed., Chapter 21

 

The big picture

Computers are used to control a wide range of systems from simple domestic machines, through games controllers, to entire manufacturing plants. Their software must react to events generated by the hardware and, often, issue control signals in response to these events. The software in these systems is embedded in system hardware, often in read-only memory, and usually responds, in real time, to events from the system's environment.

Responsiveness in real-time is the critical difference between embedded systems and other software systems, such as information systems, web-based systems or personal software systems. For non-real-time systems, correctness can be defined by specifying how system inputs map to corresponding outputs that should be produced by the system. In a real-time system, the correctness depends both on the response to an input and the time taken to generate that response. If the system takes too long to respond, then the required response may be ineffective.

A real-time system is a software system where the correct functioning of the system depends on the results produced by the system and the time at which these results are produced. A soft real-time system is a system whose operation is degraded if results are not produced according to the specified timing requirements. A hard real-time system is a system whose operation is incorrect if results are not produced according to the timing specification.

Characteristics of embedded systems:

Embedded system design

The design process for embedded systems is a systems engineering process that has to consider, in detail, the design and performance of the system hardware. Part of the design process may involve deciding which system capabilities are to be implemented in software and which in hardware. Low-level decisions on hardware, support software and system timing must be considered early in the process. These may mean that additional software functionality, such as battery and power management, has to be included in the system.

Real-time systems are often considered to be reactive systems. Given a stimulus, the system must produce a reaction or response within a specified time. Stimuli come from sensors in the systems environment and from actuators controlled by the system.

Because of the need to respond to timing demands made by different stimuli/responses, the system architecture must allow for fast switching between stimulus handlers. Timing demands of different stimuli are different so a simple sequential loop is not usually adequate. Real-time systems are therefore usually designed as cooperating processes with a real-time executive controlling these processes.

Processes in a real-time system have to be coordinated and share information. Process coordination mechanisms ensure mutual exclusion to shared resources. When one process is modifying a shared resource, other processes should not be able to change that resource. When designing the information exchange between processes, you have to take into account the fact that these processes may be running at different speeds.

Producer processes collect data and add it to the buffer. Consumer processes take data from the buffer and make elements available. Producer and consumer processes must be mutually excluded from accessing the same element. The buffer must stop producer processes adding information to a full buffer and consumer processes trying to take information from an empty buffer.

The effect of a stimulus in a real-time system may trigger a transition from one state to another. State models are therefore often used to describe embedded real-time systems. UML state diagrams may be used to show the states and state transitions in a real-time system.

Programming languages for real-time systems development have to include facilities to access system hardware, and it should be possible to predict the timing of particular operations in these languages. Systems-level languages, such as C, which allow efficient code to be generated are widely used in preference to languages such as Java. There is a performance overhead in object-oriented systems because extra code is required to mediate access to attributes and handle calls to operations. The loss of performance may make it impossible to meet real-time deadlines.

Architectural patterns for real-time software

Characteristic system architectures for embedded systems:

Observe and React pattern description
The input values of a set of sensors of the same types are collected and analyzed. These values are displayed in some way. If the sensor values indicate that some exceptional condition has arisen, then actions are initiated to draw the operator's attention to that value and, in certain cases, to take actions in response to the exceptional value.
Stimuli
Values from sensors attached to the system.
Responses
Outputs to display, alarm triggers, signals to reacting systems.
Processes
Observer, Analysis, Display, Alarm, Reactor.
Used in
Monitoring systems, alarm systems.

Environmental Control pattern description
The system analyzes information from a set of sensors that collect data from the system's environment. Further information may also be collected on the state of the actuators that are connected to the system. Based on the data from the sensors and actuators, control signals are sent to the actuators that then cause changes to the system's environment. Information about the sensor values and the state of the actuators may be displayed.
Stimuli
Values from sensors attached to the system and the state of the system actuators.
Responses
Control signals to actuators, display information.
Processes
Monitor, Control, Display, Actuator Driver, Actuator monitor.
Used in
Control systems.

Process Pipeline pattern description
A pipeline of processes is set up with data moving in sequence from one end of the pipeline to another. The processes are often linked by synchronized buffers to allow the producer and consumer processes to run at different speeds. The culmination of a pipeline may be display or data storage or the pipeline may terminate in an actuator.
Stimuli
Input values from the environment or some other process
Responses
Output values to the environment or a shared buffer
Processes
Producer, Buffer, Consumer
Used in
Data acquisition systems, multimedia systems

Timing analysis

The correctness of a real-time system depends not just on the correctness of its outputs but also on the time at which these outputs were produced. In a timing analysis, you calculate how often each process in the system must be executed to ensure that all inputs are processed and all system responses produced in a timely way. The results of the timing analysis are used to decide how frequently each process should execute and how these processes should be scheduled by the real-time operating system.

Factors in timing analysis:

Real-time operating systems

Real-time operating systems are specialized operating systems which manage the processes in the RTS. Responsible for process management and resource (processor and memory) allocation. May be based on a standard kernel which is used unchanged or modified for a particular application. Do not normally include facilities such as file management.

Real-time operating system components:

The scheduler chooses the next process to be executed by the processor. This depends on a scheduling strategy which may take the process priority into account. The resource manager allocates memory and a processor for the process to be executed. The dispatcher takes the process from ready list, loads it onto a processor and starts execution.

Scheduling strategies: