Professional Documents
Culture Documents
• All practical systems are said to be real time systems, if they meet deadlines.
• A word processor which gives response within certain time (eg:1sec) is
considered acceptable.
• Definition
Any occurrence that causes the program counter to change non-sequentiality
is considered a change of flow-of-control, and thus an event.
receive process
•Definition
A system is said to be deterministic if, for each possible state and each set of
inputs, a unique set of outputs and next state of the system can be determined.
• For any physical system certain states exist under which the system is
considered to be out of control.
• The software controlling such a system must avoid these states.
Example:
In certain guidance systems for robots or aircraft, rapid rotation
through a 180’ pitch angle can cause a physical loss of gyro control.
• The software ability to predict next state of the system given the current
state and a set of inputs.
REAL TIME CONCEPTS
Time Loading
• The selection of hardware and software, and the appropriate mix needed for
cost effective solution.
• Decide upon existing commercial RTOS or to design a special OS.
• Selection of an software language for system development.
• Maximize fault tolerance and reliability thru design and rigorous testing.
• selection of test and development equipment.
REAL TIME CONCEPTS
Examples of Real Time
Systems
1. Aircraft Navigation System
Pass by Value
Pass by Reference
Features: Abstraction
Inheritence
Polymorphism
• A variation on the polled loop uses a fixed clock interrupt to wait a period of
time between when the flag is TRUE and when the flag is set to FALSE.
• Waiting avoids interpreting settling oscillations as events.
• A delay period can be realized with a programmable timer that issues an
interrupt after a countdown period.
• while TRUE do
•Begin
•if FLAG = TRUE then begin
•counter = 0;
Chapter 3
Real Time Kernel
•while TRUE do
•Begin
•if FLAG = TRUE then begin
•counter = 0;
While counter < 3
FLAG = FALSE;
process event;
End
End
Chapter 3
Real Time Kernel
•Polled loop systems are excellent for high speed data channels.
• The processor is dedicated to handling the data channel.
•Dis:
• waste cpu incase of infrequent event.
Chapter 3
Real Time Kernel
Co-routines
•These types of kernels are employed in conjunction with code driven by finite
state automata.
• In this scheme two or more processes are coded in the state driven fashion.
• After each phase a call is made to the central dispatcher.
• The dispatcher selects next process to execute. This process continues until the
next phase is complete and the central dispatcher is called again.
• processes communicate via global variables.
•Dis: communication via global variables
Chapter 3
Real Time Kernel
CONTEXT SWITCHING
CONTEXT SWITCHING
• Contents of registers
• pc
• Coprocessor registers
• Memory page registers
•Special variables
• memory mapped I/O location mirror images
• Interrupts are disabled during the critical context switching period.
Chapter 3
Real Time Kernel
Stack Model
• The stack model for context switching is used mostly in embedded systems.
• The context is saved by the interrupt controller.
Chapter 3
Real Time Kernel
Round-Robin Systems
• The priorities are assigned so that the higher the execution frequency , the
higher the priority.
• This scheme is common in embedded applications, particularly avionics
systems, and has been studied extensively.
• In rate-monotic systems priority inversion may necessarily occur.
Process1 Process2
semlock(); semlock();
semunlock(); semunlock();
Chapter 3
Real Time Kernel
Hybrid systems
• These systems are the most common solution for embedded applications.
• They involve set of real time processes called the foreground and a collection
of noninterrupt driven processes called background.
• The foreground tasks run in round-robin, preemptive priority, or combination
fashion.
• The background task is fully preemtable by any foreground task and, in sense,
represents the lowest priority task in the system.
• All real time systems are special cases of foreground/background systems.
Chapter 3
Real Time Kernel
6.5.1 BACKGROUND Processing
• Disable Interrupts
• Set up Interrupt vectors and stacks
• perform self test
• perform system initialization
• Enable Interrupts
Chapter 3
Real Time Kernel
6.5.3 Real Time Operation
• A special data structure called a circular queue or ring buffer is used in the
same way as a first in first out.
• Ring buffers are easy to manage.
• In the ring buffer, simultaneous I/O are achieved by keeping head and tail
pointers.
• Data are loaded at the tail and read from the head.
• An implementation of ring buffer is given below;
Chapter 4
Inter task Communication
7.1.2 Ring Buffers
• A mail box is a mutually agreed upon memory location that two or more
tasks can use to pass data.
• The tasks rely on central scheduler, to write to the location via post operation
and read via pend operation.
• The data can be single piece of data or pointer to a larger data structure such
as a list or an array.
• In most implementations when the key is taken from the mailbox, the
mailbox is emptied.
• Thus several tasks can pend on the mailbox, only one task can receive the
key, since key represents the access to a critical resource.
Chapter 4
Inter task Communication
7. 2 Mail Boxes
Procedure post
mailbox gets data
End
Procedure pend
Task reads content of mailbox in data, otherwise suspend the task
End
To device
requests
server server
Ring buffer
Chapter 4
Inter task Communication
7. 3 Critical Regions
•LOAD R1,S
•TEST R1,1
•JEQ @1 S = = TRUE ????????
•STORE S,1 S = TRUE
Chapter 4
Inter task Communication
7. 4.4 The Test-and-Set Instruction
Procedure wait(S)
while test-and-set(S) = TRUE do { wait }
S = TRUE;
End
Procedure Signal(S)
begin
S = FALSE;
End
Chapter 4
Inter task Communication
7. 4.4 The Test-and-Set Instruction
The procedure wait would generate the assembly language code that may look
like;
loop:
TANDS S
JNE loop
Chapter 4
Inter task Communication
7. 5 Event Flags and Signals
• Certain Languages provide for synchronization mechanisms called event
flags.
• These constructs allow for the specification of an event that causes the
setting of some flag.
• A second process is designed to react to this flag.
• Event flags in essence represent simulated interrupts, created by the
programmer.
• Raising the event transfers flow-of-control to the operating system, which
can then invoke the appropriate handler.
• Tasks that are waiting for the occurrence of an event are said to be blocked.
Chapter 4
Inter task Communication
7. 5 Event Flags and Signals
• For Example:
In ANSI-C, the raise and signal facilities are provided.
Signal is a type of s/w interrupt handler, that is used to react to an
exception indicated by raise operation.
Chapter 4
Inter task Communication
7. 6 Deadlock
• When tasks are competing for the same set of two or more serially
reusable resources, then a deadlock situation may ensue.
• The notion of deadlock is illustrated by an example below;
Procedure Task_A; Procedure Task_B
Wait(S); Wait( R);
Update database file; update Array;
Wait( R); Wait(S);
Update Array; Update database file
Signal(R); Signal( S);
Signal(S) ; Signal( R);
End End
Chapter 4
Inter task Communication
7. 6 Deadlock
• Deadlock is a serious problem because it cannot always be detected
through testing.
• Starvation – At least one process satisfies its requirements.
• Deadlock – No processes can satisfy their requirements because all
are blocked.
Four Conditions necessary for deadlock situation;
- Mutual Exclusion.
- Circular Wait.
- Hold and Wait.
- No Preemption.
Chapter 4
Inter task Communication
7. 6 Deadlock
Mutual Exclusion : -
• Mutual exclusion applies to those resources that are not sharable.
• Example:- printers, disk devices and output channels.
• Mutual exclusion can be removed by making them sharable to an
application task.
Circular Wait : -
• Circular wait condition occurs, when several processes exist that hold
resources needed by other processes further down the chain.
• One way to impose an ordering on resources and to force all
processes to request resources in increasing order of enumeration.
Chapter 4
Inter task Communication
7. 6 Deadlock
Device Number
Disk 1
Printer 2
Motor Control 3
Monitor 4
Chapter 4
Inter task Communication
7. 6 Deadlock
Hold and Wait: -
• The hold and wait condition occurs when processes request resource
and then lock that resource until subsequent resource requests are
filled.
• One solution to this problem is to allocate to a process all potentially
required resources at the same time.
• This leads to starvation.
• Never allow a process to lock more than one resource at a time.
Chapter 4
Inter task Communication
7. 6 Deadlock
No Preemption: -
• No Preemption can lead to a deadlock.
• If a low priority process holds a resource protected by semaphore S,
and if a high priority task interrupts and then waits on semaphore S,
the priority inversion will cause the high priority task to wait forever,
since the low-priority task can never run to release the resource and
signal the semaphore.
• If we allow the higher priority task to preempt the lower one, then the
deadlock can be eliminated.
Chapter 4
Inter task Communication
7. 6.1 Deadlock Avoidance
• Several Techniques for avoiding deadlock are available;
- If the semaphores protecting critical regions are implemented by
mailboxes with timeouts, then deadlock cannot occur. But starvation
occurs.
- Allow preemption- High priority tasks should preempt low priority
tasks.
- Eliminate Hold and Wait Condition.
- Another technique uses bankers algorithm. This a slow technique
for real time systems.
Chapter 4
Inter task Communication
7. 6.2 Detect and Recover
• One algorithm called ostrich algorithm, advises that the problem must be
ignored, if it occurs infrequently.
• Another method says to restart the system completely, this may not be
acceptable for some critical systems.
• If a deadlock is detected rollback to a pre-deadlock state.
Chapter 5
System Performance Analysis And Optimization
Key Points of the Chapter