where have we been? • kernel services • task dispatching...
TRANSCRIPT
![Page 1: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/1.jpg)
Synchronization - 1
Where Have We Been?
• Kernel Services
• Task Dispatching
• Task Scheduling
• Intertask Communication (For today)
• Scheduling Algorithms
• Rate Monotonic Algorithm (RMA)• Optimal static priority, periodic task scheme
• Earliest Deadline First (EDF)• Optimal dynamic priority, periodic task scheme
• Maximum Urgency First (MUF)• Predictable Dynamic Priority
• Deferred Server (DS)• Approach to handling sporadic tasks
• RTOS Overhead
• Synchronization and Communication
![Page 2: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/2.jpg)
Synchronization - 2 Real-Time Systems
Critical Regions
Area of code accessing serially reusable resources
• Collision - Simultaneous use of a single, serially reusable resource
• Semaphore - a lock that protects critical regions
Mutual Exclusion mechanism required
![Page 3: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/3.jpg)
Synchronization - 3 Real-Time Systems
Why Not Just Use a Software Flag?
while (critical_region_in_use);critical_region_in_use = TRUE;
use_critical_region();
critical_region_in_use = FALSE;
![Page 4: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/4.jpg)
Synchronization - 4
Semaphores
• Special memory location that acts as a lock
• Semaphore Primitives
• wait - P(S)
• signal - V(S)
• Must Be Atomic
• Test-and-set instruction
• Lock out interrupts or task swapping
Binary Semaphore [PL] p. 176
![Page 5: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/5.jpg)
Synchronization - 5
Counting Semaphores [PL] p. 178
• Protect a Set of Resources
• Wait (assumed atomic)int S1 = MAX_COUNT-1; /* init semaphore */void MP(int *S){
while (*S < 0); /* “spin lock” */*S -= 1;
}
• Signal (assumed atomic)void MV(int *S){
*S += 1;}
• Preferred Method is to Suspend and Resume
![Page 6: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/6.jpg)
Synchronization - 6
Priority Inversion (sophisticated case) [JC] 9.3.3
• Tasks T1, T2, T3 in Priority Order
• Tasks T1 and T3 Access Same Shared Resource
T3 T2T1
e3
e2e1
SR
SR
T1 preempts T3 T1 suspends
(spin lock causesdeadlock)
T2 preempts T3 T1 preempts T3 again
![Page 7: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/7.jpg)
Synchronization - 7
Priority Inheritance [KS] p. 68, [JL] p. 286
• Solution: Prevent Task Swapping During Lock
• Better Solution: Bump Up Priority
• Priority Inheritance : (T1 > T2 > T3)
• T1 Blocks on a Locked Semaphore (suspends)
• If T1 is Blocked on T2’s Lock, T2’s Priority = T1’s
• When T2 Unlocks, T2 Priority Reverts
• Priority Inheritance is Transitive• T3 Blocks T2 which Blocks T1; T3 Inherits Priority of T1 through T2
• Tx can Preempt Ty if Tx not Blocked and Current Pri-ority of Tx > Current Priority of Ty
![Page 8: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/8.jpg)
Synchronization - 8
Priority Inheritance
• Tasks T1, T2, T3 in Priority Order
• Tasks T1 and T3 Access Same Shared Resource
T3 T2T1
e3
e2e1
SR
SR
T1 preempts T3 T1 blocks
T3 inheritsT1 priority
T2 releases (T3 now has T1 priority)
T1 preempts T3 again
T3 unlocks SRreverts priority
![Page 9: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/9.jpg)
Synchronization - 9
Priority Ceiling Protocol [KS] p. 69, [JL] p. 290
• Priority Inheritance can still Deadlock
• T1 > T2
• T1: P(S1); P(S2); V(S2); V(S1); (properly nested)
• T2: P(S2); P(S1); V(S1); V(S2); (properly nested)
• If T2 starts first and T1 preempts before P(S1) :-(
• Priority Ceiling Protocol
• Priority Ceiling is Highest Priority of Any Task that may Lock It
• T1 Blocks when Any Semaphore with Equal or Higher Ceiling is Locked
![Page 10: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/10.jpg)
Synchronization - 10
Priority Ceiling Protocol
• Tasks T1, T2, T3 in Priority Order
• Tasks T1 and T3 Access Same Shared Resources
T3 T2T1
e3
e2e1
S2
S1
T1 preempts T3 T1 blocks
T3 inheritsT1 priority
T2 releases (T3 now has T1 priority)
T1 preempts T3 again
T3 unlocks S2reverts priority
S1
S2
![Page 11: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/11.jpg)
Synchronization - 11
Mailboxes - Communication and Synchronization
• Known Memory Location with Key
• Post - write to the location
• Pend - read from the location
• Scheduler allows Post and Pend operations
• If no key in the mailbox, the task blocks
• Accept or Check operation - don’t block if no key
• Scheduler checks for keys and unblocks tasks
• Mailbox Interrupt may force this (no busy waiting)
• Mailbox queues (pending requests)
![Page 12: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/12.jpg)
Synchronization - 12
Communication Methods
• Global Variables
• Double Buffers
• Time-Relative Data (correlated)
• Triple Buffers ( Chimera )
• Ring Buffers (Circular Queue)
• Message Passing
![Page 13: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/13.jpg)
Synchronization - 13
Message Passing
• Setup Message Queues for message packets
• Use Mailboxes
• Secure Point-to-Point Communciation
• One-to-One
• One-to-Many
• Many-to-One
• Often Implemented as UNIX-Style Sockets
• Fairly High Overhead
Chimera: msgCreate(), msgAttach(), msgDetach(),msgSend(), msgReceive(), msgKill()
![Page 14: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/14.jpg)
Synchronization - 14
Chimera State Variables
• Global Variables
• Provably Optimum Communication Performance
• Automatic Multiprocessor Address Resolution
• No Operational Overhead
• Overhead only during initialization
• Point-to-Point Communciation
• One-to-One
• One-to-Many
• Many-to-One (Join Connector) Implemented as Module
![Page 15: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/15.jpg)
Synchronization - 15
Chimera Block Diagrams
• Simple Processor-Inspecific Construction of Apps
• Amenable to Visual Programming
![Page 16: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/16.jpg)
Synchronization - 16
Graphical Programming with Chimera - STD’s
create
destroy
reset
halt
start initHand1
Preshape&Move1
Grasp1
ViaMove1
GuardedMove1
Ungrasp1
initHand2
Preshape&Move2
Grasp2
ViaMove2
GuardedMove2
Ungrasp2
ViaMove3
end
![Page 17: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/17.jpg)
Synchronization - 17
Onika Visual Programming
![Page 18: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/18.jpg)
Synchronization - 18
Virtual Programing Interface
![Page 19: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/19.jpg)
Synchronization - 19
Virtual Programming Interface
![Page 20: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/20.jpg)
Synchronization - 20
ControlShellTM Block Diagrams
Real-Time Innovations, Inc. (www.rti.com)
![Page 21: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/21.jpg)
Synchronization - 21
StethoScopeTM Real-Time Data Logging
Real-Time Innovations, Inc. (www.rti.com)
![Page 22: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/22.jpg)
Synchronization - 22 Real-Time Systems
System Optimization
• Compute Tasks at Slowest Cycle Possible
• Ex: Helicopter cabin temperature
• Use Scaled Integer Arithmetic
• Integer Calculations Faster Than Floating Point
• Mostly I/O-Based with Finite Precision
• Use Look-Up Tables for Complex Functions
• Very Slow Transcendental Functions: Sine, Co-sine, Tangent
• Application-Dependent Mappings
• Non-Linear Functions
![Page 23: Where Have We Been? • Kernel Services • Task Dispatching ...rvoyles/Classes/RealTimeSystems_files/... · • Preferred Method is to Suspend and Resume. Synchronization - 6 Priority](https://reader034.vdocuments.mx/reader034/viewer/2022050508/5f9995944bd5cb70d92ecd11/html5/thumbnails/23.jpg)
Synchronization - 23
Code Optimization
• Eliminate Arithmetic Identities
a + 0, b * 1
• Reduction in Strength
Use fastest instruction per task
• Common Subexpression Elimination
• Use of Registers and Caches
see above
• Intrinsic Functions
in-line code and macros
x = y + a * b; t = a * b;
y = a * b + z; x = y + t;
y = t + z;