nesc Prof. Chenyang Lu How should network msg be handled? Too much memory for buffering and threads

Similar documents
nesc Ø Programming language for TinyOS and applications Ø Support TinyOS components Ø Whole-program analysis at compile time Ø Static language

Self-Organization in Autonomous Sensor/Actuator Networks [SelfOrg]

Group Members: Chetan Fegade Nikhil Mascarenhas. Mentor: Dr. Yann Hang Lee

The nesc Language: A Holistic Approach to Networked Embedded Systems

Programming Sensor Networks

Programming TinyOS. Lesson 3. Basic Structure. Main.nc

Sensors as Software. TinyOS. TinyOS. Dario Rossi Motivation

TinyOS. Lecture Overview. UC Berkeley Family of Motes. Mica2 and Mica2Dot. MTS300CA Sensor Board. Programming Board (MIB510) 1.

System Architecture Directions for Networked Sensors[1]

Sensors Network Simulators

Programming TinyOS. Lesson 2. Execution Flow. Tasks. commands. Events generated by interrupts preempt tasks Tasks do not preempt tasks

Politecnico di Milano Advanced Network Technologies Laboratory. Internet of Things. TinyOS Programming and TOSSIM (and Cooja)

Introduction to Programming Motes

Wireless Sensor Networks (WSN)

Integrating Concurrency Control and Energy Management in Device Drivers. Chenyang Lu

Sensor Networks. Part 3: TinyOS. CATT Short Course, March 11, 2005 Mark Coates Mike Rabbat. Operating Systems 101

The Emergence of Networking Abstractions and Techniques in TinyOS

System Architecture Directions for Networked Sensors. Jason Hill et. al. A Presentation by Dhyanesh Narayanan MS, CS (Systems)

A Predictable RTOS. Mantis Cheng Department of Computer Science University of Victoria

Static Analysis of Embedded C

Integrating Concurrency Control and Energy Management in Device Drivers

TinyOS. Jan S. Rellermeyer

NanoRK. EECE 494 Sathish Gopalakrishnan

Sensor Network Application Development ZIGBEE CONCEPTS 2

Midterm Exam. October 20th, Thursday NSC

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads

EVENT DRIVEN SENSOR SYSTEMS

Exam TI2720-C/TI2725-C Embedded Software

Politecnico di Milano Advanced Network Technologies Laboratory. Internet of Things. TinyOS Programming and TOSSIM

Tasks. Task Implementation and management

WSN Programming. Introduction. Olaf Landsiedel

Threads Implementation. Jo, Heeseung

WSN Programming. Introduction. Olaf Landsiedel. Programming WSNs. ! What do we need to write software for WSNs?! Programming language

Politecnico di Milano Advanced Network Technologies Laboratory. Internet of Things. TinyOS Programming and TOSSIM (and Cooja)

System Call. Preview. System Call. System Call. System Call 9/7/2018

Lecture notes Lectures 1 through 5 (up through lecture 5 slide 63) Book Chapters 1-4

Synchronization. CS61, Lecture 18. Prof. Stephen Chong November 3, 2011

AUTOBEST: A United AUTOSAR-OS And ARINC 653 Kernel. Alexander Züpke, Marc Bommert, Daniel Lohmann

Adding Preemption to TinyOS

Developing deterministic networking technology for railway applications using TTEthernet software-based end systems

Introduction to Lab 2

2. Introduction to Software for Embedded Systems

Lecture 15: I/O Devices & Drivers

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable

Towards a Resilient Operating System for Wireless Sensor Networks

Presented by: Murad Kaplan

Politecnico di Milano Advanced Network Technologies Laboratory. TinyOS

CSE 153 Design of Operating Systems

The Emergence of Networking Abstractions and Techniques in TinyOS

SMD149 - Operating Systems

Übersicht. Laufzeitumgebungen Fallstudie TinyOS

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Last 2 Classes: Introduction to Operating Systems & C++ tutorial. Today: OS and Computer Architecture

ZiLOG Real-Time Kernel Version 1.2.0

Mutex Implementation

Slide 6-1. Processes. Operating Systems: A Modern Perspective, Chapter 6. Copyright 2004 Pearson Education, Inc.

Zilog Real-Time Kernel

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Mobile and Ubiquitous Computing Routing Protocols. Niki Trigoni

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Announcements. Program #1. Reading. Due 2/15 at 5:00 pm. Finish scheduling Process Synchronization: Chapter 6 (8 th Ed) or Chapter 7 (6 th Ed)

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

galsc: A Language for Event-Driven Embedded Systems

CS349/SE382 A1 C Programming Tutorial

Voice Over Sensor Networks

CS370 Operating Systems

Peripheral State Persistence and Interrupt Management For Transiently Powered Systems

COP 5611 Operating Systems Spring Dan C. Marinescu Office: HEC 439 B Office hours: M-Wd 2:00-3:00 PM

AC OB S. Multi-threaded FW framework (OS) for embedded ARM systems Torsten Jaekel, June 2014

OVERVIEW. Last Week: But if frequency of high priority task increases temporarily, system may encounter overload: Today: Slide 1. Slide 3.

Lecture 9: Midterm Review

Synchronization. CSE 2431: Introduction to Operating Systems Reading: Chapter 5, [OSC] (except Section 5.10)

Exam Ad Hoc and Sensor Networks HS 2007

ADB: An Efficient Multihop Broadcast Protocol Based on Asynchronous Duty-Cycling in Wireless Sensor Networks

Xbee module configuration from a µcontroller

Processes. Overview. Processes. Process Creation. Process Creation fork() Processes. CPU scheduling. Pål Halvorsen 21/9-2005

Embedded Software Programming

Medium Access Control in Wireless Sensor Networks

SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T A N D S P R I N G 2018

EE458 - Embedded Systems Exceptions and Interrupts

Inter-Context Control-Flow Graph for NesC, with Improved Split-Phase Handling

Medium Access Control in Wireless IoT. Davide Quaglia, Damiano Carra

Embedded Systems. 6. Real-Time Operating Systems

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

Operating System Concepts Ch. 5: Scheduling

CPU Scheduling. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

Department of Computer Science Institute for System Architecture, Operating Systems Group REAL-TIME MICHAEL ROITZSCH OVERVIEW


SpiNNaker Application Programming Interface (API)

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

Announcements. Reading. Project #1 due in 1 week at 5:00 pm Scheduling Chapter 6 (6 th ed) or Chapter 5 (8 th ed) CMSC 412 S14 (lect 5)

Threads. Threads The Thread Model (1) CSCE 351: Operating System Kernels Witawas Srisa-an Chapter 4-5

Lecture 5: Synchronization w/locks

Multitasking. Embedded Systems

Back to RTOS. CSE466 Autumn 00-1

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

Midterm Exam Amy Murphy 6 March 2002

Real-Time Internet of Things

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads

Transcription:

nesc Prof. Chenyang Lu CSE 521S 1 How should network msg be handled? Socket/TCP/IP? Too much memory for buffering and threads Data buffered in network stack until application threads read it Application threads blocked until data is available Transmit too many bits (sequence #, ack, re-transmission) Tied with multi-threaded architecture TinyOS solution: active messages CSE 521S 2

Active Message Every message contains the name of an event handler Sender: split-phase operation Phase I Declaring buffer storage in a frame Naming a handler Requesting Transmission; exit Phase II Done completion signal Receiver Event handler is called when message is received No blocked or waiting threads on sender or receiver Behaves like any other events Reduce buffering CSE 521S 3 Send Message char TOS_COMMAND(INT_TO_RFM_OUTPUT)(int val){ int_to_led_msg* message = (int_to_led_msg*)var(msg).data; if (!VAR(pending)) { message->val = val; if (TOS_COMMAND(INT_TO_RFM_SUB_SEND_MSG)(TOS_MSG_BCAST, AM_MSG(INT_READING), &VAR(msg))) { VAR(pending) = 1; return 1; access appln msg buffer cast to defined format return 0; application specific ready check build msg request transmission destination identifier get handler identifier msg buffer CSE 521S mark busy 4

Space Breakdown Code size for ad hoc networking application Bytes 3500 3000 2500 2000 1500 1000 500 0 Interrupts Message Dispatch Initilization C-Runtime Scheduler: 144 Bytes code Light Sensor Clock Totals: 3430 Bytes code Scheduler 226 Bytes data Led Control Messaging Layer Packet Layer Radio Interface Routing Application Radio Byte Encoder D. Culler et. Al., TinyOS boot camp presentation, Feb 2001 CSE 521S 5 Power Breakdown Active Idle Sleep CPU Radio EE-Prom LED s Photo Diode Temperature 5 ma 7 ma (TX) 3 ma 4 ma 200 µa 200 µa 2 ma 4.5 ma (RX) 0 0 0 0 5 µa 5 µa 0 Lithium Battery runs for 35 hours at peak load and years at minimum load! That s three orders of magnitude difference! A one byte transmission uses the same energy as approx 11000 cycles of computation. 0 0 0 Panasonic CR2354 560 mah CSE 521S 6

Time Breakdown Components Packet reception work breakdown CPU Utilization Energy (nj/bit) AM 0.05% 0.20% 0.33 Packet 1.12% 0.51% 7.58 Ratio 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 - - 1350 Idle - 54.75% - Total 100.00% 100.00% 2028.66 50 cycle thread overhead (6 byte copies) 10 cycle event overhead (1.25 byte copies) CSE 521S 7 Advantages Small memory footprint Only needed OS components are complied/loaded Non-preemptable FIFO task scheduling Power efficient Sleep whenever task queue is empty Efficient modularity Function call (event, command) interface between components Concurrency-intensive operations Event/command + tasks Efficient interrupt/event handling (function calls, no user/kernel boundary) CSE 521S 8

Lack of Real-Time Support FIFO, non-preemptive task scheduling Urgent task may wait for non-urgent ones CSE 521S 9 Solution of Impala/ZebraNet Timetable for periodic operations Prioritize events CSE 521S 10

Impala: Scheduling CSE 521S 11 Impala: Events CSE 521S 12

What s missing? Support for different workload varying workload predictability Leverage on real-time scheduling techniques Static scheduling + schedulability analysis Dynamic scheduling + overload protection Topic for an interesting project! CSE 521S 13 nesc Programming Networked Embedded Systems CSE 521S 14

Principles Support TinyOS components and event/command interfaces Static language no malloc, no function pointers Call graph and variable access are known at compile time Whole-program analysis at compile time Detect race conditions Cross-component optimization: function inlining, eliminate unreachable code CSE 521S 15 nesc Application Implementation module: C behavior - configuration: select and wire Interfaces - provides interface - requires interface CSE 521S 16

Interface interface Clock { command result_t setrate(char interval, char scale); event result_t fire(); interface Send { command result_t send(tos_msg *msg, uint16_t length); event result_t senddone(tos_msg *msg, result_t success); interface ADC { command result_t getdata(); event result_t dataready(uint16_t data); Bidirectional interface supports split-phase operation CSE 521S 17 Module module SurgeM { provides interface StdControl; uses interface ADC; uses interface Timer; uses interface Send; implementation { uint16_t sensorreading; command result_t StdControl.init() { return call Timer.start(TIMER_REPEAT, 1000); event result_t Timer.fired() { call ADC.getData(); return SUCCESS; event result_t ADC.dataReady(uint16_t data) { sensorreading = data;... send message with data in it... return SUCCESS;... CSE 521S 18

Configuration configuration TimerC { provides { interface StdControl; interface Timer; implementation { components TimerM, HWClock; StdControl = TimerM.StdControl; Timer = TimerM.Timer; TimerM.Clock -> HWClock.Clock; CSE 521S 19 Surge CSE 521S 20

Race Conditions CSE 521S 21 Example: Race Conditions module SurgeM {... implementation { bool busy; uint16_t sensorreading; event result_t Timer.fired() { if (!busy) busy = TRUE; call ADC.getData(); return SUCCESS; Asynchronous Code CSE 521S 22

Example: Race Conditions In a command handler: /* Contains a race: */ if (state == IDLE) { state = SENDING; count++; // send a packet CSE 521S 23 Concurrency in TinyOS Asynchronous code (AC): code that is reachable from at least one interrupt handler Synchronous code (SC): code that is only reachable from tasks Key properties Any update to shared state (variable) from AC is a potential race condition Any update to shared state from SC that is also updated from AC is a potential race condition CSE 521S 24

TinyOS Two-level Scheduling Two priorities Event/command Tasks Event/command can preempt task Tasks cannot preempt another task or event/command Preempt POST Tasks FIFO events commands commands Hardware Interrupts Time CSE 521S 25 Concurrency in TinyOS Asynchronous code (AC): code that is reachable from at least one interrupt handler Event/command Synchronous code (SC): code that is only reachable from tasks Key properties Any update to shared state (variable) from AC is a potential race condition Any update to shared state from SC that is also updated from AC is a potential race condition CSE 521S 26

Solution Race-Free Invariant: Any update to shared state is either not a potential race condition (SC only), or occurs within an atomic section. Compiler check: identifies all shared states and return errors if the above invariant is violated Fix code Make the access to all shared states with potential race conditions atomic Move access to SC CSE 521S 27 Atomic Sections atomic { <Statement list> Disable interrupt when atomic code is being executed Alternative: semaphores based on test-set operations But cannot disable interrupt for long! restrictions No loops No commands/events Calls OK, but callee must meet restrictions too CSE 521S 28

module SurgeM {... implementation { bool busy; norace uint16_t sensorreading; disable interrupt enable interrupt event result_t Timer.fired() { bool localbusy; atomic { localbusy = busy; test-and-set busy = TRUE; if (!localbusy) call ADC.getData(); return SUCCESS; task void senddata() { // send sensorreading adcpacket.data = sensorreading; call Send.send(&adcPacket, sizeof adcpacket.data); return SUCCESS; event result_t ADC.dataReady(uint16_t data) { sensorreading = data; post senddata(); return SUCCESS; CSE 521S 29 Example 2 /* Contains a race: */ if (state == IDLE) { state = SENDING; count++; // send a packet /* Fixed version: */ uint8_t oldstate; atomic { oldstate = state; if (state == IDLE) { state = SENDING; if (oldstate == IDLE) { count++; // send a packet CSE 521S 30

Results CSE 521S 31 Results Tested on full TinyOS tree, plus applications 186 modules (121 modules, 65 configurations) 20-69 modules/app, 35 average 17 tasks, 75 events on average (per app) Lots of concurrency! Found 156 races: 103 real (!) About 6 per 1000 lines of code 53 false positives Fixing races: Add atomic sections Post tasks (move code to task context) CSE 521S 32

Optimization: inlining Inlining reduces code size AND improves performance! CSE 521S 33 Issues: Programming Model No dynamic memory allocation How to size buffer when amount of data varies? Bound memory footprint Prevent run-time corruption Allow offline footprint analysis (not done) Restriction: no long-running code in command/event handlers atomic sections Push errors to applications Burden application programmers Allow application-specific optimization Ex., which message needs retransmission? No kernel/user protection Application can corrupt an entire system CSE 521S 34

Reminder Project You should (at least) have a team now! If not, email cs537s@cse ASAP Discuss your ideas with me Critiques No critique is due on Tuesday This is a critique (on MAC) due on Sunday Presentations Go over your slides with me one week before your presentation CSE 521S 35 Proposal Outline 1. Team 2. Motivate the problem 3. Define the problem Assumptions, requirements, goals and non-goals 4. Related work What have been done before? How does your solution compare to them? 5. Approach (optional) Intuition and rationale: Why is it a good idea? Sketch of your approach and design. 6. Experimental plan What hardware (e.g., sensor boards) or simulation tools are you going to use? What experiments are you going to run? What criteria and metrics are you going to use to evaluate your solutions? 7. Milestones (with dates) 8. References CSE 521S 36

Proposal Requirements 4-5 pages, 10 point, double column, single space. Email me your proposal by midnight, 9/27 (Monday). See project Web page (updated today) for outline and requirements. CSE 521S 37