introduction to iot · introduction to iot.js tilmann scheller principal compiler engineer...

41
1 Samsung Open Source Group Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer [email protected] Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016 San Diego, USA, April 4 – 6, 2016

Upload: others

Post on 14-Jul-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

1Samsung Open Source Group

Introduction to IoT.js

Tilmann SchellerPrincipal Compiler Engineer

[email protected]

Samsung Open Source GroupSamsung Research UK

OpenIoT Summit 2016San Diego, USA, April 4 – 6, 2016

Page 2: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

2Samsung Open Source Group

Overview

● Introduction

● JerryScript

● IoT.js

● Memory consumption/Performance

● Demo

● Future work

● Summary

Page 3: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

3Samsung Open Source Group

Introduction

Page 4: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

4Samsung Open Source Group

What is IoT.js?

● A lightweight version of Node.js

● Attempt to bring the success of Node.js to the embedded world

● Retains backwards compatibility with Node.js as much as possible

● Runs on top of JerryScript

Page 5: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

5Samsung Open Source Group

IoT Hardware

http://postscapes.com/internet-of-things-hardware

Page 6: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

6Samsung Open Source Group

What is JerryScript?

● A really lightweight JavaScript engine

● Has a base footprint of 10KB of RAM

● Optimized for microcontrollers

● Developed from scratch by Samsung

Page 7: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

7Samsung Open Source Group

Why JavaScript on microcontrollers?

● There's a huge pool of JavaScript developers

● Opens up the possibility for web developers to easily write software for embedded devices

● Performance overhead of JavaScript less of an issue for control tasks

● Increased productivity, shorter time to market

● Ability to load code dynamically over the network

● Security: Executing JavaScript code is safer than executing arbitrary native code

Page 8: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

8Samsung Open Source Group

Open source

● Actively developed on GitHub

● JerryScript and IoT.js are both open source released under the Apache 2.0 license

● Building up a community around IoT.js/JerryScript

Page 9: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

9Samsung Open Source Group

JerryScript

Page 10: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

10Samsung Open Source Group

JerryScript History

● Development started in June 2014

● Released as open source in June 2015

● JerryScript passed 100% of the test262 conformance test suite in August 2015

● Rewritten compact byte code implementation landed in January 2016

● Current focus on performance optimization

Page 11: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

11Samsung Open Source Group

JerryScript

● Heavily optimized for a low memory footprint

● Interpreter-only

● Compact object representation

● Compressed pointers

● No AST, directly creating byte code

● Compact byte code heavily optimized for low memory consumption

Page 12: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

12Samsung Open Source Group

JerryScript Portability

● Extremely portable

● Self-contained

● Small C library

● Can run bare-metal

● Supports the STM32F4, ESP8266 boards

● Runs on Linux/OS X as well

Page 13: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

13Samsung Open Source Group

JerryScript

● Written in C99

● About 74KLOC

● Code size ~190KB when compiled with GCC LTO for ARM Thumb-2

● Implements the entire ECMAScript 5.1 standard, passes 100% of the test262 conformance test suite

● C API for embedding JerryScript

● Byte code snapshot feature

Page 14: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

14Samsung Open Source Group

JerryScript C API

Page 15: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

15Samsung Open Source Group

JerryScript C API

Page 16: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

16Samsung Open Source Group

IoT.js

Page 17: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

17Samsung Open Source Group

IoT.js

● Lightweight version of Node.js

● Focus on resource-constrained devices

● Tries to retain backwards compatibility

● Mostly written in JavaScript

Page 18: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

18Samsung Open Source Group

IoT.js Architecture

Page 19: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

19Samsung Open Source Group

IoT.js Modules

● Assert

● Buffer

● DNS

● Events

● File System

● HTTP

● Net

● Modules

● Process

● Stream

● Timers

● GPIO

Page 20: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

20Samsung Open Source Group

Target hardware

● STM32F4 developer board

● Cortex-M4F clocked at 168 MHz

● 192KB of RAM

● 1MB of flash memory

Page 21: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

21Samsung Open Source Group

NuttX

● Real-time operating system

● Open source (BSD license)

● Scales from 8-bit microcontrollers to 32-bit microcontrollers

● Supports the STM32F4 developer board

Page 22: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

22Samsung Open Source Group

libtuv

● libuv - Support library for asynchronous I/O

● libtuv - Stripped down version of Libuv

● Runs on NuttX and Linux

● Experimental support for mbed OS

Page 23: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

23Samsung Open Source Group

Memory consumption/Performance

Page 24: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

24Samsung Open Source Group

IoT.js - Memory consumption

Measured on a Raspberry Pi 2

Test name IoT.js Node.js

require('http') 40KB 6.70MB

test_httpserver.js 80KB 8.63MB

Page 25: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

25Samsung Open Source Group

SunSpider 1.0.2 - Memory consumption

3d-cube

access-binary-trees

access-fannkuch

access-nbody

bitops-3bit-bits-in-byte

bitops-bits-in-byte

bitops-bitwise-and

bitops-nsieve-bits

controlflow-recursive

crypto-aes

crypto-md5

crypto-sha1

date-format-tofte

date-format-xparb

math-cordic

math-partial-sums

math-spectral-norm

string-base64

string-fasta

0 100 200 300 400 500 600 700

76

76

32

36

24

24

24

148

136

104

152

112

60

52

32

28

32

152

44

216

240

160

172

160

160

160

384

204

268

420

304

572

220

164

160

164

324

172

JerryScript

Duktape 1.4

Max RSS in KB (lower is better) Measured on a Raspberry Pi 2

Page 26: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

26Samsung Open Source Group

SunSpider 1.0.2 - Performance

3d-cube

access-binary-trees

access-fannkuch

access-nbody

bitops-3bit-bits-in-byte

bitops-bits-in-byte

bitops-bitwise-and

bitops-nsieve-bits

controlflow-recursive

crypto-aes

crypto-md5

crypto-sha1

date-format-tofte

date-format-xparb

math-cordic

math-partial-sums

math-spectral-norm

string-base64

string-fasta

0 2 4 6 8 10 12 14 16 18 20

2.54

1.36

7.38

2.81

1.62

2.39

3.27

17.88

0.95

3.36

3.29

2.07

2.09

0.83

2.83

1.57

1.46

5.08

3.21

1.44

1.78

3.4

2.23

2.42

2.73

10.75

4.52

1.51

2.58

2.08

1.93

4.64

2.23

3.62

3.73

1.13

5.95

6.46

JerryScript

Duktape 1.4

Execution time in seconds (lower is better) Measured on a Raspberry Pi 2

Page 27: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

27Samsung Open Source Group

ubench - Memory consumption

loop-sum

loop-empty-resolve

loop-empty

function-sum

function-missing-args

function-excess-args

function-emtpy

function-correct-args

function-closure

0 100 200 300 400 500 600

24

24

24

24

24

24

24

24

32

152

152

152

156

156

156

156

156

496

JerryScript

Duktape 1.4

Max RSS in KB (lower is better) Measured on a Raspberry Pi 2

Page 28: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

28Samsung Open Source Group

ubench - Performance

loop-sum

loop-empty-resolve

loop-empty

function-sum

function-missing-args

function-excess-args

function-emtpy

function-correct-args

function-closure

0 10 20 30 40 50 60 70 80 90

35.48

3.42

30.14

18.05

16.09

20.85

19.66

22.18

2.62

76.65

6.41

55.23

23.93

27.35

27.93

38.89

27.95

18.87

JerryScript

Duktape 1.4

Execution time in seconds (lower is better) Measured on a Raspberry Pi 2

Page 29: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

29Samsung Open Source Group

Demo

Page 30: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

30Samsung Open Source Group

Tetris Demo

● Implementation of the classic Tetris game

● Each device drives one LED matrix as display

● Implemented as a Node.js module

● Both devices are running exactly the same JavaScript code

Page 31: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

31Samsung Open Source Group

Demo

Raspberry Pi 2(1GB RAM, 8GB Flash)

TetrisNode.js

V8Linux

STM32F4 board(192KB RAM, 1MB Flash)

TetrisIoT.js

JerryScriptNuttX

USB Keypad

LED Matrix LED Matrix

I2C I2C

Switches via GPIO

Page 32: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

32Samsung Open Source Group

Tetris Demo

https://youtu.be/q4iBeOAC7XI

Page 33: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

33Samsung Open Source Group

Pong Demo

● Implementation of the classic Pong game

● Display shared across two devices

● Each device drives one LED matrix

● Implemented as a Node.js module

● "AI" oppenent running on the microcontroller

Page 34: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

34Samsung Open Source Group

Demo

Raspberry Pi 2(1GB RAM, 8GB Flash)

Pong ClientNode.js

V8Linux

STM32F4 board(192KB RAM, 1MB Flash)

Pong ServerIoT.js

JerryScriptNuttX

Ethernet

USB Keypad

LED Matrix LED Matrix

I2C I2C

Page 35: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

35Samsung Open Source Group

Pong Demo

Page 36: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

36Samsung Open Source Group

Future work

Page 37: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

37Samsung Open Source Group

Future work

● Close performance gap between JerryScript and Duktape

● Further performance and memory optimizations

● Enhance JerryScript C API

● Add more IoT.js modules

● Package manager for IoT.js

● Support more devices

Page 38: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

38Samsung Open Source Group

Summary

Page 39: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

39Samsung Open Source Group

Summary

● Significantly lowers barrier of entry for JavaScript development targeting heavily constrained embedded devices

● Speeds up development

● Active community

● More information on http://www.jerryscript.net and http://www.iotjs.net

● Looking for bug reports and feedback

Page 40: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

Thank you.

40Samsung Open Source Group

Page 41: Introduction to IoT · Introduction to IoT.js Tilmann Scheller Principal Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK OpenIoT Summit 2016

41Samsung Open Source Group

Contact Information:

Tilmann [email protected]

Samsung Open Source GroupSamsung Research UK