Wireless Reprogramming HW2 • To be assigned tomorrow (Thursday) • Maté: mobile code • Due on 3/16 (Wed), 2:30pm • Agilla: mobile agent Chenyang Lu CSE 467S 1 Chenyang Lu CSE 467S 2 Motivation for Mobile Code XNP and Deluge • Need to reprogram sensors after deployment • Transmit native binary code • Change parameters • Re-flashes the instruction memory • Change/add/remove modules, e.g., filters, fusion • Large code size � code dissemination algorithms • is slow • Change whole program • is unreliable • Manual installation on a large number of nodes • has high communication and energy cost is impractical Chenyang Lu CSE 467S 3 Chenyang Lu CSE 467S 4 Maté Requirements • Byte code are disseminated through • Instruction Set wireless network • Expressive: supports most sensing applications • Concise : utilizes the least amount of network • Virtual machine interprets mobile byte bandwidth code • Tailorable: can be modified for special operations • Like mobile Java code • Virtual Machine • Small footprint : fits in rene2 (1KB data, 16KB code) • Resilient : cannot crash the mote • Efficient execution: energy conserving Chenyang Lu CSE 467S 5 Chenyang Lu CSE 467S 6
Instruction Set Simulate an operand stack • One-byte instruction (i=instruction, x=argument) pushc 3 # put the value (3) on the operand stack pushc 2 # put the value (2) on the operand stack • Basic arithmetic, sensing, halt, LED 00iiiiii add # add the two operand values together • s-class executed within send/receive 01iiixxx # and place the result (5) on the contexts # operand stack • x-class push, blez 1ixxxxxx halt # stop execution • 8 user-definable (default to no-op) • 3 variable types: values, sensors readings, messages Chenyang Lu CSE 467S 7 Chenyang Lu CSE 467S 8 Sample Program Capsules Clock Capsule: 11: pop # pop off counter • Code is divided into 24 byte capsules 00: pushc 0 12: add 01: sense # get light sensor 13: add • Each capsule fits in a single TinyOS packet reading 14: add # add up all four readings • Larger code can include up to 4 subroutine capsules 02: swap # keep counter on top 15: pushc 2 03: pushc 1 16: shiftr # divide by 4 (rt shift 2) • Types of capsules 04: add # increment the counter 17: pushm • Subroutine capsule 05: copy 18: clear # clear out message • Message send capsule: start in response to packet sent 06: inv buffer • Message receive capsule: start in response to packet received 07: pushc 4 19: add # put reading in buffer 08: add 20: send # send packet out • Timer capsule: start in response to a timer interrupt 09: blez 11 # if cnt > 4, then ave 21: pushc 0 # reset counter to zero 10: halt 22: halt Chenyang Lu CSE 467S 9 Chenyang Lu CSE 467S 10 Multiple Contexts Virtual Machine • 3 contexts: receive, send, clock Send Context • Instructions from 3 contexts can interleave • Each context has • Operand stack (data operations – depth of 16) heap Receive Context TinyOS • Return stack (subroutine invocations – depth of 8) • PC • One-word persistent heap (global variable Clock Context accessible from all contexts) Chenyang Lu CSE 467S 11 Chenyang Lu CSE 467S 12
A Context Maté Evaluation • Implementation of BLESS routing protocol • Performance measured • Acquisition of data while radio was off Byte • IPS (instructions per second) measured Code was using loop counts Operand Return heap PC Stack Stack •Post a new task to execute each instruction •Expensive for simple instructions •No race condition possible Chenyang Lu CSE 467S 13 Chenyang Lu CSE 467S 14 Energy Tradeoff Execution Overhead byte code vs. binary image • Byte code is more energy efficient than • Maté introduces quite a bit of overhead native code when frequent reprogramming is (33 to 1 at worst case) needed • 1/3 of overhead is due to each Maté • Byte codes requires less energy for dissemination instruction running as a separate task • Byte code is smaller than binary images • gdi-comm: 19 B vs. 7130 B • Byte code consumes more energy to execute Operation Mate Clock Cycles Native Clock Cycles Cost • Byte code has longer execution times Simple (and) 469 14 33.5 Downcall (rand) 435 45 9.7 • For GDI, Maté was more efficient for new Quick Split (sense) 1342 396 3.4 installations every first five days Long Split (sendr) 20,685 20,000 1.0 Chenyang Lu CSE 467S 15 Chenyang Lu CSE 467S 16 Code Safety Requirements Revisited • Instruction Set • Avoid race condition • Expressive??? • All instructions executed in tasks • Concise : utilizes the least amount of network • Maté cannot corrupt TinyOS bandwidth • Tailorable: can be modified for special operations • A “user/kernel” boundary • Virtual Machine • Maté code cannot preempt event/command • Small footprint : fits in rene2 (1KB data, 16KB code) • Memory protection: a context cannot • Resilient : cannot crash the mote access the states of another context • Efficient: energy conserving (tradeoff) • Code dissemination (“viral infection”): a forw instruction causes capsule be re-broadcasted Chenyang Lu CSE 467S 17 Chenyang Lu CSE 467S 18
Optional Readings Limitations of (Just) Mobile Code • P. Levis and D. Culler, “Maté: a Virtual Machine for • Whole network runs one application Tiny Networked Sensors.” ASPLOS, Dec 2002. • Cannot adapt to changes in • C.-L. Fok, G.-C. Roman, and C. Lu, "Rapid Development and Flexible Deployment of Adaptive Wireless Sensor • Goals Network Applications," ICDCS, June 2005. • Environment • Agilla: • Network http://www.cs.wustl.edu/mobilab/projects/agilla/ • Lack coordination among nodes Chenyang Lu CSE 467S 19 Chenyang Lu CSE 467S 20
Recommend
More recommend