Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy...

28
Contiki Contiki A Lightweight and Flexible A Lightweight and Flexible Operating System for Tiny Operating System for Tiny Networked Sensors Networked Sensors Presented by: Jeremy Schiff Presented by: Jeremy Schiff
  • 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...

Page 1: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 2: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented 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

Page 3: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 4: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 5: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

Why Loadable Why Loadable ApplicationsApplications

Smaller file to uploadSmaller file to upload

Less EnergyLess Energy

Less Dissemination Time Less Dissemination Time

Page 6: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 7: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 8: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 9: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 10: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 11: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 12: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 13: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

Power Save ModePower Save Mode

No explicit Kernel assistanceNo explicit Kernel assistance

Access to event queue size Access to event queue size

Page 14: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

ServicesServices

ApplicationApplication

Service LayerService Layer

Service InterfaceService Interface

Service ProcessService Process

Page 15: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

ApplicationApplication

Must dynamically linkMust dynamically link

Interact via Service StubInteract via Service Stub

Compiled inCompiled in Version numberVersion number Caches Service ProcessIDCaches Service ProcessID

Page 16: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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.

Page 17: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

Service ExampleService Example

Page 18: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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?

Page 19: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 20: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 21: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

Communication StackCommunication Stack

Page 22: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 23: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

Multi-Thread APIMulti-Thread API

Page 24: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 25: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 26: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 27: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

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

Page 28: Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.

Questions?Questions?