40
Maté: A Tiny Virtual Machine for Sensor Networks Philip Levis and David Culler UC Berkeley Intel Research: Berkeley

Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Maté: A Tiny Virtual Machine for Sensor Networks

Philip Levis and David Culler UC Berkeley

Intel Research: Berkeley

Page 2: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

A Sensor Network

Page 3: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Sensor Network Motes

Page 4: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

A Sensor Network

Page 5: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

A Sensor Network

Page 6: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Bottom Line

•  Need in-situ programming •  Has to be:

–  Small –  Expressive –  Concise –  Resilient –  Efficient –  Tailorable –  Simple

Page 7: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Proposal

Maté: A Tiny Virtual Machine for Sensor Networks

Page 8: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Outline

•  Sensor networks •  Requirements •  Maté •  Evaluation •  Conclusion

Page 9: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Technological Constraints Mote Type WeC Rene Rene2 Dot Mica

Date Sep-99 Oct-00 Jun-01 Aug-01 Feb-02

Microcontroller (4MHz)

Type AT90LS8535 ATMega163 ATMega103/128

Prog. Mem. (KB) 8 16 128

RAM (KB) 0.5 1 4 Communication

Radio RFM TR1000

Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Page 10: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Example Application Scenario

•  Monitor Storm Petrel nesting on Great Duck Island

•  Inaccessible: 50 nodes in bird nests •  Simple sense and send loop •  Runs every 8 seconds – low duty cycle •  Frequent reprogramming would be useful

–  Biologists don't know what they need until they see it!

Page 11: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Proposal: Use a Virtual Machine!

•  Can express a wide range of applications •  Abstraction of complex operations •  Safe execution environment •  Interpretation overhead small •  Customizable instruction sets •  VM can handle code dissemination

Page 12: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

System Requirements

Requirement •  Small •  Expressive •  Concise •  Resilient •  Efficient •  Tailorable •  Simple

Maté provides •  7286B code, 603B RAM •  Bytecode interpeter •  GDI app is 19 bytes •  Safe execution environment •  Small CPU overhead •  User-definable instructions •  Viral self-programming

Page 13: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Why We Need a New VM

•  Communication centric •  Extensibility •  Power a critical consideration •  JVMs (KVM, PicoJava, etc.)

–  Need over 50 KB of RAM –  Strings? Are you crazy?

•  FORTH –  How do you install code? –  Maté draws on FORTH's design decisions

Page 14: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Maté in a Nutshell

•  Built on TinyOS, runs on rene and mica •  Three concurrent execution contexts •  Execution triggered by predefined events •  Two stack architecture •  Tiny code capsules self-propagate •  Communication and sensing instructions

–  built-in multihop routing

Page 15: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Maté Architecture

0 1 2 3

Subroutines

Clock

Send

Receive

Events

gets/sets

Code

Operand Stack

Return Stack

Maté

PC Mate Context

Page 16: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Maté Instructions

•  One byte per instruction •  Three classes: basic, s-type, x-type

–  basic: data, arithmetic, communication, sensing –  s-type: message headers –  x-type: embedded operands (e.g. push constant)

•  usr0-7 instructions: tailorability

basic 00iiiiii i = instruction s-type 01iiixxx x = argument x-type 1ixxxxxx

Page 17: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Maté Sense and Send

pushc 1 # Light is sensor 1 sense # Push light reading on stack pushm # Push message buffer on stack clear # Clear message buffer add # Append reading to buffer send # Send message on built-in halt # ad-hoc protocol

Page 18: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Maté Capsules

•  Hold up to 24 instructions •  Small enough to fit in a single

TinyOS packet –  atomic installation –  no buffering

•  Four types: send, receive, clock, subroutine –  context-specific: send, receive,

clock –  shared: subroutines 0-3 (call, ret)

0 1 2 3

Subroutines C

lock

Send

Receive

Events

gets/sets

Code

Operand Stack

Return Stack

PC

Page 19: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

But, How Do Capsules Get There?

Page 20: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Viral Code

•  Every capsule contains a version number •  Maté installs newer capsules it hears •  Programs can forward capsules

–  local broadcast –  forw, forwo

Page 21: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Self-Forwarding Sense and Send

pushc 1 # Light is sensor 1 sense # Push light reading on stack pushm # Push message buffer on stack clear # Clear message buffer add # Append reading to buffer send # Send message forw # Forward this capsule halt

Page 22: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Propagation Example

Page 23: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Propagation Example

Page 24: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Propagation Example

Page 25: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Propagation Example

Page 26: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Propagation Example

Page 27: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Propagation Example

Page 28: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Propagation Complete

Page 29: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Node Enters the Network

Page 30: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Node Joins the Network

Page 31: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Evaluation

•  What do we care about? –  CPU cycles –  bandwidth

– energy •  Execution rate •  Code propagation behavior

Page 32: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Maté Interpretation Overhead

•  ~10,000 instructions per second •  34:1 to 1.03:1 compared to native code

Operation Maté Native Cost and 469 inst 14 inst 34:1 rand 435 45 9.5:1 sense 1342 396 3.4:1 send 685 + ~20,000 ~20,000 1.03:1

Page 33: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Where Do the Cycles Go? Instruction Time Time portion pushc 1 40 us 0.06 % sense 240 us 0.24 % pushm 40 us 0.06 % clear 40 us 0.06 % add 50 us 0.08 % send 60,000 us 99.44 % halt 40 us 0.06%

•  Dominated by send •  Aggregate overhead: ~1.15:1

Page 34: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Code Propagation Methodology

•  42 node network •  3 x 14 grid, spaced 20 cm apart •  3 hop network (radio at very low power)

–  Cells were 15-30 nodes •  TinyOS 0.61 10Kb networking stack

Page 35: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Time to Complete Infection

•  Self-forwarding timer capsule runs every 20 seconds

•  Measures a quiet network (< 10% bandwidth)

Network Programming Rate

0%20%40%60%80%100%

0 20 40 60 80 100120140 160180200 220240

Time (seconds)

Perc

ent

Pro

gram

med

Page 36: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Propagation Rate Scalability

•  Timer capsule ran every second •  Capsule had a forwarding probability:

–  if ((rand & 0x1) == 0x1) forward(); •  Network cell bandwidth: 16 packets/second

Probability Expected Interval Time 12.5% 8 s 23 s 25% 4 s 10 s 50% 2 s 21 s

100% 1 s 400 s

Page 37: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Energy Consumption

•  Maté imposes a CPU overhead •  Maté provides a reprogramming savings

•  Rough energy cost comparison (1 hop) –  full active: ~15mA x 3V x seconds –  sense and send overhead/sample (2.5 ms) –  sleep (~15 uA) –  reprogramming savings (120 seconds) ⇒  50,000 samples equals one reprogram budget ⇒  400,000 seconds, 5 days

Page 38: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Conclusions

•  Maté can conserve energy •  Spectrum of reprogramming emerges

–  hardware –  native code –  bytecode interpreter

Page 39: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

Future Work

•  VM-land can replace user-land •  Higher-level languages: motlle •  Concurrency control •  Code propagation •  Bombilla: application specific Maté flavors

Page 40: Maté: A Tiny Virtual Machine for Sensor Networks€¦ · Prog. Mem. (KB) 8 16 128 RAM (KB) 0.5 1 4 Communication Radio RFM TR1000 Rate (Kbps) 10 10/40 Modulation Type OOK OOK/ASK

TinyOS Sense and Send event result_t Timer.fired() { if (state == IDLE && call Photo.sense()) {state = SENSE;} return SUCCESS; }

event result_t Photo.dataReady(uint16_t data) { if (state == SENSE) { packet->reading = data; if (call SendMsg.send(packet, sizeof(DataBuf)) { state = SENDING; } else {state = IDLE;} } return SUCCESS; }

event result_t SendMsg.sendDone(TOS_MsgPtr msg) { if (state == SENDING) {state = IDLE;} return SUCCESS; }