Accelerating Renode simulation on Linux-based x86-64 machines with KVM support
Published:
Topics: Open simulation, Open source tools
Antmicro’s open source Renode simulation framework executes code using binary translation - if you run a Cortex-M target on your typical Linux, you need to translate the Arm-M instruction set to x86-64. However, if you want to simulate an x86 platform and you’re running on a host with matching architecture, there should be no need to translate anything - you could just run the code of the guest payload.
The code for the simulated platform is different from a typical Linux application: it needs to interact with devices, physical memory, etc. This is why virtualization is needed - to present the code with an environment it can perceive as the actual hardware. The goal is to make the code execute in hypervisor, but also retain the peripherals modeled in Renode.
In this article we describe our work on introducing the Linux KVM (Kernel-based Virtual Machine) bare metal hypervisor to Renode as an alternative core implementation method. This new approach to simulating x86 platforms is significantly faster, as it doesn’t require Renode to handle the CPU part and instead reuses the host CPU. In the following paragraphs we will detail the initial KVM CPU implementation in Renode and showcase it with a demo.
Implementing a KVM-based core in Renode
KVM, or Kernel-based Virtual Machine, is an environment for virtualization in Linux. KVM changes Linux into a Type 1 hypervisor that is a lightweight management solution for running guest software directly on the host’s hardware.
The implementation of a KVM-based core for Renode can be split into two parts, a native library for executing KVM system calls and a CPU model. The model communicates with the library to receive or set register values, perform system bus or IO port accesses, raise interrupts, etc. It also manages the virtual time that Renode operates on and translates it into real time. The library executes the guest software with KVM for a given period using real-time timers.
Renode’s time management is based on quantification of time, so that after executing a given amount of time a synchronization of cores is performed. For this reason, before the KVM is started with the guest software, a timer is set to trigger the alarm signal to interrupt the execution. This way a performant execution of code is possible while providing an approximate control over the execution time.
With the introduction of KVM-based cores, we created sister platform descriptions based on the already supported generic x86 target and ACRN’s x86-64 target. Now you can choose between either the standard i386.repl / acrn_x86_64.repl platforms that will work e.g. when running Renode on an ARM64 host, and the new i386-kvm.repl and i386_64-kvm.repl platforms for better performance on x86-64 hosts.
Demo: running Linux on a 64-bit i386 KVM platform
For the newly supported i386_64 KVM platform, we’ve added Linux and SeaBIOS demo scripts that are shipped with Renode, ready to be used.
Note that those demos are intended to be run on x86-64 Linux systems with KVM supported and loaded.
Below we are presenting the demo that runs Linux. Running the following snippet in Renode will pop up a console that shows the boot-up logs.
(monitor) include @scripts/single-node/i386_64-kvm-linux.resc
(i386_64-kvm) start
In about a second, a login prompt will be presented: there’s no password and the user is root
. After logging in, an sh
shell will be presented:
Similar Linux and SeaBIOS demos are also available for the 32-bit i386 KVM platform.
Boosting Renode’s performance on Linux workstations
The initial KVM CPU implementation in Renode proves that the new approach works and could potentially be expanded beyond just x86/x86-64 machines; it should work on any host, provided that the payload is targeting the matching architecture and the host operating system supports the virtualization API. Our next goal is to replicate this setup with a VirtIO-based filesystem and with Linux on Arm cores, e.g. using a Raspberry Pi platform as host.
If you’re interested in integrating Renode with your workflows or expanding its capabilities for your use case, reach out to us at contact@antmicro.com and visit our offering page to learn more about our engineering services.