Real-time systems
z Systems which monitor and control their
environment.
Real-time Software Design z Inevitably associated with hardware devices
• Sensors: Collect data from the system
environment;
• Actuators: Change (in some way) the system's
environment;
z Time is critical. Real- time systems MUST
respond within specified times.
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 1 ©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 2
Definition Stimulus/Response Systems
z A real- time system is a software system where z Given a stimulus, the system must produce a
the correct functioning of the system depends on response within a specified time.
the results produced by the system and the time z Periodic stimuli. Stimuli which occur at
at which these results are produced. predictable time intervals
z A soft real- time system is a system whose • For example, a temperature sensor may be polled 10
operation is degraded if results are not produced times per second.
according to the specified timing requirements. z Aperiodic stimuli. Stimuli which occur at
unpredictable times
z A hard real- time system is a system whose
• For example, a system power failure may trigger an
operation is incorrect if results are not produced interrupt which must be processed by the system.
according to the timing specification.
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 3 ©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 4
Architectural considerations A real-time system model
z 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.
z Timing demands of different stimuli are different so a
simple sequential loop is not usually adequate.
z Real-time systems are therefore usually designed as
cooperating processes with a real-time executive
controlling these processes.
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 5 ©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 6
Sensor/actuator processes System elements
z Sensor control processes
• Collect information from sensors. May buffer
information collected in response to a sensor
stimulus.
z Data processor
• Carries out processing of collected information
and computes the system response.
z Actuator control processes
• Generates control signals for the actuators.
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 7 ©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 8
Real-time programming Java as a real-time language
z Hard
- real time systems may have to z Java supports lightweight concurrency (threads and
synchronized methods) and can be used for some
programmed in assembly language to soft real-time systems.
ensure that deadlines are met. z Java 2.0 is not suitable for hard RT programming but
z Languages such as C allow efficient real-time versions of Java are now available that
address problems such as
programs to be written but do not have
• Not possible to specify thread execution time;
constructs to support concurrency or shared • Different timing in different virtual machines;
resource management. • Uncontrollable garbage collection;
• Not possible to discover queue sizes for shared
resources;
• Not possible to access system hardware;
• Not possible to do space or timing analysis.
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 9 ©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 10
System design R-T systems design process
z Design both the hardware and the software z Identify the stimuli to be processed and the
associated with system. Partition functions to required responses to these stimuli.
either hardware or software. z For each stimulus and response, identify the
z Design decisions should be made on the timing constraints.
basis on non - functional system z Aggregate the stimulus and response
requirements. processing into concurrent processes. A
z Hardware delivers better performance but process may be associated with each class
potentially longer development and less of stimulus and response.
scope for change.
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 11 ©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 12
R-T systems design process Timing constraints
z Design algorithms to process each class of z May require extensive simulation and
stimulus and response. These must meet the experiment to ensure that these are met by
given timing requirements. the system.
z Design a scheduling system which will z May mean that certain design strategies
such as object- oriented design cannot be
ensure that processes are started in time to used because of the additional overhead
meet their deadlines. involved.
z Integrate using a real- time operating system. z May mean that low - level programming
language features have to be used for
performance reasons.
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 13 ©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 14
Real-time system modelling Petrol pump state model
z The effect of a stimulus in a real-time system may
trigger a transition from one state to another.
z Finite state machines can be used for modelling
real-time systems.
z However, FSM models lack structure. Even simple
systems can have a complex model.
z The UML includes notations for defining state
machine models
z See Chapter 8 for further examples of state machine
models.
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 15 ©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 16
Real-time operating systems
z Real-time operating systems are specialised
operating systems which manage the processes in
the RTS.
z Responsible for process management and
resource (processor and memory) allocation.
z May be based on a standard kernel which
is used unchanged or modified for a particular
application.
z Do not normally include facilities such as file
management.
14
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 17