Detecting Access Anomalies in Programs with Critical Sections

14
Detecting Access Anomalies in Programs with Critical Sections Anne Dinning Edith Schonberg 2010. 4. 3 OSLab

description

Detecting Access Anomalies in Programs with Critical Sections. Anne Dinning Edith Schonberg 2010. 4. 3 OSLab. Access Anomaly. At least one access is a write The two tasks do not synchronize between the accesses. i = 2. i = 1. doall i = 1, N … X := i + 7 endall Y := X * 3. - PowerPoint PPT Presentation

Transcript of Detecting Access Anomalies in Programs with Critical Sections

Page 1: Detecting Access Anomalies in Programs with Critical Sections

Detecting Access Anomalies in Pro-grams with Critical Sections

Anne DinningEdith Schonberg

2010. 4. 3OSLab

Page 2: Detecting Access Anomalies in Programs with Critical Sections

2

Access Anomaly

At least one access is a write The two tasks do not synchronize between the accesses

X := i + 7X := i + 7

i = 1 i = 2

Y := X * 3

8 = 1 + 7 9 = 2 + 7

i = 1: 24 = 8 * 3 i = 2: 27 = 9 * 3 nondeterministic result

doall i = 1, N…X := i + 7

endallY := X * 3

Page 3: Detecting Access Anomalies in Programs with Critical Sections

3

POEG (Partial Order execution Graph)

X := Y

lock (L)

Y := Y + i

unlock (L)

lock (L)

Y := Y + i

unlock (L) unlock (L)

Y := Y + i

lock (L)

X := i

task-terminate ( )

task-create (3)

Vertices - parallel operations (task create/terminate, lock/unlock) - an instruction blockEdges - execution ordering of parallel operations

Page 4: Detecting Access Anomalies in Programs with Critical Sections

4

On-the-fly detection

Advantage – diagnostic precision– space efficient (cf. traced-based methods)

Restriction – SISE property (single input, single execution)

A single execution instance is sufficient to determine

the existence of an anomaly for a given input.

Page 5: Detecting Access Anomalies in Programs with Critical Sections

5

On-the-fly detection using the POEG

Information– Which blocks are ordered (tag)– What variables are accessed by each block

Access history– Readers (X), Writers (X) (a variable X)– Only the most recent accesses

The maximum parallelismOf the program

At most of a single tag

Readers (X) Writers (X)

guaranteed to detect at least one anomaly

Page 6: Detecting Access Anomalies in Programs with Critical Sections

6

procedure Subtract-Read(X)for all a in Readers(X) do

if Ordered(current-tag, a) then delete a from Readers(X)endforadd current-tag to Readers(X)

end procedure

procedure Subtract-Write(X)Readers(X) = ØWriters(X) = {current-tag}

end procedure

procedure Check-Read(X)for all a in Writers(X) do

if not Ordered(current-tag, a) then report Access Anomalyendfor

end procedure

procedure Check-Write(X)for all a in Readers(X) U Writers(X) do

if not Ordered(current-tag, a) then report Access Anomalyendfor

end procedure

Check for Read and Write Events

Subtraction for Read and Write Events

Page 7: Detecting Access Anomalies in Programs with Critical Sections

7

Problems with POEG representation

X := Y

lock (L)

Y := Y + i

unlock (L)

lock (L)

Y := Y + i

unlock (L) unlock (L)

Y := Y + i

lock (L)

X := i

task-terminate ( )

task-create (3)

Page 8: Detecting Access Anomalies in Programs with Critical Sections

8

Properties of unlock-lock edges

Accesses inside critical sections protected by the same lock L never appear as access anomalies

Accesses that occur before and after critical sections, as well as ac-cesses within critical sections, are ordered by these edges.

L L

r w

L Lr

w

Page 9: Detecting Access Anomalies in Programs with Critical Sections

9

Lock Covers

X := Y

lock (L)

Y :=L Y + i

unlock (L) unlock (L)

Y := L Y + i

lock (L)

X := i

task-terminate ()

task-create (3)

Lock Cover (LC)– the set of the locks

(a block B)

lock (L)

Y := L Y + i

unlock (L)

Page 10: Detecting Access Anomalies in Programs with Critical Sections

10

Anomaly detection using Lock Covers

Access History

The maximum parallelismof the program

At most of a single tag

Readers (X) Writers (X)

<tag, lock cover> <tag, lock cover>

CS-Readers (X) CS-Writers (X)

The maximum parallelismof the program

At most of a single tag

Readers (X) Writers (X)

Page 11: Detecting Access Anomalies in Programs with Critical Sections

11

Detection using LC

X := Y

lock (L)

Y :=L Y + i

unlock (L)

lock (L)

Y := L Y + i

unlock (L) unlock (L)

Y := L Y + i

lock (L)

X := i

task-terminate ()

task-create (3)

R W CS_R CS_W

Access History (Y)

1

234567

1

2 3

54

76

8

Report Access Anomaly

<tag> <tag, lc>

X := i8

3

53

1-3 1-5

1

1

1

1

753

5-8 7-8

Page 12: Detecting Access Anomalies in Programs with Critical Sections

12

Nested lock

B1 B3

X := L1

B2 B4

X := L1, L2 X := L2 X := L2

Hidden Anomaly

Page 13: Detecting Access Anomalies in Programs with Critical Sections

13

Non-SISE

A[1] :=

lock (L)

j := SS := S + 1

unlock (L)

j := SS := S + 1

lock (L)

A[1] :=

A[2] := S := 1doall i = 1, 2 A[i] := … lock(L) j := S S := S + 1 unlock(L) if (j = 1) then A[1] := …endall

Static analysis approach, based on program slicing

unlock (L)

Page 14: Detecting Access Anomalies in Programs with Critical Sections

14

False Anomalies

A[j] :=

lock (L)

enqueue(j)

unlock (L) unlock (L)

k := dequeue(j)

lock (L)

:= A[k]

A[j] := … lock(L) enqueue(j) Unlock(L)

lock(L) k := dequeue(j) Unlock(L) … := A[k]

* j and k are private variables