where have we been? • kernel services • task dispatching...

23
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

Upload: others

Post on 07-Aug-2020

3 views

Category:

Documents


0 download

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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;