Reasoning about the C/C++ weak memory model

Size: px
Start display at page:

Download "Reasoning about the C/C++ weak memory model"

Transcription

1 Reasoning about the C/C++ weak memory model Viktor Vafeiadis Max Planck Institute for Software Systems (MPI-SWS) 13 October 2014

2 Talk outline I. Introduction Weak memory models The C11 concurrency model II. Verifying concurrent C11 programs Relaxed separation logic III. Verifying C11 compilers Which program transformations are allowed? IV. Debugging the model Checking for mathematical sanity Viktor Vafeiadis Reasoning about the C/C++ weak memory model 2/32

3 Sequential consistency Sequential consistency (SC): Interleave each thread s atomic accesses. The standard model for concurrency. Almost all verification work assumes it. Fairly intuitive. Initially, x = y = 0. x := 1; print(y); y := 1; print(x); In SC, this program can print 01, 10, or 11. Viktor Vafeiadis Reasoning about the C/C++ weak memory model 3/32

4 Sequential consistency Sequential consistency (SC): Interleave each thread s atomic accesses. The standard model for concurrency. Almost But allsc verification is invalidated workby: assumes it. Fairly intuitive. Compiler optimisations Initially, x = Hardware y = 0. implementations x := 1; print(y); y := 1; print(x); In SC, this program can print 01, 10, or 11. Viktor Vafeiadis Reasoning about the C/C++ weak memory model 3/32

5 Store buffering in x86-tso cpu 1 write... cpu n read... write-back Memory Initially, x = y = 0. x := 1; print(y); y := 1; print(x); This program can also print 00. Viktor Vafeiadis Reasoning about the C/C++ weak memory model 4/32

6 IRIW: Not just store buffering Initially, x = y = 0. x := 1 y := 1 print(x); no-reord-fence print(y); print(y); no-reord-fence print(x); Both threads can print 10. x:=1 y:=1 print(x) print(y) print(y) print(x) Viktor Vafeiadis Reasoning about the C/C++ weak memory model 5/32

7 The C11 memory model Two types of locations: ordinary and atomic Races on ordinary accesses error A spectrum of atomic accesses: Relaxed no fence Release writes no fence (x86); lwsync (PPC) Acquire reads no fence (x86); isync (PPC) Seq. consistent full memory fence A few advanced features (fences, consume reads) Viktor Vafeiadis Reasoning about the C/C++ weak memory model 6/32

8 Relaxed behaviour: store buffering Initially x = y = 0. x.store(1, rlx); t 1 = y.load(rlx); y.store(1, rlx); t 2 = x.load(rlx); This can return t 1 = t 2 = 0. Justification: W rlx (x, 1) R rlx (y, 0) [x = y = 0] W rlx (y, 1) R rlx (x, 0) Behaviour observed on x86/power/arm Viktor Vafeiadis Reasoning about the C/C++ weak memory model 7/32

9 Release-acquire synchronization: message passing Initially a = x = 0. a = 5; x.store(1, release); while (x.load(acq) == 0); print(a); This will always print 5. Justification: W na (a, 5) R acq (x, 1) W rel (x, 1) R na (a, 5) Release-acquire synchronization Viktor Vafeiadis Reasoning about the C/C++ weak memory model 8/32

10 Relaxed accesses don t synchronize Initially a = x = 0. a = 5; x.store(1, rlx); while (x.load(rlx) == 0); print(a); The program is racy undefined semantics. Justification: W na (a, 5) W rlx (x, 1) R rlx (x, 1) race R na (a,?) Relaxed accesses don t synchronize Viktor Vafeiadis Reasoning about the C/C++ weak memory model 9/32

11 Dependency cycles Initially x = y = 0. if (x.load(rlx) == 1) y.store(1, rlx); if (y.load(rlx) == 1) x.store(1, rlx); C11 allows the outcome x = y = 1. Justification: R rlx (x, 1) R rlx (y, 1) W rlx (y, 1) W rlx (x, 1) Relaxed accesses don t synchronize Viktor Vafeiadis Reasoning about the C/C++ weak memory model 10/32

12 Part II Verifying concurrent C11 programs Separation logic Relaxed separation logic

13 Separation logic Key concept of ownership : Resourceful reading of Hoare triples. P} C Q} To access a normal location, you must own it: x v } t = x x v t = v } x v } x = v x v } Disjoint parallelism: P1 } C1 Q1 } P2 } C2 Q2 } P1 P 2 } C1 C 2 Q1 Q 2 } Viktor Vafeiadis Reasoning about the C/C++ weak memory model 12/32

14 Relaxed separation logic (simplified) Joint work with Chinmay Narayan, published at OOPSLA 13 Ownership transfer by rel-acq synchronizations. Atomic allocation pick loc. invariant Q. Q(v) } x = alloc(v); WQ (x) R Q (x) } Release write give away permissions. Q(v) WQ (x) } x.store(v, rel); true } Acquire read gain permissions. RQ (x) } t = x.load(acq); Q(t) } Viktor Vafeiadis Reasoning about the C/C++ weak memory model 13/32

15 Message passing in RSL Let Q(v) def = v = 0 &a 7. true } atomic_int x = 0; int a = 0; &a 0 WQ (x) R Q (x) } &a 0 WQ (x) } a = 7; &a 7 WQ (x) } x.store(1, release); } true true } t = x.load(acq); t = 0 &a 7) } if (t 0) &a 7 } print(a); true } Viktor Vafeiadis Reasoning about the C/C++ weak memory model 14/32

16 Multiple readers/writers Write permissions can be duplicated: W Q (l) W Q (l) W Q (l) Read permissions cannot, but may be split: R Q1 Q 2 (l) R Q1 (l) R Q2 (l) a = 7; b = 8; x.store(1, rel); t = x.load(acq); if (t 0) print(a); t = x.load(acq); if (t 0) print(b); Viktor Vafeiadis Reasoning about the C/C++ weak memory model 15/32

17 Relaxed accesses Basically, disallow ownership transfer. Relaxed reads: RQ (x) } x.load(rlx) y. Q(y) false } Relaxed writes: Q(v) = emp WQ (x) } x.store(v, rlx) true } Viktor Vafeiadis Reasoning about the C/C++ weak memory model 16/32

18 Relaxed accesses Basically, disallow ownership transfer. Relaxed reads: RQ (x) } x.load(rlx) y. Q(y) false } Relaxed writes: Q(v) = emp WQ (x) } x.store(v, rlx) true } Unfortunately not sound because of a bug in the C11 memory model. Viktor Vafeiadis Reasoning about the C/C++ weak memory model 16/32

19 Dependency cycles in C11 Initially x = y = 0. if (x.load(rlx) == 1) y.store(1, rlx); if (y.load(rlx) == 1) x.store(1, rlx); The formal C11 model allows x = y = 1. Justification: R rlx (x, 1) W rlx (y, 1) R rlx (y, 1) W rlx (x, 1) Relaxed accesses don t synchronize Viktor Vafeiadis Reasoning about the C/C++ weak memory model 17/32

20 Dependency cycles in C11 Initially x = y = 0. if (x.load(rlx) == 1) y.store(1, rlx); if (y.load(rlx) == 1) x.store(1, rlx); The formal C11 model allows x = y = 1. What goes wrong: Non-relational invariants are unsound. x = 0 y = 0 The DRF-property does not hold. Viktor Vafeiadis Reasoning about the C/C++ weak memory model 17/32

21 Dependency cycles in C11 Initially x = y = 0. if (x.load(rlx) == 1) y.store(1, rlx); if (y.load(rlx) == 1) x.store(1, rlx); The formal C11 model allows x = y = 1. How to fix this: Don t use relaxed writes Require acyclic(sb rf ). (Disallow RW reodering.) Viktor Vafeiadis Reasoning about the C/C++ weak memory model 17/32

22 Part III Towards verifying C11 compilers Which program transformations are allowed?

23 A study of optimisations under C11 Reorderings of memory accesses Elimination of redundant accesses (overwritten write, read after same R/W) (write after same read is invalid) Introduction of unused reads (invalid may race) Elimination of unused reads (only non-atomic, others may synchronise) Caveat: We must correct the model... Viktor Vafeiadis Reasoning about the C/C++ weak memory model 19/32

24 Valid instruction reorderings a ; b b ; a a \ b R sc R sc W na W rlx W rel C rlx acq C rel F acq F rel R na ( ) ( ) ( ) R rlx ( ) ( ) ( ) R acq W sc W sc C rlx rel ( ) ( ) ( ) C acq F acq = F rel = Roach motel semantics: Cannot move accesses out of critical regions Viktor Vafeiadis Reasoning about the C/C++ weak memory model 20/32

25 Redundant instruction eliminations Overwritten write: x.store(v, M) ; C ; x.store(v, M) C ; x.store(v, M) Read after write: x.store(v, M) ; C ; t = x.load(m ) x.store(v, M) ; C ; t = v C has no rel & no x accesses C has no acq & no x accesses Read after read: t = x.load(m) ; C ; t = x.load(m) C has no acq t = x.load(m) ; C ; t = t & no x accesses Viktor Vafeiadis Reasoning about the C/C++ weak memory model 21/32

26 Write-after-read elimination is invalid t = x.load(m) ; x.store(t, rlx) t = x.load(m) There could be a CAS in between y.store(1, rlx); fence(release); t 1 = x.load(rlx); x.store(t 1, rlx); x = y = 0; t 2 = x.cas(0, 1, acq); t 3 = y.load(rlx); t 4 = x.load(rlx); Can we get t 1 = t 2 = t 3 = 0 and t 4 = 1? Viktor Vafeiadis Reasoning about the C/C++ weak memory model 22/32

27 Part IV Debugging the model Checking mathematical sanity Monotonicity Prefix closure

28 Monotonicity Examples: Adding synchronisation should not introduce new behaviours Adding a memory fence Strengthening the access mode of an operation Reducing parallelism, C 1 C 2 C 1 ; C 2 Expression evaluation linearisation: x = a + b ; t 1 = a ; t 2 = b ; x = t 1 + t 2 ; (Roach motel reorderings) Viktor Vafeiadis Reasoning about the C/C++ weak memory model 24/32

29 Obstacles to monotonicity 1. The axiom for non-atomic reads rf(b) = a (isna(a) isna(b)) = hb(a, b) (in combination with dependency cycles) 2. The axiom for SC reads 3. No intra-thread synchronisation Viktor Vafeiadis Reasoning about the C/C++ weak memory model 25/32

30 Sequentialisation is invalid a = 1; if (x.load(rlx) == 1) if (a == 1) y.store(1, rlx); if (y.load(rlx) == 1) x.store(1, rlx); [a = x = y = 0] W na (a, 1) R rlx (x, 1) R na (a, 1) R rlx (y, 1) W rlx (x, 1) W rlx (y, 1) rf(b) = a (isna(a) isna(b)) = hb(a, b) Viktor Vafeiadis Reasoning about the C/C++ weak memory model 26/32

31 SC read restriction There shall be a single total order S on all seq_cst operations [... ] such that each seq_cst operation B that loads a value from an atomic object M observes one of the following values: the result of the last modification A of M that precedes B in S, if it exists, or if A exists, the result of some modification of M in the visible sequence of side effects with respect to B that is not seq_cst and that does not happen before A, or if A does not exist, [... ] [N1570, ] rf(b) = c issc(b) = iscr(c, b) issc(c) a. hb(c, a) iscr(a, b) where iscr(c, b) def = scr(c, b) d. scr(c, d) scr(d, b) scr(c, b) def = iswrite locs(b) (c) sc(c, b) Viktor Vafeiadis Reasoning about the C/C++ weak memory model 27/32

32 Strengthening is invalid x.store(1, rlx); x.store(2, sc); y.store(1, sc); x.store(3, rlx); y.store(2, sc); y.store(3, sc); r = x.load(sc); s 1 = x.load(rlx); s 2 = x.load(rlx); s 3 = x.load(rlx); t 1 = y.load(rlx); t 2 = y.load(rlx); t 3 = y.load(rlx); r = s 1 = t 1 = 1 s 2 = t 2 = 2 s 3 = t 3 = 3 Disallowed W rlx (x, 1) W sc (x, 2) sc W sc (y, 1) sc W rlx (x, 3) W sc (y, 2) W sc (y, 3) sc sc R sc (x, 1) Viktor Vafeiadis Reasoning about the C/C++ weak memory model 28/32

33 Strengthening is invalid x.store(1, rlx); x.store(2, sc); y.store(1, sc); x.store(3, sc); y.store(2, sc); y.store(3, sc); r = x.load(sc); r = s 1 = t 1 = 1 s 2 = t 2 = 2 s 3 = t 3 = 3 Allowed s 1 = x.load(rlx); s 2 = x.load(rlx); s 3 = x.load(rlx); t 1 = y.load(rlx); t 2 = y.load(rlx); t 3 = y.load(rlx); W rlx (x, 1) W sc (x, 2) sc W sc (y, 1) sc sc W sc (x, 3) sc W sc (y, 2) W sc (y, 3) sc sc R sc (x, 1) Viktor Vafeiadis Reasoning about the C/C++ weak memory model 28/32

34 No intra-thread synchronisation Initially x = y = 0. a = 1; x.store(1, rel); if (x.load(cons)) y.store(1, rel); if (y.load(acq)) a = 2; sequentialise threads 2 & 3 a = 1; x.store(1, rel); if (x.load(cons)) y.store(1, rel); if (y.load(acq)) a = 2; Only different thread rel-acq synchronize. Proposed fix: drop this restriction Viktor Vafeiadis Reasoning about the C/C++ weak memory model 29/32

35 Prefix closure Removing (hb rf)-maximal events should preserve consistency Maximal events should not affect other events Does not hold because of release sequences Viktor Vafeiadis Reasoning about the C/C++ weak memory model 30/32

36 Release sequences are too strong Initially x = y = 0. a = 1; x.store(1, rel); x.store(3, rlx); while (x.load(acq) 3); a = 2; This program is not racy. The acquire synchronizes with the release. rselem(a, b) def = samethread(a, b) isrmw(b) rseq(a, b) def = a = b rselem(a, b) mo(a, b) ( c. mo(a, c) mo(c, b) rselem(a, c)) Viktor Vafeiadis Reasoning about the C/C++ weak memory model 31/32

37 Release sequences are too strong Initially x = y = 0. a = 1; x.store(1, rel); x.store(3, rlx); while (x.load(acq) 3); a = 2; x.store(2, rlx); But this one is racy according to C11. The acquire no longer synchronizes with the release. rselem(a, b) def = samethread(a, b) isrmw(b) rseq(a, b) def = a = b rselem(a, b) mo(a, b) ( c. mo(a, c) mo(c, b) rselem(a, c)) Viktor Vafeiadis Reasoning about the C/C++ weak memory model 31/32

38 Summary The C11 memory model is broken But is largely fixable Dependency cycles still an open problem Tools for understanding weak memory models: Source-to-source program transformations Relaxed program logics Viktor Vafeiadis Reasoning about the C/C++ weak memory model 32/32

Program logics for relaxed consistency

Program logics for relaxed consistency Program logics for relaxed consistency UPMARC Summer School 2014 Viktor Vafeiadis Max Planck Institute for Software Systems (MPI-SWS) 1st Lecture, 28 July 2014 Outline Part I. Weak memory models 1. Intro

More information

An introduction to weak memory consistency and the out-of-thin-air problem

An introduction to weak memory consistency and the out-of-thin-air problem An introduction to weak memory consistency and the out-of-thin-air problem Viktor Vafeiadis Max Planck Institute for Software Systems (MPI-SWS) CONCUR, 7 September 2017 Sequential consistency 2 Sequential

More information

Taming release-acquire consistency

Taming release-acquire consistency Taming release-acquire consistency Ori Lahav Nick Giannarakis Viktor Vafeiadis Max Planck Institute for Software Systems (MPI-SWS) POPL 2016 Weak memory models Weak memory models provide formal sound semantics

More information

Relaxed Memory: The Specification Design Space

Relaxed Memory: The Specification Design Space Relaxed Memory: The Specification Design Space Mark Batty University of Cambridge Fortran meeting, Delft, 25 June 2013 1 An ideal specification Unambiguous Easy to understand Sound w.r.t. experimentally

More information

C11 Compiler Mappings: Exploration, Verification, and Counterexamples

C11 Compiler Mappings: Exploration, Verification, and Counterexamples C11 Compiler Mappings: Exploration, Verification, and Counterexamples Yatin Manerkar Princeton University manerkar@princeton.edu http://check.cs.princeton.edu November 22 nd, 2016 1 Compilers Must Uphold

More information

Declarative semantics for concurrency. 28 August 2017

Declarative semantics for concurrency. 28 August 2017 Declarative semantics for concurrency Ori Lahav Viktor Vafeiadis 28 August 2017 An alternative way of defining the semantics 2 Declarative/axiomatic concurrency semantics Define the notion of a program

More information

Overhauling SC atomics in C11 and OpenCL

Overhauling SC atomics in C11 and OpenCL Overhauling SC atomics in C11 and OpenCL John Wickerson, Mark Batty, and Alastair F. Donaldson Imperial Concurrency Workshop July 2015 TL;DR The rules for sequentially-consistent atomic operations and

More information

Multicore Programming: C++0x

Multicore Programming: C++0x p. 1 Multicore Programming: C++0x Mark Batty University of Cambridge in collaboration with Scott Owens, Susmit Sarkar, Peter Sewell, Tjark Weber November, 2010 p. 2 C++0x: the next C++ Specified by the

More information

The C1x and C++11 concurrency model

The C1x and C++11 concurrency model The C1x and C++11 concurrency model Mark Batty University of Cambridge January 16, 2013 C11 and C++11 Memory Model A DRF model with the option to expose relaxed behaviour in exchange for high performance.

More information

Relaxed Separation Logic: A Program Logic for C11 Concurrency

Relaxed Separation Logic: A Program Logic for C11 Concurrency Relaxed Separation Logic: A rogram Logic for C11 Concurrency Viktor Vafeiadis Max lanck Institute for Software Systems (MI-SWS) viktor@mpi-sws.org Chinmay Narayan Indian Institute of Technology, Delhi

More information

The C/C++ Memory Model: Overview and Formalization

The C/C++ Memory Model: Overview and Formalization The C/C++ Memory Model: Overview and Formalization Mark Batty Jasmin Blanchette Scott Owens Susmit Sarkar Peter Sewell Tjark Weber Verification of Concurrent C Programs C11 / C++11 In 2011, new versions

More information

Repairing Sequential Consistency in C/C++11

Repairing Sequential Consistency in C/C++11 Technical Report MPI-SWS-2016-011, November 2016 Repairing Sequential Consistency in C/C++11 Ori Lahav MPI-SWS, Germany orilahav@mpi-sws.org Viktor Vafeiadis MPI-SWS, Germany viktor@mpi-sws.org Jeehoon

More information

Repairing Sequential Consistency in C/C++11

Repairing Sequential Consistency in C/C++11 Repairing Sequential Consistency in C/C++11 Ori Lahav MPI-SWS, Germany orilahav@mpi-sws.org Chung-Kil Hur Seoul National University, Korea gil.hur@sf.snu.ac.kr Viktor Vafeiadis MPI-SWS, Germany viktor@mpi-sws.org

More information

Common Compiler Optimisations are Invalid in the C11 Memory Model and what we can do about it

Common Compiler Optimisations are Invalid in the C11 Memory Model and what we can do about it Comn Compiler Optimisations are Invalid in the C11 Mery Model and what we can do about it Viktor Vafeiadis MPI-SWS Thibaut Balabonski INRIA Soham Chakraborty MPI-SWS Robin Morisset INRIA Francesco Zappa

More information

Repairing Sequential Consistency in C/C++11

Repairing Sequential Consistency in C/C++11 Repairing Sequential Consistency in C/C++11 Ori Lahav MPI-SWS, Germany orilahav@mpi-sws.org Viktor Vafeiadis MPI-SWS, Germany viktor@mpi-sws.org Jeehoon Kang Seoul National University, Korea jeehoon.kang@sf.snu.ac.kr

More information

RELAXED CONSISTENCY 1

RELAXED CONSISTENCY 1 RELAXED CONSISTENCY 1 RELAXED CONSISTENCY Relaxed Consistency is a catch-all term for any MCM weaker than TSO GPUs have relaxed consistency (probably) 2 XC AXIOMS TABLE 5.5: XC Ordering Rules. An X Denotes

More information

Can Seqlocks Get Along with Programming Language Memory Models?

Can Seqlocks Get Along with Programming Language Memory Models? Can Seqlocks Get Along with Programming Language Memory Models? Hans-J. Boehm HP Labs Hans-J. Boehm: Seqlocks 1 The setting Want fast reader-writer locks Locking in shared (read) mode allows concurrent

More information

High-level languages

High-level languages High-level languages High-level languages are not immune to these problems. Actually, the situation is even worse: the source language typically operates over mixed-size values (multi-word and bitfield);

More information

Parallel Computer Architecture Spring Memory Consistency. Nikos Bellas

Parallel Computer Architecture Spring Memory Consistency. Nikos Bellas Parallel Computer Architecture Spring 2018 Memory Consistency Nikos Bellas Computer and Communications Engineering Department University of Thessaly Parallel Computer Architecture 1 Coherence vs Consistency

More information

On the C11 Memory Model and a Program Logic for C11 Concurrency

On the C11 Memory Model and a Program Logic for C11 Concurrency On the C11 Memory Model and a Program Logic for C11 Concurrency Manuel Penschuck Aktuelle Themen der Softwaretechnologie Software Engineering & Programmiersprachen FB 12 Goethe Universität - Frankfurt

More information

Multicore Programming Java Memory Model

Multicore Programming Java Memory Model p. 1 Multicore Programming Java Memory Model Peter Sewell Jaroslav Ševčík Tim Harris University of Cambridge MSR with thanks to Francesco Zappa Nardelli, Susmit Sarkar, Tom Ridge, Scott Owens, Magnus O.

More information

Load-reserve / Store-conditional on POWER and ARM

Load-reserve / Store-conditional on POWER and ARM Load-reserve / Store-conditional on POWER and ARM Peter Sewell (slides from Susmit Sarkar) 1 University of Cambridge June 2012 Correct implementations of C/C++ on hardware Can it be done?...on highly relaxed

More information

Foundations of the C++ Concurrency Memory Model

Foundations of the C++ Concurrency Memory Model Foundations of the C++ Concurrency Memory Model John Mellor-Crummey and Karthik Murthy Department of Computer Science Rice University johnmc@rice.edu COMP 522 27 September 2016 Before C++ Memory Model

More information

Hoare logic. A proof system for separation logic. Introduction. Separation logic

Hoare logic. A proof system for separation logic. Introduction. Separation logic Introduction Hoare logic Lecture 6: Examples in separation logic In the previous lecture, we saw how reasoning about pointers in Hoare logic was problematic, which motivated introducing separation logic.

More information

Overhauling SC atomics in C11 and OpenCL

Overhauling SC atomics in C11 and OpenCL Overhauling SC atomics in C11 and OpenCL Mark Batty, Alastair F. Donaldson and John Wickerson INCITS/ISO/IEC 9899-2011[2012] (ISO/IEC 9899-2011, IDT) Provisional Specification Information technology Programming

More information

A Program Logic for C11 Memory Fences

A Program Logic for C11 Memory Fences A Program Logic for C11 Memory Fences Marko Doko and Viktor Vafeiadis Max Planck Institute for Software Systems (MPI-SWS) Abstract. We describe a simple, but powerful, program logic for reasoning about

More information

Unit 12: Memory Consistency Models. Includes slides originally developed by Prof. Amir Roth

Unit 12: Memory Consistency Models. Includes slides originally developed by Prof. Amir Roth Unit 12: Memory Consistency Models Includes slides originally developed by Prof. Amir Roth 1 Example #1 int x = 0;! int y = 0;! thread 1 y = 1;! thread 2 int t1 = x;! x = 1;! int t2 = y;! print(t1,t2)!

More information

C++ Memory Model. Don t believe everything you read (from shared memory)

C++ Memory Model. Don t believe everything you read (from shared memory) C++ Memory Model Don t believe everything you read (from shared memory) The Plan Why multithreading is hard Warm-up example Sequential Consistency Races and fences The happens-before relation The DRF guarantee

More information

Coherence and Consistency

Coherence and Consistency Coherence and Consistency 30 The Meaning of Programs An ISA is a programming language To be useful, programs written in it must have meaning or semantics Any sequence of instructions must have a meaning.

More information

Typed Assembly Language for Implementing OS Kernels in SMP/Multi-Core Environments with Interrupts

Typed Assembly Language for Implementing OS Kernels in SMP/Multi-Core Environments with Interrupts Typed Assembly Language for Implementing OS Kernels in SMP/Multi-Core Environments with Interrupts Toshiyuki Maeda and Akinori Yonezawa University of Tokyo Quiz [Environment] CPU: Intel Xeon X5570 (2.93GHz)

More information

GPS: Navigating Weak Memory with Ghosts, Protocols, and Separation

GPS: Navigating Weak Memory with Ghosts, Protocols, and Separation * Evaluated * OOPSLA * Artifact * AEC GPS: Navigating Weak Memory with Ghosts, Protocols, and Separation Aaron Turon Viktor Vafeiadis Derek Dreyer Max Planck Institute for Software Systems (MPI-SWS) turon,viktor,dreyer@mpi-sws.org

More information

Memory Consistency Models. CSE 451 James Bornholt

Memory Consistency Models. CSE 451 James Bornholt Memory Consistency Models CSE 451 James Bornholt Memory consistency models The short version: Multiprocessors reorder memory operations in unintuitive, scary ways This behavior is necessary for performance

More information

Effective Stateless Model Checking for C/C++ Concurrency

Effective Stateless Model Checking for C/C++ Concurrency 17 Effective Stateless Model Checking for C/C++ Concurrency MICHALIS KOKOLOGIANNAKIS, National Technical University of Athens, Greece ORI LAHAV, Tel Aviv University, Israel KONSTANTINOS SAGONAS, Uppsala

More information

NOW Handout Page 1. Memory Consistency Model. Background for Debate on Memory Consistency Models. Multiprogrammed Uniprocessor Mem.

NOW Handout Page 1. Memory Consistency Model. Background for Debate on Memory Consistency Models. Multiprogrammed Uniprocessor Mem. Memory Consistency Model Background for Debate on Memory Consistency Models CS 258, Spring 99 David E. Culler Computer Science Division U.C. Berkeley for a SAS specifies constraints on the order in which

More information

Relaxed Memory-Consistency Models

Relaxed Memory-Consistency Models Relaxed Memory-Consistency Models Review. Why are relaxed memory-consistency models needed? How do relaxed MC models require programs to be changed? The safety net between operations whose order needs

More information

Using Weakly Ordered C++ Atomics Correctly. Hans-J. Boehm

Using Weakly Ordered C++ Atomics Correctly. Hans-J. Boehm Using Weakly Ordered C++ Atomics Correctly Hans-J. Boehm 1 Why atomics? Programs usually ensure that memory locations cannot be accessed by one thread while being written by another. No data races. Typically

More information

The Java Memory Model

The Java Memory Model The Java Memory Model The meaning of concurrency in Java Bartosz Milewski Plan of the talk Motivating example Sequential consistency Data races The DRF guarantee Causality Out-of-thin-air guarantee Implementation

More information

CS510 Advanced Topics in Concurrency. Jonathan Walpole

CS510 Advanced Topics in Concurrency. Jonathan Walpole CS510 Advanced Topics in Concurrency Jonathan Walpole Threads Cannot Be Implemented as a Library Reasoning About Programs What are the valid outcomes for this program? Is it valid for both r1 and r2 to

More information

Quis Custodiet Ipsos Custodes The Java memory model

Quis Custodiet Ipsos Custodes The Java memory model Quis Custodiet Ipsos Custodes The Java memory model Andreas Lochbihler funded by DFG Ni491/11, Sn11/10 PROGRAMMING PARADIGMS GROUP = Isabelle λ β HOL α 1 KIT 9University Oct 2012 of the Andreas State of

More information

Program Verification under Weak Memory Consistency using Separation Logic

Program Verification under Weak Memory Consistency using Separation Logic Program Verification under Weak Memory Consistency using Separation Logic Viktor Vafeiadis MPI-SWS, Kaiserslautern and Saarbrücken, Germany Abstract. The semantics of concurrent programs is now defined

More information

New Programming Abstractions for Concurrency in GCC 4.7. Torvald Riegel Red Hat 12/04/05

New Programming Abstractions for Concurrency in GCC 4.7. Torvald Riegel Red Hat 12/04/05 New Programming Abstractions for Concurrency in GCC 4.7 Red Hat 12/04/05 1 Concurrency and atomicity C++11 atomic types Transactional Memory Provide atomicity for concurrent accesses by different threads

More information

Overview: Memory Consistency

Overview: Memory Consistency Overview: Memory Consistency the ordering of memory operations basic definitions; sequential consistency comparison with cache coherency relaxing memory consistency write buffers the total store ordering

More information

Taming Release-Acquire Consistency

Taming Release-Acquire Consistency Taming Release-Acquire Consistency Ori Lahav Nick Giannarakis Viktor Vafeiadis Max Planck Institute for Software Systems (MPI-SWS), Germany {orilahav,nickgian,viktor}@mpi-sws.org * POPL * Artifact Consistent

More information

CS5460: Operating Systems

CS5460: Operating Systems CS5460: Operating Systems Lecture 9: Implementing Synchronization (Chapter 6) Multiprocessor Memory Models Uniprocessor memory is simple Every load from a location retrieves the last value stored to that

More information

A unified machine-checked model for multithreaded Java

A unified machine-checked model for multithreaded Java A unified machine-checked model for multithreaded Java Andre Lochbihler IPD, PROGRAMMING PARADIGMS GROUP, COMPUTER SCIENCE DEPARTMENT KIT - University of the State of Baden-Wuerttemberg and National Research

More information

Memory Consistency Models

Memory Consistency Models Memory Consistency Models Contents of Lecture 3 The need for memory consistency models The uniprocessor model Sequential consistency Relaxed memory models Weak ordering Release consistency Jonas Skeppstedt

More information

Hoare Logic and Model Checking

Hoare Logic and Model Checking Hoare Logic and Model Checking Kasper Svendsen University of Cambridge CST Part II 2016/17 Acknowledgement: slides heavily based on previous versions by Mike Gordon and Alan Mycroft Introduction In the

More information

Symmetric Multiprocessors: Synchronization and Sequential Consistency

Symmetric Multiprocessors: Synchronization and Sequential Consistency Constructive Computer Architecture Symmetric Multiprocessors: Synchronization and Sequential Consistency Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology November

More information

Safe Optimisations for Shared-Memory Concurrent Programs. Tomer Raz

Safe Optimisations for Shared-Memory Concurrent Programs. Tomer Raz Safe Optimisations for Shared-Memory Concurrent Programs Tomer Raz Plan Motivation Transformations Semantic Transformations Safety of Transformations Syntactic Transformations 2 Motivation We prove that

More information

THÈSE DE DOCTORAT de l Université de recherche Paris Sciences Lettres PSL Research University

THÈSE DE DOCTORAT de l Université de recherche Paris Sciences Lettres PSL Research University THÈSE DE DOCTORAT de l Université de recherche Paris Sciences Lettres PSL Research University Préparée à l École normale supérieure Compiler Optimisations and Relaxed Memory Consistency Models ED 386 sciences

More information

New Programming Abstractions for Concurrency. Torvald Riegel Red Hat 12/04/05

New Programming Abstractions for Concurrency. Torvald Riegel Red Hat 12/04/05 New Programming Abstractions for Concurrency Red Hat 12/04/05 1 Concurrency and atomicity C++11 atomic types Transactional Memory Provide atomicity for concurrent accesses by different threads Both based

More information

Hoare Logic and Model Checking. A proof system for Separation logic. Introduction. Separation Logic

Hoare Logic and Model Checking. A proof system for Separation logic. Introduction. Separation Logic Introduction Hoare Logic and Model Checking In the previous lecture we saw the informal concepts that Separation Logic is based on. Kasper Svendsen University of Cambridge CST Part II 2016/17 This lecture

More information

GPU Concurrency: Weak Behaviours and Programming Assumptions

GPU Concurrency: Weak Behaviours and Programming Assumptions GPU Concurrency: Weak Behaviours and Programming Assumptions Jyh-Jing Hwang, Yiren(Max) Lu 03/02/2017 Outline 1. Introduction 2. Weak behaviors examples 3. Test methodology 4. Proposed memory model 5.

More information

Relaxed Memory-Consistency Models

Relaxed Memory-Consistency Models Relaxed Memory-Consistency Models [ 9.1] In Lecture 13, we saw a number of relaxed memoryconsistency models. In this lecture, we will cover some of them in more detail. Why isn t sequential consistency

More information

Designing Memory Consistency Models for. Shared-Memory Multiprocessors. Sarita V. Adve

Designing Memory Consistency Models for. Shared-Memory Multiprocessors. Sarita V. Adve Designing Memory Consistency Models for Shared-Memory Multiprocessors Sarita V. Adve Computer Sciences Department University of Wisconsin-Madison The Big Picture Assumptions Parallel processing important

More information

A separation logic for a promising semantics

A separation logic for a promising semantics A separation logic for a promising semantics Kasper Svendsen, Jean Pichon-Pharabod 1, Marko Doko 2, Ori Lahav 3, and Viktor Vafeiadis 2 1 University of Cambridge 2 MPI-SWS 3 Tel Aviv University Abstract.

More information

SharedArrayBuffer and Atomics Stage 2.95 to Stage 3

SharedArrayBuffer and Atomics Stage 2.95 to Stage 3 SharedArrayBuffer and Atomics Stage 2.95 to Stage 3 Shu-yu Guo Lars Hansen Mozilla November 30, 2016 What We Have Consensus On TC39 agreed on Stage 2.95, July 2016 Agents API (frozen) What We Have Consensus

More information

Motivations. Shared Memory Consistency Models. Optimizations for Performance. Memory Consistency

Motivations. Shared Memory Consistency Models. Optimizations for Performance. Memory Consistency Shared Memory Consistency Models Authors : Sarita.V.Adve and Kourosh Gharachorloo Presented by Arrvindh Shriraman Motivations Programmer is required to reason about consistency to ensure data race conditions

More information

<atomic.h> weapons. Paolo Bonzini Red Hat, Inc. KVM Forum 2016

<atomic.h> weapons. Paolo Bonzini Red Hat, Inc. KVM Forum 2016 weapons Paolo Bonzini Red Hat, Inc. KVM Forum 2016 The real things Herb Sutter s talks atomic Weapons: The C++ Memory Model and Modern Hardware Lock-Free Programming (or, Juggling Razor Blades)

More information

The Java Memory Model

The Java Memory Model Jeremy Manson 1, William Pugh 1, and Sarita Adve 2 1 University of Maryland 2 University of Illinois at Urbana-Champaign Presented by John Fisher-Ogden November 22, 2005 Outline Introduction Sequential

More information

Module 15: "Memory Consistency Models" Lecture 34: "Sequential Consistency and Relaxed Models" Memory Consistency Models. Memory consistency

Module 15: Memory Consistency Models Lecture 34: Sequential Consistency and Relaxed Models Memory Consistency Models. Memory consistency Memory Consistency Models Memory consistency SC SC in MIPS R10000 Relaxed models Total store ordering PC and PSO TSO, PC, PSO Weak ordering (WO) [From Chapters 9 and 11 of Culler, Singh, Gupta] [Additional

More information

Hardware Memory Models: x86-tso

Hardware Memory Models: x86-tso Hardware Memory Models: x86-tso John Mellor-Crummey Department of Computer Science Rice University johnmc@rice.edu COMP 522 Lecture 9 20 September 2016 Agenda So far hardware organization multithreading

More information

Lecture 13: Consistency Models. Topics: sequential consistency, requirements to implement sequential consistency, relaxed consistency models

Lecture 13: Consistency Models. Topics: sequential consistency, requirements to implement sequential consistency, relaxed consistency models Lecture 13: Consistency Models Topics: sequential consistency, requirements to implement sequential consistency, relaxed consistency models 1 Coherence Vs. Consistency Recall that coherence guarantees

More information

Shared Memory Consistency Models: A Tutorial

Shared Memory Consistency Models: A Tutorial Shared Memory Consistency Models: A Tutorial By Sarita Adve, Kourosh Gharachorloo WRL Research Report, 1995 Presentation: Vince Schuster Contents Overview Uniprocessor Review Sequential Consistency Relaxed

More information

Programming Language Memory Models: What do Shared Variables Mean?

Programming Language Memory Models: What do Shared Variables Mean? Programming Language Memory Models: What do Shared Variables Mean? Hans-J. Boehm 10/25/2010 1 Disclaimers: This is an overview talk. Much of this work was done by others or jointly. I m relying particularly

More information

Hardware models: inventing a usable abstraction for Power/ARM. Friday, 11 January 13

Hardware models: inventing a usable abstraction for Power/ARM. Friday, 11 January 13 Hardware models: inventing a usable abstraction for Power/ARM 1 Hardware models: inventing a usable abstraction for Power/ARM Disclaimer: 1. ARM MM is analogous to Power MM all this is your next phone!

More information

Shared Memory Programming with OpenMP. Lecture 8: Memory model, flush and atomics

Shared Memory Programming with OpenMP. Lecture 8: Memory model, flush and atomics Shared Memory Programming with OpenMP Lecture 8: Memory model, flush and atomics Why do we need a memory model? On modern computers code is rarely executed in the same order as it was specified in the

More information

Reasoning About The Implementations Of Concurrency Abstractions On x86-tso. By Scott Owens, University of Cambridge.

Reasoning About The Implementations Of Concurrency Abstractions On x86-tso. By Scott Owens, University of Cambridge. Reasoning About The Implementations Of Concurrency Abstractions On x86-tso By Scott Owens, University of Cambridge. Plan Intro Data Races And Triangular Races Examples 2 sequential consistency The result

More information

CS 252 Graduate Computer Architecture. Lecture 11: Multiprocessors-II

CS 252 Graduate Computer Architecture. Lecture 11: Multiprocessors-II CS 252 Graduate Computer Architecture Lecture 11: Multiprocessors-II Krste Asanovic Electrical Engineering and Computer Sciences University of California, Berkeley http://www.eecs.berkeley.edu/~krste http://inst.eecs.berkeley.edu/~cs252

More information

7/6/2015. Motivation & examples Threads, shared memory, & synchronization. Imperative programs

7/6/2015. Motivation & examples Threads, shared memory, & synchronization. Imperative programs Motivation & examples Threads, shared memory, & synchronization How do locks work? Data races (a lower level property) How do data race detectors work? Atomicity (a higher level property) Concurrency exceptions

More information

Weak memory models. Mai Thuong Tran. PMA Group, University of Oslo, Norway. 31 Oct. 2014

Weak memory models. Mai Thuong Tran. PMA Group, University of Oslo, Norway. 31 Oct. 2014 Weak memory models Mai Thuong Tran PMA Group, University of Oslo, Norway 31 Oct. 2014 Overview 1 Introduction Hardware architectures Compiler optimizations Sequential consistency 2 Weak memory models TSO

More information

Distributed Operating Systems Memory Consistency

Distributed Operating Systems Memory Consistency Faculty of Computer Science Institute for System Architecture, Operating Systems Group Distributed Operating Systems Memory Consistency Marcus Völp (slides Julian Stecklina, Marcus Völp) SS2014 Concurrent

More information

Motivation & examples Threads, shared memory, & synchronization

Motivation & examples Threads, shared memory, & synchronization 1 Motivation & examples Threads, shared memory, & synchronization How do locks work? Data races (a lower level property) How do data race detectors work? Atomicity (a higher level property) Concurrency

More information

Lowering C11 Atomics for ARM in LLVM

Lowering C11 Atomics for ARM in LLVM 1 Lowering C11 Atomics for ARM in LLVM Reinoud Elhorst Abstract This report explores the way LLVM generates the memory barriers needed to support the C11/C++11 atomics for ARM. I measure the influence

More information

CMSC Computer Architecture Lecture 15: Memory Consistency and Synchronization. Prof. Yanjing Li University of Chicago

CMSC Computer Architecture Lecture 15: Memory Consistency and Synchronization. Prof. Yanjing Li University of Chicago CMSC 22200 Computer Architecture Lecture 15: Memory Consistency and Synchronization Prof. Yanjing Li University of Chicago Administrative Stuff! Lab 5 (multi-core) " Basic requirements: out later today

More information

CS533 Concepts of Operating Systems. Jonathan Walpole

CS533 Concepts of Operating Systems. Jonathan Walpole CS533 Concepts of Operating Systems Jonathan Walpole Shared Memory Consistency Models: A Tutorial Outline Concurrent programming on a uniprocessor The effect of optimizations on a uniprocessor The effect

More information

Relaxed Memory Consistency

Relaxed Memory Consistency Relaxed Memory Consistency Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE3054: Multicore Systems, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu)

More information

Lecture 12: TM, Consistency Models. Topics: TM pathologies, sequential consistency, hw and hw/sw optimizations

Lecture 12: TM, Consistency Models. Topics: TM pathologies, sequential consistency, hw and hw/sw optimizations Lecture 12: TM, Consistency Models Topics: TM pathologies, sequential consistency, hw and hw/sw optimizations 1 Paper on TM Pathologies (ISCA 08) LL: lazy versioning, lazy conflict detection, committing

More information

A Proposal for Weak-Memory Local Reasoning

A Proposal for Weak-Memory Local Reasoning A Proposal for Weak-Memory Local Reasoning Ian Wehrman and Josh Berdine Abstract Program logics are formal systems for specifying and reasoning about software programs. Most program logics make the strong

More information

Relaxed Memory-Consistency Models

Relaxed Memory-Consistency Models Relaxed Memory-Consistency Models [ 9.1] In small multiprocessors, sequential consistency can be implemented relatively easily. However, this is not true for large multiprocessors. Why? This is not the

More information

Beyond Sequential Consistency: Relaxed Memory Models

Beyond Sequential Consistency: Relaxed Memory Models 1 Beyond Sequential Consistency: Relaxed Memory Models Computer Science and Artificial Intelligence Lab M.I.T. Based on the material prepared by and Krste Asanovic 2 Beyond Sequential Consistency: Relaxed

More information

Weak Memory Models: an Operational Theory

Weak Memory Models: an Operational Theory Opening Weak Memory Models: an Operational Theory INRIA Sophia Antipolis 9th June 2008 Background on weak memory models Memory models, what are they good for? Hardware optimizations Contract between hardware

More information

11/19/2013. Imperative programs

11/19/2013. Imperative programs if (flag) 1 2 From my perspective, parallelism is the biggest challenge since high level programming languages. It s the biggest thing in 50 years because industry is betting its future that parallel programming

More information

High-Level Small-Step Operational Semantics for Software Transactions

High-Level Small-Step Operational Semantics for Software Transactions High-Level Small-Step Operational Semantics for Software Transactions Katherine F. Moore Dan Grossman The University of Washington Motivating Our Approach Operational Semantics Model key programming-language

More information

A Revisionist History of Denotational Semantics

A Revisionist History of Denotational Semantics A Revisionist History of Denotational Semantics Stephen Brookes Carnegie Mellon University Domains XIII July 2018 1 / 23 Denotational Semantics Compositionality Principle The meaning of a complex expression

More information

C++ Concurrency - Formalised

C++ Concurrency - Formalised C++ Concurrency - Formalised Salomon Sickert Technische Universität München 26 th April 2013 Mutex Algorithms At most one thread is in the critical section at any time. 2 / 35 Dekker s Mutex Algorithm

More information

Portland State University ECE 588/688. Memory Consistency Models

Portland State University ECE 588/688. Memory Consistency Models Portland State University ECE 588/688 Memory Consistency Models Copyright by Alaa Alameldeen 2018 Memory Consistency Models Formal specification of how the memory system will appear to the programmer Places

More information

Java Memory Model. Jian Cao. Department of Electrical and Computer Engineering Rice University. Sep 22, 2016

Java Memory Model. Jian Cao. Department of Electrical and Computer Engineering Rice University. Sep 22, 2016 Java Memory Model Jian Cao Department of Electrical and Computer Engineering Rice University Sep 22, 2016 Content Introduction Java synchronization mechanism Double-checked locking Out-of-Thin-Air violation

More information

C++ Memory Model Tutorial

C++ Memory Model Tutorial C++ Memory Model Tutorial Wenzhu Man C++ Memory Model Tutorial 1 / 16 Outline 1 Motivation 2 Memory Ordering for Atomic Operations The synchronizes-with and happens-before relationship (not from lecture

More information

Announcements. ECE4750/CS4420 Computer Architecture L17: Memory Model. Edward Suh Computer Systems Laboratory

Announcements. ECE4750/CS4420 Computer Architecture L17: Memory Model. Edward Suh Computer Systems Laboratory ECE4750/CS4420 Computer Architecture L17: Memory Model Edward Suh Computer Systems Laboratory suh@csl.cornell.edu Announcements HW4 / Lab4 1 Overview Symmetric Multi-Processors (SMPs) MIMD processing cores

More information

Review of last lecture. Peer Quiz. DPHPC Overview. Goals of this lecture. Lock-based queue

Review of last lecture. Peer Quiz. DPHPC Overview. Goals of this lecture. Lock-based queue Review of last lecture Design of Parallel and High-Performance Computing Fall 2016 Lecture: Linearizability Motivational video: https://www.youtube.com/watch?v=qx2driqxnbs Instructor: Torsten Hoefler &

More information

Chasing Away RAts: Semantics and Evaluation for Relaxed Atomics on Heterogeneous Systems

Chasing Away RAts: Semantics and Evaluation for Relaxed Atomics on Heterogeneous Systems Chasing Away RAts: Semantics and Evaluation for Relaxed Atomics on Heterogeneous Systems Matthew D. Sinclair *, Johnathan Alsop^, Sarita V. Adve + * University of Wisconsin-Madison ^ AMD Research + University

More information

Memory Consistency Models: Convergence At Last!

Memory Consistency Models: Convergence At Last! Memory Consistency Models: Convergence At Last! Sarita Adve Department of Computer Science University of Illinois at Urbana-Champaign sadve@cs.uiuc.edu Acks: Co-authors: Mark Hill, Kourosh Gharachorloo,

More information

MultiJav: A Distributed Shared Memory System Based on Multiple Java Virtual Machines. MultiJav: Introduction

MultiJav: A Distributed Shared Memory System Based on Multiple Java Virtual Machines. MultiJav: Introduction : A Distributed Shared Memory System Based on Multiple Java Virtual Machines X. Chen and V.H. Allan Computer Science Department, Utah State University 1998 : Introduction Built on concurrency supported

More information

Lecture 12: Relaxed Consistency Models. Topics: sequential consistency recap, relaxing various SC constraints, performance comparison

Lecture 12: Relaxed Consistency Models. Topics: sequential consistency recap, relaxing various SC constraints, performance comparison Lecture 12: Relaxed Consistency Models Topics: sequential consistency recap, relaxing various SC constraints, performance comparison 1 Relaxed Memory Models Recall that sequential consistency has two requirements:

More information

Lecture 11: Relaxed Consistency Models. Topics: sequential consistency recap, relaxing various SC constraints, performance comparison

Lecture 11: Relaxed Consistency Models. Topics: sequential consistency recap, relaxing various SC constraints, performance comparison Lecture 11: Relaxed Consistency Models Topics: sequential consistency recap, relaxing various SC constraints, performance comparison 1 Relaxed Memory Models Recall that sequential consistency has two requirements:

More information

Implementing the C11 memory model for ARM processors. Will Deacon February 2015

Implementing the C11 memory model for ARM processors. Will Deacon February 2015 1 Implementing the C11 memory model for ARM processors Will Deacon February 2015 Introduction 2 ARM ships intellectual property, specialising in RISC microprocessors Over 50 billion

More information

Pattern-based Synthesis of Synchronization for the C++ Memory Model

Pattern-based Synthesis of Synchronization for the C++ Memory Model Pattern-based Synthesis of Synchronization for the C++ Memory Model Yuri Meshman Technion Noam Rinetzky Tel Aviv University Eran Yahav Technion Abstract We address the problem of synthesizing efficient

More information

On partial order semantics for SAT/SMT-based symbolic encodings of weak memory concurrency

On partial order semantics for SAT/SMT-based symbolic encodings of weak memory concurrency On partial order semantics for SAT/SMT-based symbolic encodings of weak memory concurrency Alex Horn and Daniel Kroening University of Oxford April 30, 2015 Outline What s Our Problem? Motivation and Example

More information

A Concurrency Semantics for Relaxed Atomics that Permits Optimisation and Avoids Thin-Air Executions

A Concurrency Semantics for Relaxed Atomics that Permits Optimisation and Avoids Thin-Air Executions A Concurrency Semantics for Relaxed Atomics that Permits Optimisation and Avoids Thin-Air Executions Jean Pichon-Pharabod Peter Sewell University of Cambridge, United Kingdom first.last@cl.cam.ac.uk Abstract

More information