SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Downloaden Sie, um offline zu lesen
1
Real-Time Operating Systems &
Resource Management
Tei-Wei Kuo, Ph.D.
ktw@csie.ntu.edu.tw
Dept. of Computer Science &
Information Engineering
National Taiwan University
Taipei, Taiwan, ROC
Remark: This set of slides comes from my class slides, my research work, slides generously provided by Dr. Jane W.S. Liu,
and class slides contributed by authors of MicroC/OS-II (CMP Book).
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Contents
Overview
A General Architecture of Real-Time/
Embedded Operating Systems
Scheduling Strategies & System
Analysis
Process Synchronization over IPC
Handling of Sporadic Events
Summary
2
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Overview
The Purposes of Operating Systems
Convenience
Efficiency
Characteristics of Many Real-Time/
Embedded Applications
More specific in their applications.
More drastic for their failures.
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Overview
A Typical Control System Example
Rates - sensors & actuators, peripheral,
control program
Phases - takeoff, cruise, and landing, etc.
sensors
actuators
environment
controlled
process
Task
Executions
Clock
Display
operator
3
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Overview
Potential Timing Hazards:
Loop
…...
Sensor();
……..
computation……
……..
t = time();
SleepTime := ReadyTime + PERIOD - t;
ReadyTime = ReadyTime + PERIOD;
Sleep(SleepTime);
EndLoop;
Loop
Size?
Time
Elapsed
Here?
Timer Granularity?
Real Sleep
Time?
???Multiprogramming???
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Overview
General Concerns:
Could I verify the performance of my
system?
How to avoid timing hazards?
Is there any good way in scheduling
processes or allocating resources?
Understand your operating system
and hardware, and use resources
intelligently!
4
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Contents
Overview
A General Architecture of Real-Time/
Embedded Operating Systems
(RTOS’s)
Scheduling Strategies & System
Analysis
Process Synchronization over IPC
Handling of Sporadic Events
Summary
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
A General Architecture of RTOS’s
Various Requirements
Predictability – Verifiability
Reliability – Strictness of Deadline
Violations
Reconfigurability – System Size and
Functionality
Efficiency of System Components – Time
Granularity, Threads, and Resource
Management
Variable Models of Task Communication –
Characteristics of Applications
5
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
A General Architecture of RTOS’s
Objectives in the Design of Many
RTOS’s
Efficient Scheduling Mechanisms
Good Resource Management Policies
Predictable Performance
Common Functionality of Many RTOS’s
Task Management
Memory Management
Resource Control, Including Devices
Process Synchronization
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
A General Architecture
Bottom
Half
Top
Half
processes
User
Space
OS
hardware
Timer expires to
• Expire the running process’s
time quota
• Keep the accounting info
for each process
System calls such as I/O requests
which may cause the releasing
CPU of a process!
Interrupts for Services
6
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
A General Architecture
2-Step Interrupt Services
Immediate Interrupt Service
Interrupt priorities > process priorities
Time: Completion of higher priority ISR,
context switch, disabling of certain
interrupts, starting of the right ISR
(urgent/low-level work, set events)
Scheduled Interrupt Service
Usually done by preemptable threads
Remark: Reducing of non-preemptable
code, Priority Tracking/Inheritance
(LynxOS), etc.
ISR
I
Interrupt/ISRLatency
SecheduledService
ISTLatency
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
A General Architecture
Scheduler
A central part in the kernel
The scheduler is usually driven by a
clock interrupt periodically, except
when voluntary context switches
occur – thread quantum?
Timer Resolution
Tick size vs Interrupt Frequency
10ms? 1ms? 1us? 1ns?
Fine-grained hardware clock
7
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
A General Architecture – Time
Granularity
Clock
interrupts
Expiration times
Timer expiration is detected!
Timeout detected
Timer DPCs
For example, the timer granularity is equal to
1 ms or larger:
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
A General Architecture – For More
Deterministic Periodicity
Your timer
settings
Timer
interrupts
Starts of
periods
0 1 2 3 4 5 6
0 1 2 3 4,5 6
Set the timer resolution to x.
Round off all of timeout intervals to integer
multiples of x!
8
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Performance (time stamp) counter drifts.
Counters on different processors are not
synchronized.
A thread reads the counter on the
processor where it executes.
Consistent time stamps =
Readings of the same counter!
A General Architecture – Timer
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
A General Architecture
Memory Management
No protection for many embedded
systems
Memory-locking to avoid paging
Process Synchronization
Sources of Priority Inversion
Nonpreemptible code
Critical sections
A limited number of priority levels, etc.
9
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Contents
Overview
A General Architecture of Real-Time/
Embedded Operating Systems
(RTOS’s)
Scheduling Strategies & System
Analysis
Process Synchronization over IPC
Handling of Sporadic Events
Summary
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Scheduling Strategies &
System Analysis
Why a process in my application does
not meet its deadline?
Factors:
Impacts from the executions of higher-
priority processes – preemption cost
Lengthy execution time of the process
Blocking time from lower-priority
processes – priority inversion
10
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Scheduling Strategies &
System Analysis
Possible Questions:
How do I assign priorities to processes?
How are my processes scheduled by the
OS?
How long is the blocking time/non-
preemptable critical sections (from lower-
priority processes or interrupts)?
Understand your schedulers
Fixed-Priorities or Dynamic Priorities
Preemptive or Non-Preemptive Scheduling
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Scheduling Strategies & System
Analysis Scheduling Strategy
Major Components of a Scheduler
Priority Assignment Policy
The number of priority levels, e.g., 256?
Aging Effects?
Priority-Driven Scheduling Mechanism
Priority Queue
Thread Quantum?
Preemption Lock – Disabling of
Preemption
etc.
11
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Introduction to Real-Time Process
Scheduling
Q: Many theories and algorithms in real-time
process scheduling seem to have simplified
assumptions without direct solutions to
engineers’ problems. Why should we know
them?
A:
Provide insight in choosing a good
system design and scheduling algorithm.
Avoid poor or erroneous choices.
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Popular Process Model
Periodic process
each periodic process arrives at a regular frequency -
a special case of demand.
r: ready time, d: relative deadline, p: period, c:
maximum computation time.
For example, maintaining a display
Sporadic process
An aperiodic process with bounded inter-arrival time p.
For example, turning on a light
Other requirements and issues:
process synchronization including precedence and
critical sections, process value, etc.
12
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Performance Metrics
Metrics for hard real-time processes:
Schedulability, etc.
Metrics for soft real-time processes:
Miss ratio
Accumulated value
Response time, etc.
Other metrics:
Optimality, overload handling, mode-
change handling, stability, jitter, etc.
Combinations of metrics.
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Basic Definitions
Preemptive scheduling: allows process preemptions. (vs
non-preemptive scheduling)
Online scheduling: allocates resources for processes
depending on the current workload. (vs offline scheduling)
Static scheduling: operates on a fixed set of processes and
produces a single schedule that is fixed at all time. (vs dynamic
scheduling)
Firm real-time process: will be killed after it misses its
deadline. (vs hard and soft real-time)
Fixed-priority scheduling: in which the priority of each
process is fixed for any instantiation. (vs dynamic-priority
scheduling)
13
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Rate Monotonic Scheduling
Algorithm
Assumptions:
all periodic fixed-priority processes
relative deadline = period
independent process - no non-preemptable resources
Rate Monotonic (RM) Scheduling Algorithm
RM priority assignment: priority ~ 1/period.
preemptive priority-driven scheduling.
Example: T1 (p1=4, c1=2) and T2 (p2=5, c1=1)
Time
T1 T2 T1 T2
0 1 2 3 4 5 6 7 8
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Rate Monotonic Scheduling
Algorithm
Critical Instant 1
An instant at which a request of the process have the
largest completion/response time.
An instance at which the process is requested
simultaneously with requests of all higher priority
processes
Usages
Worst-case analysis
Fully utilization of the processor power
Example: T1 (p1=4, c1=2) and T2 (p2=5, c1=1)
1 Liu and Layland, “Scheduling Algorithms for multiprogramming in a hard real-time Environment,” JACM, vol. 20, no. 1, January 1973, pp. 46-61.
Time
T1 T2 T1 T2
0 1 2 3 4 5 6 7 8
T2 T2
14
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Rate Monotonic Scheduling
Algorithm
Schedulability Test:
A sufficient but not necessary condition
Achievable utilization factor α
of a scheduling policy P -> any process set with
total utilization factor no more than α is
schedulable.
Given n processes, α =
Stability:
Let processes be sorted in RM order. The ith
process is schedulable if
An optimal fixed priority scheduling algorithm
c
p
i
i
∑
( )n n
2 11/
−
( )
c
p
ij
j
j
i i
≤ −=∑ 1
1
2 1/
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Schedulability Tests – A
Sufficient Condition
Theorem 0 [Liu&Layland 73]: A set of n
periodic processes is schedulable if the total
utilization factor of the process set is no larger
than
Theorem 1 [Kuo, et al. 00]: Suppose that Ti-1
is schedulable. Let k be the number of roots in Ti.
If the total utilization factor of Ti is no larger than
then Ti is schedulable.
)12(
1
−n
n
)12(
1
−k
k
15
60
3
20
5
15
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Schedulability Tests – Effects
of Interrupts
Task Γ1 : C1 =20ms, P1 =100ms, U1=0.2
Task Γ2 : C2 =40ms, P2 =150ms, U2=0.267
Interrupt : Cint=60ms, Pint=200ms, Uint=0.3
Task Γ3 :C3 =20ms, P3 =350ms, U3=0.057
Γ1
Γ2
Γ3
Int
10 100 200 300
Exec with
RM priority
Γ1
Γ2
Γ3
Int
10 100 200 300
Exec with
an Interrupt
priority
The last task
was not
affected!
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Schedulability Tests – Effects
of Priority Mapping
Ready Queue
…
Priority-decreasing
0-3
4-7
8-11
proc[i] proc[j]
proc[k]
allproc
zombproc
freeproc
proc[j] …
proc[m] …
proc[n] …
exit()
wait()
Let processes be sorted
in RM order. The ith
process is schedulable if
( )( ) /c
p
c B
p
ij
j
i i
i
j
i i
+
+
≤ −=
−
∑ 1
1 1
2 1
16
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Rate Monotonic Analysis – A
Sufficient & Necessary Condition
Rate Monotonic Analysis (RMA) 2
Basic Idea:
Before time t after the critical instance of process τi, a high
priority process τj may request amount of
computation time.
Formula:
A sufficient and necessary condition and many
extensions...
2 Sha, “An Intorduction to Rate Monotonic Analysis,” tutorial notes, SEI, CMU, 1992
Time
c
t
p
j
j








t
deadline of τi
t
pj








0
for some t in
 { | ,..., ; ,..., / }kp j i k p pj i j= =1 1
( ) i
i
j
j
ji dt
p
t
ctW ≤≤








= ∑ =1
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Rate Monotonic Analysis – A
Sufficient & Necessary Condition
A RMA Example:
T1(20,100), T2(30,150), T3(80, 210), T4(100,400)
T1
c1 <= 100
T2
c1 + c2 <= 100 or
2c1 + c2 <= 150
T3
c1 + c2 + c3 <= 100 or
2c1 + c2 + c3 <= 150 or
2c1 + 2c2 + c3 <= 200 or
3c1 + 2c2 + c3 <= 210
T4
c1 + c2 + c3 + c4 <= 100 or
2c1 + c2 + c3 + c4 <= 150 or
....
Time
W3(t)
50 100 150 200
130
150
170
190
210
17
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Rate Monotonic Scheduling
Algorithm
RM was chosen by
Space Station Freedom Project
FAA Advanced Automation System
(AAS)
RM influenced
the specs of IEEE Futurebus+
RMA is widely used for off-line
analysis of time-critical systems.
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Earliest Deadline First Scheduling
Algorithm
Assumptions (similar to RM):
all periodic dynamic-priority processes
relative deadline = period
independent process - no non-preemptable resources
Earliest Deadline First (EDF) Scheduling Algorithm:
EDF priority assignment: priority ~ absolute deadline.
i.e., arrival time t + relative deadline d.
preemptive priority-driven scheduling
Example: T1(c1=1, p1=2), T2(c2=2, p2=7)
Time
T1 T2
0 1 2 3 4 5 6 7 8
T1 T1 T1T2 T2
18
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Earliest Deadline First Scheduling
Algorithm
Schedulability Test:
A sufficient and necessary condition
Any process set is schedulable by EDF iff
EDF is optimal for any independent process
scheduling algorithms
However, its implementation has
considerable overheads on OS’s with a fixed-
priority scheduler and is bad for (transiently)
overloaded systems.
c
p
j
j
j
i
≤=∑ 1
1
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Contents
Overview
A General Architecture of Real-Time/
Embedded Operating Systems
(RTOS’s)
Scheduling Strategies & System
Analysis
Process Synchronization over IPC
Handling of Sporadic Events
Summary
19
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Synchronization & IPC
Why Inter-Process Communication
(IPC)?
Exchanging of Data and Control
Information!
Why Process Synchronization?
Protect critical sections!
Ensure the order of executions!
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Synchronization & IPC
Critical Sections: A portion of code must
be treated indivisibly.
To protect shared resources from
corrupting due to race conditions.
Could be implemented by using interrupt
enable/disable, semaphores, events,
mailboxes, etc.
20
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Synchronization & IPC
Common Facility for IPC?
Shared Memory
Message Transmission
Common Facility for Synchronization?
Semaphores
Signals
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Synchronization & IPC
Shared Memory
Characteristics: High
bandwidth and low latency,
but very primitive!
Needs: Ways to
synchronize its access to
avoid racing conditions!
Potential deadlocks/
livelocks/blocking
problems
e.g., semaphores, bakery
algorithm, etc.
flag[i]=TRUE;
while flag[j]
;
…
flag[i]=FALSE;
key=TRUE;
for(swap(lock,key); key==TRUE; )
swap(lock,key) ;
…
lock=FALSE;
Example 1:
Example 2: (initially, lock=FALSE)
Deadlock?
Livelocks?
21
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Synchronization & IPC
Message Transmission
Characteristics: Simple & clean
interface with various extensions: m:m
communication, multi-machines
Needs: A priority-based message
transmission/notification/processing
mechanism
e.g., message priority, non-blocking
library functions, notification of msg
arrivals, servicing order of msgs (with
respect to other threads in the system),
etc.
A B
OS
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Synchronization & IPC
General Concerns:
How to enforce mutual exclusion?
We should not rely on OS scheduling to
avoid race conditions!
How to process critical messages first?
There is a tight coupling between
message processing and OS scheduling!
After all, we want to manage the priority
inversion problem!
How to let critical jobs be done with
minimized interferences from less
important jobs!
22
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Synchronization & IPC
Solutions??
Synchronization Methods
Priority-Driven Resource Scheduling
Support!
Popular Approaches
Semaphore-Based Synchronization?!
Signals are too slow.
Priority Inheritance?!
Ceiling?
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Synchronization & IPC – Signals?
The Design of Signal Mechanisms
Inform processes/threads of the
occurrences of exceptions or events
Posting of a signal to a process
An appropriate signal is added to the set
of pending signals for the process.
Delivering within the context of the
receiver
if (sig = CURSIG(p))
postsig(sig)
Signal handlers: user-mode routines
A B
OS
…
23
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Synchronization & IPC – Signals
Questions?
How fast can a signal be delivered?
Complicated actions done by OS
The length of a signal handler?
Signal handlers are executed prior to
returning control to the user code.
Real-Time Support
Application-defined signals
Queuing of signals while being blocked.
Signals are delivered in the priority order.
etc
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Synchronization & IPC – Can we
manage the priority inversion
problem?
What are the sources of priority
inversion?
Synchronization and mutual exclusion
Nonpreemptable regions of code
FIFO of any other non-priority-based
queues
Interrupts
A limited number of priorities
24
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Synchronization & IPC – Can we
manage the priority inversion
problem?
Popular Synchronization Methods
Nonpreemptable Critical Sections
Highest Locker’s Priority
Priority Inheritance
Priority Ceiling
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
1. Nonpreemptible Critical Section
Critical sections are executed at an
“infinitely” high priority!
Synchronization Protocols
τL
τM
τH
Note that τH & τM have no intention to
enter a critical section!
Time
25
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Synchronization Protocols
2. Highest Locker’s Priority Protocol
Execute critical section at the priority of
the highest-priority task that may lock the
semaphore(/resource); higher-priority tasks
may preempt the critical section.
τL
τM
τH
τvH
Note that τvH is no longer blocked by τL
Time
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
3. Basic Inheritance Protocol (BIP) [Sha87]
Execute the critical section at the priority of the
highest-priority task being blocked; higher-priority
tasks may preempt the critical section.
S1τL
τM
τH
τvH
S1
S2
S2
S2
t
blocked
blocked
Time
- Note that τM is no longer blocked until necessary.
- However, system may be deadlocked or have chained
blocking!
Synchronization Protocols
S2S1 & S2
26
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
4. Priority Ceiling Protocol [Sha87]
BIP + a “Priority Ceiling” rule about when to grant
lock requests (see [Sha 87, 90] )
S1τL
τM
τH
τvH
S1
S2
S1
blocked Time
- No deadlock & chained blocking at the cost of reducing
the concurrency level of the system.
- Blocked-at-most-once.
Synchronization Protocols
blocked
S1
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Priority Ceiling Protocol
Assumptions:
all periodic fixed-priority processes
relative deadline = period
Non-preemptable resources guarded by
semaphores
Basic Ideas and Mechanisms:
Bound the priority inversions by early blocking of
processes that could cause them, and
Minimize a priority inversion’s length by allowing a
temporary rise in the blocking process’s priority.
Contribution of the Priority Ceiling Protocol
Efficiently find a suboptimal solution with a clever
allocation policy, guaranteeing at the same time a
minimum level of performance.
27
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Priority Ceiling Protocol
Pre-requirements: nested critical sections!
Priority Ceiling Protocol (PCP):
Define a semaphore’s priority ceiling as the
priority of the highest priority process that may
lock the semaphore.
Lock request for a semaphore is granted only if
the requesting process’s priority is higher than
the ceiling of all semaphores concurrently
locked by other processes.
In case of blocking, the task holding the lock
inherits the requesting process’s priority until it
unlocks the corresponding semaphore. (Def:
priority inheritance)
1 Sha, Rajkumar, and Lehoczky, “Priority Inheritance Protocols: an Approach to Real-Time Synchronization,” IEEE Transactions on computers, Vol. 39, No. 9, Sept. 1990, pp. 1,175-1,185.
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Priority Ceiling Protocol
A PCP Example: deadlock avoidance
Timeτ1
Timeτ2
S1
t1
attempt to lock S2
S1,S2
t2
S1
t4
priority inheritance
unlock S1 and reset priority
S2 S1,S2
t6 t7
28
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Priority Ceiling Protocol
A PCP Example: avoid chain blocking
Timeτ0
Timeτ1
Timeτ2
S1
t1
attempt to lock S2
S1
t2
attempt to lock S2
S1
t3
t4
priority inheritance
S2
unlock S1 and reset priority
S2 S1,S2
t5 t6
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Priority Ceiling Protocol
A PCP Example: one priority inversion
Timeτ0
Timeτ1
Timeτ2
S1
t1
attempt to lock S2
S1,S2
t2
attempt to lock S1
S1
t3
t4
priority inheritance
S1
unlock S1 and reset priority
t5
S2 S1,S2
t6 t7
29
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Priority Ceiling Protocol
Important Properties:
A process is blocked at most once before it
enters its critical section.
PCP prevents deadlocks.
Schedulability Test of τi
worst case blocking time Bi - an approximation!
Let processes be sorted in the RM priority
order
–– BSi = { τj | j > i & Max(s in Sj) (ceiling(s)) >= priority(τi)}
– Bi = Max(τj in BSi) |critical section|
– Sj = { S | semaphore S is accessed by τj }
( )( ) /c
p
c B
p
ij
j
i i
i
j
i i
+
+
≤ −=
−
∑ 1
1 1
2 1
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Priority Ceiling Protocol
Variations of PCP:
Stack Resource Policy - not permitted to
start unless resources are all available.
multi-units per resource
dynamic and fixed priority assignments
Dynamic Priority Ceiling Protocol
extend PCP into an EDF scheduler.
2 Baker, “Stack-Based Scheduling of Real-Time Processes,” J. Real-Time Systems, Vol. 3, No. 1, March 1991, pp. 67-99.
3 Chen and Lin, “Dynamic Priority Ceilings: A Concurrency Control Protocol for Real-time Systems,” J. Real-Time Systems, Vol. 2, No. 4, Nov. 1990, pp. 325-340.
30
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Summary of Synchronization
Methods
YesYesPriority Ceiling
NoBoundedPriority Inheritance
YesYesHighest Locker’s
Priority
YesYesNon-preemptible
Critical Section
Deadlock
Avoidance
Blocked
at Once
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Remarks on Priority Inversion
Symmetric Multi-Processor (SMP)
Hyperthreading
Deferred Procedure Call (DPC)
31
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Priority Inversion in SMP
Threads Processors
Find-ready-thread function may not
select the highest priority thread!
Ready-thread function may not
preempt the lowest priority thread!
Guarantee: The highest priority thread
runs immediately after it becomes ready.
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Process Inversion on
Hyperthreading Processors
Systems with hyperthreading is not
equivalent to those with SMP!!
Threads might share components!
32
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
DPC: Deferred Procedure Call
(Similar to tasklets in Linux)
ISRs
DPCs
Dispatcher
Interrupts
Processors
DPC queues
P1 P2
On P1 On P2
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Threaded (Preemptive) DPC
On each processor, there are:
Normal
DPC’s
Threaded
DPC’s
Executed nonpreemptively
ahead of threads
Executed by a dedicated
thread for the processor
Initialize each DPC either as a normal DPC
or a threaded DPC.
Use a new set of spinlock functions for
threaded DPC’s.
33
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Contents
Overview
A General Architecture of Real-Time/
Embedded Operating Systems
(RTOS’s)
Scheduling Strategies & System
Analysis
Process Synchronization over IPC
Handling of Sporadic Events
Summary
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Scheduling Aperiodic Tasks
– Polling ~ Average Response Time = 50 units
99
100
– Interrupt Handler ~ Average Response Time = 1 unit
100
– Deferrable Server [Lehoczky87] ~ Average Response Time = 1 unit
1000
0
0
An on-demand service type
When execution budget is used up, server execution drops to a lower
(background) priority until the budgeted execution time is replenished.
34
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Polling Services – Modeling of
Sporadic Processes
Lemma 3[Mok, RTSS84]: Suppose we replace every
sporadic process τi = (ci, pi, di) with a periodic process
τ'i = (c'i, p'i, d'i) with c'i = ci , p'i = min(pi , (di – ci + 1)),
and d'i = ci . If the result set of all periodic processes
can be successfully scheduled, then the original set of
processes can be scheduled without a priori knowledge
of the request times of the sporadic processes.
Proof.
Time
p'i = di – ci + 1
1 ci
di
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
In general, we can replace each sporadic process
τi = (ci, pi, di) with a periodic process τ'i = (c'i,
p'i, d'i) if the following conditions are satisfied:
[Mok, RTSS84]
(1) d ≥ d' ≥ c;
(2) c' = c;
(3) p' ≤ d - d' + 1
Proof.
Time
p' = d – d' + 1
1 d'
d
Polling Services – Modeling of
Sporadic Processes
35
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Deferrable Server (DS) [Lehoczky87]
τ1 as a DS server to preserve CPU bandwidth
for a collection of aperiodic tasks.
τ1 has an entire period to use its C run-time
and gets replenished at the beginning of each
of its period.
Theorem 3 [Lehoczky87]: For τ1 as the highest priority
DS server, and τ2 … τn as periodic tasks, the
achievable utilization factor is
When U is minimized to 0.6518 when U1 = 0.186.
J.P. Lehoczky, L. Sha, and J.K. Strosnider, “Enhancd Aperiodic Responsiveness in Hard Real-Time Environment,” RTSS’87, pp261-270.
]1)
1
2
)[(1( )1/(1
1
1
1 −
+
+
−+= −n
U
U
nUU
∞→n
)
12
2
ln(1
1
1
+
+
+=
U
U
UU
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Remarks:
– Deferrable Servers:
–fixed execution budget
–replenishment interval
–priority adjusted to meet requirements.
Note that the response time performance improves as the
replenishment rate decreases because the execution budget
increases and more services can be provided.
– Polling:
–From the scheduling point of view, polling converts the servicing of
aperiodic events into an “equivalent” periodic tasks.
–Not an on-demand service type.
–As the rate of polling increases, the response time for polling
approach improves.
– The rationale behind aperiodic servers:
–No “system” benefit to finish periodic work early!
36
Sporadic Server [Sprunt et. al. 90]
Modeled as periodic tasks
fixed execution budget(c)
replenishment interval (p)
5 5 5
0 100 200 300
Execution
Budget
P=100ms 100ms
Replenishment occurs one “period” after the start of
usage !
Priority adjusted to meet requirements.
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
A sporadic server differs from a
deferrable server in its replenishment
policy:
A 100 msec deferrable server replenishes
its execution budget every 100 msec , no
matter when the execution budget is used.
The affect of a sporadic server on lower
priority tasks is no worse than a periodic
task with the same period and execution
time.
Sporadic Server [Sprunt et. al. 90]
37
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Sporadic Server [Sprunt et. al. 90]
A sporadic server (SS) under the fixed-
priority scheduling framework.
Terms:
Ps: the priority at which the system is executing.
Pi: one priority level in the system.
Active: A priority level Pj is active is Pj <= Ps.
Idle: not active
RTi: replenishment time for SS executing at priority
level Pi
Brinkley Sprunt, “Aperiodic Task Scheduling for Real-Time Systems,” Ph.D. Thesis
Dept. of Electrical and Computer Engineering, Carnegie Mellon University, August 1990.
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Rules:
Replenishment Time RTi
• If SS has execution time available, and Pi
becomes active at time t, then RTi = t + Pi.
• If SS’s execution time is exhausted, and SS’s
execution time becomes non-zero (is replenished)
at time t and Pi is active, then RTi = t + Pi.
Replenishment Amount
• Determined when Pi becomes idle or SS’s
execution time has been exhausted.
• The amount is equal to the amount of server
execution time consumed since the last time at
which the status of Pi changes from idle to active.
Sporadic Server [Sprunt et. al. 90]
38
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Important theorems:
Theorem 1 [Sprunt90:p28]:Given a real-time
system composed of soft-real-time aperiodic tasks
and hard real-time periodic tasks, let the soft real-time
aperiodic tasks be serviced by a polling server that
starts at full capacity and executes at the priority level
of the highest priority periodic task. If the polling
server is replaced with a sporadic server having the
same period, execution time, and priority, the
sporadic server will provide high-priority aperiodic
service at times earlier than or equal to the times the
polling server would provide high-priority aperiodic
service.
Sporadic Server [Sprunt et. al. 90]
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Theorem 5 [Sprunt90:p34]: A periodic task set
that is schedulable with a periodic task Ti, is also
schedulable if Ti is replaced by a sporadic server
with the same period and execution time.
Schedulability analysis of sporadic servers is
equivalent to periodic tasks! -> overcome the
penalty paid by the deferrable servers!
Remark
In terms of server size, the sporadic server approach is better
than the deferrable server approach.
Although the sporadic server approach claims low
implementation overhead, it seems to be a little bit higher than
the deferrable server approach.
If aperiodic services are requested very heavily , the differences
between DS and SS will diminish.
Sporadic Server [Sprunt et. al. 90]
39
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
A Sporadic Server Example
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Contents
Overview
A General Architecture of Real-Time/
Embedded Operating Systems
(RTOS’s)
Scheduling Strategies & System
Analysis
Process Synchronization over IPC
Handling of Sporadic Events
Summary
40
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Some Ways to Better Predictability
Eliminate major causes of unpredictability.
(Poor hardware and drivers may block
threads for a few hundred milliseconds.)
Statically configure real-time components.
Minimize the need for priority tracking
across components and layers.
Use synchronization protocols to control
priority inversion.
Verify drivers and applications.
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Summary
Understand your operating
systems and hardware!
There is no substitute for
intelligent resource allocation
methods!
41
Remarks on Multiprocessor
Scheduling
郭大維 教授
ktw@csie.ntu.edu.tw
即時暨嵌入式系統實驗室
(Real-Time and Embedded Systems Laboratory)
國立臺灣大學資訊工程系
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Preemptive Multiprocessor Scheduling
Theorems of Mok in 1983
Goal:Understand the limitations of EDF.
Conditions:
different ready times.
Theorem 0: Earliest-deadline-first scheduling
is not optimal in the multiprocessor case.
Example, T1(c=1,d=1), T2(c=1,d=2), T3(c=3,d=3.5), two
processors.
Theorem 1: For two or more processors, no
deadline scheduling algorithm can be optimal
without complete a priori knowledge of deadlines,
computation times, and process start times.
A.K. Mok, “Fundamental Design Problems of Distributed Systems for the Hard Real-Time Environment,” Ph.D. Thesis, Dept. of Electrical Engineering and Computer science, MIT, May 1983.
42
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Multiprocessor Anomalies
Theorem of Graham in 1976.
Goal:Notice anomaly and provide better design.
Conditions;
A set of processes is optimally scheduled on a
multiprocessor with some priority order, fixed execution
times, precedence constraints, and a fixed number of
processors.
Theorem 0: For the stated problem, changing
the priority list, increasing the number of
processors, reducing execution times, or
weakening the precedence constraints can
increase the schedule length.
R. Graham, “Bounds on the Performance of Scheduling Algorithms,” Computer and Job Shop Scheduling theory, E.G. Coffman, ed., John Wiley and Sons, 1976, pp. 165-227.
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002.
Multiprocessor Anomalies
An Example
P1
P2
P1
P2

Weitere ähnliche Inhalte

Was ist angesagt?

Real-Time Scheduling
Real-Time SchedulingReal-Time Scheduling
Real-Time Schedulingsathish sak
 
Real time scheduling - basic concepts
Real time scheduling - basic conceptsReal time scheduling - basic concepts
Real time scheduling - basic conceptsStudent
 
Real Time Systems
Real Time SystemsReal Time Systems
Real Time Systemsleo3004
 
Components in real time systems
Components in real time systemsComponents in real time systems
Components in real time systemsSaransh Garg
 
Survey of Real Time Scheduling Algorithms
Survey of Real Time Scheduling AlgorithmsSurvey of Real Time Scheduling Algorithms
Survey of Real Time Scheduling AlgorithmsIOSR Journals
 
Real time operating-systems
Real time operating-systemsReal time operating-systems
Real time operating-systemskasi963
 
Clock driven scheduling
Clock driven schedulingClock driven scheduling
Clock driven schedulingKamal Acharya
 
Hard versus Soft real time system
Hard versus Soft real time systemHard versus Soft real time system
Hard versus Soft real time systemKamal Acharya
 
Reference model of real time system
Reference model of real time systemReference model of real time system
Reference model of real time systemKamal Acharya
 
Full solution manual real time system by jane w s liu solution manual
Full solution manual real time system by jane w s liu solution manualFull solution manual real time system by jane w s liu solution manual
Full solution manual real time system by jane w s liu solution manualneeraj7svp
 
Rtos concepts
Rtos conceptsRtos concepts
Rtos conceptsanishgoel
 
Approaches to real time scheduling
Approaches to real time schedulingApproaches to real time scheduling
Approaches to real time schedulingKamal Acharya
 
REAL TIME OPERATING SYSTEM PART 1
REAL TIME OPERATING SYSTEM PART 1REAL TIME OPERATING SYSTEM PART 1
REAL TIME OPERATING SYSTEM PART 1Embeddedcraft Craft
 
Chapter 19 - Real Time Systems
Chapter 19 - Real Time SystemsChapter 19 - Real Time Systems
Chapter 19 - Real Time SystemsWayne Jones Jnr
 

Was ist angesagt? (20)

Real Time System
Real Time SystemReal Time System
Real Time System
 
Real-Time Scheduling
Real-Time SchedulingReal-Time Scheduling
Real-Time Scheduling
 
Real time scheduling - basic concepts
Real time scheduling - basic conceptsReal time scheduling - basic concepts
Real time scheduling - basic concepts
 
Real time system
Real time systemReal time system
Real time system
 
Real Time Systems
Real Time SystemsReal Time Systems
Real Time Systems
 
Components in real time systems
Components in real time systemsComponents in real time systems
Components in real time systems
 
Survey of Real Time Scheduling Algorithms
Survey of Real Time Scheduling AlgorithmsSurvey of Real Time Scheduling Algorithms
Survey of Real Time Scheduling Algorithms
 
Periodic
PeriodicPeriodic
Periodic
 
Real time operating-systems
Real time operating-systemsReal time operating-systems
Real time operating-systems
 
Clock driven scheduling
Clock driven schedulingClock driven scheduling
Clock driven scheduling
 
Hard versus Soft real time system
Hard versus Soft real time systemHard versus Soft real time system
Hard versus Soft real time system
 
Reference model of real time system
Reference model of real time systemReference model of real time system
Reference model of real time system
 
Real time systems 1 and 2
Real time systems 1 and 2Real time systems 1 and 2
Real time systems 1 and 2
 
Full solution manual real time system by jane w s liu solution manual
Full solution manual real time system by jane w s liu solution manualFull solution manual real time system by jane w s liu solution manual
Full solution manual real time system by jane w s liu solution manual
 
Rtos concepts
Rtos conceptsRtos concepts
Rtos concepts
 
Real Time System
Real Time SystemReal Time System
Real Time System
 
Approaches to real time scheduling
Approaches to real time schedulingApproaches to real time scheduling
Approaches to real time scheduling
 
REAL TIME OPERATING SYSTEM PART 1
REAL TIME OPERATING SYSTEM PART 1REAL TIME OPERATING SYSTEM PART 1
REAL TIME OPERATING SYSTEM PART 1
 
Chapter 19 - Real Time Systems
Chapter 19 - Real Time SystemsChapter 19 - Real Time Systems
Chapter 19 - Real Time Systems
 
S emb t12-os
S emb t12-osS emb t12-os
S emb t12-os
 

Andere mochten auch

experience_page
experience_pageexperience_page
experience_pageKarl Chase
 
лекция нтс 1
лекция нтс 1лекция нтс 1
лекция нтс 1Medinvest
 
чулымцы участники вовойны
чулымцы   участники вовойнычулымцы   участники вовойны
чулымцы участники вовойныЕлена Ерфилова
 
à l'abri craint des vains conforts (poèmes vécus)
à l'abri craint des vains conforts (poèmes vécus)à l'abri craint des vains conforts (poèmes vécus)
à l'abri craint des vains conforts (poèmes vécus)Joseph K Bioux Amis
 
Analysis of ancillary products
Analysis of ancillary productsAnalysis of ancillary products
Analysis of ancillary productsJackDickson
 
Habilidades sociales (1)
Habilidades sociales (1)Habilidades sociales (1)
Habilidades sociales (1)yola_irene
 
MHIT 603: Introduction to Interaction Design
MHIT 603: Introduction to Interaction DesignMHIT 603: Introduction to Interaction Design
MHIT 603: Introduction to Interaction DesignMark Billinghurst
 

Andere mochten auch (13)

Props list
Props listProps list
Props list
 
FSYC - Exposición sobre envejecimiento activo
FSYC - Exposición sobre envejecimiento activoFSYC - Exposición sobre envejecimiento activo
FSYC - Exposición sobre envejecimiento activo
 
experience_page
experience_pageexperience_page
experience_page
 
лекция нтс 1
лекция нтс 1лекция нтс 1
лекция нтс 1
 
Piawai 1
Piawai 1Piawai 1
Piawai 1
 
чулымцы участники вовойны
чулымцы   участники вовойнычулымцы   участники вовойны
чулымцы участники вовойны
 
à l'abri craint des vains conforts (poèmes vécus)
à l'abri craint des vains conforts (poèmes vécus)à l'abri craint des vains conforts (poèmes vécus)
à l'abri craint des vains conforts (poèmes vécus)
 
Analysis of ancillary products
Analysis of ancillary productsAnalysis of ancillary products
Analysis of ancillary products
 
Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled Presentation
 
Habilidades sociales (1)
Habilidades sociales (1)Habilidades sociales (1)
Habilidades sociales (1)
 
Blogger-blog
Blogger-blogBlogger-blog
Blogger-blog
 
El circo de las Estrellas
El circo de las Estrellas El circo de las Estrellas
El circo de las Estrellas
 
MHIT 603: Introduction to Interaction Design
MHIT 603: Introduction to Interaction DesignMHIT 603: Introduction to Interaction Design
MHIT 603: Introduction to Interaction Design
 

Ähnlich wie Rt kernel-prn

OVERVIEW OF RTOS
OVERVIEW OF RTOSOVERVIEW OF RTOS
OVERVIEW OF RTOStaruian
 
Operating System Concepts ( PDFDrive ).pptx
Operating System Concepts ( PDFDrive ).pptxOperating System Concepts ( PDFDrive ).pptx
Operating System Concepts ( PDFDrive ).pptxODINARARCH
 
Schedulability of Rate Monotonic Algorithm using Improved Time Demand Analysi...
Schedulability of Rate Monotonic Algorithm using Improved Time Demand Analysi...Schedulability of Rate Monotonic Algorithm using Improved Time Demand Analysi...
Schedulability of Rate Monotonic Algorithm using Improved Time Demand Analysi...IJECEIAES
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating SystemsPawandeep Kaur
 
Real-Time Operating Systems Real-Time Operating Systems RTOS .ppt
Real-Time Operating Systems Real-Time Operating Systems RTOS .pptReal-Time Operating Systems Real-Time Operating Systems RTOS .ppt
Real-Time Operating Systems Real-Time Operating Systems RTOS .pptlematadese670
 
IRJET- A Testbed for Real Time Water Level Control System
IRJET- 	  A Testbed for Real Time Water Level Control SystemIRJET- 	  A Testbed for Real Time Water Level Control System
IRJET- A Testbed for Real Time Water Level Control SystemIRJET Journal
 
Scheduling and Scheduler's Process and Premptive
Scheduling and Scheduler's Process and PremptiveScheduling and Scheduler's Process and Premptive
Scheduling and Scheduler's Process and Premptivechoudharyxdevansh
 
Real time os(suga)
Real time os(suga) Real time os(suga)
Real time os(suga) Nagarajan
 
Testing real-time Linux. What to test and how
Testing real-time Linux. What to test and how Testing real-time Linux. What to test and how
Testing real-time Linux. What to test and how Chirag Jog
 
Operating Systems 1 (10/12) - Scheduling
Operating Systems 1 (10/12) - SchedulingOperating Systems 1 (10/12) - Scheduling
Operating Systems 1 (10/12) - SchedulingPeter Tröger
 
Embedded Intro India05
Embedded Intro India05Embedded Intro India05
Embedded Intro India05Rajesh Gupta
 
RTOS: Scheduling policies-1 – Embedded system.pdf
RTOS: Scheduling policies-1 – Embedded system.pdfRTOS: Scheduling policies-1 – Embedded system.pdf
RTOS: Scheduling policies-1 – Embedded system.pdfKeerthiVasshini
 

Ähnlich wie Rt kernel-prn (20)

ESC UNIT 3.ppt
ESC UNIT 3.pptESC UNIT 3.ppt
ESC UNIT 3.ppt
 
Rtos Concepts
Rtos ConceptsRtos Concepts
Rtos Concepts
 
OVERVIEW OF RTOS
OVERVIEW OF RTOSOVERVIEW OF RTOS
OVERVIEW OF RTOS
 
Operating System Concepts ( PDFDrive ).pptx
Operating System Concepts ( PDFDrive ).pptxOperating System Concepts ( PDFDrive ).pptx
Operating System Concepts ( PDFDrive ).pptx
 
Schedulability of Rate Monotonic Algorithm using Improved Time Demand Analysi...
Schedulability of Rate Monotonic Algorithm using Improved Time Demand Analysi...Schedulability of Rate Monotonic Algorithm using Improved Time Demand Analysi...
Schedulability of Rate Monotonic Algorithm using Improved Time Demand Analysi...
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
Real Time Operating System
Real Time Operating SystemReal Time Operating System
Real Time Operating System
 
Rtos presentation
Rtos presentationRtos presentation
Rtos presentation
 
Real-Time Operating Systems Real-Time Operating Systems RTOS .ppt
Real-Time Operating Systems Real-Time Operating Systems RTOS .pptReal-Time Operating Systems Real-Time Operating Systems RTOS .ppt
Real-Time Operating Systems Real-Time Operating Systems RTOS .ppt
 
IRJET- A Testbed for Real Time Water Level Control System
IRJET- 	  A Testbed for Real Time Water Level Control SystemIRJET- 	  A Testbed for Real Time Water Level Control System
IRJET- A Testbed for Real Time Water Level Control System
 
Scheduling and Scheduler's Process and Premptive
Scheduling and Scheduler's Process and PremptiveScheduling and Scheduler's Process and Premptive
Scheduling and Scheduler's Process and Premptive
 
Real time os(suga)
Real time os(suga) Real time os(suga)
Real time os(suga)
 
Testing real-time Linux. What to test and how
Testing real-time Linux. What to test and how Testing real-time Linux. What to test and how
Testing real-time Linux. What to test and how
 
Event Scheduling
Event SchedulingEvent Scheduling
Event Scheduling
 
Operating Systems 1 (10/12) - Scheduling
Operating Systems 1 (10/12) - SchedulingOperating Systems 1 (10/12) - Scheduling
Operating Systems 1 (10/12) - Scheduling
 
Linux Internals - Interview essentials 4.0
Linux Internals - Interview essentials 4.0Linux Internals - Interview essentials 4.0
Linux Internals - Interview essentials 4.0
 
Lab3F22.pdf
Lab3F22.pdfLab3F22.pdf
Lab3F22.pdf
 
Pharos
PharosPharos
Pharos
 
Embedded Intro India05
Embedded Intro India05Embedded Intro India05
Embedded Intro India05
 
RTOS: Scheduling policies-1 – Embedded system.pdf
RTOS: Scheduling policies-1 – Embedded system.pdfRTOS: Scheduling policies-1 – Embedded system.pdf
RTOS: Scheduling policies-1 – Embedded system.pdf
 

Kürzlich hochgeladen

Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

Rt kernel-prn

  • 1. 1 Real-Time Operating Systems & Resource Management Tei-Wei Kuo, Ph.D. ktw@csie.ntu.edu.tw Dept. of Computer Science & Information Engineering National Taiwan University Taipei, Taiwan, ROC Remark: This set of slides comes from my class slides, my research work, slides generously provided by Dr. Jane W.S. Liu, and class slides contributed by authors of MicroC/OS-II (CMP Book). * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Contents Overview A General Architecture of Real-Time/ Embedded Operating Systems Scheduling Strategies & System Analysis Process Synchronization over IPC Handling of Sporadic Events Summary
  • 2. 2 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Overview The Purposes of Operating Systems Convenience Efficiency Characteristics of Many Real-Time/ Embedded Applications More specific in their applications. More drastic for their failures. * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Overview A Typical Control System Example Rates - sensors & actuators, peripheral, control program Phases - takeoff, cruise, and landing, etc. sensors actuators environment controlled process Task Executions Clock Display operator
  • 3. 3 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Overview Potential Timing Hazards: Loop …... Sensor(); …….. computation…… …….. t = time(); SleepTime := ReadyTime + PERIOD - t; ReadyTime = ReadyTime + PERIOD; Sleep(SleepTime); EndLoop; Loop Size? Time Elapsed Here? Timer Granularity? Real Sleep Time? ???Multiprogramming??? * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Overview General Concerns: Could I verify the performance of my system? How to avoid timing hazards? Is there any good way in scheduling processes or allocating resources? Understand your operating system and hardware, and use resources intelligently!
  • 4. 4 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Contents Overview A General Architecture of Real-Time/ Embedded Operating Systems (RTOS’s) Scheduling Strategies & System Analysis Process Synchronization over IPC Handling of Sporadic Events Summary * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. A General Architecture of RTOS’s Various Requirements Predictability – Verifiability Reliability – Strictness of Deadline Violations Reconfigurability – System Size and Functionality Efficiency of System Components – Time Granularity, Threads, and Resource Management Variable Models of Task Communication – Characteristics of Applications
  • 5. 5 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. A General Architecture of RTOS’s Objectives in the Design of Many RTOS’s Efficient Scheduling Mechanisms Good Resource Management Policies Predictable Performance Common Functionality of Many RTOS’s Task Management Memory Management Resource Control, Including Devices Process Synchronization * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. A General Architecture Bottom Half Top Half processes User Space OS hardware Timer expires to • Expire the running process’s time quota • Keep the accounting info for each process System calls such as I/O requests which may cause the releasing CPU of a process! Interrupts for Services
  • 6. 6 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. A General Architecture 2-Step Interrupt Services Immediate Interrupt Service Interrupt priorities > process priorities Time: Completion of higher priority ISR, context switch, disabling of certain interrupts, starting of the right ISR (urgent/low-level work, set events) Scheduled Interrupt Service Usually done by preemptable threads Remark: Reducing of non-preemptable code, Priority Tracking/Inheritance (LynxOS), etc. ISR I Interrupt/ISRLatency SecheduledService ISTLatency * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. A General Architecture Scheduler A central part in the kernel The scheduler is usually driven by a clock interrupt periodically, except when voluntary context switches occur – thread quantum? Timer Resolution Tick size vs Interrupt Frequency 10ms? 1ms? 1us? 1ns? Fine-grained hardware clock
  • 7. 7 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. A General Architecture – Time Granularity Clock interrupts Expiration times Timer expiration is detected! Timeout detected Timer DPCs For example, the timer granularity is equal to 1 ms or larger: * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. A General Architecture – For More Deterministic Periodicity Your timer settings Timer interrupts Starts of periods 0 1 2 3 4 5 6 0 1 2 3 4,5 6 Set the timer resolution to x. Round off all of timeout intervals to integer multiples of x!
  • 8. 8 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Performance (time stamp) counter drifts. Counters on different processors are not synchronized. A thread reads the counter on the processor where it executes. Consistent time stamps = Readings of the same counter! A General Architecture – Timer * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. A General Architecture Memory Management No protection for many embedded systems Memory-locking to avoid paging Process Synchronization Sources of Priority Inversion Nonpreemptible code Critical sections A limited number of priority levels, etc.
  • 9. 9 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Contents Overview A General Architecture of Real-Time/ Embedded Operating Systems (RTOS’s) Scheduling Strategies & System Analysis Process Synchronization over IPC Handling of Sporadic Events Summary * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Scheduling Strategies & System Analysis Why a process in my application does not meet its deadline? Factors: Impacts from the executions of higher- priority processes – preemption cost Lengthy execution time of the process Blocking time from lower-priority processes – priority inversion
  • 10. 10 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Scheduling Strategies & System Analysis Possible Questions: How do I assign priorities to processes? How are my processes scheduled by the OS? How long is the blocking time/non- preemptable critical sections (from lower- priority processes or interrupts)? Understand your schedulers Fixed-Priorities or Dynamic Priorities Preemptive or Non-Preemptive Scheduling * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Scheduling Strategies & System Analysis Scheduling Strategy Major Components of a Scheduler Priority Assignment Policy The number of priority levels, e.g., 256? Aging Effects? Priority-Driven Scheduling Mechanism Priority Queue Thread Quantum? Preemption Lock – Disabling of Preemption etc.
  • 11. 11 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Introduction to Real-Time Process Scheduling Q: Many theories and algorithms in real-time process scheduling seem to have simplified assumptions without direct solutions to engineers’ problems. Why should we know them? A: Provide insight in choosing a good system design and scheduling algorithm. Avoid poor or erroneous choices. * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Popular Process Model Periodic process each periodic process arrives at a regular frequency - a special case of demand. r: ready time, d: relative deadline, p: period, c: maximum computation time. For example, maintaining a display Sporadic process An aperiodic process with bounded inter-arrival time p. For example, turning on a light Other requirements and issues: process synchronization including precedence and critical sections, process value, etc.
  • 12. 12 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Performance Metrics Metrics for hard real-time processes: Schedulability, etc. Metrics for soft real-time processes: Miss ratio Accumulated value Response time, etc. Other metrics: Optimality, overload handling, mode- change handling, stability, jitter, etc. Combinations of metrics. * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Basic Definitions Preemptive scheduling: allows process preemptions. (vs non-preemptive scheduling) Online scheduling: allocates resources for processes depending on the current workload. (vs offline scheduling) Static scheduling: operates on a fixed set of processes and produces a single schedule that is fixed at all time. (vs dynamic scheduling) Firm real-time process: will be killed after it misses its deadline. (vs hard and soft real-time) Fixed-priority scheduling: in which the priority of each process is fixed for any instantiation. (vs dynamic-priority scheduling)
  • 13. 13 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Rate Monotonic Scheduling Algorithm Assumptions: all periodic fixed-priority processes relative deadline = period independent process - no non-preemptable resources Rate Monotonic (RM) Scheduling Algorithm RM priority assignment: priority ~ 1/period. preemptive priority-driven scheduling. Example: T1 (p1=4, c1=2) and T2 (p2=5, c1=1) Time T1 T2 T1 T2 0 1 2 3 4 5 6 7 8 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Rate Monotonic Scheduling Algorithm Critical Instant 1 An instant at which a request of the process have the largest completion/response time. An instance at which the process is requested simultaneously with requests of all higher priority processes Usages Worst-case analysis Fully utilization of the processor power Example: T1 (p1=4, c1=2) and T2 (p2=5, c1=1) 1 Liu and Layland, “Scheduling Algorithms for multiprogramming in a hard real-time Environment,” JACM, vol. 20, no. 1, January 1973, pp. 46-61. Time T1 T2 T1 T2 0 1 2 3 4 5 6 7 8 T2 T2
  • 14. 14 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Rate Monotonic Scheduling Algorithm Schedulability Test: A sufficient but not necessary condition Achievable utilization factor α of a scheduling policy P -> any process set with total utilization factor no more than α is schedulable. Given n processes, α = Stability: Let processes be sorted in RM order. The ith process is schedulable if An optimal fixed priority scheduling algorithm c p i i ∑ ( )n n 2 11/ − ( ) c p ij j j i i ≤ −=∑ 1 1 2 1/ * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Schedulability Tests – A Sufficient Condition Theorem 0 [Liu&Layland 73]: A set of n periodic processes is schedulable if the total utilization factor of the process set is no larger than Theorem 1 [Kuo, et al. 00]: Suppose that Ti-1 is schedulable. Let k be the number of roots in Ti. If the total utilization factor of Ti is no larger than then Ti is schedulable. )12( 1 −n n )12( 1 −k k 15 60 3 20 5
  • 15. 15 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Schedulability Tests – Effects of Interrupts Task Γ1 : C1 =20ms, P1 =100ms, U1=0.2 Task Γ2 : C2 =40ms, P2 =150ms, U2=0.267 Interrupt : Cint=60ms, Pint=200ms, Uint=0.3 Task Γ3 :C3 =20ms, P3 =350ms, U3=0.057 Γ1 Γ2 Γ3 Int 10 100 200 300 Exec with RM priority Γ1 Γ2 Γ3 Int 10 100 200 300 Exec with an Interrupt priority The last task was not affected! * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Schedulability Tests – Effects of Priority Mapping Ready Queue … Priority-decreasing 0-3 4-7 8-11 proc[i] proc[j] proc[k] allproc zombproc freeproc proc[j] … proc[m] … proc[n] … exit() wait() Let processes be sorted in RM order. The ith process is schedulable if ( )( ) /c p c B p ij j i i i j i i + + ≤ −= − ∑ 1 1 1 2 1
  • 16. 16 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Rate Monotonic Analysis – A Sufficient & Necessary Condition Rate Monotonic Analysis (RMA) 2 Basic Idea: Before time t after the critical instance of process τi, a high priority process τj may request amount of computation time. Formula: A sufficient and necessary condition and many extensions... 2 Sha, “An Intorduction to Rate Monotonic Analysis,” tutorial notes, SEI, CMU, 1992 Time c t p j j         t deadline of τi t pj         0 for some t in  { | ,..., ; ,..., / }kp j i k p pj i j= =1 1 ( ) i i j j ji dt p t ctW ≤≤         = ∑ =1 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Rate Monotonic Analysis – A Sufficient & Necessary Condition A RMA Example: T1(20,100), T2(30,150), T3(80, 210), T4(100,400) T1 c1 <= 100 T2 c1 + c2 <= 100 or 2c1 + c2 <= 150 T3 c1 + c2 + c3 <= 100 or 2c1 + c2 + c3 <= 150 or 2c1 + 2c2 + c3 <= 200 or 3c1 + 2c2 + c3 <= 210 T4 c1 + c2 + c3 + c4 <= 100 or 2c1 + c2 + c3 + c4 <= 150 or .... Time W3(t) 50 100 150 200 130 150 170 190 210
  • 17. 17 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Rate Monotonic Scheduling Algorithm RM was chosen by Space Station Freedom Project FAA Advanced Automation System (AAS) RM influenced the specs of IEEE Futurebus+ RMA is widely used for off-line analysis of time-critical systems. * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Earliest Deadline First Scheduling Algorithm Assumptions (similar to RM): all periodic dynamic-priority processes relative deadline = period independent process - no non-preemptable resources Earliest Deadline First (EDF) Scheduling Algorithm: EDF priority assignment: priority ~ absolute deadline. i.e., arrival time t + relative deadline d. preemptive priority-driven scheduling Example: T1(c1=1, p1=2), T2(c2=2, p2=7) Time T1 T2 0 1 2 3 4 5 6 7 8 T1 T1 T1T2 T2
  • 18. 18 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Earliest Deadline First Scheduling Algorithm Schedulability Test: A sufficient and necessary condition Any process set is schedulable by EDF iff EDF is optimal for any independent process scheduling algorithms However, its implementation has considerable overheads on OS’s with a fixed- priority scheduler and is bad for (transiently) overloaded systems. c p j j j i ≤=∑ 1 1 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Contents Overview A General Architecture of Real-Time/ Embedded Operating Systems (RTOS’s) Scheduling Strategies & System Analysis Process Synchronization over IPC Handling of Sporadic Events Summary
  • 19. 19 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Synchronization & IPC Why Inter-Process Communication (IPC)? Exchanging of Data and Control Information! Why Process Synchronization? Protect critical sections! Ensure the order of executions! * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Synchronization & IPC Critical Sections: A portion of code must be treated indivisibly. To protect shared resources from corrupting due to race conditions. Could be implemented by using interrupt enable/disable, semaphores, events, mailboxes, etc.
  • 20. 20 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Synchronization & IPC Common Facility for IPC? Shared Memory Message Transmission Common Facility for Synchronization? Semaphores Signals * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Synchronization & IPC Shared Memory Characteristics: High bandwidth and low latency, but very primitive! Needs: Ways to synchronize its access to avoid racing conditions! Potential deadlocks/ livelocks/blocking problems e.g., semaphores, bakery algorithm, etc. flag[i]=TRUE; while flag[j] ; … flag[i]=FALSE; key=TRUE; for(swap(lock,key); key==TRUE; ) swap(lock,key) ; … lock=FALSE; Example 1: Example 2: (initially, lock=FALSE) Deadlock? Livelocks?
  • 21. 21 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Synchronization & IPC Message Transmission Characteristics: Simple & clean interface with various extensions: m:m communication, multi-machines Needs: A priority-based message transmission/notification/processing mechanism e.g., message priority, non-blocking library functions, notification of msg arrivals, servicing order of msgs (with respect to other threads in the system), etc. A B OS * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Synchronization & IPC General Concerns: How to enforce mutual exclusion? We should not rely on OS scheduling to avoid race conditions! How to process critical messages first? There is a tight coupling between message processing and OS scheduling! After all, we want to manage the priority inversion problem! How to let critical jobs be done with minimized interferences from less important jobs!
  • 22. 22 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Synchronization & IPC Solutions?? Synchronization Methods Priority-Driven Resource Scheduling Support! Popular Approaches Semaphore-Based Synchronization?! Signals are too slow. Priority Inheritance?! Ceiling? * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Synchronization & IPC – Signals? The Design of Signal Mechanisms Inform processes/threads of the occurrences of exceptions or events Posting of a signal to a process An appropriate signal is added to the set of pending signals for the process. Delivering within the context of the receiver if (sig = CURSIG(p)) postsig(sig) Signal handlers: user-mode routines A B OS …
  • 23. 23 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Synchronization & IPC – Signals Questions? How fast can a signal be delivered? Complicated actions done by OS The length of a signal handler? Signal handlers are executed prior to returning control to the user code. Real-Time Support Application-defined signals Queuing of signals while being blocked. Signals are delivered in the priority order. etc * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Synchronization & IPC – Can we manage the priority inversion problem? What are the sources of priority inversion? Synchronization and mutual exclusion Nonpreemptable regions of code FIFO of any other non-priority-based queues Interrupts A limited number of priorities
  • 24. 24 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Synchronization & IPC – Can we manage the priority inversion problem? Popular Synchronization Methods Nonpreemptable Critical Sections Highest Locker’s Priority Priority Inheritance Priority Ceiling * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. 1. Nonpreemptible Critical Section Critical sections are executed at an “infinitely” high priority! Synchronization Protocols τL τM τH Note that τH & τM have no intention to enter a critical section! Time
  • 25. 25 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Synchronization Protocols 2. Highest Locker’s Priority Protocol Execute critical section at the priority of the highest-priority task that may lock the semaphore(/resource); higher-priority tasks may preempt the critical section. τL τM τH τvH Note that τvH is no longer blocked by τL Time * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. 3. Basic Inheritance Protocol (BIP) [Sha87] Execute the critical section at the priority of the highest-priority task being blocked; higher-priority tasks may preempt the critical section. S1τL τM τH τvH S1 S2 S2 S2 t blocked blocked Time - Note that τM is no longer blocked until necessary. - However, system may be deadlocked or have chained blocking! Synchronization Protocols S2S1 & S2
  • 26. 26 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. 4. Priority Ceiling Protocol [Sha87] BIP + a “Priority Ceiling” rule about when to grant lock requests (see [Sha 87, 90] ) S1τL τM τH τvH S1 S2 S1 blocked Time - No deadlock & chained blocking at the cost of reducing the concurrency level of the system. - Blocked-at-most-once. Synchronization Protocols blocked S1 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Priority Ceiling Protocol Assumptions: all periodic fixed-priority processes relative deadline = period Non-preemptable resources guarded by semaphores Basic Ideas and Mechanisms: Bound the priority inversions by early blocking of processes that could cause them, and Minimize a priority inversion’s length by allowing a temporary rise in the blocking process’s priority. Contribution of the Priority Ceiling Protocol Efficiently find a suboptimal solution with a clever allocation policy, guaranteeing at the same time a minimum level of performance.
  • 27. 27 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Priority Ceiling Protocol Pre-requirements: nested critical sections! Priority Ceiling Protocol (PCP): Define a semaphore’s priority ceiling as the priority of the highest priority process that may lock the semaphore. Lock request for a semaphore is granted only if the requesting process’s priority is higher than the ceiling of all semaphores concurrently locked by other processes. In case of blocking, the task holding the lock inherits the requesting process’s priority until it unlocks the corresponding semaphore. (Def: priority inheritance) 1 Sha, Rajkumar, and Lehoczky, “Priority Inheritance Protocols: an Approach to Real-Time Synchronization,” IEEE Transactions on computers, Vol. 39, No. 9, Sept. 1990, pp. 1,175-1,185. * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Priority Ceiling Protocol A PCP Example: deadlock avoidance Timeτ1 Timeτ2 S1 t1 attempt to lock S2 S1,S2 t2 S1 t4 priority inheritance unlock S1 and reset priority S2 S1,S2 t6 t7
  • 28. 28 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Priority Ceiling Protocol A PCP Example: avoid chain blocking Timeτ0 Timeτ1 Timeτ2 S1 t1 attempt to lock S2 S1 t2 attempt to lock S2 S1 t3 t4 priority inheritance S2 unlock S1 and reset priority S2 S1,S2 t5 t6 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Priority Ceiling Protocol A PCP Example: one priority inversion Timeτ0 Timeτ1 Timeτ2 S1 t1 attempt to lock S2 S1,S2 t2 attempt to lock S1 S1 t3 t4 priority inheritance S1 unlock S1 and reset priority t5 S2 S1,S2 t6 t7
  • 29. 29 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Priority Ceiling Protocol Important Properties: A process is blocked at most once before it enters its critical section. PCP prevents deadlocks. Schedulability Test of τi worst case blocking time Bi - an approximation! Let processes be sorted in the RM priority order –– BSi = { τj | j > i & Max(s in Sj) (ceiling(s)) >= priority(τi)} – Bi = Max(τj in BSi) |critical section| – Sj = { S | semaphore S is accessed by τj } ( )( ) /c p c B p ij j i i i j i i + + ≤ −= − ∑ 1 1 1 2 1 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Priority Ceiling Protocol Variations of PCP: Stack Resource Policy - not permitted to start unless resources are all available. multi-units per resource dynamic and fixed priority assignments Dynamic Priority Ceiling Protocol extend PCP into an EDF scheduler. 2 Baker, “Stack-Based Scheduling of Real-Time Processes,” J. Real-Time Systems, Vol. 3, No. 1, March 1991, pp. 67-99. 3 Chen and Lin, “Dynamic Priority Ceilings: A Concurrency Control Protocol for Real-time Systems,” J. Real-Time Systems, Vol. 2, No. 4, Nov. 1990, pp. 325-340.
  • 30. 30 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Summary of Synchronization Methods YesYesPriority Ceiling NoBoundedPriority Inheritance YesYesHighest Locker’s Priority YesYesNon-preemptible Critical Section Deadlock Avoidance Blocked at Once * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Remarks on Priority Inversion Symmetric Multi-Processor (SMP) Hyperthreading Deferred Procedure Call (DPC)
  • 31. 31 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Priority Inversion in SMP Threads Processors Find-ready-thread function may not select the highest priority thread! Ready-thread function may not preempt the lowest priority thread! Guarantee: The highest priority thread runs immediately after it becomes ready. * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Process Inversion on Hyperthreading Processors Systems with hyperthreading is not equivalent to those with SMP!! Threads might share components!
  • 32. 32 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. DPC: Deferred Procedure Call (Similar to tasklets in Linux) ISRs DPCs Dispatcher Interrupts Processors DPC queues P1 P2 On P1 On P2 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Threaded (Preemptive) DPC On each processor, there are: Normal DPC’s Threaded DPC’s Executed nonpreemptively ahead of threads Executed by a dedicated thread for the processor Initialize each DPC either as a normal DPC or a threaded DPC. Use a new set of spinlock functions for threaded DPC’s.
  • 33. 33 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Contents Overview A General Architecture of Real-Time/ Embedded Operating Systems (RTOS’s) Scheduling Strategies & System Analysis Process Synchronization over IPC Handling of Sporadic Events Summary * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Scheduling Aperiodic Tasks – Polling ~ Average Response Time = 50 units 99 100 – Interrupt Handler ~ Average Response Time = 1 unit 100 – Deferrable Server [Lehoczky87] ~ Average Response Time = 1 unit 1000 0 0 An on-demand service type When execution budget is used up, server execution drops to a lower (background) priority until the budgeted execution time is replenished.
  • 34. 34 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Polling Services – Modeling of Sporadic Processes Lemma 3[Mok, RTSS84]: Suppose we replace every sporadic process τi = (ci, pi, di) with a periodic process τ'i = (c'i, p'i, d'i) with c'i = ci , p'i = min(pi , (di – ci + 1)), and d'i = ci . If the result set of all periodic processes can be successfully scheduled, then the original set of processes can be scheduled without a priori knowledge of the request times of the sporadic processes. Proof. Time p'i = di – ci + 1 1 ci di * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. In general, we can replace each sporadic process τi = (ci, pi, di) with a periodic process τ'i = (c'i, p'i, d'i) if the following conditions are satisfied: [Mok, RTSS84] (1) d ≥ d' ≥ c; (2) c' = c; (3) p' ≤ d - d' + 1 Proof. Time p' = d – d' + 1 1 d' d Polling Services – Modeling of Sporadic Processes
  • 35. 35 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Deferrable Server (DS) [Lehoczky87] τ1 as a DS server to preserve CPU bandwidth for a collection of aperiodic tasks. τ1 has an entire period to use its C run-time and gets replenished at the beginning of each of its period. Theorem 3 [Lehoczky87]: For τ1 as the highest priority DS server, and τ2 … τn as periodic tasks, the achievable utilization factor is When U is minimized to 0.6518 when U1 = 0.186. J.P. Lehoczky, L. Sha, and J.K. Strosnider, “Enhancd Aperiodic Responsiveness in Hard Real-Time Environment,” RTSS’87, pp261-270. ]1) 1 2 )[(1( )1/(1 1 1 1 − + + −+= −n U U nUU ∞→n ) 12 2 ln(1 1 1 + + += U U UU * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Remarks: – Deferrable Servers: –fixed execution budget –replenishment interval –priority adjusted to meet requirements. Note that the response time performance improves as the replenishment rate decreases because the execution budget increases and more services can be provided. – Polling: –From the scheduling point of view, polling converts the servicing of aperiodic events into an “equivalent” periodic tasks. –Not an on-demand service type. –As the rate of polling increases, the response time for polling approach improves. – The rationale behind aperiodic servers: –No “system” benefit to finish periodic work early!
  • 36. 36 Sporadic Server [Sprunt et. al. 90] Modeled as periodic tasks fixed execution budget(c) replenishment interval (p) 5 5 5 0 100 200 300 Execution Budget P=100ms 100ms Replenishment occurs one “period” after the start of usage ! Priority adjusted to meet requirements. * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. A sporadic server differs from a deferrable server in its replenishment policy: A 100 msec deferrable server replenishes its execution budget every 100 msec , no matter when the execution budget is used. The affect of a sporadic server on lower priority tasks is no worse than a periodic task with the same period and execution time. Sporadic Server [Sprunt et. al. 90]
  • 37. 37 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Sporadic Server [Sprunt et. al. 90] A sporadic server (SS) under the fixed- priority scheduling framework. Terms: Ps: the priority at which the system is executing. Pi: one priority level in the system. Active: A priority level Pj is active is Pj <= Ps. Idle: not active RTi: replenishment time for SS executing at priority level Pi Brinkley Sprunt, “Aperiodic Task Scheduling for Real-Time Systems,” Ph.D. Thesis Dept. of Electrical and Computer Engineering, Carnegie Mellon University, August 1990. * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Rules: Replenishment Time RTi • If SS has execution time available, and Pi becomes active at time t, then RTi = t + Pi. • If SS’s execution time is exhausted, and SS’s execution time becomes non-zero (is replenished) at time t and Pi is active, then RTi = t + Pi. Replenishment Amount • Determined when Pi becomes idle or SS’s execution time has been exhausted. • The amount is equal to the amount of server execution time consumed since the last time at which the status of Pi changes from idle to active. Sporadic Server [Sprunt et. al. 90]
  • 38. 38 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Important theorems: Theorem 1 [Sprunt90:p28]:Given a real-time system composed of soft-real-time aperiodic tasks and hard real-time periodic tasks, let the soft real-time aperiodic tasks be serviced by a polling server that starts at full capacity and executes at the priority level of the highest priority periodic task. If the polling server is replaced with a sporadic server having the same period, execution time, and priority, the sporadic server will provide high-priority aperiodic service at times earlier than or equal to the times the polling server would provide high-priority aperiodic service. Sporadic Server [Sprunt et. al. 90] * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Theorem 5 [Sprunt90:p34]: A periodic task set that is schedulable with a periodic task Ti, is also schedulable if Ti is replaced by a sporadic server with the same period and execution time. Schedulability analysis of sporadic servers is equivalent to periodic tasks! -> overcome the penalty paid by the deferrable servers! Remark In terms of server size, the sporadic server approach is better than the deferrable server approach. Although the sporadic server approach claims low implementation overhead, it seems to be a little bit higher than the deferrable server approach. If aperiodic services are requested very heavily , the differences between DS and SS will diminish. Sporadic Server [Sprunt et. al. 90]
  • 39. 39 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. A Sporadic Server Example * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Contents Overview A General Architecture of Real-Time/ Embedded Operating Systems (RTOS’s) Scheduling Strategies & System Analysis Process Synchronization over IPC Handling of Sporadic Events Summary
  • 40. 40 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Some Ways to Better Predictability Eliminate major causes of unpredictability. (Poor hardware and drivers may block threads for a few hundred milliseconds.) Statically configure real-time components. Minimize the need for priority tracking across components and layers. Use synchronization protocols to control priority inversion. Verify drivers and applications. * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Summary Understand your operating systems and hardware! There is no substitute for intelligent resource allocation methods!
  • 41. 41 Remarks on Multiprocessor Scheduling 郭大維 教授 ktw@csie.ntu.edu.tw 即時暨嵌入式系統實驗室 (Real-Time and Embedded Systems Laboratory) 國立臺灣大學資訊工程系 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Preemptive Multiprocessor Scheduling Theorems of Mok in 1983 Goal:Understand the limitations of EDF. Conditions: different ready times. Theorem 0: Earliest-deadline-first scheduling is not optimal in the multiprocessor case. Example, T1(c=1,d=1), T2(c=1,d=2), T3(c=3,d=3.5), two processors. Theorem 1: For two or more processors, no deadline scheduling algorithm can be optimal without complete a priori knowledge of deadlines, computation times, and process start times. A.K. Mok, “Fundamental Design Problems of Distributed Systems for the Hard Real-Time Environment,” Ph.D. Thesis, Dept. of Electrical Engineering and Computer science, MIT, May 1983.
  • 42. 42 * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Multiprocessor Anomalies Theorem of Graham in 1976. Goal:Notice anomaly and provide better design. Conditions; A set of processes is optimally scheduled on a multiprocessor with some priority order, fixed execution times, precedence constraints, and a fixed number of processors. Theorem 0: For the stated problem, changing the priority list, increasing the number of processors, reducing execution times, or weakening the precedence constraints can increase the schedule length. R. Graham, “Bounds on the Performance of Scheduling Algorithms,” Computer and Job Shop Scheduling theory, E.G. Coffman, ed., John Wiley and Sons, 1976, pp. 165-227. * All rights reserved, Tei-Wei Kuo, National Taiwan University, 2002. Multiprocessor Anomalies An Example P1 P2 P1 P2