# Development of a Novel Open Control System Implementation Method under Industrial IoT
## 3 Implementation of Open Control Systems Under Industrial IoT
### Container- and WebAssembly-Based Control Task Virtualization  
As Section 2.2 mentions, container is incompetent with respect to the complexity of the control domain and the heterogeneity of infrastructures in the environment of the industrial IoT. Thus, this paper utilizes WebAssembly as a complementary method to virtualize control tasks. WebAssembly (wasm) is a compact binary bytecode format released by the major browser vendors to complement and work alongside JavaScript, the only built-in language of the web. It supports browsers to run native code fast, portably, and securely for sophisticated and interactive applications, like 3D games, virtual and augmented reality, and so on [24]. Rather than be written by hand, wasn is the compilation target for multiple source languages, such as C, C++, Rust, etc. That is, codes written in these languages can be compiled as wasn modules. Since wasn is designed with formal semantics from the start, there is no need for an extra trust mechanism to execute wasn modules efficiently and securely [25]. As Figure 7 presents, moreover, with the wasn system interface (WASI) released to abstract the host operating system, wasn modules started running outside of the browser runtime [26]. WASI defines a standardized set of interfaces and functionalities of the operating system in a modular, independent, and capability-oriented manner. The wasn runtime translates WASI calls into the surrounding system calls to finally interact with the host operating system. The wasn runtime provides each wasn module with an  
Figure 6: Classdiagram of the proposed hierarchical formal model. independent sandboxed environment. In a nutshell, wasm is a virtual instruction set architecture (ISA) between the real assembly and Java bytecode (or.NET intermediate language), and its execution depends on WASI to provide a uniform abstraction of different host operating systems. Its advantages, such as its tiny size, low memory footprint, fast booting, great isolation and security, high portability, etc., make it an attractive virtualization technology, especially for resource-constrained hardware in the industrial IoT [27]. As an operating-system-level virtualization, wasm-based control applications can also rely on a real-time operating system to satisfy the time determinacy of control systems. In order to evaluate the performance of wasm-based virtualization, two tests have been designed. The first test evaluates the execution efficiency of wasm modules. A bubble sort program written in the C language is compiled into two wasm modules, one in the interpreter mode and the other in the Ahead-of-Time (AoT) mode. The test platform is Raspberry Pi 4B (processor clocked at 1.8 GHz, 8G of SDRAM). The result indicates that the average running time of the interpreter mode wasm module is 3.88-times that of the native program, while the AoT mode is only 1.06, near the native program. The second test tries to compile a motor controller into a wasm module. The motor controller contains three real-time threads and a main thread. One real-time thread executes the PID algorithm cyclically, and the other two real-time threads listen to the edge-triggered interrupt of the encode. The main thread initializes the controller and interacts with users. However, the result indicates that the whole controller fails to be compiled as a wasm module because some necessary APIs used in the real-time threads are not defined in the current WASI standard, such as sched_setscheduler(), poll(), signal(), settimer(), etc. But, the parts of the motor controller that do not rely on these APIs, for instance the user interaction part of the main thread and the PID computation part, can be compiled as wasm modules and have good portability across infrastructures (different operating systems). In this paper, therefore, a hybrid control task virtualization method based on containers and wasm is designed, as Figure 8 shows.