26
6/17/2002 1 Philip Levis UC Berkeley Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

  • View
    219

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 1 Philip LevisUC Berkeley

Maté: A Tiny Virtual Machine

Viral Programs with a Certain Cosmopolitan Charm

Page 2: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 2 Philip LevisUC Berkeley

Maté

• Motivation• Overview• Architecture, Instructions• Viral code• Evaluation• Bombadillo• Conclusion

Page 3: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 3 Philip LevisUC Berkeley

Motivation

• TinyOS programming complex• Application flexibility needed• Binary reprogramming takes ~2 minutes– significant energy cost– can lose motes

Page 4: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 4 Philip LevisUC Berkeley

Maté Overview

• TinyOS component• 7286 bytes code, 603 bytes RAM• Three concurrent execution contexts• Stack-based bytecode interpreter• Code broken into 24 instruction capsules• Self-forwarding code• Rapid reprogramming• Message receive and send contexts

Page 5: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 5 Philip LevisUC Berkeley

Maté Overview, Continued

• Three execution contexts– Clock, Receive, Send

• Seven code capsules– Clock, Receive, Send, Subroutines 0-3

• One word heap– gets/sets instructions

• Two-stack architecture– Operand stack, return address stack

Page 6: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 6 Philip LevisUC Berkeley

Maté Architecture

0 1 2 3

Subroutines

Clo

ck

Sen

d

Receive

Events

gets/sets

Co

de

OperandStack

ReturnStack

Maté

PC MateContext

Page 7: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 7 Philip LevisUC Berkeley

Maté Instructions

0 1 2 3

Subroutines

Clo

ck

Sen

d

Receive

Events

gets/sets

Co

de

OperandStack

ReturnStack

Maté

PC MateContext

Page 8: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 8 Philip LevisUC Berkeley

Maté Instructions

• Two-stack architecture• One byte per instruction• Three classes: basic, s-type, x-type– basic: data, arithmetic, communication, sensing– s-type: used in send/receive contexts– x-type: embedded operands

basic 00iiiiii i = instruction

s-type 01iiixxx x = argument

x-type 1ixxxxxx

Page 9: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 9 Philip LevisUC Berkeley

Code Snippet: cnt_to_leds

gets # Push heap variable on stackpushc 1 # Push 1 on stackadd # Pop twice, add, push resultcopy # Copy top of stacksets # Pop, set heappushc 7 # Push 0x0007 onto stackand # Take bottom 3 bits of valueputled # Pop, set LEDs to bit patternhalt #

Page 10: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 10 Philip LevisUC Berkeley

cnt_to_leds, Binary

gets # 0x1bpushc 1 # 0xc1add # 0x06copy # 0x0bsets # 0x1apushc 7 # 0xc7and # 0x02putled # 0x08halt # 0x00

Page 11: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 11 Philip LevisUC Berkeley

Sending a Message

pushc 1 # Light is sensor 1sense # Push light reading on stackpushm # Push message buffer on stackclear # Clear message bufferadd # Append reading to buffersend # Send message using built-inhalt # ad-hoc routing system

Page 12: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 12 Philip LevisUC Berkeley

Maté Capsules

0 1 2 3

Subroutines

Clo

ck

Sen

d

Receive

Events

gets/sets

Co

de

OperandStack

ReturnStack

Maté

PC MateContext

Page 13: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 13 Philip LevisUC Berkeley

Maté Capsules

• Hold up to 24 instructions• Fit in a single TinyOS AM packet– Installation is atomic

• Four types: send, receive, clock, subroutine• Context-specific: send, receive, clock• Called: subroutines 0-3• Version information

Page 14: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 14 Philip LevisUC Berkeley

Maté Contexts

0 1 2 3

Subroutines

Clo

ck

Sen

d

Receive

Events

gets/sets

Co

de

OperandStack

ReturnStack

Maté

PC MateContext

Page 15: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 15 Philip LevisUC Berkeley

Contexts

• Each context associated with a capsule• Executed in response to event– external: clock, receive– internal: send (in response to sendr)

• Execution model– preemptive: clock– non-preemptive: send, receive

• Every instruction executed as TinyOS task

Page 16: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 16 Philip LevisUC Berkeley

Viral Code

• Every capsule has version information• Maté installs newer capsules it hears on

network• Motes can forward their capsules (local

broadcast)– forw– forwo

Page 17: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 17 Philip LevisUC Berkeley

Forwarding: cnt_to_leds

gets # Push heap variable on stackpushc 1 # Push 1 on stackadd # Pop twice, add, push resultcopy # Copy top of stacksets # Pop, set heappushc 7 # Push 0x0007 onto stackand # Take bottom 3 bits of valueputled # Pop, set LEDs to bit patternforw # Forward capsulehalt #

Page 18: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 18 Philip LevisUC Berkeley

Evaluation

• Code Propagation• Execution Rate• 42 motes: 3x14 grid• 3 hop network– largest cell 30 motes– smallest cell 15 motes

Page 19: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 19 Philip LevisUC Berkeley

Code Propagation

Network Programming Rate

0%

20%

40%

60%

80%

100%

0 20 40 60 80 100 120 140 160 180 200 220 240

Time (seconds)

Per

cen

t P

rog

ram

med

Page 20: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 20 Philip LevisUC Berkeley

Code Propagation, Continued(seconds)

  Network: 1/8 Network: 1/4

New Mean Std. Dev. Mean Std. Dev

1/8 23 8 28 15

1/4 10 4 10 4

1/2 7 3 7 2

1/1 8 2 12 5

  Network: 1/2 Network: 1/1

New Mean Std. Dev. Mean Std. Dev

1/8 45 24 361 252

1/4 19 10 425 280

1/2 21 10 226 199

1 14 4 400 339

Page 21: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 21 Philip LevisUC Berkeley

Maté Instruction Issue Rate

• ~10,000 instructions per second• Task operations are 1/3 of Maté overhead

Page 22: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 22 Philip LevisUC Berkeley

Energy Consumption

• Compare with binary reprogramming• Maté imposes a CPU overhead• Maté provides a reprogramming time savings• Energy tradeoff

Page 23: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 23 Philip LevisUC Berkeley

Case Study: GDI

• Great Duck Island application• Simple sense and send loop• Runs every 8 seconds – low duty cycle• 19 Maté instructions, 8K binary code• Energy tradeoff: if you run GDI application

for less than 6 days, Maté saves energy

Page 24: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 24 Philip LevisUC Berkeley

Future Work

• Execution model• Programming language: motlle• Concurrency• Code propagation• Bombadillo: application specific virtual

machines

Page 25: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 25 Philip LevisUC Berkeley

Conclusions

• Spectrum of reprogramming emerges– Hardware– Native code– Bytecode interpreter

• VM can provide user-land guarantees• Will be available in next TinyOS release

Page 26: Philip Levis UC Berkeley 6/17/20021 Maté: A Tiny Virtual Machine Viral Programs with a Certain Cosmopolitan Charm

6/17/2002 26 Philip LevisUC Berkeley

Questions