1.. _user_vm_guide:
2
3User VM Guide
4#############
5
6The ACRN hypervisor uses a Linux-based Service VM and can run User VMs
7simultaneously, providing a powerful software platform to build complex
8computing systems. A User VM can run a variety of OSs including Linux or
9Windows, or an RTOS such as Zephyr or VxWorks. As shown in the :ref:`gsg`,
10you use the ACRN Configurator to define options used to build the static
11configuration of your ACRN system based on your system design, available
12capabilities of your target hardware, and performance characteristics such as
13those required for real-time needs. The Configurator also lets you define
14dynamic settings for launching User VMs and specifying the resources they need
15access to.
16
17ACRN provides a framework called the :ref:`ACRN Device Model
18<dm_architecture_intro>`, for sharing physical system resources and providing
19virtual device emulation with rich I/O mediators.  The Device Model also
20supports non-emulated device passthrough access to satisfy time-sensitive
21requirements and low-latency access needs of real-time applications.
22
23In this and accompanying documents, we provide guidance for configuring and
24deploying post-launched User VMs, and additional information about OS-specific
25settings based on your User VM OS choice. We also show how to configure the
26system for accessing virtual devices emulated by the ACRN Device Model or
27passthrough resources dedicated to a specific VM.
28
29ACRN also supports pre-launched User VMs, with dedicated resources that are not
30shared with other VMs. Pre-launched VMs are configured statically using the
31Configurator, with their own boot devices, CPU, memory, and other system
32resources.  We'll discuss pre-launched VMs separately.
33
34
35User VM OS Choices
36******************
37
38ACRN has no restrictions on what OS is used by a User VM. The ACRN team has
39tested Standard User VMs running Ubuntu 20.04 and Windows 10, and real-time User
40VMs running Zephyr, VxWorks, Xenomai, and Linux VMs running on a
41PREEMPT_RT-patched kernel.
42
43The ACRN Service VM and its Device Model run on Ubuntu 20.04 using a patched
44kernel built from the `acrn-kernel GitHub repository
45<https://github.com/projectacrn/acrn-kernel>`_. The Service VM can access
46hardware resources directly by running native drivers and provides device
47sharing services to post-launched User VMs. The Service VM is not dependent on
48any settings in your User VM configuration and is used for both Standard and
49Real-time post-launched User VMs.  The Service VM is not used by pre-launched
50User VMs.
51
52Configuration Overview
53**********************
54
55In the following sections, we provide general guidance and then link to
56OS-specific guidance documents based on your choice of User VM OS.
57
58Separately, and out of scope for this document, you'll need to create a combined
59application and User VM OS image for each User VM.
60
61The ACRN Device Model within the Service VM starts your User VM image using a
62launch script created by the ACRN Configurator, based on the settings you
63provided. These settings include the location on the target system storage
64device for that image, User VM memory size, console, vUART settings for
65communication, virtual I/O devices your application uses, and more. Available
66launch script options are documented in the :ref:`acrn-dm_parameters` and the
67:ref:`scenario-config-options` documentation.  We'll also provide examples for
68selected capabilities in our OS-specific guidance.
69
70This guide assumes you've already followed the Getting Started Guide and have
71followed steps to prepare the development computer and installed development
72system prerequisites, prepared the target and generated a board configuration
73file, and have installed the ACRN Configurator.
74
75Using the ACRN Configurator
76===========================
77
78Independent of your User VM OS choice, run the ACRN Configurator and create a
79scenario with a Post-launched VM for each User VM you will be running. We use
80one Ubuntu-based User VM in this overview:
81
82.. figure:: images/vm-guide-create-new-scenario.png
83   :align: center
84   :width: 600px
85   :name: vm-guide-create-new-scenario
86   :class: drop-shadow
87
88   Creating a new scenario in the Configurator
89
90Use the Configurator to give the VM a name, and define configuration options
91specific for this VM, such as memory and VM type (Standard or Real-time):
92
93.. figure:: images/vm-guide-set-vm-basic-parameters.png
94   :align: center
95   :width: 600px
96   :name: vm-guide-set-vm-basic-parameters
97   :class: drop-shadow
98
99   Set VM basic configuration options
100
101And define where the User VM image will be on the target system (in this
102example, an Ubuntu 20.04 desktop ISO image):
103
104.. figure:: images/vm-guide-image-virtio-block.png
105   :align: center
106   :width: 600px
107   :name: vm-guide-image-virtio-block
108   :class: drop-shadow
109
110   Set VM image using virtio block device
111
112After the configuration settings are to your liking, save the configuration.
113When saving, the ACRN Configurator first validates your scenario configuration and
114reports any issues that need your attention.  If successful, it writes out the
115updated scenario XML file and launch script to your working directory.  You'll
116use this launch script to start the User VM on the target.
117
118Rebuild the ACRN Hypervisor
119===========================
120
121After exiting the ACRN Configurator,  build the ACRN hypervisor (based on the static
122configuration parameters in your scenario) on your development computer, as was
123done in the :ref:`gsg`::
124
125   cd ~/acrn-work/acrn-hypervisor
126   make clean && make BOARD=~/acrn-work/MyConfiguration/my_board.board.xml SCENARIO=~/acrn-work/MyConfiguration/scenario.xml
127
128The build typically takes a few minutes. When done, the build generates a Debian
129package in the ``./build`` directory.
130
131This Debian package contains the ACRN hypervisor and tools to ease installing ACRN on the target.
132
133Transfer Files to the Target, Install, and Reboot
134=================================================
135
136We'll need to get the Debian package containing the hypervisor files we built to
137the target system, along with the launch scripts and User VM images. In the
138:ref:`gsg`, we used a USB stick, but you could also use the network to copy
139files using ``scp``.  Install the Debian package and reboot to run ACRN and the
140Service VM.  Then use the launch script to start each User VM.
141
142User VM Persistence
143*******************
144
145In the :ref:`gsg` (and in the previous overview), we used a standard Ubuntu
14620.04 ISO image as our User VM image. By its nature, an ISO image is read-only.
147This means that when you reboot the ACRN system, any changes you made to the
148User VM such as installing a new package, would be lost; the unmodified ISO
149image is used again for the User VM when the system is rebooted.  While this
150could be the usage model you'd like, an alternative is to set up the User VM
151image as read-write so it will retain any changes made while it was running and
152return to that state after a reboot.
153
154One way to create a persistent VM image is by using KVM to define virtual disk
155partitions, boot the underlying OS, add additional packages and even an
156application to that image, and then save and convert that QCOW2 image to a raw
157format we can use with ACRN.
158
159In separate companion documentation, we provide detail guides for running
160User VMs with different OSs, and provide considerations for each of those
161standard and real-time OS configurations.
162
163Standard VM OS Considerations
164*****************************
165
166Here is a list of Standard User VM OS guides with details and topics to consider
167when using one of these OSs:
168
169* :ref:`using_ubuntu_as_user_vm`
170* :ref:`using_windows_as_user_vm`
171* :ref:`using_celadon_as_user_vm`
172
173Real-time VM OS Considerations
174******************************
175
176Here is a list of real-time User VM OS guides with details and topics to consider
177when using one of these OSs:
178
179* :ref:`using_xenomai_as_user_vm`
180* :ref:`using_vxworks_as_user_vm`
181* :ref:`using_zephyr_as_user_vm`
182
183We also recommend reading these RTVM performance guides:
184
185* :ref:`rtvm_workload_guideline`
186* :ref:`rt_perf_tips_rtvm`
187* :ref:`rt_performance_tuning`
188