Compiling the -calculus into a Multithreaded Typed Assembly Language by variablepitch346

VIEWS: 3 PAGES: 22

									Compiling the π-calculus into a Multithreaded Typed Assembly Language
Tiago Cogumbreiro cogumbreiro@di.fc.ul.pt Joint work with Francisco Martins Vasco T. Vasconcelos
Universidade de Lisboa

Workshop on Places ’08

Goal Compilation from the π-calculus into a multithreaded typed assembly language (MIL) Result Type-preserving translation

Source language: typed π-Calculus

P ::= 0 x v x(y ).P P |Q ! x(y ).P

Processes nil output input parallel replicated input

v ::= ... x T ::= int (T ) 0

Values . . . integer name Types integer type channel type

(ν x : (T ))P restriction

Target language: MIL (architecture)

CPU core 1 registers instruction cache

CPU core N registers instruction cache

run pool

heap

Target language: MIL (features)

Locks
Create α, r := newLock b Acquire r := testSetLock v Release unlock v

Threads
Create fork v Finish yield

Type system enforces race-condition freedom

Translating processes and values

P

Environment fn(P) [[P]]

x

State Messages Processes

Translation of nil processes

[[0]]

yield

Translation of nil processes

[[0]]

yield

CPU core 1 registers [[0]]

CPU core 1 registers yield

Translation of output processes
[[x v ]] jump send(x, v )

Translation of output processes
[[x v ]] jump send(x, v ) Supporting Library enqueue;yield

no
send [[x v ]]

o pr

s se es c

[[P{v /y }]] reduce

Translation of parallel processes

[[P | Q]]

fork [[Q]]; jump [[P]]

Translation of parallel processes

[[P | Q]]

fork [[Q]]; jump [[P]]

CPU core 1 registers [[P | Q]] Thread pool

CPU core 1 registers [[P]] Thread pool [[Q]]

Translation of input processes
[[x(y ).P]] jump receive(x, P)

Translation of input processes
[[x(y ).P]] jump receive(x, P) Supporting Library enqueue;yield

no
receive [[x(y ).P]]

m

sa es

ge

s

[[P{v /y }]] reduce

Supporting library

Queue operations (creating, enqueueing, dequeueing) Three public operations send, receive, and create channel 19 code blocks 34 type definitions 322 lines of MIL code 8 registers needed Locks are abstracted from the translation function

Lock usage

Multiple readers on environments (no contention) One lock per channel

Spin lock

s e n d [ a l p h a , t a u ] ( r 1 : tau , r 4 : ChannelType ( tau , a l p h a ) , r 5 : <l o c k ( a l p h a )>ˆ a l p h a ) { −− s p i n l o c k t o a c q u i r e t h e g l o b a l l o c k a l p h a r 2 := t s l S r 5 i f r2 = 0 −− a c q u i r e d t h e l o c k , unpack t h e c h a n n e l jump sendUnpack [ t a u ] [ a l p h a ] −− t r y a g a i n jump s e n d [ t a u ] [ a l p h a ] }

Trying to reduce

sendMessage [ alpha , tau ] ( r 1 : tau , r 2 : ChannelQueueType ( tau , a l p h a ) , r 3 : <l o c k ( a l p h a )>ˆ a l p h a ) r e q u i r e s ( alpha ; ; ) { −− g e t t h e s t a t e o f t h e c h a n n e l r 4 := C h a n n e l Q u e u e S t a t e ( r 2 ) i f r 4 = CHANNEL QUEUE WITH PROCS −− when t h e r e a r e , d e l i v e r t h e message : jump s e n d M e s s a g e R e d u c e [ t a u ] [ a l p h a ]

−− f l a g t h e c h a n n e l a s c o n t a i n i n g m e s s a g e s : C h a n n e l Q u e u e S t a t e ( r 2 ) := CHANNEL QUEUE WITH MSGS −− g e t t h e queue o f m e s s a g e s r 2 := ChannelQueueMsgs ( r 2 ) −− p u t t h e message ( r 1 ) i n t h e queue QueueAdd ( r2 , r1 , r4 , r1 , tau , a l p h a ) unlockE r3 yield }

Conclusions

Formalized translation in a multithreaded architecture Type-preservation: If P is a well typed π-process, then [[P]] is a well typed MIL program

Future work

Simplifying the supporting library Extend MIL (lock-free channels) Correctness

For publications and implementation, please refer to http://gloss.di.fc.ul.pt/mil Thank you. Any questions?


								
To top