30
Håkan Sundell, [email protected] Chalmers University of Technology 1 Using Timing Information on Wait-Free Algorithms in Real-Time Systems (2 papers) Håkan Sundell Philippas Tsigas Yi Zhang Computing Science Chalmers University of Technology

Using Timing Information on Wait-Free Algorithms in Real-Time Systems (2 papers)

Embed Size (px)

DESCRIPTION

Using Timing Information on Wait-Free Algorithms in Real-Time Systems (2 papers). Håkan Sundell Philippas Tsigas Yi Zhang Computing Science Chalmers University of Technology. Real-Time System Synchronization Algorithms (Snapshot + Buffer) Bounding Experiments Conclusions Future work. - PowerPoint PPT Presentation

Citation preview

Håkan Sundell, [email protected]

Chalmers University of Technology

1

Using Timing Information on Wait-Free Algorithms in Real-Time Systems (2

papers)

Håkan Sundell

Philippas Tsigas

Yi Zhang

Computing Science

Chalmers University of Technology

Håkan Sundell, [email protected]

Chalmers University of Technology

2

Schedule

• Real-Time System

• Synchronization

• Algorithms (Snapshot + Buffer)

• Bounding

• Experiments

• Conclusions

• Future work

Håkan Sundell, [email protected]

Chalmers University of Technology

3

Real-Time System

• Multiprocessor system

• Interconnection Network

• Shared memory (with or without constraints)

CPUCPU CPUCPU

CPUCPU CPUCPU

Håkan Sundell, [email protected]

Chalmers University of Technology

4

Real-Time System

• Cooperating Tasks

• Timing constraints

• Need synchronization– Shared Data Objects

• In this presentation: Atomic Snapshot and Atomic Buffer

Håkan Sundell, [email protected]

Chalmers University of Technology

5

Synchronization

• Synchronization methods– Lock

• Uses semaphores, spinning, disabling interrupts

• Negative– Blocking

– Priority inversion

– Risk of deadlock

• Positive– Execution time guarantees easy to do

Take lockTake lock

... do operation ...... do operation ...

Release lockRelease lock

Håkan Sundell, [email protected]

Chalmers University of Technology

6

Synchronization

• Synchronization methods– Lock-free

• Retries until not interfered by other operations

• Usually uses some kind of shared flag variable

Write flag with unique valueWrite flag with unique value

... do operation ...... do operation ...

Check flag value and maybe retryCheck flag value and maybe retry

Håkan Sundell, [email protected]

Chalmers University of Technology

7

Synchronization

• Synchronization methods– Lock-free

• Negative– No execution time guarantees, can continue forever - thus

can cause starvation

• Positive– Avoids blocking and priority inversion

– Avoids deadlock

– Fast execution when low contention

Håkan Sundell, [email protected]

Chalmers University of Technology

8

Synchronization

• Synchronization methods– Wait-free

• Uses atomic synchronization primitives

• Uses shared memory

• Negative– Complex algorithms

– Memory consuming

Test&SetTest&Set

CompareCompare&Swap&Swap

CopyingCopying

HelpingHelping

AnnouncingAnnouncing

SplitSplitoperationoperation

??????

Håkan Sundell, [email protected]

Chalmers University of Technology

9

Synchronization

• Synchronization methods– Wait-free

• Positive– Execution time guarantees

– Fast execution

– Avoids blocking and priority inversion

– Avoids deadlock

– Avoids starvation

– Same implementation on both single- and multiprocessor systems

Håkan Sundell, [email protected]

Chalmers University of Technology

10

Snapshot

• Snapshot– A consistent momentous state of a set of several

shared variables– One reader

• Reads the whole set of variables in one atomic step

– Many writers• Writes to only one variable each time

Håkan Sundell, [email protected]

Chalmers University of Technology

11

Algorithm

• Wait-Free Snapshot Algorithm– Unbounded memory– Each component represented by an infinite nil-

value-initialized array, higher index for more recent values

– A global index register where all component writers writes the updated value

– The reader scans all component arrays backwards from current position

Håkan Sundell, [email protected]

Chalmers University of Technology

12

Algorithm

• Unbounded Snapshot Protocol

tv ? ? ? ? w nil nil

v ? ? ? ? w nil nil

v ? ? ? ? w nil nilc1

ci

cc

Snapshotindex ? = previous values / nilw = writer position

Håkan Sundell, [email protected]

Chalmers University of Technology

13

Algorithm (Buffer)

• Constructing an Atomic Buffer

• N-readers and N-writers

• Constraints , non-uniform memory

• Constructing of simple components

- register that can be written by processor i and read by processor j

Håkan Sundell, [email protected]

Chalmers University of Technology

14

Algorithm

• Wait-Free Atomic Shared Buffer by Vitanyi et. al• A Matrix of 1-reader 1-writer registers

... ... ...

R21 R22 …

R11 R12 ... Readers

Writers

Rij - written by i read by j

Håkan Sundell, [email protected]

Chalmers University of Technology

15

Algorithm

• The tag increases with each write operation• Unbounded maximum size for the tag field

in the value/tag pair• Assume 8 writer tasks with 10 ms period

– Maximum tag after one hour is 2880000 which needs 22 bits!

• Memory size is very important, 8 bit computers are still most common

Håkan Sundell, [email protected]

Chalmers University of Technology

16

Bounding

• Assuming system with periodic fixed-priority scheduling

• Notations from Standard Real-Time Response Time Analysis

• Use information about– Periods , T– Computation time , C– Response times , R

)(ihpjj

j

iii C

T

RCR

Håkan Sundell, [email protected]

Chalmers University of Technology

17

Bounding (Snapshot)

• We must recycle the array indexes in some way

• Keep track of the scanner versus the updaters positions

• Previous solution by Ermedahl et. al– Synchronized using atomic Test and Set

operations

Håkan Sundell, [email protected]

Chalmers University of Technology

18

Bounding

• Needed buffer length for component k

• Can be refined even further

2max*2 )(

S

Wkwrik T

Tl i

where Ts is the period for the snapshot taskTw is the period for the writer tasks

Håkan Sundell, [email protected]

Chalmers University of Technology

19

Bounding (Buffer)

• Recycling of the tags is necessary• Timing information is available in real-time

systems (J. Chen, A. Burns)• Analysing the maximum difference between tags

possible observable by a task at two consecutive invocations of the algorithm

• Using notations from the standard response time analysis for periodic fixed priority scheduling

Håkan Sundell, [email protected]

Chalmers University of Technology

20

Bounding

• In any possible execution:

• Where– Tmax is the longest period

– Rmax is the longest response time

– Twr is the period of the writer tasks

n

i Wr

n

i Wr iiT

R

T

TMaxTagDiff

1

max

1

max

Håkan Sundell, [email protected]

Chalmers University of Technology

21

Bounding

• Analyse how to recycle the tags

• Newer tags can restart from zero when we reach a certain tag value

• In order to be able to decide if newer tags are newer we need to have:

2*MaxTagDiffzeTagFieldSi

Håkan Sundell, [email protected]

Chalmers University of Technology

22

Experiments

• Using a Sun Enterprise 10000 multiprocessor computer

• 1 scanner task and 10 updater tasks, one on each cpu

• Comparing two wait-free snapshot algorithms– Using timing information– Using test and set synchronization

Håkan Sundell, [email protected]

Chalmers University of Technology

23

Experiments

• 7 different scenarios

Scenario Scan Period (us)

Update Period (us)

Buffer Length

1 500 50 3

2 200 50 3

3 100 50 3

4 50 50 4

5 50 100 6

6 50 200 10

7 50 500 22

Håkan Sundell, [email protected]

Chalmers University of Technology

24

Experiments• Scan operation - Average Response Time

Håkan Sundell, [email protected]

Chalmers University of Technology

25

Experiments• Update operation – Average Response Time

Håkan Sundell, [email protected]

Chalmers University of Technology

26

Examples (Buffer)

• Example Task Scenario on 8 processors

Task Period Task Period

Wr1 1000 Rd1 500

Wr2 900 Rd2 450

Wr3 800 Rd3 400

Wr4 700 Rd4 350

Wr5 600 Rd5 300

Wr6 500 Rd6 250

Wr7 400 Rd7 200

Wr8 300 Rd8 150

Håkan Sundell, [email protected]

Chalmers University of Technology

27

Examples

• Tmax = Rmax = 1000

• MaxTagDiff = 38

• TagFieldSize = 76

• TagFieldBits = 7

• Unbounded algorithm would have reached tag 68400 in one hour , needing >16 bits

Håkan Sundell, [email protected]

Chalmers University of Technology

28

Conclusions (Snapshot)• Update operation

– Using timing information gives up to 400 % better performance

• Scan operation– Using timing information gives up to 20 % better

performance in common practical scenarios

• Update operation is much more frequent than Scan– Timing information can improve the performance

significantly

• Simpler algorithm

Håkan Sundell, [email protected]

Chalmers University of Technology

29

Conclusions (Buffer)

• We have presented an atomic n-reader n-writer shared buffer.

• Usage of timing information enables us to recycle the tags and thus bound the memory usage

• The modified algorithm has small space requirements

Håkan Sundell, [email protected]

Chalmers University of Technology

30

Future work

• Investigations of other wait-free synchronization methods

• Implementations in RTOS kernels