IoT Operating Systems
Chenyang Lu
1
IoT Operating Systems Chenyang Lu 1 Critiques 1/2 page critiques - - PowerPoint PPT Presentation
IoT Operating Systems Chenyang Lu 1 Critiques 1/2 page critiques of research papers Due at 10am on the class day (hard deadline) Email Corey <dairuixuan@wustl.edu> in plain txt Back-of-envelop notes - NOT whole essays
1
Ø 1/2 page critiques of research papers Ø Due at 10am on the class day (hard deadline) Ø Email Corey <dairuixuan@wustl.edu> in plain txt Ø Back-of-envelop notes - NOT whole essays Ø Guidelines: http://www.cs.wustl.edu/%7Elu/cse521s/critique.html
2
Ø Due on 9/24 Ø D. Gay, P. Levis, R. von Behren, M. Welsh, E. Brewer, and D. Culler, The nesC Language: A Holistic Approach to Networked Embedded Systems, ACM Conference on Programming Language Design and Implementation (PLDI), June 2003.
Chenyang Lu 3
Ø Due on 10/15 Ø M. Buettner, G.V. Yee, E. Anderson and R. Han, X-MAC: a Short Preamble MAC Protocol for Duty-Cycled Wireless Sensor Networks, ACM Conference on Embedded Networked Sensor Systems (SenSys), November 2006.
Chenyang Lu 4
q 6-min talk + 1-min Q&A q 4 slides q Rehearse over Zoom q Turn on your video during your presentation
5
q Team members q Concise description of project q Responsibilities of each member q Equipment needed
q Email to Corey
6
7
8
Ø Linux Ø Windows 10 IoT Core: Windows 10 optimized for ARM and x86/x64. Ø Amazon FreeRTOS: open-source FreeRTOS kernel + libraries to securely connect devices to AWS cloud services. Ø Arm Mbed: open-source OS for Arm Cortex-M microcontrollers. Ø Contiki: open-source, multi-threaded OS.
Chenyang Lu 9
Chenyang Lu 10
TelosB Ø TI MSP430 microcontroller, 4/8 MHz, 8 bit Ø Memory: 10KB data, 48 KB program Ø IEEE 802.15.4 radio: max 250 Kbps Raspberry Pi 4 Ø Quad core Cortex-A72 64-bit SoC, 1.5GHz Ø 2GB-8GB SDRAM Ø IEEE 802.11ac wireless, Bluetooth 5.0, BLE Ø Gigabit Ethernet
Chenyang Lu 11
I/O (some shared) 8 ADC (12 bit) 2 DAC (12 bit) 1 I2C 1 JTAG 1 1-Wire 2 SPI 2 UART 8 general, 8 interrupt, and 5 special pin connectors
12
16 MB Flash memory CC2420 radio 802.15.4 6LoWPAN/IPv6 Typical sleep current 9μA at 3V, radio active ~20mA
3 V TI MSP430
2.5 x 2.5 cm Unique hardware ID Clock 4/8 MHz
q I2C, SPI, ADC
q Turn peripherals on only when needed q Turn off otherwise
13
Chenyang Lu 14
q Support reconfigurable hardware and software
Chenyang Lu 15
q who gets the CPU; q when I/O takes place; q how much memory is allocated; q power management
Chenyang Lu 16
Chenyang Lu 17
engine controller
q Several copies of a program may run simultaneously.
q Data in registers, Program Counter (PC), status. q Stored in Process Control Block (PCB)
q Threads share memory space in a same process.
Chenyang Lu 18
q ready to run; q executing on the CPU; q waiting for data.
Chenyang Lu 19
executing ready waiting needs data gets data needs data preempted gets CPU
Chenyang Lu 20
time P2 released P1 released P3 released 30 10 20 60 40 50 P2 P2 P1 P3
Chenyang Lu 21
CPU
memory
q Preempted threads waste memory q Context switch overhead
q Blocking I/O: waste memory on blocked threads q Polling (busy-wait): waste CPU cycles and power
Chenyang Lu 22
Ø QNX context switch = 2400 cycles on x86 Ø pOSEK context switch > 40 µs Ø Creem -> no preemption
Chenyang Lu 23
Name Code Size Target CPU pOSEK 2K Microcontrollers pSOSystem PII->ARM Thumb VxWorks 286K Pentium -> Strong ARM QNX Nutrino >100K Pentium II -> NEC QNX RealTime 100K Pentium II -> SH4 OS-9 Pentium -> SH4 Chorus OS 10K Pentium -> Strong ARM ARIEL 19K SH2, ARM Thumb Creem 560 bytes ATMEL 8051
System architecture directions for network sensors, J. Hill, R. Szewczyk, A. Woo, S. Hollar, D. Culler, K. Pister. ASPLOS 2000.
q Application = scheduler + graph of components q Compiled into one executable q Only needed components are complied/loaded
Chenyang Lu 24
Co Commun mmunicati tion Ac Actuating ing Se Sensing Co Commun mmunicati tion Ap Applic icatio ion n (User Compone nent nts) Ma Main (includes s Scheduler) r) Ha Hardware Abstractions
Modified from D. Culler et al., TinyOS boot camp presentation, Feb 2001
Chenyang Lu 25
SurgeC BootC SurgeP
StdControl ADC Timer Leds SendMsg StdControl
PhotoC
ADC StdControl
TimerC MultihopC LedsC
Leds SendMsg StdControl Timer StdControl
q <1 week on two AA batteries in active mode q >1 year battery life on sleep modes!
Chenyang Lu 26
Chenyang Lu 27
RFM Radio Byte (MAC) Radio Packet i2c Temp photo Messaging Layer clocks bit byte packet Routing Layer sensing application application
HW SW
ADC messaging routing
q Interrupts trigger lowest level events q Events can signal events, call commands, or post tasks
Chenyang Lu 28
Hardware Interrupts events commands FIFO Tasks POST Preempt Time commands
q Immediate execution of function calls q e.g., get bit out of radio before it gets lost.
q e.g., encoding.
Chenyang Lu 29
Chenyang Lu 30
Timing diagram of event propagation (step 0-6 takes about 95 microseconds total)
q Respond quickly q Event/command implemented as function calls
q Reduce context switch à efficiency q Single stack à low memory footprint q TinyOS 2 supports pluggable task scheduler (default: FIFO).
q no event/command is running q task queue is empty
Chenyang Lu 31
Chenyang Lu 32
500 1000 1500 2000 2500 3000 3500
Bytes
Interrupts Message Dispatch Initilization C-Runtime Light Sensor Clock Scheduler Led Control Messaging Layer Packet Layer Radio Interface Routing Application Radio Byte Encoder
Scheduler: 144 Bytes code Totals: 3430 Bytes code 226 Bytes data
q Lithium battery runs for 35 hours at peak load and years at
minimum load!
q A one byte transmission uses the same energy as
approximately 11000 cycles of computation.
Chenyang Lu 33
Active Idle Sleep CPU 5 mA 2 mA 5 μA Radio 7 mA (TX) 4.5 mA (RX) 5 μA EE-Prom 3 mA LED’s 4 mA Photo Diode 200 μA Temperature 200 μA
Panasonic CR2354 560 mAh
Ø 50 cycle task overhead (6 byte copies) Ø 10 cycle event overhead (1.25 byte copies)
Chenyang Lu 34
Components
Packet reception work breakdown CPU Utilization Energy (nj/Bit) AM
0.05% 0.20% 0.33
Packet
1.12% 0.51% 7.58
Radio handler
26.87% 12.16% 182.38
Radio decode thread
5.48% 2.48% 37.2
RFM
66.48% 30.08% 451.17
Radio Reception
Idle
100.00% 100.00% 2028.66
q Only needed components are complied/loaded q Single stack for tasks
q Put CPU to sleep whenever the task queue is empty q TinyOS 2 (ICEM) provides power management for peripherals.
q Event/command interfaces between components q Event/command implemented as function calls
q Event/command + tasks
Chenyang Lu 35
Chenyang Lu 36
q Improve robustness: detect race conditions q Optimization: function inlining
q No function pointer q No malloc q Call graph and variable access are known at compile time
Chenyang Lu 37
q provides interface q uses interface
Chenyang Lu 38
q module: C behavior q configuration: select & wire
SurgeC BootC SurgeP
StdControl ADC Timer Leds SendMsg StdControl
PhotoC
ADC StdControl
TimerC MultihopC LedsC
Leds SendMsg StdControl Timer StdControl
Chenyang Lu 39
q provides interface q uses interface
module TimerP { provides { interface StdControl; interface Timer; } uses interface Clock; ... }
Clock Timer StdControl
TimerP
q module: C behavior q configuration: select & wire
interface Clock { command error_t setRate(char interval, char scale); event error_t fire(); } interface Send { command error_t send(message_t *msg, uint16_t length); event error_t sendDone(message_t *msg, error_t success); } interface ADC { command error_t getData(); event error_t dataReady(uint16_t data); }
Chenyang Lu 40
Chenyang Lu 41
module SurgeP { provides interface StdControl; uses interface ADC; uses interface Timer; uses interface Send; } implementation { bool busy; norace uint16_t sensorReading; async event result_t Timer.fired() { bool localBusy; atomic { localBusy = busy; busy = TRUE; } if (!localBusy) call ADC.getData(); return SUCCESS; } async event result_t ADC.dataReady(uint16_t data) { sensorReading = data; post sendData(); return SUCCESS; } ... }
Chenyang Lu 42
TimerC
Clock
HWClock
Clock Timer StdControl
TimerP
Timer StdControl
configuration TimerC { provides { interface StdControl; interface Timer; } } implementation { components TimerP, HWClock; StdControl = TimerP.StdControl; Timer = TimerP.Timer; TimerP.Clock -> HWClock.Clock; }
Chenyang Lu 43
SurgeC BootC SurgeP
StdControl ADC Timer Leds SendMsg StdControl
PhotoC
ADC StdControl
TimerC MultihopC LedsC
Leds SendMsg StdControl Timer StdControl
Ø Race condition: concurrent interrupts/tasks update shared variables. Ø Only interrupts cause preemption à concurrency
q Asynchronous code (AC): reachable from at least one interrupt. q Synchronous code (SC): reachable from tasks only.
Ø Any update of a shared variable from AC is a potential race condition!
Chenyang Lu 44
module SurgeP { ... } implementation { bool busy; norace uint16_t sensorReading; async event result_t Timer.fired() { if (!busy) { busy = TRUE; call ADC.getData(); } return SUCCESS; } task void sendData() { // send sensorReading adcPacket.data = sensorReading; call Send.send(&adcPacket, sizeof adcPacket.data); return SUCCESS; } async event result_t ADC.dataReady(uint16_t data) { sensorReading = data; post sendData(); return SUCCESS; }
Chenyang Lu 45
q No loop q No command/event q Function calls OK, but callee must meet restrictions too
Chenyang Lu 46
module SurgeP { ... } implementation { bool busy; norace uint16_t sensorReading; async event result_t Timer.fired() {
bool localBusy; atomic { localBusy = busy; busy = TRUE; } if (!localBusy) call ADC.getData(); return SUCCESS; }
Chenyang Lu 47
test-and-set
disable interrupt enable interrupt
q is from SC only, or q occurs within an atomic section.
q Make access to shared variables atomic. q Move access to shared variables to tasks.
Chenyang Lu 48
q 186 modules (121 modules, 65 configurations) q 20-69 modules/app, 35 average q 17 tasks, 75 events on average (per application) - lots of concurrency!
q About 6 per 1000 lines of code!
q Add atomic sections q Post tasks (move code to task context)
Chenyang Lu 49
Chenyang Lu CSE 467S 50
Chenyang Lu 51
App Code size Code reduction Data size CPU reduction inlined noninlined Surge 14794 16984 12% 1188 15% Maté 25040 27458 9% 1710 34% TinyDB 64910 71724 10% 2894 30%
Ø Caller: call a function
q Push return address to stack q Push parameters to stack q Jump to function
Ø Callee: receive a call
q Pop parameters from stack
Ø Callee: return
q Pop return address from stack q Push return value to stack q Jump back to caller
Ø Caller: return
q Pop return value
Chenyang Lu 52
qInterface, modules, configuration
qImprove robustness: detect race conditions qOptimization: function inlining qMore: memory footprint.
qNo malloc, no function pointers
Chenyang Lu 53
q Bound memory footprint q Allow offline footprint analysis q How to size buffer when data size varies dynamically?
q command/event handlers q atomic sections
Chenyang Lu 54
Ø D. Gay, P . Levis, R. von Behren, M. Welsh, E. Brewer, and D. Culler, The nesC Language: A Holistic Approach to Networked Embedded Systems. [Critique #1] Ø J. Hill, R. Szewczyk, A. Woo, S. Hollar, D. Culler, and K. Pister, System Architecture Directions for Network Sensors. Ø P . Levis and D. Gay, TinyOS Programming, 2009.
q Purchase the book online q Download the first half of the published version for free
Ø http://www.tinyos.net/
Chenyang Lu 55