Friday, December 1, 2023

QEMU: For Faster Virtualisation And Better Emulation

By Ashwin Gopinath

- Advertisement -

For the uninitiated, virtualisation and emulation might seem to be two words that can be used interchangeably, and that would be as wrong as you could get. Virtualisation involves simulating the functioning of a computer’s hardware like CPU, CD-ROM, graphics controller and the like. While a program like VMWare can provide a virtual environment for running a virtual Windows PC, it cannot work on any real hardware other than its native x86 PC.

On the other hand, in an emulator, the virtual machine simulates the complete hardware in software. This allows an operating system of one computer architecture to be run on the architecture for which the emulator is written. If you have ever tried Contra on a PC, then you know what function an emulator performs.

Two birds with one sharp stone

In this article we will talk about QEMU, a software that can do both, emulate and virtualise.

- Advertisement -

QEMU, or Quick EMUlator, is a virtual machine monitor that emulates CPUs through dynamic binary translation, providing a variety of models through which it runs a bevy of guest operating systems. Table I shows the various formats and architectures it supports.

QEMU on source and destination
Fig. 1: QEMU on source and destination

How a virtual machine runs

All virtual machines generally work on the principle that the operating system allocates resources of the system to any process that requires it, be it disk space, memory, peripherals and so on. When a user program needs these resources, it sends a syscall to the operating system. When the syscall is sent to a real operating system, the operating system, in turn, accesses the hardware personally and facilitates the release.

However, in the case of a virtual machine, the guest operating system does not have access to the hardware. So it does something straight out of a con-job movie. It impersonates the host operating system. By using a process known as trap-and-execute, it traps syscalls and then reroutes these via the guest operating system to masquerade as coming from the host operating system. This process allows the guest operating system to think that it is in fact the host operating system of the machine and, hence, has control over its hardware.

Multiple modes of operation

There are four modes in which QEMU operates. Let us take a look at how these help you.

User-mode emulation. In this mode, the emulator runs Linux or Mac OSX programs that were compiled for a different instruction set. Cross-debugging and fast cross-compilation are the main targets in this mode.

System emulation. This mode results in emulation of a full computer system, including peripherals. This mode can be used to provide virtual hosting of several virtual computers on a single computer—that is a lot of virtual for a very real system.

KVM hosting. In order to host a kernel virtual machine (KVM), this mode assists in setting up and migration of KVM images. Though still involved in emulation of hardware, execution is done as requested by QEMU.

Xen hosting. In this laziest of modes, all QEMU does is emulate the hardware, and execution of the guest is totally hidden from QEMU.

QEMU is quick as an emulator, but it works as a virtualiser as well, wherein it can achieve near-native performance by executing the code directly on the host CPU. It is a favourite at EFY because of its extensive reach, be it architectures supported or the interfaces it can handle, and due to it being open source.

There are some minor security flaws associated with QEMU, which are being worked on. As QEMU is written in C, and not Java, it is not easy to port it on to a new system. QEMU also has issues with not being able to utilise multiple host CPUs, rather running all virtual CPUs from a single thread. Unlike similar programs, like VirtualBox and VMWare, QEMU does not provide a GUI to manage virtual machines, nor does it provide a way to create persistent virtual machines with saved settings. However, there are several front-ends with GUI for it, like qemu-launcher, qtemu and aqemu.


A KVM is a Linux kernel module that allows a user program to utilise the hardware virtualisation features of various processors. It supports a host of processor architectures like Intel, AMD, ARM and MIPS32. QEMU can make use of KVM when it is running a target architecture that is the same as the host architecture. If you are running qemu-system-x64 on an x64-compatible processor, you can utilise HW virtualisation offered by KVM. To use KVM, pass — enable-kvm to QEMU.

How QEMU is different from KVM

KVM is a part of QEMU executable, and different teams are working on both. Where QEMU team focuses on hardware emulation and portability, KVM developers focus on the kernel module and interfacing.


Electronics News

Truly Innovative Tech

MOst Popular Videos

Electronics Components