Characteristics of RTS: Large and Complex
Characteristics of RTS: Large and Complex
Characteristics of RTS
Large and complex Concurrent control of separate system components Facilities to interact with special purpose hardware. Guaranteed response times Extreme reliability Efficient implementation
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
81
Concurrent Programming
The name given to programming notation and techniques for expressing potential parallelism and solving the resulting synchronisation and communication problems Implementation of parallelism is a topic in computer systems (hardware and software) that is essentially independent of concurrent programming Concurrent programming is important because it provides an abstract setting in which to study parallelism without getting bogged down in the implementation details
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
82
Why we need it
To fully utilise the processor
10
2 1
10 0 10 -1 10 10 -3 10 -4 10 10 10 10 10 10
-5 -6 -7 -8 -9 -2
human
tape floppy CD
memory processor
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
83
Signal Completion Interrupt I/O Routine I/O Finished Continue with Outstanding Requests
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
84
Why we need it
To allow the expression of potential parallelism so that more than one computer can be used to solve the problem Consider trying to find the way through a maze
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
85
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
86
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
87
Why we need it
To model the parallelism in the real world Virtually all real-time systems are inherently concurrent devices operate in parallel in the real world This is, perhaps, the main reason to use concurrency
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
88
Why we need it
The alternative is to use sequential programming techniques The programmer must construct the system so that it involves the cyclic execution of a program sequence to handle the various concurrent activities This complicates the programmer's already difficult task and involves him/her in considerations of structures which are irrelevant to the control of the activities in hand The resulting programs will be more obscure and inelegant It makes decomposition of the problem more complex Parallel execution of the program on more than one processor will be much more difficult to achieve The placement of code to deal with faults is more problematic
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
89
Terminology
A concurrent program is a collection of autonomous sequential processes, executing (logically) in parallel Each process has a single thread of control The actual implementation (i.e. execution) of a collection of processes usually takes one of three forms. Multiprogramming
processes multiplex their executions on a single processor
Multiprocessing
processes multiplex their executions on a multiprocessor system where there is access to shared memory
Distributed Processing
processes multiplex their executions on several processors which do not share memory
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
90
Process States
Non-existing Non-existing
Created
Initialising
Terminated
Executable
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
91
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
92
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
93
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
94
Concurrent Execution
Processes differ in Structure static, dynamic Level nested, flat Granularity coarse, fine Initialisation parameter passing, IPC Termination
completion of execution of the process body; suicide, by execution of a self-terminate statement; abortion, through the explicit action of another process; occurrence of an untrapped error condition; never: processes are assumed to be non-terminating loops; when no longer needed.
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
95
Nested Processes
Hierarchies of processes can be created and interprocess relationships formed For any process a distinction can be made between the process (or block) that created it and the process (or block) which is affected by its termination The former relationship is known as parent/child and has the attribute that the parent may be delayed while the child is being created and initialised The latter relationship is termed guardian/dependent. A process may be dependent on the guardian process itself or on an inner block of the guardian The guardian is not allowed to exit from a block until all dependent processes of that block have terminated
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
96
Nested Processes
A guardian cannot terminate until all of its dependents have terminated A program cannot terminate until all of its processes have terminated A parent of a process may also be its guardian (e.g. with languages that allow only static process structures) With dynamic nested process structures, the parent and the guardian may or may not be identical
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
97
Process States
Non-existing Non-existing
Created
Initialising
Terminated
Executable
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
98
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
99
Process Representation
Co-routines Fork and Join Co-begin Explicit Process Declaration
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
100
Co-routine B 2 4
Co-routine C 5 resume A 6
3 resume C
13 14 resume B
12
9 resume A 15
10
101
Note
No return statement only a resume statement The value of the data local to the co-routine persist between successive calls The execution of a co-routine is suspended as control leaves it, only to carry on where it left off when it resumed
102
After the fork, P and F will be executing concurrently. At the point of the join, P will wait until the F has finished (if it has not already done so)
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
103
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
104
Cobegin
The co-begin (or parbegin or par) is a structured way of denoting the concurrent execution of a collection of statements:
cobegin S1; S2; S3; . . Sn coend
S1, S2 etc, execute concurrently The statement terminates when S1, S2 etc have terminated Each Si may be any statement allowed within the language
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
105
Languages that support explicit process declaration may have explicit or implicit process/task creation
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
106
Screen
DAC
Pump/Valve
Overall objective is to keep the temperature and pressure of some chemical process within well-defined limits
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
107
108
109
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
110
Disadvantages
Both tasks send data to the screen, but the screen is a resource that can only sensibly be accessed by one process at a time A third entity is required. This has transposed the problem from that of concurrent access to a nonconcurrent resource to one of resource control It is necessary for controller tasks to pass data to the screen resource The screen must ensure mutual exclusion The whole approach requires a run-time support system
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
111
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
112
113
Summary
The use of a concurrent programming language is not without its costs. In particular, it becomes necessary to use a run-time support system to manage the execution of the system processes The behaviour of a process is best described in terms of states
non-existing created initialised executable waiting dependent termination waiting child initialisation terminated
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
114
level
top level processes only (flat) multilevel (nested)
initialization
with or without parameter passing
granularity
fine or coarse grain
termination
natural, suicide abortion, untrapped error never, when no longer needed
representation
Slides Alan Burns and Andy Wellings, 2001 Co-routines, fork/join, cobegin, explicit processOriginal declarations Modified - CLR-Jan 2002, Sep 2005.
115
Characteristics of a RTS
Large and complex Concurrent control of separate system components Facilities to interact with special purpose hardware Guaranteed response times Extreme reliability Efficient implementation
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
116
Memory
CPU
Devices
Devices
Address Address
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
117
Data
CPU
Memory
Devices
Devices
Address
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
118
Device Interface
The interface to a device is normally through a set of registers Separate buses: two sets of assembly instructions one for memory access the other for device register access The latter normally take the form of: IN AC, PORT OUT AC, PORT E.g., the Intel 486 and Pentium range Memory-mapped I/O: certain addresses access memory others the device registers; e.g., M68000 and PowerPC ranges The interface is used to control the devices operations and to control the data transfer Two control mechanisms: status driven and interrupt driven control
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
119
Status Driven
A program performs explicit tests in order to determine the status of a given device Three kinds of hardware instructions:
test operations that enable the program to determine the status of the given device control operations that direct the device to perform non-transfer device dependent actions such as positioning read heads I/O operations that perform the actual transfer of data between the device and the CPU
Nowadays most devices are interrupt driven. Interrupts can of course be turned off and polling of device status used instead. Interrupts are often not allowed in Safety Critical Systems
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
120
Interrupt Driven
Interrupt-driven program-controlled Interrupt-driven program-initiated (DMA) Interrupt-driven channel-program controlled
DMA and channel programs can cause cycle stealing from the processor; this may make it difficult to estimate the worst-case execution time of a process
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
121
It may be necessary to supplement the actions of the hardware by explicit software support
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
122
Elements Needed
2 Interrupting device identification
A vectored mechanism consists of a set of dedicated, contiguous memory locations (an interrupt vector) and a hardware mapping of device addresses onto the interrupt vector With a status mechanism, each interrupt has an associated status word which specifies the device causing the interrupt and the reason for the interrupt The polling device identification mechanism involves interrogating the status of each device
With some modern computer architectures, interrupt handling is directly associated with a high-level language primitive With these systems, an interrupt is often viewed as a synchronisation message down an associated channel; the device is identified by the channel which becomes active
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
123
Elements Needed
3 Interrupt identification Once the device has been identified, the appropriate interrupt handling routine must determine why it generated the interrupt This can be supplied by either status information provided by the device or by having different interrupts from the same device occurring through different vectored locations or channels
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
124
Elements Needed
4 Interrupt control Once a device is switched on its interrupts must be enabled. Enabling/disabling of interrupts may be performed by:
Status mechanisms provide flags to enable/disable interrupts. Mask interrupt control mechanisms associate device interrupts with particular locations in an interrupt mask word Level-interrupt control mechanisms have devices associated with certain levels; the current level of the processor determines which devices may or may not interrupt
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
125
Elements Needed
5 Priority control Some devices have higher urgency than others and, therefore, a priority facility is often associated with interrupts This mechanism may be static or dynamic and is usually related to the device interrupt control facility and the priority levels of the processor
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
126
127
A device may have more than one csr and dbr, the exact number being dependent on the nature of the device. On an interrupt, the processor stores the PC and the current program status word (PSW) on the system stack The new PC and PSW are loaded from an interrupt vector The first word contains the address of the interrupt service routine and the second contains the PSW including the priority at which the interrupt is to be handled
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
128
Language Requirements
Modularity & encapsulation facilities
Device interfacing is machine dependent. It is important to separate the non-portable sections of code from the portable ones.
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
129
Abstract Models
All models require facilities for addressing and manipulating device registers
A device register may be represented as a program variable, an object, or even a communications channel
All except procedure, view the handler as executing in the scope of a process, and therefore require a full context switch
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
130
Only scalar data types can be mapped onto a device register; registers which have internal structures are considered to be of the predefined type bits whose definition is:
type bits = array 0:no_of_bits_in_word OF BOOLEAN;
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
131
The following will enable the device and turn interrupts off
rcsr[0] := TRUE; rcsr[6] :=False;
In general these facilities are not powerful enough to handle all types of registers conveniently; consider setting 10 - 8 : Unit select to the value 5
rcsr[10] := true; rcsr[9] := false; rcsr[8] := true;
Clumsy
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.
132
Note
On many machines more than one device register can be mapped to the same physical address; these registers are often read or write only Care must be taken when manipulating device registers. If the CSR was a pair of registers mapped to the same location, the code will not have the desired affect. WHY? It is advisable to have other variables in a program which represent device registers; these can be manipulated in the normal way When the required register format has been constructed it may then be assigned to the actual device register Such variables are often called shadow device registers
Original Slides Alan Burns and Andy Wellings, 2001 Modified - CLR-Jan 2002, Sep 2005.