Introduction to virtio-gpu

background:

The improvement of graphics cards has always been a difficult problem in virtualization scenarios. Qemu currently provided video card has two kinds
one is cirrus graphics card, one is vga graphics card. These two kinds of graphics cards are simulated by qemu, and they only achieve the functions that can be used by virtual machines.
The 3D acceleration capabilities required by the game are not well simulated.

The graphics card itself needs powerful computing power. Here qemu uses cpu purely to simulate the function of gpu.

The emergence of new functions virtio-gpu has brought some new breath to the virtualized graphics card function. The following briefly introduces the virtio-gpu function.

Introduction to virtio-gpu

Like all virtio devices, virtio-gpu also consists of this front-end graphics card and back-end graphics card.
The front-end graphics card of virtio-gpu entered the backbone in kernel 4.2 and only has 2D functions. The 3D function was incorporated in 4.4.
So if you want to experience this function, you need to use kernel 4.4 or later.

The relevant codes of virtio-gpu are mainly in the drivers / gpu / drm / virtio directory of the kernel.
Here is a brief introduction to drm. For details, please refer to DRM introduction.
DRM can directly access the hardware of DRM clients. The DRM driver is used to handle DMA, memory management, resource locks and secure hardware access.

In this way, you can see that the relevant memory information is managed through DRM, so that the memory information can be passed to the backend through virtio-gpu.

The next step is to look at the backend implementation in qemu.

Virtio-gpu support began in qemu 2.5.
And ready to support spice graphics card in qemu2.6.
As a typical virtio device, you also need to implement the virtio interface. The code of the virtio-gpu backend is included in qemu's hw / display.

Here qemu used the Virgil 3D project to simulate the graphics card. Reference Virgil 3D

The purpose of Virgil 3D is to use Host's 3D acceleration technology to implement a virtual 3D GPU for virtual machines.

Having said that, of course, you must experience a virtio-gpu yourself.
In virtio-gpu describes the process of how to use the virtio-gpu's.
The process of my test is also written here below.

Virtio-gpu test process

I use the hardware environment:

CPU: Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz (2194MHz) x2

GPU: Intel(R) HD Graphics 5500 20.19.15.4331 (1024MB) x1

Use personal PC to build centos7.2.

installation

spice-server-0.13.1-20160524.b122.g70f04bd.x86_64
spice-server-devel-0.13.1-20160524.b122.g70f04bd.x86_64
spice-glib-0.31-20160321.b000.g0a1f9bf.x86_64
spice-vdagent-0.14.0-10.el7.x86_64
spice-gtk3-0.31-20160321.b000.g0a1f9bf.x86_64
virglrenderer-0.5.0-1.20160411git61846f92f.el7.centos.x86_64
virglrenderer-devel-0.5.0-1.20160411git61846f92f.el7.centos.x86_64

Of course, we still need 2.6 version of qemu

Compile time configuration

./configure --enable-debug --enable-gtk --target-list=x86_64-softmmu

Need to confirm the following support

 virgl support     yes
 spice support     yes (0.12.11/0.13.1)

So our hypervisor is ready.

Since kernel 4.4 and above only support the virtio-gpu driver,
Fedora-Server-dvd-x86_64-24-1.2 was selected as the guest OS for testing.

Need to install KDE desktop environment to test the 3D effect.

Use the start command of virtio-gpu. Use spice to enable gl = on. The current spice implementation only supports local access.
It cannot be provided to the remote in the form of TCP.

x86_64-softmmu/qemu-system-x86_64 -m 4000 --enable-kvm -vga virtio -cpu host -smp 2 -drive file=/home/test.img,if=virtio -usb -usbdevice tablet -spice gl=on,unix,addr=/home/spice.sock,disable-ticketing

Connect to a virtual machine

remote-viewer spice+unix:///home/spice.sock 

So you can see the picture with 3D acceleration.

How to confirm that 3D acceleration is turned on?
Use glxinfo to see if direct is Yes

glxinfo|grep direct

What is the performance of virtio-gpu? Of course, there is a test.
Unigine_Valley-1.0 graphics card performance test tool is selected here.
software download

wget http://ftp.nluug.nl/pub/games/PC/guru3d/benchmark/Unigine_Valley-1.0-[Guru3D.com].run

After installation, you can start testing directly.

type Host Guest
FPS 10.2 1.1
Score 425 44
My FPS 5.4 1.0
Max FPS 20.5 1.2

It can be seen that the performance loss of virtio-gpu is also very high.

Foreign friends also tested the benchmark .

Here there is a small discovery, when using -vag qxl analog graphics card, 3D acceleration inquiry, also Yes, but
can not run 3D test software. Will report that a function cannot be found. Guess that the analog graphics card has implemented some 3D acceleration instructions.

In addition, if you don't use spice, you can also use qemu's display to enable virtio-gpu acceleration.

x86_64-softmmu/qemu-system-x86_64 -m 4000 --enable-kvm -display gtk,gl=on -vga virtio -cpu host -smp 2 -drive file=/home/test.img,if=virtio -usb -usbdevice tablet

summary:

The advantages of virtio-gpu are obvious, and I wo n’t say much here. If you want to use it as a product, there are currently some restrictions:

  • At present, it can provide 3D acceleration support, which is related to the performance of the local graphics card, and the performance loss is still slightly higher.
  • Currently, the client side of Spice only supports local use, and needs to provide remote access capabilities.
  • The virtio-gpu driver is only provided for linux, and most desktop systems are still windows, which requires the windows version of the driver.
Published 6 original articles · Likes0 · Visitors 10,000+

Guess you like

Origin blog.csdn.net/ssdxiao0/article/details/52221422