1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui,...

52
LAWS OF ORDER: EXPENSIVE SYNCHRONIZATION IN CONCURRENT ALGORITHMS CANNOT BE ELIMINATED 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael
  • date post

    20-Dec-2015
  • Category

    Documents

  • view

    212
  • download

    0

Transcript of 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui,...

Page 1: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

LAWS OF ORDER: EXPENSIVE SYNCHRONIZATION IN CONCURRENT ALGORITHMS CANNOT BE ELIMINATED

1

Martin Vechev IBM T.J. Watson Research Center

Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael

Page 2: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

2

Concurrency

…is about synchronization

Page 3: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

3

Synchronization

but how much ?

Page 4: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

4

Synchronization

we don’t know

Page 5: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

5

Synchronization

manual empirical process

Page 6: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

6

Synchronization

time consuming

Page 7: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

7

Synchronization

too much is inefficient

Page 8: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

8

Synchronization

too little is incorrect

Page 9: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

9

Example: Set ADT

bool add(int key){ ???}

bool remove(int key){ ???}

bool contains(int key){ ???}

Page 10: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

10

Our Result

Concurrent abstract data types (stacks, queues, sets, hash tables,

counters …)

and mutual exclusion algorithms

must use expensive synchronization

Page 11: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

11

Implications

concurrent programming:

guidance on when avoiding expensive synchronization is futile

Page 12: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

12

“…although I hope that these shortcomings will be addressed, I hasten to add that they are insignificant compared to the huge step forward that this paper represents….”

-- Linux Weekly News, Jan 26, 2011

https://lwn.net/Articles/423994/

Implications

Page 13: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

13

Implications

hardware design:

motivation to lower cost of specific synchronization

Page 14: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

14

Implications

API design:

API specification affects synchronization

Page 15: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

15

Implications

program verification:

- declare incorrect when synchronization is missing - simplify verification under weak memory models

Page 16: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

16

What expensive synchronization?

order: read-after-write

Page 17: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

17

... write X read Y ...

read Ywrite X

modern architectures/languages

Read-after write

reordering

... write X fence read Y

Fence: enforce order

Example: Read-after-Write

Page 18: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

18

What expensive synchronization?

atomicity: atomic write-after-read

Page 19: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

Atomic Write-after-Read

... read X write Y ...

... read X write X ...

Examples:compare-and-swapfetch-and-addread-modify-write

Page 20: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

20

Which abstract data types ?

Atomicity

DeterminismCommutativity

Page 21: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

21

Example: Set ADT

bool add(v) add v bool remove(v) remove v bool contains(v) check if v is in the set

Page 22: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

22

Example: Set ADT

Example Histories:

add(5): true; remove(5): true; … add(5): true; add(5): false; … add(5): true; contains(5): true; …

Page 23: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

23

specification of Set is deterministic

Example: Set ADT

Page 24: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

24

commutativity: a way to select methods

Page 25: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

25

select non-commutative methods

Page 26: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

26

method A is non-commutative if there exists another method B where:

A influences Band

B influences A

Page 27: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

27

bool add(v) is non-commutative:

Example: Set ADT

add(v) influences

add(v)

Page 28: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

28

Example: Set ADT

{} add(5): true; add(5): false;

(add influences add)

Page 29: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

29

bool remove (v) is non-commutative:

Example: Set ADT

remove (v) influences

remove(v)

Page 30: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

30

bool contains(v) is commutative:

Example: Set ADT

contains(v) does not influence add(v), remove(v) or contains(v)

Page 31: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

31

How about void add(v) ?

void add(v) is commutative

Example: Set ADT

nobody can influence void add(v)

Page 32: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

32

Atomicity

DeterminismCommutativity

Which abstract data types ?

Page 33: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

33

Linearizability

DeterminismCommutativity

Which abstract data types ?

Page 34: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

34

Linearizability:

when a concurrent implementation

is equivalent to a sequential specification

[Herlihy&Wing – TOPLAS’90][Filipovic et. al – ESOP 2009]

Page 35: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

35

Theorem

given: deterministic sequential

specification, non-commutative method M

then: any linearizable implementation of spec

contains sequential executions of M that use

RAW or AWAR

Page 36: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

36

bool add(int key){ ???}

bool remove(int key){ ???}

bool contains(int key){ ???}

Example: Set ADT

Page 37: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

37

Set specification is deterministic

bool remove(v) is non-commutative

Any linearizable implementation of remove (v) must have sequential

executions with RAW or AWAR

Example: Set ADT

Page 38: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

38

bool add(int key){ ???}

bool remove(int key){ RAW or AWAR}

bool contains(int key){ ???}

Example: Set ADT

Page 39: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

39

Set specification is deterministic

bool contains(v) is commutative

cannot say anything about contains(v)

Example: Set ADT

Page 40: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

40

bool add(int key){ ???}

bool remove(int key){ RAW or AWAR}

bool contains(int key){ ???}

Example: Set ADT

Page 41: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

41

Set specification is deterministic

bool add(v) is non-commutative

Any linearizable implementation of add(v) must have sequential

executions with RAW or AWAR

Example: Set ADT

Page 42: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

42

bool add(int key){ RAW or AWAR}

bool remove(int key){ RAW or AWAR}

bool contains(int key){ ???}

Example: Set ADT

Page 43: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

43

Proof Intuition: Writing

show a method must write

otherwise, it cannot influence anyone

hence, method would be commutative

Page 44: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

44

{}

Proof Intuition: Writing

add(5) true {}

no shared write

add(5) true

add(5) did not influence add(5)

Page 45: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

45

Proof Intuition: Reading

show a method must read

otherwise, it cannot be influenced by anyone

hence, method would be commutative

Page 46: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

46

Proof Intuition: RAW

{}

add(5)

trueadd(5)

true

W

no RAW

add(5) true trueadd(5)

Linearization

{}

Page 47: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

47

Summary

Atomicity (Linearizability)

DeterminismCommutativity

RAWAWAR

Page 48: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

48

Future Directions

Even when laws have been written down, they ought not always to remain unaltered -- Aristotle

Page 49: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

49

Future Directions

Algorithm Specialization:

Relax dimensions to obtain new algorithms

Page 50: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

50

Future Directions

Can the dimensions be weakened? (while keeping lower bound)

Sequential Consistency ? Weaker Commutativity ? Abstract Determinism ?

Page 51: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

51

Future Directions

Can the result by strengthened ?

write-write read-read

sequences of reads and writes composite operations

more (all) executions

Page 52: 1 Martin Vechev IBM T.J. Watson Research Center Joint work with: Hagit Attiya, Rachid Guerraoui, Danny Hendler, Petr Kuznetsov, Maged Michael.

52

The End