TinyOS Hardw are Evolution • Miniature hardware devices manufactured economically in large numbers • Microprocessors • Sensors • Wireless interfaces 5’’X3’’ 1’’X1’’ 1 mm 2 1 nm 2 Chenyang Lu 1 Chenyang Lu 2 Mi Mica2 M ca2 Mote te Hardw are Constraints • Processor • Microcontroller: 7.4 MHz, 8 bit Severe constraints on power, size, and cost � • Memory: 4KB data, 128 KB program • Slow CPU • Radio • Low-bandwidth radio • Max 38.4 Kbps • Limited memory • Sensors • Limited hardware parallelisms -> CPU hit by many interrupts! • Light, temperature, acceleration, acoustic, magnetic… • Manage sleep modes in hardware components • Power • <1 week on two AA batteries in active mode • >1 year battery life on sleep modes! Chenyang Lu 3 Chenyang Lu 4 Softw are Challenges Traditional OS • Small memory footprint • Multi-threaded • Efficiency - power and processing • Preemptive scheduling • Concurrency-intensive operations • Threads: Diversity in applications and platform � efficient modularity • • ready to run; • Support reconfigurable hardware and software • executing on the CPU; executing • waiting for data. gets CPU preempted needs data gets data Scheduler ready waiting needs data Chenyang Lu 5 Chenyang Lu 6
Existing Embedded OS Pros and Cons of Traditional OS Name Code Size Target CPU • Multi-threaded + preemptive scheduling pOSEK 2K Microcontrollers • Blocked threads waste memory pSOSystem PII->ARM Thumb • Context switch overhead VxWorks 286K Pentium -> Strong ARM QNX Nutrino >100K Pentium II -> NEC • I/O QNX RealTime 100K Pentium II -> SH4 • Blocking I/O: waste memory on blocked threads OS-9 Pentium -> SH4 • Polling (busy-wait): waste CPU cycles and power Chorus OS 10K Pentium -> Strong ARM ARIEL 19K SH2, ARM Thumb Creem 560 bytes ATMEL 8051 • QNX context switch = 2400 cycles on x86 • pOSEK context switch > 40 µs • Creem -> no preemption System architecture directions for network sensors, J. Hill, R. Szewczyk, A. Woo, S. Hollar, D. Culler, K. Pister. ASPLOS 2000. Chenyang Lu 7 Chenyang Lu 8 Typical Application TinyOS Solutions D. Culler et. Al., TinyOS boot camp presentation, Feb 2001 • Efficient modularity application sensing application • Application = scheduler + graph of components • Compiled into one executable Routing Layer routing • Only needed components are complied/loaded • Concurrency: event-driven architecture messaging Messaging Layer Main (includes Scheduler) packet Radio Packet Application (User Components) Radio Byte (MAC) byte Temp photo SW Actuating Sensing Communication Communication HW RFM ADC i2c Hardware Abstractions bit clocks Modified from D. Culler et. Al., TinyOS boot camp presentation, Feb 2001 Chenyang Lu 9 Chenyang Lu 10 Tw o-level Scheduling Multiple Data Flow s • Events handle interrupts • Interrupts trigger lowest level events • Respond quickly: sequence of event/command • Events can signal events, call commands, or post tasks through the component graph. • Immediate execution of function calls • Tasks perform deferred computations • e.g., get bit out of radio hw before it gets lost. • Interrupts preempt tasks and interrupts • Post tasks for deferred computations. • e.g., encoding. Preempt Tasks POST • Events preempt tasks to handle new interrupts. FIFO events commands commands Interrupts Time Hardware Chenyang Lu 11 Chenyang Lu 12
Scheduling Receiving a Message • Interrupts preempt tasks • Respond quickly • Event/command implemented as function calls • Task cannot preempt tasks • Reduce context switch � efficiency • Single stack � low memory footprint • TinyOS 2 supports pluggable task scheduler (default: FIFO). • Scheduler puts processor to sleep when • no event/command is running • task queue is empty Timing diagram of event propagation (step 0-6 takes about 95 microseconds total) Chenyang Lu 13 Chenyang Lu 14 Space Breakdow n… Pow er Breakdow n… Code size for ad hoc networking application Active Idle Sleep 5 μ A CPU 5 mA 2 mA 5 μ A Radio 7 mA (TX) 4.5 mA (RX) EE-Prom 3 mA 0 0 3500 Interrupts Panasonic Message Dispatch LED’s 4 mA 0 0 CR2354 3000 Initilization 200 μ A 560 mAh Photo Diode 0 0 C-Runtime Scheduler: 144 Bytes code 2500 Light Sensor 200 μ A Temperature 0 0 Totals: 3430 Bytes code Clock 2000 Bytes 226 Bytes data Scheduler • Lithium Battery runs for 35 hours at peak load and years at Led Control 1500 minimum load! Messaging Layer Packet Layer • That’s three orders of magnitude difference! 1000 Radio Interface • A one byte transmission uses the same energy as approx Routing Application 500 Radio Byte Encoder 11000 cycles of computation. 0 D. Culler et. Al., TinyOS boot camp presentation, Feb 2001 Chenyang Lu 15 Chenyang Lu 16 Time Breakdow n… Advantages Packet reception • Small memory footprint Components work breakdown CPU Utilization Energy (nj/Bit) • Only needed components are complied/loaded 0.05% 0.20% 0.33 AM • Single stack for tasks 1.12% 0.51% 7.58 Packet 26.87% 12.16% 182.38 • Power efficiency Ratio handler 5.48% 2.48% 37.2 Radio decode thread • Put CPU to sleep whenever the task queue is empty 66.48% 30.08% 451.17 RFM • TinyOS 2 provides efficient power management for peripherals - - 1350 and microprocessors. Radio Reception Idle - 54.75% - • Efficient modularity Total 100.00% 100.00% 2028.66 • Event/command interfaces between components • Event/command implemented as function calls • 50 cycle task overhead (6 byte copies) • Concurrency-intensive operations • 10 cycle event overhead (1.25 byte copies) • Event/command + tasks Chenyang Lu 17 Chenyang Lu 18
Disadvantages More • Lack preemptive real-time scheduling • Multi-threaded vs. event-driven architectures • Urgent task may wait for non-urgent ones • Lack empirical comparison against existing OSes • Lack flexibility • A “standard” OS is more likely to be adopted by industry • Jury is still out… • Static linking only • Alternative: Native Java Virtual Machine? • Cannot change parts of the code dynamically • Java programming • Virtual memory? • Virtual machine provides protection • Example: Sun SPOT Chenyang Lu 19 Chenyang Lu 20 Reading • J. Hill, R. Szewczyk, A. Woo, S. Hollar, D. Culler, and K. Pister, System Architecture Directions for Network Sensors. Chenyang Lu 21
Recommend
More recommend