Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy...
-
date post
19-Dec-2015 -
Category
Documents
-
view
217 -
download
1
Transcript of Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy...
ContikiContiki
A Lightweight and Flexible A Lightweight and Flexible Operating System for Tiny Operating System for Tiny
Networked SensorsNetworked Sensors
Presented by: Jeremy SchiffPresented by: Jeremy Schiff
ObjectivesObjectives
LightweightLightweight
Event Driven ModelEvent Driven Model Has Multi-Threading Support as LibraryHas Multi-Threading Support as Library
Dynamic Loading and Replacement Dynamic Loading and Replacement of Individual Servicesof Individual Services
Contiki MotivationsContiki Motivations
No memory protection between appsNo memory protection between apps
Kernel very minimalKernel very minimal CPU multiplexingCPU multiplexing Loading ProgramsLoading Programs
All other abstractions by librariesAll other abstractions by libraries Custom ApplicationsCustom Applications
DifferentiationDifferentiation
TinyOSTinyOS Statically linked entire applicationsStatically linked entire applications
MagnetOSMagnetOS Virtual Machine – byte codeVirtual Machine – byte code
MantisMantis Pure MultiThreadPure MultiThread
ContikiContiki Dynamic Linking of binariesDynamic Linking of binaries Event/Thread HybridEvent/Thread Hybrid
Why Loadable Why Loadable ApplicationsApplications
Smaller file to uploadSmaller file to upload
Less EnergyLess Energy
Less Dissemination Time Less Dissemination Time
Why No Threads?Why No Threads?
Thread stacks must be allocated at creation Thread stacks must be allocated at creation timetime
Stack Memory Over-ProvisionedStack Memory Over-Provisioned No Virtual Memory SystemNo Virtual Memory System No Memory Protection Mechanisms No Memory Protection Mechanisms
Locking for state exclusionLocking for state exclusion Stack memory is inaccessible to other Stack memory is inaccessible to other
threadsthreads
EventsEvents
No lockingNo locking Only one running at a timeOnly one running at a time
Only one stackOnly one stack Locking rareLocking rare
Hard to express some things as state Hard to express some things as state machinemachine
Problem: Cryptography takes 2 seconds, Problem: Cryptography takes 2 seconds, everything else blocked.everything else blocked.
Solution: Preemptive ThreadsSolution: Preemptive Threads
System OverviewSystem Overview
Service – Something that implements Service – Something that implements functionality for more than one functionality for more than one applicationapplication
Apps have direct access to hardwareApps have direct access to hardware Single Address SpaceSingle Address Space Inter-process communication via event Inter-process communication via event
postingposting Always Through KernelAlways Through Kernel
Core vs. Loaded ProgramCore vs. Loaded Program
Partitioned at compile Partitioned at compile timetime
CoreCore Single Binary Single Binary Ideally never modifiedIdeally never modified
ProgramProgram Easily upgradedEasily upgraded
KernelKernel
Execution via: Kernel Events or Execution via: Kernel Events or Polling EventsPolling Events
No preemption of scheduled events No preemption of scheduled events Synchronous vs Asynchronous EventsSynchronous vs Asynchronous Events
Synch: Like Function CallSynch: Like Function Call Asynch: Like posting new eventAsynch: Like posting new event
Asynch reduces stack spaceAsynch reduces stack space Debugging issuesDebugging issues
Two Level SchedulingTwo Level Scheduling
Events Events Can’t preempt one anotherCan’t preempt one another
Interrupts Interrupts Can preempt eventsCan preempt events Can use “underyling real-time executive” Can use “underyling real-time executive”
Provides realtime guaranteesProvides realtime guarantees Non-hardwareNon-hardware
Can’t post eventsCan’t post events Use polling flag insteadUse polling flag instead Prevent race conditionsPrevent race conditions
Loading ProgramsLoading Programs
Relocation Information in BinaryRelocation Information in Binary
Check for space before loadingCheck for space before loading
Call Initialization FunctionCall Initialization Function Replace or Starts new ProgramReplace or Starts new Program
Power Save ModePower Save Mode
No explicit Kernel assistanceNo explicit Kernel assistance
Access to event queue size Access to event queue size
ServicesServices
ApplicationApplication
Service LayerService Layer
Service InterfaceService Interface
Service ProcessService Process
ApplicationApplication
Must dynamically linkMust dynamically link
Interact via Service StubInteract via Service Stub
Compiled inCompiled in Version numberVersion number Caches Service ProcessIDCaches Service ProcessID
Service LayerService Layer
Works with KernelWorks with Kernel Provides lookup for specific serviceProvides lookup for specific service Returns a Service InterfaceReturns a Service Interface
Has pointers to all functions service providesHas pointers to all functions service provides Contains a version NumberContains a version Number Interface description implemented by Service Interface description implemented by Service
ProcessProcess
Version numbers must matchVersion numbers must match Failure Support? MANTIS thinks about this better.Failure Support? MANTIS thinks about this better.
Service ExampleService Example
Service ReplacementService Replacement
Process ID must be preservedProcess ID must be preserved Kernel supportedKernel supported Kernel instructs service to remove itselfKernel instructs service to remove itself
Could lead to problemsCould lead to problems Kernel provides mechanism to transfer state Kernel provides mechanism to transfer state Service state also versionedService state also versioned Service state must be stored in a shared Service state must be stored in a shared
space during swap due to reallocations of old space during swap due to reallocations of old version’s spaceversion’s space Is there a better way to do this - SOS?Is there a better way to do this - SOS?
LibrariesLibraries
Application optionsApplication options Static link with coreStatic link with core Static link with librariesStatic link with libraries
Single binarySingle binary Call a serviceCall a service
Memcpy() vs Atoi()Memcpy() vs Atoi() MemCpy in CoreMemCpy in Core
CommunicationCommunication Architecture makes easy to replace Architecture makes easy to replace
Communication Stack Communication Stack A service like any otherA service like any other Enables multiple communication stack for Enables multiple communication stack for
comparisoncomparison
Comm Services use Service Mechanism to Comm Services use Service Mechanism to call one anothercall one another
Comm Services use Synchronous events to Comm Services use Synchronous events to communicates with applicationscommunicates with applications No copying of buffers because Synch events No copying of buffers because Synch events
can’t be preemptedcan’t be preempted
Communication StackCommunication Stack
Multi-ThreadingMulti-Threading
Optional Library linked inOptional Library linked in
Kernel interactionKernel interaction Platform IndependentPlatform Independent
Stack Switching / Preemption Stack Switching / Preemption primitivesprimitives Platform DependentPlatform Dependent
Multi-Thread APIMulti-Thread API
Over the air Over the air ProgrammingProgramming
1 node took 30 seconds1 node took 30 seconds
40 nodes took 30 minutes40 nodes took 30 minutes
1 component for 40 nodes took 2 1 component for 40 nodes took 2 minutesminutes
Used naïve protocolUsed naïve protocol
Code SizeCode Size
Bigger than TinyOS, Smaller than Bigger than TinyOS, Smaller than MantisMantis
Polling Handlers and Increase Polling Handlers and Increase FlexibilityFlexibility
Less compiler optimization possibleLess compiler optimization possible
Preemption DemoPreemption Demo
Start 8 second Start 8 second process at 5 process at 5 Seconds and Seconds and continually pingcontinually ping
~.1 ms latency ~.1 ms latency increaseincrease
Poll handler Poll handler caused spikescaused spikes Mainly Radio Mainly Radio
Packet driverPacket driver
PortabilityPortability
Custom Code in a portCustom Code in a port Boot up codeBoot up code Device DriversDevice Drivers Architecture specific parts of program Architecture specific parts of program
loaderloader Stack switching code of the multithreading Stack switching code of the multithreading
librarylibrary
Kernel and Service layer need no Kernel and Service layer need no changeschanges
Questions?Questions?