framework for synthesis of host-assisted scripting engines for adaptive embedded systems

30
Framework for Synthesis of Framework for Synthesis of Host-Assisted Host-Assisted Scripting Scripting Engines Engines for Adaptive for Adaptive Embedded Systems Embedded Systems Jiwon Hahn, Qiang Xie, Pai Chou Center for Embedded Computer Systems, UC Irvine CODES+ISSS September 22, 2005 Rappit Rappit

Upload: yehudi

Post on 17-Mar-2016

36 views

Category:

Documents


0 download

DESCRIPTION

Framework for Synthesis of Host-Assisted Scripting Engines for Adaptive Embedded Systems. Jiwon Hahn, Qiang Xie, Pai Chou Center for Embedded Computer Systems, UC Irvine CODES+ISSS September 22, 2005. Rappit. Embedded Systems. Host-involved. Standalone. GPS tracer. Toy. ATM. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

Framework for Synthesis of Framework for Synthesis of Host-AssistedHost-Assisted Scripting Scripting

EnginesEngines for Adaptive for Adaptive Embedded SystemsEmbedded Systems Jiwon Hahn, Qiang Xie, Pai Chou

Center for Embedded Computer Systems, UC Irvine

CODES+ISSSSeptember 22, 2005

RappitRappit

Page 2: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

2 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Embedded Systems

Embedded systems

Host-involved Standalone

Hybrid

Medical Device

GPS tracer

Printer

Sensor-net

Battery emulator

MP3 player

PDA

Cell phones

Digital camera

Set-top box

Toy ATM

Copier

Disk drives

DVD

SD

DATAXeZ 128K TA ER DR RS/C CS SO/T RD/R CD/1

32 16 8 4 2 1 SYNCOVFERR -

ALM TEST PWR

ERR INS ERR RSTMODE

0 1

RATE ST SP NCRMODE RATE

+ +

SD

Smart-UPS

6 2 0

www.apcc.com

Vending machine

Page 3: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

3 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Embedded Systems Programming Embedded Systems Programming Current Methodology

Low-level programming (e.g., C, assembly)Single processor, platform specific approachUnchanged for decades!

DrawbackTime consuming on re-inventing low-level abstractions

eg., registers, timers, interrupts, I/O portsError proneRequires frequent firmware update

Programming flash or burning EEPROMIn-field configuration unsupportedNot adequate for emerging large-scale, distributed, adaptive embedded systems

Page 4: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

4 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Our Solution: ScriptingOur Solution: Scripting High-level programming

Human readable Utilize platform-independent APIsProductivity gain

InteractivityEasy communication between user and platformEnables efficient test/debugging

ReconfigurabilityNo compilation or F/W update requiredIn-field configuration

Code size reductionScripts are usually x5 to x10 shorter than C code [Ousterhout]Reduce memory size & cost, power

Page 5: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

5 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Traditional: 6-stage debugging cycle

Scripting: 3-stage debugging cycle

Comparison of design flow

F/W coding Compile

Restart BoardExecute

Write script

Erase Flash Load

Program Verify Flash

Synthesize scripting engine (F/W)

Execute

Load script Compile

Restart Board

Enter bootloader mode

Erase Flash Load

Program Verify Flash

Enter bootloader mode

F/W coding Compile

Restart BoardExecute Erase Flash Load

Program Verify Flash

Enter bootloader mode

Write script Execute

Load script

Page 6: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

6 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Scripting vs. Runtime Overhead Scripting vs. Runtime Overhead Scripting for General Purpose Computers

Assume unlimited resourcesFull feature scripting engine for convenienceSlower than system programming language

Scripting for Embedded SystemsLimited memory, CPU, power, …Need scripting engine optimization

Host assistLanguage subsettingLibrary subsettingEfficient memory usage

Scripting may be even faster than compiled code!

Page 7: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

7 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

OutlineOutline Related Work Our Methodology

Code Synthesis Runtime environment

Experimental Results Conclusion Future Work

Page 8: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

8 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Related Work Related Work

Name Platform Language H I R C POPyBAR Router Python Y Y Y N/A x10SensorWare Sensor tinyTcl Y Y Y >237K ‘high’Mate Sensor asm-like Y Y 17K ‘low’Agilla Sensor asm-like Y Y 45K ‘low’Luxdbg General Tcl Y Y N >237K x10.6Rappit General Python-like

+ APIsY Y Y 1K-17K None

* H: High level I: Interactivity R: Reconfigurability C: Code size PO: Performance overhead compared to compiled implementation

Page 9: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

9 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Overview of Rappit Runtime SystemOverview of Rappit Runtime System

Provide user one integrated environment Provide user one integrated environment of the host and target systemsof the host and target systems

H/ W Device

Device Drivers

#include <stdio.h>void main(void){ int a; . . For(i=0;i<2;i++) { . a =b * c; } . . return;}

Rappit F/ W

ApplicationScript

Target SystemHostRappit S/W

Wired/Wireless link

Page 10: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

10 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Runtime FlowRuntime FlowHost Comm

LinkTarget

Platform

Scriptmsg (cmd)Pa

rser

Msg

Gen

erat

or

Pack

etiz

er

Dep

acke

tizer

Scrip

ting

Engi

ne

Platform Control

Command

I/O

GUI

Pack

etiz

er

Scrip

ting

Engi

ne

Pars

er

Dep

acke

tizer

Response

I/O

msg (ack)

Platform Response

Page 11: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

11 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Scripting Engine OptimizationScripting Engine Optimization Language Subsetting Host Assist

Library Subsetting

RF SPI InterruptsGPIOUART ADC

MCUFull-Featured Component Library

RFInterrupts

GPIO UART

ADC Sensor1

Customized Library

“print reg1” Host Parser/Msg. gen.

“0x4A0x01”• User friendly • Easy to parse at node

• Efficient command representation

(compact packet size and runtime repr.)

JoystickLCD Sensor1 Sensor2Dataflash

Page 12: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

12 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Our MethodologyOur Methodology

Host-AssistedParser

ComponentLibrary

CodeSynthesizer

GUIMCU

Scripting Engine

ApplicationPrimitives

1. Code Synthesis Flow

2. Runtime Flow

ScriptScript

SystemSystem

DescriptionDescription

Page 13: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

13 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Output

I. Code SynthesisI. Code Synthesis

ComponentLibrary

CodeSynthesis

Target F/W(Scripting

Engine,Native

Routines, …)

Architecture

Description

Application

Description

Communication

Description

CompatibleMessage format

Interactive Language

Binary Executable

HostTarget System

Host S/W(Parser, MsgGen,GUI, …)

Input

Page 14: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

14 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

I. Code Synthesis - I. Code Synthesis - Packet Format ExamplesPacket Format Examples

Command Packet Format

Response Packet Format

Dest. Msg ID Opcode Arg1 Arg2 Arg3 CRC

Src. Msg ID Msg Type Data Type Payload CRC EOP

Command Message Format

Response Message Format

Page 15: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

15 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

II. Runtime EnvironmentII. Runtime Environment

Parser

ComponentLibrary

Packetizer/Dispatcher

PacketManager

GUI

Cmd prompt

IDE Packetizer/Depacketizer

ScriptingEngine

AdmissionController

Native Routines

Host

command

response

packet

MCU

Msg Gen.

Page 16: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

16 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

II. Runtime Environment – II. Runtime Environment – Scripting ExamplesScripting Examples

Interactive port setting >> PORTA[2] = 1; PORTA[2] = 0 # toggle clock>> PORTA[1] = 1 # set port A pin 1>> PORTA[0] # read input pin0>> PORTA[2] = 1; PORTA[2] = 0 # toggle clock>> PORTA[0] # read input pin1

System configuration >> mcu.sysclock = 1 MHz # set system clock speed>> uart.baudrate = 9600 bps # set baudrate for UART>> rf.power = -5 db # set RF tx power>> rf.speed = 1 Mbps # set RF throughput>> rf.config # query the configuration{’payload’: 1, ’power’: -5, ’speed’: 1000000, ’channel’:100, ’mode’: ’TX’}

Scheduling>> every(50 ms, ’sample’) >> stop(’sample’)

Page 17: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

17 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Experimental Setup IExperimental Setup I

Atmel ATmega1698-bit MCU @ 8MHz, 512B EEPROM, 1KB SRAM, 16KB program flashConnected to dataflash, speaker, sensors, joystick, LCDUSART serial link at 9600 baud

AVR Butterfly board

AVR ButterflyAVR Butterfly AVR Butterfly w/ Wireless moduleAVR Butterfly w/ Wireless module

Page 18: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

18 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Experimental Setup IIExperimental Setup II HC12 Controller in Mini-FDPM

FreeScale16-bit MC9S12NE6416KB RAM, 64KB program flashSPI, I2C, GPIO, ADCBuilt-in Ethernet

AmplitudeDetector

PhaseDetector

Mixer

PowerSplitter

CrystalFilter

Laser 1

Laser 2

Laser 3

Laser 4

RFSwitch FilterMixer

Mixer

PowerDivider

Filter

Filter

Amp

Amp

PowerCoupler

LocalOscillator

BroadbandOscillator

2

BroadbandOscillator

1

TCXO

16bit microcontroller with ethernet

Host ComputerHost Computer

Mini-FDPMMini-FDPM

HC12HC12

EthernetEthernet

Page 19: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

19 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Metrics and ModalityMetrics and Modality Observation Metrics

Execution Modality

Metric UnitCode size BytesExecution Speed Cmds/sec

Modality Approach Programming MethodNative Compiled Program the firmware onto the Flash

Batch Scripting Preload a script program onto the RAMInteractive Scripting Send one line of command to the RAM

Page 20: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

20 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Experimental Results - Code Size Experimental Results - Code Size Experiment

Test code included 100 cmds, 9 instruction typesSame subroutines and packet handlers usedCode size observed from compiled code and memory map

ResultScripting engine is a thin layerRappit achieves big reduction in application code size

Page 21: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

21 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Experimental Results - Execution SpeedExperimental Results - Execution Speed Experiment

Relative comparison by setting host timer with same conditionsSame experiment repeated several times3 different applications

ResultBatch mode scripting can be faster than native!Same pattern observed in other experimentsObserved up to 25.7% speed-upMemory access could be the key

Page 22: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

22 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Summary of ResultsSummary of Results Code size reduction

Performance overhead components analysisNative Interactive Batch

Communication 1 3 1

RAM Access 3 1 1

ROM Access 3 1 1

Packetization 1 2 2

Interpretation 1 2 2

Total cmd/sec 92 4.75 111

Application Native Rappit ReductionReg setting 4.356 KB 1.664 KB 61.8%

LCD usage 12.45 KB 4.2 KB 66.3%

1: fast 2: tolerable 3: slow (bottleneck)

Page 23: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

23 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

ConclusionConclusion Scripted the embedded systems

High-level programmingInteractivityReconfigurabilityCode size reduction

Overcame scripting overheadHost assistanceScript subsettingLibrary subsettingEffective memory usage

Synthesis Systematic generation of scripting environment

Page 24: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

24 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Future WorkFuture Work More dynamic scheme

Allow new native code to be added

Mapping to richer set of syntaxEg., http to allow access as web device

Memory management in the targetSet evaluation order to reduce memory usage

Parser optimizationParsing simplicity vs. expressiveness

Page 25: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

25 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Thank you!Thank you!

Page 26: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

26 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Backup SlidesBackup Slides

Page 27: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

27 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Code Size of Each Rappit ComponentsCode Size of Each Rappit Components

Host Code (.py) Lines Size (KB)GUI 644 21.8Cmd 127 2.87Parser &Msg Generator

221 4.97

Library 263 6.396Packetizer &Depacketizer

82 2.0

Packet Mgr 42 0.92Total 1379 38.96

MCU Code (.c) Lines Size (KB)

Interpreter 260 -Primitives 90 -Packetizer & Depacketizer

300 -

Total 750 1.484

Page 28: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

28 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

Goals of Embedded SystemsGoals of Embedded Systems

Embedded Embedded SystemSystem

GoalsGoals

High Adaptability

Low power

Low cost

High performance (speed)

Small size

Fast development cycle

Page 29: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

29 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

I. Code SynthesisI. Code Synthesis Input: system description script# example: pin mapping for an RF modulemcu = MCU(ATmega169) # instantiate an atmega169 MCUimport RF # load a transceiver modulerf = RF(nRF2401) # instantiate nRF2401 transceiverrf.CS = mcu.PORTB[0] # connect the chip select pinrf.CE = mcu.PORTB[1] # connect the chip enable pinrf.DR1 = mcu.PORTB[2] # connect the data ready pinrf.CLK1 = mcu.PORTF[1] # connect the clock pinrf.DOUT1 = mcu.PORTF[2] # connect the data pin

Output: Rappit software for host, firmware for the target platform

Page 30: Framework for Synthesis of  Host-Assisted Scripting Engines  for Adaptive Embedded Systems

30 www.ece.uci.edu/~jhahn/www.ece.uci.edu/~jhahn/

I. Code SynthesisI. Code Synthesis Command Format

Machine-efficient representation of a commandApplication-specificPain to reinvent for each applicationNeed auxiliary code to handle each command format

Automatic Command Format definitionSynthesizer generates the command formatCoherent between host and target

End user syntax parsed and mapped to command format in the host parserCommand format interpreted by the target scripting engine