BITS ZG553 Real Time Systems L-1a KGK
BITS ZG553 Real Time Systems L-1a KGK
BITS ZG553 Real Time Systems L-1a KGK
1
RTS Primer – For Light Reading
Note: Students are requested to NOT to rely on PPTs/Recorded sessions as their only source of knowledge, explore sources within your own organization or
web for any specific topic; attend classes regularly and involve in discussions;
PLEASE DO NOT PRINT PPTs, Save the Environment!
3
Source PPT Courtesy: Some of the contents of this PPT is sourced from Presentatoons of Prof K R Anupa, BITS-Pilani WILP Faculty
Performance Criteria for RTS
RT NRT
Timeliness
Simultaneity Throughput
Predictability CPU Utilization Factor
Dependability
RTS- K.R.Anupama 4
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Aspects of Dependability
Dependability
RTS- K.R.Anupama 5
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Prediction of execution
RTS- K.R.Anupama
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Factors that affect execution time
Source Code
Compiler
Hardware
– Processor
– Memory
– I/O
– Interconnections
– Interrupt Priorities and Latency
Cache
OS
RTS- K.R.Anupama 7
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Source Code
Load c
13 texec
Load b (Li) 14 texec (L1.i)
Multiply
Store into a
L1: a = b * c
L2: g = d + e
L3: h = a – f
RTS- K.R.Anupama 8
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Loops - while
while (p) do
Q1
Q2
Q3
end while
RTS- K.R.Anupama 9
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Loops if then else
if B1 then
S1 T(B1) + T(S1) + T(JMP)
elseif B2 then
S2 T(B2) + T(B1) + T(S2)+ T(JMP)
elseif B3 then
T(B3) + T(B2) + T(B1) + T(S3)+
S3 T(JMP)
else
S4
endif
RTS- K.R.Anupama 10
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
A Quick Review
The Basics
RTS- K.R.Anupama
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
What’s an Operating System?
RTS- K.R.Anupama 12
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Do I Really Need An OS?
Not always
Simplest approach: cyclic executive
loop
do part of task 1
do part of task 2
do part of task 3
end loop
RTS- K.R.Anupama 13
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Cyclic Executive
Advantages
– Simple implementation
– Low overhead
– Very predictable
Disadvantages
– Can’t handle sporadic events
– Everything must operate in lockstep
– Code must be scheduled manually
RTS- K.R.Anupama 14
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Interrupts
RTS- K.R.Anupama 15
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Handling an Interrupt
1. Normal program
execution
3. Processor state
saved 4. Interrupt routine
2. Interrupt runs
occurs
6. Processor state
restored 5. Interrupt routine
terminates
7. Normal
program
execution
resumes
RTS- K.R.Anupama 16
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Interrupt Service Routines
RTS- K.R.Anupama 17
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Drawbacks of CE + Interrupts
RTS- K.R.Anupama 18
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Cooperative Multitasking
A cheap alternative
Non-preemptive
Processes responsible for relinquishing control
Examples: Original Windows, Macintosh
A process had to periodically call get_next_event() to let other processes proceed
Drawbacks:
– Programmer had to ensure this was called frequently
– An errant program would lock up the whole system
RTS- K.R.Anupama 19
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Concurrency Provided by OS
Basic philosophy:
– Let the operating system handle scheduling, and let
the programmer handle function
Scheduling and function usually orthogonal
Changing the algorithm would require a change in
scheduling.
RTS- K.R.Anupama 20
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Batch Operating Systems
RTS- K.R.Anupama 21
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Timesharing Operating Systems
Solution
– Store multiple batch jobs in memory at once
– When one is waiting for the tape, run the other one
RTS- K.R.Anupama 22
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Real-Time Is Not Fair
RTS- K.R.Anupama 23
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Role of an OS in Real Time Systems
Standalone Applications
– Often no OS involved
– Micro controller based Embedded Systems
Some Real Time Applications are huge & complex
– Multiple threads
– Complicated Synchronization Requirements
– Filesystem / Network / Windowing support
– OS primitives reduce the software design time
RTS- K.R.Anupama 24
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Features of RTOS’s
Scheduling.
Resource Allocation.
Interrupt Handling.
RTS- K.R.Anupama 25
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Scheduling in RTOS
More information about the tasks are known
– No of tasks
– Resource Requirements
– Release Time
– Execution time
– Deadlines
Being a more deterministic system better scheduling
algorithms can be devised.
RTS- K.R.Anupama 26
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Characteristics
RTS - Tasks
A program in execution
An instance of a program running on a computer
The entity that can be assigned to and executed on a processor
A unit of activity characterized by
– the execution of a sequence of instructions
– a current state
– an associated set of system resources
RTS- K.R.Anupama
28
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Process Concept
Process Includes
– Program Counter
– Code
– Data
– Stack
RTS- K.R.Anupama
29
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Process & Threads
RTS- K.R.Anupama 30
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Multiprogramming
RTS- K.R.Anupama
31
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Processes
The Process Model
RTS- K.R.Anupama 32
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Multiprogramming
RTS- K.R.Anupama
33
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Cooperating Processes
RTS- K.R.Anupama
34
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Cooperating Processes
RTS- K.R.Anupama
35
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Threads: Motivation
RTS- K.R.Anupama
36
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Threads- The Thread Model
RTS- K.R.Anupama 40
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The Thread Model
Each thread has its own stack
RTS- K.R.Anupama 39
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Threads/ Process
Similarities Differences
Share CPU - only one thread active Threads are not independent of
(running) at a time one another
Threads within a processes execute
sequentially. All threads can access every
Can create children. address in the task
If one thread is blocked- another thread can
Thread are designed to assist one
run.
other- processes might/not – as
they originate from different users
RTS- K.R.Anupama
40
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Why Threads
Threads can share common data - do not need to use inter-process commn
Context switching fast - only have to save and/or restore PC, SP & regs
But this cheapness does not come free - the biggest drawback is that there is no protection
between threads.
RTS- K.R.Anupama
41
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Thank You.
Any Questions?
42