Chapter 8 - Self-Stabilizing Computing1 Chapter 8 – Self-Stabilizing Computing Self-Stabilization...
-
date post
19-Dec-2015 -
Category
Documents
-
view
217 -
download
2
Transcript of Chapter 8 - Self-Stabilizing Computing1 Chapter 8 – Self-Stabilizing Computing Self-Stabilization...
chapter 8 - Self-Stabilizing Computing 1
Chapter 8 – Self-Stabilizing
Computing
Self-StabilizationShlomi DolevMIT Press , 2000
Draft of January 2004Shlomi Dolev, All Rights Reserved ©
chapter 8 - Self-Stabilizing Computing 2
Chapter 8: roadmap
8.1 The Computation Power of Self-Stabilizing Systems
8.2 Queue Machine
chapter 8 - Self-Stabilizing Computing 3
The Computation Power of Self-Stabilizing Systems
l
l
l
l l
l
l
l
n
1 2
n
. ..
.
chapter 8 - Self-Stabilizing Computing 4
Modeling the problem The single processor is modeled by a
Universal-Turing-Machine* (UTM) The distributed system will simulate the UTM
in a self-stabilized fashion The distributed system topology will be a
simple chain of n processors, each processor represents a single working cell
* note: The use of UTM eliminates the transition table size factor, since we use the code of the algorithm as part of the input
chapter 8 - Self-Stabilizing Computing 5
Token passing with a constant amount of memory
The distributed system uses a version of Dijkstra’s second mutual exclusion algorithm:
The algorithm simulates a token with a color field of three values
P1 Pn
chapter 8 - Self-Stabilizing Computing 6
Version of Dijkstra’s mutual exclusion algorithm:
01 P1
02 lr2,1.color r2,1.color 03 if lr2,1.color r1,2.color then04 r1,2.color (r1,2.color + 1) (mod 3)01 Pi (i 1, n)
02 lri-1,i.color ri-1,i.color03 ri,i+1.color lri-1,i.color04 lri+1,i.color ri+1,i.color05 if lri+1,i.color lri-1,i.color then06 ri,i-1.color lri+1,i.color01 Pn
02 lrn-1, n.color rn-1, n.color 03 rn, n -1.color lrn-1, n.color
chapter 8 - Self-Stabilizing Computing 7
Self-Stabilization of the algorithm
Lemma 8.1: In every fair execution, P1 changes
the value of r1,2.color infinitely often
Lemma 8.2: In every fair execution, a configuration is reached in which all the color fields of the communication registers and internal variables have identical values
chapter 8 - Self-Stabilizing Computing 8
By using these Lemmas (8.1, 8.2) we can see the algorithm works as expected. Once the safe configuration has been achieved, the token will traverse the chain
Self-Stabilization of the algorithmSelf-Stabilization of the algorithm
chapter 8 - Self-Stabilizing Computing 9
A simple running example
P1,C1 P2,C1 P3,C2
r1,21
lr2,12
r3,22
lr2,32
r2,11
r2,30
lr1,20
lr3,22
Lets look at a system with three processors that start at a random configuration:
Ci is the state of the processor (the line in the code it’s about to execute).
chapter 8 - Self-Stabilizing Computing 10
A simple running example
P1,C2 P2,C1 P3,C2
r1,21
lr2,11
r3,22
lr2,32
r2,11
r2,30
lr1,20
lr3,22
P1 executes line 2: it reads the value of r2,1 into the local variable lr2,1 .
chapter 8 - Self-Stabilizing Computing 11
A simple running example
P1,C2 P2,C2 P3,C2
r1,21
lr2,11
r3,22
lr2,32
r2,11
r2,31
lr1,21
lr3,22
P2 executes line 2: it reads the value of r1,2 into the local variable lr1,2
chapter 8 - Self-Stabilizing Computing 12
A simple running example
P1,C2 P2,C3 P3,C2
r1,21
lr2,11
r3,22
lr2,32
r2,11
r2,31
lr1,21
lr3,22
P2 executes line 3: it writes the value of lr1,2 into r2,3
chapter 8 - Self-Stabilizing Computing 13
A simple running example
P1,C2 P2,C4 P3,C2
r1,21
lr2,11
r3,22
lr2,32
r2,11
r2,31
lr1,21
lr3,22
P2 executes line 4: it reads the value of r3,2 into lr3,2 .Line 6 is not executed since lr1,2 ≠ lr3,2 .
chapter 8 - Self-Stabilizing Computing 14
A simple running example
P1,C2 P2,C4 P3,C2
r1,21
lr2,11
r3,22
lr2,31
r2,11
r2,31
lr1,21
lr3,22
P3 executes line 2: it reads the value of r2,3 into the local variable lr2,3
chapter 8 - Self-Stabilizing Computing 15
A simple running example
P1,C2 P2,C4P3,C3 (a full round)
r1,21
lr2,11
r3,21
lr2,31
r2,11
r2,31
lr1,21
lr3,22
P3 executes line 3: it writes the value of lr2,3 into r3,2
chapter 8 - Self-Stabilizing Computing 16
A simple running example
P1,C2 P2,C2-6 P3,C1
r1,21
lr2,11
r3,21
lr2,31
r2,11
r2,31
lr1,21
lr3,21
SAFE!!!
P2 executes lines 2-6 and we gate a safe configuration…
chapter 8 - Self-Stabilizing Computing 17
The Simulation
Each processor represents a working tape cell.The processor’s input represents the initial
configuration of the UTM.The processor’s output represents the
UTM’s decision,i.e. output = 1 (0) UTM accepted (rejected) the input using no more than n working tape cells.
chapter 8 - Self-Stabilizing Computing 18
The Simulation
Each processor maintains 3 local variables:1. HeadMarki (1-bit) – true if the head is
currently on the working tape cell this processor simulates.
2. WorkSymboli (2-bit) – the current content of the tape cell.
3. Counteri (2-bit) – used to bound the execution of the simulation, and initialize it from time to time. (will be explained soon)
chapter 8 - Self-Stabilizing Computing 19
The number of configurations A certain UTM exists , thus the number of states C is
bounded by 56 [Hopcroft & Ullman 1979] which possesses:
n memory bits which can contain 2n different tape contents.
n possibilities for the location of the first ⊥. n possibilities for the location of the reading head Thus: cn2 2n is the total number of the UTM’s
configurations. Note: for n 14 : 22n cn2 2n.
So a UTM execution that exceeds 22n steps (configurations) must repeat at least one configuration twice, resulting in an infinite loop.
How to maintain a distributed counter that count up to 22n ?
chapter 8 - Self-Stabilizing Computing 20
All processors maintain a distributed counter using their local variable Counteri.
The system is initialized when counter overflow occurs. (increasing the counter in the following example will end up in initialization)
System initialization
P3 P2 P1
11
11
11
In this example the value of the counter is 63.
chapter 8 - Self-Stabilizing Computing 21
A Simple Example
P3 P2 P1
11
11
10
Carry:0Reset:0
I am the token,
moving leftI am a counter
I am a processor
MSB LSB
Rest is 1 there is an overflow
chapter 8 - Self-Stabilizing Computing 22
A Simple Example
P3 P2 P1
11
11
10
Carry:0Reset:0
The start configuration of this example, the token is moving to the left.
chapter 8 - Self-Stabilizing Computing 23
A Simple Example
P3 P2 P1
11
11
10
Carry:0Reset:0
chapter 8 - Self-Stabilizing Computing 24
A Simple Example
P3 P2 P1
11
11
10
Carry:0Reset:0
chapter 8 - Self-Stabilizing Computing 25
A Simple Example
P3 P2 P1
11
11
11
Carry:0Reset:0
P1 increments the counter without generating a carry
chapter 8 - Self-Stabilizing Computing 26
A Simple Example
P3 P2 P1
11
11
11
Carry:0Reset:0
chapter 8 - Self-Stabilizing Computing 27
A Simple Example
P3 P2 P1
11
11
11
Carry:0Reset:0
chapter 8 - Self-Stabilizing Computing 28
A Simple Example
P3 P2 P1
11
11
11
Carry:0Reset:0
chapter 8 - Self-Stabilizing Computing 29
A Simple Example
P3 P2 P1
11
11
00
Carry:1Reset:0
P1 increments the counter which results in generating a carry
chapter 8 - Self-Stabilizing Computing 30
A Simple Example
P3 P2 P1
11
00
00
Carry:1Reset:0
chapter 8 - Self-Stabilizing Computing 31
A Simple Example
P3 P2 P1
00
00
00
Carry:1Reset:1
P3 doesn’t have the option to pass on the carry (which means an overflow) and it start a reset.
chapter 8 - Self-Stabilizing Computing 32
A Simple Example
P3 P2 P1
00
00
00
Carry:0Reset:1
chapter 8 - Self-Stabilizing Computing 33
A Simple Example
P3 P2 P1
00
00
00
Carry:0Reset:1
Reset finished, and:
HeadMark1 = true
i ≠ 1:HeadMarki = false
chapter 8 - Self-Stabilizing Computing 34
The Simulation When processor Pi, with HeadMarki = true,
receives the token, it computes the next step, i.e. WorkSymboli, State, Right/Left, using:
1. Current state, retrieved from the token.2. WorkSymboli.
3. UTM’s transition table. The head movement is simulated by sending
the token to the Right (or Left) neighbor and changing its HeadMark value to be true.
When a processor reaches a decision state it notifies all other to write the correct output.
chapter 8 - Self-Stabilizing Computing 35
A Simple Example
P1 P2 P3
Set head:truestate: q1
HeadMark false
Working Cell
0
counter 01
Move head Ø
output 0
HeadMark true
Working Cell
1
counter 00
Move head Ø
output 0
HeadMark false
Working Cell
1
counter 00
Move head Ø
output 1
I am the token, moving
left
A token arrives to P2, with “set head = true”.
chapter 8 - Self-Stabilizing Computing 36
P2 consults the UTM transition table, and decides to write 0, and move right. Since the token is moving left now (until it get to the end) P2 will remember to set the HeadMark when the token returns.
A Simple Example
P1 P2 P3
HeadMark false
Working Cell
0
counter 01
Move head Ø
output 0
HeadMark true
Working Cell
1
counter 00
Move head R
output 0
HeadMark false
Working Cell
1
counter 00
Move head Ø
output 1
chapter 8 - Self-Stabilizing Computing 37
A Simple Example
P1 P2 P3
Set head:falsestate: q26
HeadMark false
Working Cell
0
counter 11
Move head Ø
output 0
HeadMark false
Working Cell
0
counter 00
Move head R
output 0
HeadMark false
Working Cell
1
counter 00
Move head Ø
output 1
P1 is working and increase the counter, but doesn’t calculate a UTM step since the W/R head is not in his cell.
chapter 8 - Self-Stabilizing Computing 38
A Simple Example
P1 P2 P3
Set head:falsestate: q26
HeadMark false
Working Cell
0
counter 11
Move head Ø
output 0
HeadMark false
Working Cell
0
counter 00
Move head R
output 0
HeadMark false
Working Cell
1
counter 00
Move head Ø
output 1
P2 remember that the W/R head should move right so he will change the Set head to be true
chapter 8 - Self-Stabilizing Computing 39
A Simple Example
P1 P2 P3
Set head:truestate: q26
HeadMark false
Working Cell
0
counter 11
Move head Ø
output 0
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 0
HeadMark true
Working Cell
1
counter 00
Move head Ø
output 1
chapter 8 - Self-Stabilizing Computing 40
Token arrived at P3, with “set head = true”.P3 consults the UTM transition table, and decides to write 1 change the state to 32, and move left (note; the token travels left now!).
A Simple Example
P1 P2 P3
HeadMark false
Working Cell
0
counter 11
Move head Ø
output 0
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 0
HeadMark true
Working Cell
1
counter 00
Move head L
output 1
chapter 8 - Self-Stabilizing Computing 41
A Simple Example
P1 P2 P3
Set head:truestate: q32
HeadMark false
Working Cell
0
counter 11
Move head Ø
output 0
HeadMark true
Working Cell
1
counter 00
Move head Ø
output 0
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
chapter 8 - Self-Stabilizing Computing 43
A Simple Example
P1 P2 P3
HeadMark false
Working Cell
0
counter 11
Move head Ø
output 0
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
Token arrived at P2, with “set head = true”.P2 consults the UTM transition table, and decides to accept. P2 will place a clear message in the token.
HeadMark true
Working Cell
1
counter 00
Move head Ø
output 0
chapter 8 - Self-Stabilizing Computing 44
A Simple Example
P1 P2 P3
Set head:truestate: qaccept
HeadMark false
Working Cell
0
counter 11
Move head Ø
output 0
HeadMark true
Working Cell
0
counter 00
Move head Ø
output 1
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
chapter 8 - Self-Stabilizing Computing 45
A Simple Example
P1 P2 P3
ClearResult:1
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
chapter 8 - Self-Stabilizing Computing 46
A Simple Example
P1 P2 P3
ClearResult:1
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
chapter 8 - Self-Stabilizing Computing 47
A Simple Example
P1 P2 P3
ClearResult:1
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
chapter 8 - Self-Stabilizing Computing 48
A Simple Example
P1 P2 P3
ClearResult:1
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
chapter 8 - Self-Stabilizing Computing 49
A Simple Example
P1 P2 P3
ClearResult:1
HeadMark true
Working Cell
0
counter 10
Move head Ø
output 1
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
HeadMark false
Working Cell
0
counter 00
Move head Ø
output 1
Now, P1 will start the computation again.
chapter 8 - Self-Stabilizing Computing 50
Chapter 8: roadmap
8.1 The Computation Power of Self-Stabilizing Systems
8.2 Queue Machine
chapter 8 - Self-Stabilizing Computing 51
What is a Queue Machine?
A queue machine Q is a finite state machine equipped with a queue. The queue initially contains a non-empty word from ∑for some (finite) alphabet ∑ .
In each step of the computation, Q performs:1) Reads and deletes a letter from the head of the queue.2) Adds zero or more letters from ∑ to the tail of the queue.3) Changes a state.
The computation terminates when the queue becomes empty.
+
chapter 8 - Self-Stabilizing Computing 52
Token Controller - Definition
Token controller is a special type of a queue machine.
Assume that the alphabet ∑ contains a subset T oftoken letters.A queue machine is a token controller if, starting with a non-empty queue of arbitrary content and in an arbitrary state of the finite-state machine, eventually there is exactly 2 different segments,
eachof them contains exactly one letter from T.
chapter 8 - Self-Stabilizing Computing 53
Token Controller - Definition
The token controller is an abstraction of the token-passing task.
The sender is the finite-state machine that receives(finite-length) messages and sends massages in response. The massages in transit form the
contentof the queue.
Token controller messages
chapter 8 - Self-Stabilizing Computing 54
Does a Token Controller exist ?
The Controller, if exists, cannot compute any estimation of the number of tokens in the queue.
The Controller is finite and the queue may
contain any number of messages hence the finite control cannot “remember” what he saw.
The solution: all the information needed is stored within the queue. The controller makes decisions while the messages are passing.
chapter 8 - Self-Stabilizing Computing 55
Token Controller Algorithm
01 do forever02 dequeue (color, CounterBit, Token)03 if color = TokenColor then (*token arrives*)04 begin05 if carry = 1 then enqueue (color, 1, false)06 TokenColor := (color + CounterXor +1)(mod
3)07 CounterXor := 008 carry := 109 Token := true10 end11 CounterXor := CounterXor CounterBit12 NewCounterBit := carry CounterBit13 carry := carry CounterBit14 enqueue (TokenColor, NewCounterBit, Token)15 Token := false16 od
chapter 8 - Self-Stabilizing Computing 56
Token Controller Algorithm The algorithm uses three colors to color the
messages it sends. TokenColor - the current color.
Each message caries a bit - CounterBit. A segment of messages is a maximal sequence of
messages in the queue with identical color. CounterBit1 is the first massage who left the controller.
N (segment) - the integer whose binary form is: CounterBiti , CounterBiti -1 … CounterBit1
N=41 0 0 0 1
1
1
0 1 1 1
CounterBit1 is the least significant bit
chapter 8 - Self-Stabilizing Computing 57
Token Controller Algorithm
While a segment passes, the Controller performs:
1) Change the color of each massage to TokenColor .
2) Calculate XOR (N ( segment ) ).3) Increments N(segment) by binary addition
(using the carry).4) When a segment with TokenColor arrives
calculate the new color.
chapter 8 - Self-Stabilizing Computing 58
Distributed counter
1 1 0 0 1
Token color = 1Carry = 0counterXor = 0 …
Red = 0
Turquoise= 1
Orange = 2
The current color of the
controller
The color of the head massage:
Color = 10
1 0 0 1
Token color = 2Carry = 1counterXor = 1 …
chapter 8 - Self-Stabilizing Computing 59
Distributed counter (cont)
0
0 0 1
Token color = 2Carry = 1counterXor = 0 …
0
0
0 0 1
Token color = 0Carry=1counterXor = 0
01
…
chapter 8 - Self-Stabilizing Computing 60
Distributed counter (summary)
1 1 0 100…
Token color = 1Carry = 1counterXor = 0
1 1 0 0 1
Token color = 1Carry = 1counterXor = 0 …
Starting at this
configuration we will eventually
arrived to configuration without green colored massages
chapter 8 - Self-Stabilizing Computing 61
Distributed counter (summary)
1 1 0 100
Token color = 1Carry = 1counterXor = 0
And we will eventually
arrived to configuration with only one color at the messages.
1 1 0 100…
Token color = 1Carry = 1counterXor = 0
chapter 8 - Self-Stabilizing Computing 62
pseudo-stabilized configuration
When in some configuration c, a message with TokenColor arrives, we say that c is a pseudo-stabilized configuration.
A pseudo-stabilized configuration is a safe configuration when there is only one segment in c.
chapter 8 - Self-Stabilizing Computing 63
S1
S3
S2
S4
The Number of Segments
S'1
S3S2
S4
New color = color(S2)
The Number of Segments Preserves
chapter 8 - Self-Stabilizing Computing 64
S1
S3
S2
S4
The Number of Segments
S1’+S2’
S3
S4
New color = color(S3)
The Number of Segments Reduces
chapter 8 - Self-Stabilizing Computing 65
Token Controller, is Self-Stabilizing
The colors of the segments in the first pseudo-configuration define the periodic sequence that must be used to preserve the number of segments.
If the sender chooses differently and the number of segments is greater then one, then the number of segments is reduced.
Define Xor(x) as the parity of the binary representation of x.
XorSeq = xor(0), xor(1), xor(2), xor(3)… = 0 1 1 0… is eventually aperiodic (Lemma 8.3).
chapter 8 - Self-Stabilizing Computing 66
Lemma 8.3: The Infinite Sequence XorSeq is Eventually Aperiodic - proofl and p numbers such that the suffix of XorSeq that follows the first l elements of XorSeq is periodicwith period of length p.
Case 1 : xor(p) = 1 . o Let l1 = 2k such that 2k-1 > l and l1 > 2p .o xor ( l1 + p ) = 0 , xor ( l1 ) = 1.o Example: p = 11111, xor ( p ) = 1. l1 = 1000000 , xor ( l 1) = 1.
xor ( l1 + p ) = xor ( 1011111 ) = 0 The suffix that follows l has no period p.
l l+p
l+2p l+3p …l1
chapter 8 - Self-Stabilizing Computing 67
Lemma 8.3 – proof (cont)
Case 2 : xor (p) = 0 .o Let l2 = 2j such that 2j p 2j+1 ( 2j is the most
significant bit of p ).o xor ( p + l2 ) = xor ( p ) = 0 .
o xor ( l1 + p + l2 ) = 1, while xor ( l1 + l2 ) = 0. o Example: p = 11110, xor( p ) = 0. l1 = 1000000 , l2 = 10000.
xor ( p + l2 ) = xor(101110) = 0.
xor ( l1 + l2 ) = xor ( 1010000 ) = 0.
xor ( l1 + p + l2 ) = xor ( 1101110 ) = 1.
chapter 8 - Self-Stabilizing Computing 68
Token Controller, is Self-Stabilizing
Theorem 8.1 : In any execution in which the number of segments in the pseudo-stabilized configuration isfixed, the sequence of colors produced by thealgorithm is aperiodic. Proof :
o The sequence CounterXor is aperiodic for each segment.
o If the combined sequence is periodic then each sequence is periodic.
o CounterXor is aperiodic, so the sequence of colors choose by the algorithm is aperiodic.