Repairing Sequential Consistency in C/C++11 Ori Lahav 1 Viktor - - PowerPoint PPT Presentation

repairing sequential consistency in c c 11
SMART_READER_LITE
LIVE PREVIEW

Repairing Sequential Consistency in C/C++11 Ori Lahav 1 Viktor - - PowerPoint PPT Presentation

Repairing Sequential Consistency in C/C++11 Ori Lahav 1 Viktor Vafeiadis 1 Jeehoon Kang 2 Chung-Kil Hur 2 Derek Dreyer 1 1 Max Planck Institute for Software Systems (MPI-SWS) 2 Seoul National University PLDI 2017 C11s spectrum of consistency


slide-1
SLIDE 1

Repairing Sequential Consistency in C/C++11

Ori Lahav1 Viktor Vafeiadis1 Jeehoon Kang2 Chung-Kil Hur2 Derek Dreyer1

1Max Planck Institute for Software Systems (MPI-SWS) 2Seoul National University

PLDI 2017

slide-2
SLIDE 2

C11’s spectrum of consistency

Access modes non- atomic

  • relaxed
  • release/

acquire

  • sc
slide-3
SLIDE 3

C11’s spectrum of consistency

Access modes non- atomic

  • relaxed
  • release/

acquire

  • sc

Message passing x :=sc 1; y :=sc 1; a := ysc; / / 1 b := xsc; / / 0 ∼ = x :=rlx 1; y :=rel 1; a := yacq; / / 1 b := xrlx; / / 0 Store buffer x :=sc 1; a := ysc; / / 0 y :=sc 1; b := xsc; / / 0 ∼ = x :=rel 1; a := ysc; / / 0 y :=sc 1; b := xsc; / / 0

slide-4
SLIDE 4

C11’s spectrum of consistency

Access modes non- atomic

  • relaxed
  • release/

acquire

  • sc

Message passing x :=sc 1; y :=sc 1; a := ysc; / / 1 b := xsc; / / 0 ∼ = x :=rlx 1; y :=rel 1; a := yacq; / / 1 b := xrlx; / / 0 Store buffer x :=sc 1; a := ysc; / / 0 y :=sc 1; b := xsc; / / 0 ∼ = x :=rel 1; a := ysc; / / 0 y :=sc 1; b := xsc; / / 0

slide-5
SLIDE 5

C11’s spectrum of consistency

Access modes non- atomic

  • relaxed
  • release/

acquire

  • sc

Message passing x :=sc 1; y :=sc 1; a := ysc; / / 1 b := xsc; / / 0 ∼ = x :=rlx 1; y :=rel 1; a := yacq; / / 1 b := xrlx; / / 0 Store buffer x :=sc 1; a := ysc; / / 0 y :=sc 1; b := xsc; / / 0 ∼ = x :=rel 1; a := ysc; / / 0 y :=sc 1; b := xsc; / / 0

  • 1. SC semantics is too strong (new correctness problem!)
  • 2. SC semantics is too weak (SC-fences)
  • 3. Out-of-thin-air reads (relaxed accesses)
slide-6
SLIDE 6

C11’s spectrum of consistency

Access modes non- atomic

  • relaxed
  • release/

acquire

  • sc

Message passing x :=sc 1; y :=sc 1; a := ysc; / / 1 b := xsc; / / 0 ∼ = x :=rlx 1; y :=rel 1; a := yacq; / / 1 b := xrlx; / / 0 Store buffer x :=sc 1; a := ysc; / / 0 y :=sc 1; b := xsc; / / 0 ∼ = x :=rel 1; a := ysc; / / 0 y :=sc 1; b := xsc; / / 0

  • 1. SC semantics is too strong (new correctness problem!)
  • 2. SC semantics is too weak (SC-fences)
  • 3. Out-of-thin-air reads (relaxed accesses)

We show how to get SC semantics just right!

slide-7
SLIDE 7

C11’s spectrum of consistency

Access modes non- atomic

  • relaxed
  • release/

acquire

  • sc

Message passing x :=sc 1; y :=sc 1; a := ysc; / / 1 b := xsc; / / 0 ∼ = x :=rlx 1; y :=rel 1; a := yacq; / / 1 b := xrlx; / / 0 Store buffer x :=sc 1; a := ysc; / / 0 y :=sc 1; b := xsc; / / 0 ∼ = x :=rel 1; a := ysc; / / 0 y :=sc 1; b := xsc; / / 0

  • 1. SC semantics is too strong (new correctness problem!)
  • 2. SC semantics is too weak (SC-fences)
  • 3. Out-of-thin-air reads (relaxed accesses)

We show how to get SC semantics just right!

slide-8
SLIDE 8

Semantics of SC-atomics is too strong!

Example due to Yatin Manerkar et al. [CoRR abs/1611.01507]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0

C/C++11: behavior disallowed

slide-9
SLIDE 9

Semantics of SC-atomics is too strong!

Example due to Yatin Manerkar et al. [CoRR abs/1611.01507]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0

C/C++11: behavior disallowed Compilation of C/C++11 to Power Rrlx → ld Wrlx → st Racq → ld;lwsync Wrel → lwsync;st Leading sync: Rsc → sync;ld;lwsync Wsc → sync;st Trailing sync: Rsc → ld; sync Wsc → lwsync;st;sync

slide-10
SLIDE 10

Semantics of SC-atomics is too strong!

Example due to Yatin Manerkar et al. [CoRR abs/1611.01507]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0

C/C++11: behavior disallowed Compilation of C/C++11 to Power Rrlx → ld Wrlx → st Racq → ld;lwsync Wrel → lwsync;st Leading sync: Rsc → sync;ld;lwsync Wsc → sync;st Trailing sync: Rsc → ld; sync Wsc → lwsync;st;sync Compilation result with “trailing sync” convention: a := x; / / 1 lwsync; b := y; / / 0 sync; x := 1; sync; y := 1; sync; c := y; / / 1 lwsync; d := x; / / 0 sync; Power: behavior allowed

slide-11
SLIDE 11

Semantics of SC-atomics is too strong!

Other examples show unsoundness of:

◮ Leading sync compilation (implemented in GCC and LLVM) ◮ Placing sync both before and after SC-accesses

In order to recover the correctness of existing compilers, we suggest to weaken the standard.

slide-12
SLIDE 12

C11’s declarative semantics 101

Batty et al. [POPL’16]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0

slide-13
SLIDE 13

C11’s declarative semantics 101

Batty et al. [POPL’16]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0 Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order

slide-14
SLIDE 14

C11’s declarative semantics 101

Batty et al. [POPL’16]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0 Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order Stage 0: choose reads-from Every read reads from a corresponding write.

slide-15
SLIDE 15

C11’s declarative semantics 101

Batty et al. [POPL’16]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0 Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from Stage 0: choose reads-from Every read reads from a corresponding write.

slide-16
SLIDE 16

C11’s declarative semantics 101

Batty et al. [POPL’16]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0 Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from Stage 1: calculate happens-before a b

po

a b

hb

a : W⊒rel b : R⊒acq

rf

a b

hb

a b

hb

b c

hb

a c

hb

slide-17
SLIDE 17

C11’s declarative semantics 101

Batty et al. [POPL’16]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0 Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from happens-before Stage 1: calculate happens-before a b

po

a b

hb

a : W⊒rel b : R⊒acq

rf

a b

hb

a b

hb

b c

hb

a c

hb

slide-18
SLIDE 18

C11’s declarative semantics 101

Batty et al. [POPL’16]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0 Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from happens-before Stage 2: “SC-per-location” Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

slide-19
SLIDE 19

C11’s declarative semantics 101

Batty et al. [POPL’16]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0 Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from happens-before Stage 2: “SC-per-location” Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

slide-20
SLIDE 20

C11’s declarative semantics 101

Batty et al. [POPL’16]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0 Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from happens-before Stage 2: “SC-per-location” Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

slide-21
SLIDE 21

C11’s declarative semantics 101

Batty et al. [POPL’16]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0 Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from happens-before Stage 2: “SC-per-location” Wna

x (0)①

Wna

y (0)

Wsc

x (1)③

Racq

x (1)④

Rsc

y (0)

Racq

y (1)

Rsc

x (0)②

Wsc

y (1)

slide-22
SLIDE 22

C11’s declarative semantics 101

Batty et al. [POPL’16]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0 Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from happens-before sc-per-loc Stage 2: “SC-per-location” Wna

x (0)①

Wna

y (0)

Wsc

x (1)③

Racq

x (1)④

Rsc

y (0)

Racq

y (1)

Rsc

x (0)②

Wsc

y (1)

slide-23
SLIDE 23

C11’s declarative semantics 101

Batty et al. [POPL’16]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0 Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from happens-before sc-per-loc Stage 3: global restrictions on SC-accesses

Order all SC-accesses while respecting: a : *sc b : *sc

hb

a b

sc-order

a : *sc

x

b : Wsc

x

sc-per-loc

a b

sc-order

slide-24
SLIDE 24

C11’s declarative semantics 101

Batty et al. [POPL’16]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0 Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from happens-before sc-order sc-per-loc Stage 3: global restrictions on SC-accesses

Order all SC-accesses while respecting: a : *sc b : *sc

hb

a b

sc-order

a : *sc

x

b : Wsc

x

sc-per-loc

a b

sc-order

slide-25
SLIDE 25

C11’s declarative semantics 101

Batty et al. [POPL’16]

a := xacq; / / 1 b := ysc; / / 0 x :=sc 1; y :=sc 1; c := yacq; / / 1 d := xsc; / / 0 Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from happens-before sc-order sc-per-loc C/C++11: behavior disallowed Stage 3: global restrictions on SC-accesses

Order all SC-accesses while respecting: a : *sc b : *sc

hb

a b

sc-order

a : *sc

x

b : Wsc

x

sc-per-loc

a b

sc-order

slide-26
SLIDE 26

What went wrong and how to fix it

Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from happens-before sc-order sc-per-loc C/C++11: behavior disallowed

slide-27
SLIDE 27

What went wrong and how to fix it

Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from happens-before sc-order sc-per-loc C/C++11: behavior disallowed a : *sc b : *sc

hb

a b

sc-order ◮ There are hb-paths between SC-accesses without sync fence in between.

slide-28
SLIDE 28

What went wrong and how to fix it

Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from happens-before sc-order sc-per-loc C/C++11: behavior disallowed a : *sc b : *sc

hb

a b

sc-order ◮ There are hb-paths between SC-accesses without sync fence in between. ◮ Both compilation schemes ensure a sync fence on hb-paths between

SC-accesses that start and end with “program order”.

slide-29
SLIDE 29

What went wrong and how to fix it

Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from happens-before sc-order sc-per-loc C/C++11: behavior disallowed

✟✟✟✟✟✟✟ ✟ ❍❍❍❍❍❍❍ ❍

a : *sc b : *sc

hb

a b

sc-order ◮ There are hb-paths between SC-accesses without sync fence in between. ◮ Both compilation schemes ensure a sync fence on hb-paths between

SC-accesses that start and end with “program order”.

slide-30
SLIDE 30

What went wrong and how to fix it

Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from happens-before sc-order sc-per-loc C/C++11: behavior disallowed

✟✟✟✟✟✟✟ ✟ ❍❍❍❍❍❍❍ ❍

a : *sc b : *sc

hb

a b

sc-order

a : *sc b : *sc

po

a b

sc-order

a : *sc b : *sc

po po hb

a b

sc-order ◮ There are hb-paths between SC-accesses without sync fence in between. ◮ Both compilation schemes ensure a sync fence on hb-paths between

SC-accesses that start and end with “program order”.

slide-31
SLIDE 31

What went wrong and how to fix it

Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from happens-before sc-order sc-per-loc C/C++11: behavior disallowed

✟✟✟✟✟✟✟ ✟ ❍❍❍❍❍❍❍ ❍

a : *sc b : *sc

hb

a b

sc-order

a : *sc b : *sc

po

a b

sc-order

a : *sc b : *sc

po po hb

a b

sc-order ◮ There are hb-paths between SC-accesses without sync fence in between. ◮ Both compilation schemes ensure a sync fence on hb-paths between

SC-accesses that start and end with “program order”.

slide-32
SLIDE 32

What went wrong and how to fix it

Wna

x (0)

Wna

y (0)

Wsc

x (1)

Racq

x (1)

Rsc

y (0)

Racq

y (1)

Rsc

x (0)

Wsc

y (1)

program order reads from happens-before sc-order sc-per-loc C/C++11: behavior disallowed Fixed model: behavior allowed

✟✟✟✟✟✟✟ ✟ ❍❍❍❍❍❍❍ ❍

a : *sc b : *sc

hb

a b

sc-order

a : *sc b : *sc

po

a b

sc-order

a : *sc b : *sc

po po hb

a b

sc-order ◮ There are hb-paths between SC-accesses without sync fence in between. ◮ Both compilation schemes ensure a sync fence on hb-paths between

SC-accesses that start and end with “program order”.

slide-33
SLIDE 33

Results

The fixed model is not too strong:

◮ correctness of existing compilation schemes

◮ Power/ARMv7 (Alglave et al. ’14): leading/trailing sync ◮ x86-TSO: mfence after-SC-writes/before-SC-reads

◮ soundness of compiler optimizations

The fixed model is not too weak:

◮ DRF theorem (without relaxed accesses) ◮ coincides with C11 when SC-accesses are to distinguished locations

slide-34
SLIDE 34

SC-fences

Store buffer

x := 1; a := y; / / 0 y := 1; b := x; / / 0 How to guarantee only SC behaviors (i.e., a = 1 ∨ b = 1)? x :=sc 1; a := ysc; y :=sc 1; b := xsc; ∼ = x :=rlx 1; fencesc; a := yrlx; y :=rlx 1; fencesc; b := xrlx;

slide-35
SLIDE 35

Semantics of SC-fences is too weak!

◮ SC-fences, even when placed between every two accesses,

do not restore SC.

Example a := xrlx; / / 1 fencesc; b := yrlx; / / 0 x :=rlx 1; y :=rlx 1; c := yrlx; / / 1 fencesc; d := xrlx; / / 0 C/C++11: behavior allowed!

◮ Algorithm designers may have to unnecessarily strengthen

access modes, leading to redundant hardware fences.

◮ Chase-Lev concurrent deque [Lê et al. ’13]: “unrecoverable

  • verheads” in the interaction between atomic operations and

memory barriers in C11.

slide-36
SLIDE 36

Stronger semantics for SC fences

Global restrictions on SC-fences

Order all SC-fences while respecting: a : Fsc b : Fsc

hb

a b

sc-order

a : Fsc *x *x b : Fsc

hb hb sc-per-loc

a b

sc-order ◮ We prove the correctness of existing compilation schemes

and compiler optimizations for the strengthened model.

◮ SC-fences between every two accesses suffice to restore

SC (assuming no data races on non-atomics).

slide-37
SLIDE 37

Thin-air conservative solution

non- atomic

  • relaxed
  • release/

acquire

  • sc

The out-of-thin-air problem Relaxed accesses are overly weak:

◮ Values appear out-of-thin-air ◮ DRF is broken Load-buffering + data dependency a := xrlx; / / 1 y :=rlx a; b := yrlx; / / 1 x :=rlx b; Load-buffering + control dependency a := xrlx; / / 1 if (a = 1) y :=rlx 1; b := yrlx; / / 1 if (b = 1) x :=rlx 1;

slide-38
SLIDE 38

Thin-air conservative solution

non- atomic

  • relaxed
  • release/

acquire

  • sc

The out-of-thin-air problem Relaxed accesses are overly weak:

◮ Values appear out-of-thin-air ◮ DRF is broken Load-buffering + data dependency a := xrlx; / / 1 y :=rlx a; b := yrlx; / / 1 x :=rlx b; Load-buffering + control dependency a := xrlx; / / 1 if (a = 1) y :=rlx 1; b := yrlx; / / 1 if (b = 1) x :=rlx 1;

Conservative solution [Boehm&Demsky ’14]

◮ Require acyclicity of (program order ∪ reads-from) ◮ More expensive compilation:

  • 1. (fake) control dependency after relaxed reads
  • 2. or: (lightweight) fence before relaxed writes
slide-39
SLIDE 39

Correctness of conservative solution

Conservative solution [Boehm&Demsky ’14]

◮ Require acyclicity of (program order ∪ reads-from) ◮ More expensive compilation:

  • 1. (fake) control dependency after relaxed reads
  • 2. or: (lightweight) fence before relaxed writes

We proved correctness of compilation to Power/ARMv7 for scheme (1). Main challenge

◮ Hardware models allow (program order ∪ reads-from) cycles

(involving non-atomic reads in the source).

◮ We have to show that such cycles can be untangled to produce a

racy consistent execution.

slide-40
SLIDE 40

Summary

We presented RC11, a repaired model for C/C++11 concurrency:

◮ weaker semantics for SC-accesses ◮ stronger semantics for SC-fences ◮ disallow (program order ∪ reads-from) cycles

We proved:

◮ correctness of compilation schemes ◮ soundness of compiler optimizations ◮ programming guarantees (DRF, SC-fences can restore SC)

Future Work

◮ Mechanize our proofs ◮ ARMv8

slide-41
SLIDE 41

Summary

We presented RC11, a repaired model for C/C++11 concurrency:

◮ weaker semantics for SC-accesses ◮ stronger semantics for SC-fences ◮ disallow (program order ∪ reads-from) cycles

We proved:

◮ correctness of compilation schemes ◮ soundness of compiler optimizations ◮ programming guarantees (DRF, SC-fences can restore SC)

Future Work

◮ Mechanize our proofs ◮ ARMv8

Thank you!

slide-42
SLIDE 42

Correctness of compilation to different hardware

C/C++11 Batty et al. [POPL’16] RC11 Strong RC11 Strongest x86-TSO ✓ ✓ ✓ ✗ ✗ POWER ✗ ✗ ✓ ✓ ✗ ARMv7 (no isb) ✓ ✓ ✓ ✓ ✓ ARMv7 (with isb) ✗ ✗ ✓ ✓ ✗ ARMv8 POP ✗ ✗ ✓ ∗ ? ✗ ARMv8.2 (with STLR,LDAR) ✓ ∗ ✓ ∗ ✓ ∗ ✓ ∗ ✓ ∗

eco

def

= (rf ∪ mo ∪ rb)+ pohbpo

def

= po|=loc; hb; po|=loc RC11

def

= acyclic(([Esc] ∪ [Fsc]; hb?); (po ∪ pohbpo ∪ rf ∪ mo ∪ rb); ([Esc] ∪ hb?; [Fsc]) ∪ [Fsc]; hb?; (hb ∪ eco); hb?; [Fsc]) Strong-RC11

def

= acyclic(([Esc] ∪ [Fsc]; hb?); (po ∪ pohbpo ∪ eco); ([Esc] ∪ hb?; [Fsc]) ∪ [Fsc]; hb?; (hb ∪ eco); hb?; [Fsc]) Strongest

def

= acyclic([Esc] ∪ [Fsc]; hb?); (hb ∪ eco); ([Esc] ∪ hb?; [Fsc])

slide-43
SLIDE 43

Strengthening C11’s declarative semantics for SC-fences

a := xrlx; / / 1 fencesc; b := yrlx; / / 0 x :=rlx 1; y :=rlx 1; c := yrlx; / / 1 fencesc; d := xrlx; / / 0

slide-44
SLIDE 44

Strengthening C11’s declarative semantics for SC-fences

a := xrlx; / / 1 fencesc; b := yrlx; / / 0 x :=rlx 1; y :=rlx 1; c := yrlx; / / 1 fencesc; d := xrlx; / / 0 Wna

x (0)

Wna

y (0)

Wrlx

x (1)

Rrlx

x (1)

Fsc Rrlx

y (0)

Rrlx

y (1)

Fsc Rrlx

x (0)

Wrlx

y (1)

program order reads from happens-before sc-order sc-per-loc reads from happens-before sc-order sc-per-loc

slide-45
SLIDE 45

Strengthening C11’s declarative semantics for SC-fences

a := xrlx; / / 1 fencesc; b := yrlx; / / 0 x :=rlx 1; y :=rlx 1; c := yrlx; / / 1 fencesc; d := xrlx; / / 0 Wna

x (0)

Wna

y (0)

Wrlx

x (1)

Rrlx

x (1)

Fsc Rrlx

y (0)

Rrlx

y (1)

Fsc Rrlx

x (0)

Wrlx

y (1)

program order reads from happens-before sc-order sc-per-loc reads from happens-before sc-order sc-per-loc Global restrictions on SC-fences Order all SC-fences while respecting: a : Fsc b : Fsc

hb

a b

sc-order

a : Fsc *x Wx b : Fsc

po po sc-per-loc

a b

sc-order

slide-46
SLIDE 46

Strengthening C11’s declarative semantics for SC-fences

a := xrlx; / / 1 fencesc; b := yrlx; / / 0 x :=rlx 1; y :=rlx 1; c := yrlx; / / 1 fencesc; d := xrlx; / / 0 Wna

x (0)

Wna

y (0)

Wrlx

x (1)

Rrlx

x (1)

Fsc Rrlx

y (0)

Rrlx

y (1)

Fsc Rrlx

x (0)

Wrlx

y (1)

program order reads from happens-before sc-order sc-per-loc reads from happens-before sc-order sc-per-loc C/C++11: behavior allowed! Global restrictions on SC-fences Order all SC-fences while respecting: a : Fsc b : Fsc

hb

a b

sc-order

a : Fsc *x Wx b : Fsc

po po sc-per-loc

a b

sc-order

slide-47
SLIDE 47

Strengthening C11’s declarative semantics for SC-fences

a := xrlx; / / 1 fencesc; b := yrlx; / / 0 x :=rlx 1; y :=rlx 1; c := yrlx; / / 1 fencesc; d := xrlx; / / 0 Wna

x (0)

Wna

y (0)

Wrlx

x (1)

Rrlx

x (1)

Fsc Rrlx

y (0)

Rrlx

y (1)

Fsc Rrlx

x (0)

Wrlx

y (1)

program order reads from happens-before sc-order sc-per-loc reads from happens-before sc-order sc-per-loc C/C++11: behavior allowed! Global restrictions on SC-fences Order all SC-fences while respecting: a : Fsc b : Fsc

hb

a b

sc-order

a : Fsc *x *x

✚ ✚ ❩ ❩

Wx b : Fsc

po po sc-per-loc

a b

sc-order

slide-48
SLIDE 48

Strengthening C11’s declarative semantics for SC-fences

a := xrlx; / / 1 fencesc; b := yrlx; / / 0 x :=rlx 1; y :=rlx 1; c := yrlx; / / 1 fencesc; d := xrlx; / / 0 Wna

x (0)

Wna

y (0)

Wrlx

x (1)

Rrlx

x (1)

Fsc Rrlx

y (0)

Rrlx

y (1)

Fsc Rrlx

x (0)

Wrlx

y (1)

program order reads from happens-before sc-order sc-per-loc reads from happens-before sc-order sc-per-loc C/C++11: behavior allowed! Global restrictions on SC-fences Order all SC-fences while respecting: a : Fsc b : Fsc

hb

a b

sc-order

a : Fsc *x *x

✚ ✚ ❩ ❩

Wx b : Fsc

po po sc-per-loc

a b

sc-order

slide-49
SLIDE 49

Strengthening C11’s declarative semantics for SC-fences

a := xrlx; / / 1 fencesc; b := yrlx; / / 0 x :=rlx 1; y :=rlx 1; c := yrlx; / / 1 fencesc; d := xrlx; / / 0 Wna

x (0)

Wna

y (0)

Wrlx

x (1)

Rrlx

x (1)

Fsc Rrlx

y (0)

Rrlx

y (1)

Fsc Rrlx

x (0)

Wrlx

y (1)

program order reads from happens-before sc-order sc-per-loc reads from happens-before sc-order sc-per-loc C/C++11: behavior allowed! Fixed model: behavior disallowed! Global restrictions on SC-fences Order all SC-fences while respecting: a : Fsc b : Fsc

hb

a b

sc-order

a : Fsc *x *x

✚ ✚ ❩ ❩

Wx b : Fsc

po po sc-per-loc

a b

sc-order

slide-50
SLIDE 50

Strengthening C11’s declarative semantics for SC-fences

a := xrlx; / / 1 fencesc; b := yrlx; / / 0 x :=rlx 1; y :=rlx 1; c := yrlx; / / 1 fencesc; d := xrlx; / / 0 Wna

x (0)

Wna

y (0)

Wrlx

x (1)

Rrlx

x (1)

Fsc Rrlx

y (0)

Rrlx

y (1)

Fsc Rrlx

x (0)

Wrlx

y (1)

program order reads from happens-before sc-order sc-per-loc reads from happens-before sc-order sc-per-loc C/C++11: behavior allowed! Fixed model: behavior disallowed! Global restrictions on SC-fences Order all SC-fences while respecting: a : Fsc b : Fsc

hb

a b

sc-order

a : Fsc *x *x

✚ ✚ ❩ ❩

Wx b : Fsc

hb hb

✚ ✚ ❩ ❩

po

✚ ✚ ❩ ❩

po sc-per-loc

a b

sc-order