29
Colorama: Architectural Support for Data- Centric Synchronization Luis Ceze, Pablo Montesinos, Christoph von Praun, Josep Torrellas

Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Colorama: Architectural Support for Data-Centric Synchronization

Luis Ceze, Pablo Montesinos, Christoph von Praun, Josep Torrellas

Page 2: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Code-Centric vs. Data-Centric Synchronization

2

lock Lld Ast Bst Cunlock L

lock Lst Ast Bunlock L

ld Ast Bst C

st Ast B

A B C

inferred criticalsections

A B Cdeclare A,B,C declare A,B,C

color red A,B,C

Page 3: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Code-Centric vs. Data-Centric Synchronization

3

CCS DCS

reasoning non-local mostly local

critical sections

explicitly defined

inferred by system

models Locks, TM ☺

Page 4: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Example from mysql

4

header

info

•header fields same color

• each info different color

DCS

CCS• declared in a single place

•header protected by global lock

• 29 sites

•info protected by its own lock

• 14 sites

header

info

header

info

Page 5: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Software DCS

•Software-only DCS concurrently developed [Vaziri PoPL’06]

• for object-oriented languages (Java)

•Needs whole-program analysis• might be impractical

•Some code-centric annotations necessary • lack of dynamic information

•What about C/C++?

5

Page 6: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Colorama: Architecture Support for DCS

•Main advantage: cheaply watch all memory references

•Interface to color shared data

•Enter critical section if colored data is touched• HW checks the color of every memory access

•Exit critical section using an exit policy• HW provides mechanisms to exit critical sections and enforce policy

•Flexible HW• provides the main hooks, software makes decisions

6

Page 7: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Start

Address

End

Address ColorID

Palette

Shared Per Thread

Owned Colors Array

Color Acquire Bitmap

Register (CAB)

Color Release Bitmap

Register (CRB)

Thread Color Status

ColorIDi

Architecture Components

7

Page 8: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Colorama Operation Example

8

ld Ast Bst C

st Est F

color A redcolor B redcolor C redcolor E greencolor F green

PaletteA redB redC redE greenF green

✓trap to user-level handler, start red critical section

✓trap to user-level handler, exit red critical section

Thread 1’s Owned Colors

Array

redgreen

✓trap to user-level handler, start green critical section

✓trap to user-level handler, exit green critical section

thread 1

inferred criticalsections

Page 9: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Exiting a Critical Section

•Knowing when to start a critical section is easy

•Knowing when to end is very hard

•Optimal place undecidable

•Solution is to rely on programming model restrictions

•We use:• Return of subroutine where the critical section started

9

Page 10: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

void proc1()

{

...

...

<access variable

with ColorID1>

...

...

...

}

ColorID1

critical

section

void proc1()

{

...

<access variable

with ColorID1>

proc2();

...

}

void proc2()

{

...

<access variable

with ColorID2>

...

}

ColorID1

critical

section

ColorID2

critical

section

void proc1()

{

...

...

<access variable

with ColorID1>

...

...

<access variable

with ColorID2>

...

...

}

ColorID1

critical

sectionColorID

2

critical

section

Exit Policy

10

Page 11: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Intuition Behind Exit Policy

•Functions are natural units of work

•Programmers already think this way• empirical data later

•Most bad cases are easily avoided

•Consistent with concurrently developed S-DCS work• [Vaziri PoPL’06] uses whole methods as critical sections

11

Page 12: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Pointer Watching

12

•colorcheck instructions are inserted by the compiler

void htUpdate()

{

...

lock(L)

i = readHash(htPtr)

...

writeHash(htPtr, i)

unlock(L)

...

}

Lock-based code

color hashTable, red

void htUpdate()

{

...

i = readHash(htPtr)

...

writeHash(htPtr, i)

...

}

Colorama code

void htUpdate()

{

...

colorcheck htPtr i = readHash(htPtr)

...

colorcheck htPtr writeHash(htPtr, i)

...

}

critical

section

Colorama code with

colorcheck

color hashTable, red

Page 13: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Detailed Operation

13

f()

call g()

ld A

Red

Color Acquire Bitmap(CAB register)

Blue Green

ld B

ld Z

stack ← CABCAB ← 0

CRB ← CABCAB ← stack

✓ exits critical sections Red and Green

...

ret

Blue

...

...

subroutine prologue/epilogueinserted by the compiler

Owned Colors Array

ld T

BlueRedGreen

Page 14: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Thread

ID

Virtual Address

Tag

12b 12b 12b...2b 2b...

Permissions

InfoColor ID

Info

PLB entry

MMP with the Palette extensions

Processor Memory

Protection Lookaside

Buffer (PLB)

MultilevelPermissions

Table

Palette Implementation

14

•Mondrian Memory Protection [Witchel ASPLOS’02]• extensions for coloring (shaded)

Page 15: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

void foo1()

{

lock(LA)

A = ...

unlock(LA)

lock(LB)

B = ...

unlock(LB)

}

void foo2()

{

lock(LB)

B = ...

unlock(LB)

lock(LA)

A = ...

unlock(LA)

}

ColorIDB

critical

section

void foo1()

{

A = ...

B = ...

}

ColorIDA

critical

section

void foo2()

{

B = ...

A = ...

}

ColorIDA

critical

section

ColorIDB

critical

section

Deadlock Issues in Lock-based Implementation

15

• Inherent limitation of a lock-based Colorama implementation

• TM-based implementation recommended ☺

• Color Ownership Table in memory (SW) for deadlock detection

• Less problems as programmers get used to model

Page 16: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Colorama Evaluation

•No Colorama programs (yet)

•Evaluation consisted in detailed profiling of open-source parallel programs• Developed Pin tool to profile critical sections

• Used MySQL, FireFox, aolserver, tuxracer, ...

•Estimated programming model suitability

•Estimated overheads

16

Page 17: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Exit Policy Suitability

aolserver

barnesfirefox

gaim gftp mysqltuxracer

Avg0

102030405060708090

100

% C

ritica

l Sec

tions Unmatched

Matched

D S D S D S D S D S D S D S D S

17

Page 18: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Memory Overhead of Coloring

Palette

MMPwithPermissionInfo

aolserver

barnesfirefox

gaim gftp mysqltuxracer

Avg0

5

10

15

20

25

30

Mem

ory

Ove

rhea

d (%

) 8 bit colorID16 bit colorID24 bit colorID32 bit colorID

18

Page 19: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Colorama Evaluation Summary

19

•Programming model apparently suitable• few static corner cases, even fewer dynamic

•Overheads tolerable• most of the overhead comes from baseline fine-grain memory

protection

Page 20: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Colorama Conclusion

•DCS can greatly simplify parallel programming• programmer only specifies the colors and follows a simple policy

• the system, in return, guarantees consistency of shared data

•Hardware has important advantages over a software-only approach

20

Page 21: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Backup Slides

Page 22: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Code-Centric Synchronization

•Locks and TM are code-centric approaches• the programmer explicitly defines code inside the critical sections

•May require non-local reasoning• changing one critical section implies reasoning about effects on critical

sections located in other parts of the program

•Annotations proportional to number of accesses to shared data

•TM is a major simplification over locks• can we go beyond that?

22

Page 23: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Data-Centric Synchronization (DCS)

•Programmer explicitly assigns all shared data to consistency domains• typical domains contain multiple data structures

• domains define sets of data that need to be kept self-consistent

•The system then infers the critical sections automatically• guarantees mutual consistency of data inside same domain

•Main benefits: more local reasoning• programmer thinks about data consistency at declaration time

• annotations proportional to the number of shared data structures [Vaziri PoPL’06]

23

Page 24: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

CCS x DCS Reasoning

•Non-Local• What other parts of the code should I visit to make sure what I did is

correct?

• How do critical sections interfere?

•Local• Think about data consistency when creating data-structures

• the rest should be (mostly) automatic

•Every time shared data is touched• programmer needs to insert code for critical sections

• critical sections exist to keep data consistent, why not annotate data?

24

Page 25: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

void unrealize (Widget *w)

{

if (w->realized) {

lock (L);

<free structure> /*CRASH*/

w->realized = false;

unlock (L);

}

}

Code-centric (with data race)

color(w, sizeof(*w), GREEN);

void unrealize(Widget *w)

{

if (w->realized) {

<free structure>

w->realized = false;

}

}

Colorama (data-race free)

Another Example

25

Page 26: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Monitors

•Conceptually Data-Centric approach to concurrency management

•Programmer still needs to specify what code operates the monitored data (code-centric)• monitor interface, needs to be adjusted according to the operation

• still allow for high-level data-races

•H-DCS is essentially hardware support for very flexible monitors• monitor operations are “inferred” from actual code, no need to often

redefine monitor interface

26

Page 27: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Refining Exit Policy - Detecting Partial Updates

27

st Cst Dret

st Ast Bret...st Cst Dret

ld Ald Bld Cret

exit policy

violation

ABCD

Last Update

C0

C1

C2

C1

C1C0

C0

C2

C2

C1C1C0

not all tags are the same,possible atomicity violation

Page 28: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

Refining Exit Policy - Making It Shorter

28

st Pst Qld R

ret

CRB ← CAB

if T !colored CRB ← CAB

st T

CAB ← stack

provably local data (not-colored)

CRB ← CABpossibly local

Page 29: Colorama: Architectural Support for Data- Centric ...iacoma.cs.uiuc.edu/iacoma-papers/PRES/present_hpca07.pdf · Colorama: Architecture Support for DCS •Main advantage: cheaply

API

29

System Callscolor (StartAddr, Size, ColorID)colorprop(StartAddr,Size,ColoredAddr)decolor (Addr)

Instructionscolorcheck Addrgetcolorid Addr, regmov reg, CABmov CAB, regmov reg, CRB

Library Callscolor release ()color release (Addr)color temp release (Addr)color reacquire ()