Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
akkyie committed Dec 20, 2018
1 parent fd49273 commit 35f7f51
Show file tree
Hide file tree
Showing 17 changed files with 292 additions and 102 deletions.
98 changes: 82 additions & 16 deletions bib/main.bib
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
@misc{aws_iot,
author = "AWS IoT",
url = "{https://docs.aws.amazon.com/ja_jp/iot/latest/developerguide/what-is-aws-iot.html}"
}

@misc{sakura_io,
author = "sakura.io",
url = "{sakura.io}"
}

@misc{esp32,
author = "Espressif Systems",
title = "{ESP32 Series Datasheet}",
year = 2018,
url = "{https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf}"
howpublished = "\url{https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf}",
}

@misc{esp_idf,
author = "{Espressif Systems}",
title = "{ESP-IDF Programming Guide}",
howpublished = "\url{https://docs.espressif.com/projects/esp-idf}"
}

@misc{esp_toolchain,
author = "{Espressif Systems}",
title = "{Get Started - ESP-IDF Programming Guide}",
howpublished = "\url{https://docs.espressif.com/projects/esp-idf/en/latest/get-started/#setup-toolchain}"
}

@misc{arduino_ide,
title = "{Arduino Software (IDE)}",
howpublished = "\url{https://www.arduino.cc/en/main/software}"
}

@misc{esp_arduino,
author = "{Espressif Systems}",
title = "{Arduino core for ESP32 WiFi chip}",
howpublished = "\url{https://github.com/espressif/arduino-esp32}"
}

@misc{xtensa_isa,
author = "{Tensilica, Inc.}",
title = "{Xtensa\textsuperscript{\textregistered} Instruction Set Architecture (ISA) Reference Manual}",
howpublished = "\url{https://github.com/espressif/arduino-esp32}"
}

@misc{llvm_matrix,
author = "{LLVM Project.}",
title = "{LLVM 8 documentation, The LLVM Target-Independent Code Generator, Target Feature Matrix}",
howpublished = "\url{https://github.com/espressif/arduino-esp32}"
}

http://llvm.org/docs/CodeGenerator.html#id72
@techreport{rfc7228,
author = "C. Bormann and M. Ersue and A. Keranen",
title = "{Terminology for Constrained-Node Networks}",
Expand All @@ -27,8 +54,47 @@ @techreport{rfc7228
issn = "{2070-1721}",
pages = "1-17",
doi = "{10.17487/RFC7228}",
howpublished = "{Internet Requests for Comments}",
url = "{http://www.rfc-editor.org/rfc/rfc7228.txt}"
howpublished = "{Internet Requests for Comments}"
}

@book{jvms,
author = "Tim Lindholm and Frank Yellin and 村上 雅章",
title = "Java{\texttrademark}仮想マシン仕様",
edition = "第2版",
publisher = "ピアソン・エデュケーション",
isbn = "ISBN489471356X",
year = 2001,
}

@book{ieee754,
title={{IEEE standard for binary floating-point arithmetic}},
booktitle={{IEEE standard for binary floating-point arithmetic}},
publisher={Institute of Electrical and Electronics Engineers},
year={1985}
}

@inproceedings{webassembly,
abstract = {The maturation of theWeb platform has given rise to sophis- ticated and demandingWeb applications such as interactive 3D visualization, audio and video software, and games.With that, efficiency and security of code on theWeb has become more important than ever. Yet JavaScript as the only built- in language of the Web is not well-equipped to meet these requirements, especially as a compilation target. Engineers from the four major browser vendors have risen to the challenge and collaboratively designed a portable low-level bytecode called WebAssembly. It offers compact representation, efficient validation and compilation, and safe low to no-overhead execution. Rather than committing to a specific programming model, WebAssembly is an abstrac- tion over modern hardware, making it language-, hardware-, and platform-independent, with use cases beyond just the Web. WebAssembly has been designed with a formal se- mantics from the start. We describe the motivation, design and formal semantics of WebAssembly and provide some preliminary experience with implementations.},
author = {Haas, Andreas and Rossberg, Andreas and Schuff, Derek L. and Titzer, Ben L. and Holman, Michael and Gohman, Dan and Wagner, Luke and Zakai, Alon and Bastien, JF},
booktitle = {Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation - PLDI 2017},
doi = {10.1145/3062341.3062363},
isbn = {9781450349888},
issn = {03621340},
pages = {185--200},
title = {{Bringing the web up to speed with WebAssembly}},
howpublished = "\url{http://dl.acm.org/citation.cfm?doid=3062341.3062363}",
year = {2017}
}

@misc{wasm_spec,
title = "{WebAssembly Specification}",
howpublished = "\url{http://webassembly.github.io/spec/core/index.html}"
}

@article{ecma2018,
author = {Ecma International},
title = {{ECMAScript{\textsuperscript{\textregistered}} 2018 Language Specification}},
year = {2019}
}

@article{__japanese,
Expand All @@ -49,8 +115,8 @@ @inproceedings{__english
year = "2008"
}

@misc{__url,
author = "@kurokobo",
url = "{http://wiki.kurokobo.com/index.php?LaTeX}"
@misc{__website,
\urlauthor = "@kurokobo",
howpublished = "\url{http://wiki.kurokobo.com/index.php?LaTeX}"
}

Binary file added img/esp32_libwasm.pdf
Binary file not shown.
Binary file added img/exec_time.pdf
Binary file not shown.
Binary file added img/heap_size.pdf
Binary file not shown.
Binary file added img/libwasm_arch.pdf
Binary file not shown.
Binary file added img/new_world.pdf
Binary file not shown.
Binary file added img/wasm_module.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions src/000_meta.tex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
\bibliographystyle{jplain}

\jclass {卒業論文}
\jtitle {低消費電力デバイスのためのWebAssembly実行環境の実装と評価}
\jtitle {ESP32のためのWebAssembly実行環境の実装と評価}
\juniv {慶應義塾大学}
\jfaculty {環境情報学部}
\jauthor {安井 瑛男}
Expand All @@ -35,7 +35,7 @@
\jdate {2019年1月}

\eclass {Bachelor's Thesis}
\etitle {Implementation and Evaluation of a WebAssembly Runtime for Low-power Devices}
\etitle {Implementation and Evaluation of a WebAssembly Runtime for ESP32}
\euniv {Keio University}
\efaculty {Bachelor of Arts in Environment and Information Studies}
\eauthor {Akio Yasui}
Expand Down
89 changes: 36 additions & 53 deletions src/010_introduction.ja.tex
Original file line number Diff line number Diff line change
@@ -1,79 +1,62 @@
\chapter{序論}
\label{chap:introduction}

\section{本研究の背景}
\section{背景}
\label{section:background}

低消費電力デバイスの性能向上と低価格化により、身の回りの家具や家電をはじめとしたあらゆるものがインターネットに接続し、
組み込み向けデバイスの性能向上と低価格化により、身の回りの家具や家電をはじめとしたあらゆるものがインターネットに接続し、
協調して動作することで生活を豊かにするInternet of Things(IoT)が普及しつつある。

また、低消費電力デバイスの性能向上は、これらの上にTLSやHTTPといった比較的高負荷・高フットプリントなプロトコルを実装することも可能とした。
これにより、端末間の接続、また端末とデータを集約するサーバとの接続に汎用的なプロトコルを用いることができるようになり、高い相互接続性を実現できるようになった。

また、単一のチップでWi-FiやBluetooth、Bluetooth Low Energy(BLE)による接続を提供するものも登場している。
こうした端末を用いることで、電波環境や電力消費といったリソースを効率的に利用することが可能なため、IoTシステムを適用できる環境は大きく広がっている。

たとえば、Espressif Systems社のESP32\cite{esp32}は、以下の仕様を持っている。
Espressif Systemsによって開発されたESP32\cite{esp32}は、組み込み向けデバイスの中でも比較的高性能かつ廉価なSoCの一つである。

\begin{itemize}
\item Xtensa single-/dual-core 32-bit LX6 microprocessor(s), up to 600 MIPS
\item 448 KB ROM, 536 KB SRAM
\item QSPI supports multiple flash/SRAM chips
\item 802.11 b/g/n
\item Compliant with Bluetooth v4.2 BR/EDR and BLE specifications
\end{itemize}

ESP32は豊富な計算資源と高度な無線接続機能を提供する一方で、ESP32が搭載しているXtensaマイクロプロセッサが用いるXtensa命令セットアーキテクチャ\cite{xtensa_isa}は、幅広い開発環境にサポートされているとは言えない。
現在、ESP32向けのソフトウェア開発環境としてEspressif Systemsにより公式に提供されているのは、以下の2通りの手段である\cite{esp_toolchain}。
\begin{itemize}
\item C/C++でプログラムを記述し、ESP32 Toolchainによりコンパイルする
\item Arduino言語でプログラムを記述し、Arduino IDEと
Arduino core for ESP32 WiFi chipによりコンパイルする
\end{itemize}

一方で、各デバイス上で動作するソフトウェアは、依然としてそれぞれの開発環境に合わせて実装する必要がある。
x86やARMといったアーキテクチャが一般に用いられる個人向けコンピュータやサーバと異なり、低消費電力デバイスが搭載するマイクロコントローラの
アーキテクチャは多岐にわたる。また、サポートされているコンパイラもそれぞれに異なり、開発者はデバイス毎に切り替えて開発を行わなければならない。

(FreeRTOSがサポートするマイコンのアーキテクチャ一覧の表?)

\section{本研究の目的}

本研究の目的は、異なるCPUアーキテクチャを搭載した低消費電力デバイス間で、同一のWebAssemblyバイナリを実行できることを示すことである。
x86やARMといった、広く利用されている命令セットアーキテクチャを搭載するPCやサーバ向けのソフトウェア開発では、開発者には多くの開発環境を選択肢として選択できる。
例えばプログラミング言語の選択という観点では、LLVMが機械語生成の対象としてサポートされているハードウェアであれば、LLVMを機械語生成に用いるプログラミング言語の全てが選択肢となりうる。
しかし、組み込み向けマイクロコントローラなど、用途が限定されているアーキテクチャの中でサポートされているものは限られている\cite{llvm_matrix}。
Xtensaも、LLVMによってサポートされていないアーキテクチャの一つである。

一般に、複数のアーキテクチャで共通のバイナリを実行することは、それぞれのアーキテクチャ向けにコンパイルされたバイナリを実行するよりも
オーバーヘッドが大きく、CPUの性能やメモリの容量が限られている低消費電力デバイスには向かない。
\section{本研究が着目する課題}

そこで本研究では、低消費電力デバイスでも低オーバーヘッドで実行可能なバイナリ表現としてWebAssemblyを用いることを提案する。
まず、既存の手法(JVM、CPUエミュレーション)と比べ、また実行環境の実装が容易であること、少ないオーバーヘッドで実行できることを示す。
続いて、C言語でクロスプラットフォームなWebAssemblyランタイムを実装し、ESP32と(ラズパイ?)で同一のバイナリを実行することで、
異なる低消費電力デバイスで同一のバイナリを実行できることを示す。
本研究では、\ref{section:background}節で述べた、ESP32向けのソフトウェア開発環境が限られている点に着目する。
多くの開発環境でサポートされているアーキテクチャをESP32上で実行することができれば、ESP32に向けたソフトウェア開発環境の選択肢を広げることができる。

\section{本研究が対象とする環境}
\section{本研究の目的とアプローチ}

RFC 7228\cite{rfc7228}では、CPU、メモリおよび電力といったリソースにおいて強い制約を持つデバイスを
{\it constrained device}として定義し、いくつかの{\it class}に分類している。
本研究の目的は、Xtensaアーキテクチャよりも多くの開発環境でサポートされているアーキテクチャ向けにコンパイルされたプログラムを、ESP32上で実行することである。

\begin{itembox}[l]{とりあえずコピペした表}
\begin{verbatim}
+-------------+-----------------------+-------------------------+
| Name | data size (e.g., RAM) | code size (e.g., Flash) |
+-------------+-----------------------+-------------------------+
| Class 0, C0 | << 10 KiB | << 100 KiB |
| | | |
| Class 1, C1 | ~ 10 KiB | ~ 100 KiB |
| | | |
| Class 2, C2 | ~ 50 KiB | ~ 250 KiB |
+-------------+-----------------------+-------------------------+
\end{verbatim}
\end{itembox}
そこで、本研究では仮想命令セットアーキテクチャとしてWebAssemblyを用いることを提案する。
また、実行形式としてWebAssemblyバイナリフォーマットを用いることを提案する。

本研究では、ある程度使用できるリソースに制約を持ちながら、すでに広く用いられているプロトコルスタック(TCP/IP、HTTP、TLSなど)を
利用できる程度のリソースを持つ、{\it Class 2}以上のデバイスを想定している
本研究では、WebAssembly実行環境をESP32上に実装し、汎用的な開発環境を用いて生成されたプログラムを実行できることを示す。
これにより、仮想命令セットアーキテクチャとしてWebAssemblyを用いることで、ESP32の開発環境の選択肢を広げられることを示す

\begin{quote}
Class 2 devices are less constrained and fundamentally capable of
supporting most of the same protocol stacks as used on notebooks or
servers
\end{quote}
\begin{figure}[htbp]
\caption{現状と展望}
\label{fig:new_world}
\begin{center}
\includegraphics[bb=0 0 800 600,width=12cm]{img/new_world.pdf}
\end{center}
\end{figure}

\section{本研究の構成}

本論文における以降の構成は次の通りである。

\ref{chap:related_works}章では、異なるCPUアーキテクチャで同一のバイナリを実行するための既存の手法を示す。
\ref{chap:comparison}章では、既存の各手法では低消費電力デバイスでの利用が難しいことを示し、WebAssemblyを用いる利点について述べる。
\ref{chap:implementation}章では、本研究で実装するWebAssemblyランタイムとそれを実行するプログラムについて、設計と実装を示す。
\ref{chap:evaluation}章では、本研究の実装の有効性を評価し、その結果を考察する。
\ref{chap:conclusion}章では、本研究の結論についてまとめるとともに、今後の展望を示す。
\ref{chap:related_works}章では、関連技術として〜。
\ref{chap:implementation}章では、本研究で実装するWebAssembly実行環境について、設計と実装を示す。
\ref{chap:evaluation}章では、〜。
\ref{chap:conclusion}章では、〜。
57 changes: 54 additions & 3 deletions src/020_related_works.ja.tex
Original file line number Diff line number Diff line change
@@ -1,6 +1,57 @@
\chapter{既存研究}
\chapter{関連技術}
\label{chap:related_works}

\section{JVM}
\section{WebAssembly}

\section{CPUエミュレータ}
WebAssemblyは、Google、Microsoft、MozillaおよびAppleの主導によって開発された仮想命令セットである\cite{webassembly}。
従来、WebブラウザにおいてはECMAScript(JavaScript)が事実上唯一の標準化された実行形式であった。
しかし、ECMAScriptはスクリプト言語({\it scripting language})として設計された言語であり\cite{ecma2018}、実行速度や実行効率といった面で最適化されていない。
そこで、WebAssemblyはWebブラウザにおいて高速で安全な実行が可能な形式として設計された。

\subsection{バイナリフォーマット}

\begin{figure}[htbp]
\caption{WebAssemblyバイナリフォーマットの構成}
\label{fig:wasm_module}
\begin{center}
\includegraphics[bb=0 0 800 600,width=12cm]{img/wasm_module.pdf}
\end{center}
\end{figure}

\paragraph{}

i32、i64、f32、f64。

\paragraph{関数}

\paragraph{テーブル}

外部の関数への参照テーブルのサイズ情報と型情報。

\paragraph{エレメント}

テーブルを初期化するためのデータ。

\paragraph{メモリ領域}

線形なメモリ領域(ヒープ)のサイズ情報。

\paragraph{データ}

メモリ領域を初期化するためのデータ。

\paragraph{グローバル変数}

グローバル変数の初期値。

\paragraph{インポート}

他のモジュールの型/テーブル/メモリ/グローバル変数への参照。

\paragraph{エクスポート}

他のモジュールへ公開する型/テーブル/メモリ/グローバル変数。

\subsection{検証}

\subsection{実行}
6 changes: 0 additions & 6 deletions src/030_comparison.ja.tex

This file was deleted.

29 changes: 29 additions & 0 deletions src/030_implementation.ja.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
\chapter{設計と実装}
\label{chap:implementation}

\section{構成}

本研究において実装したESP32上で動作するプログラムの実装の構成を示す。

まず、WebAssembly Core Specification\cite{wasm_spec}により規定された仕様を基に、WebAssemblyインタプリタをライブラリとして実装した(libwasm)。
libwasmは、標準C(C11)により規定された仕様のみを用いて、プラットフォーム非依存な形で実装した。

次に、定数として保持した静的なWebAssemblyバイナリをlibwasmを用いて実行し、結果を出力するだけの簡単なプログラムを、ESP-IDF\cite{esp_idf}を用いてFreeRTOS上に実装した。

構成の概観を図\ref{fig:esp32_libwasm}に示した。

\begin{figure}[htbp]
\caption{本実装の構成}
\label{fig:esp32_libwasm}
\begin{center}
\includegraphics[bb=0 0 800 300,width=12cm]{img/esp32_libwasm.pdf}
\end{center}
\end{figure}

\begin{figure}[htbp]
\caption{libwasmの構成}
\label{fig:libwasm_arch}
\begin{center}
\includegraphics[bb=0 0 800 600,width=12cm]{img/libwasm_arch.pdf}
\end{center}
\end{figure}
Loading

0 comments on commit 35f7f51

Please sign in to comment.