GPU on KVM Gabriel Laskar <gabriel@lse.epita.fr> Introduction - - PowerPoint PPT Presentation

gpu on kvm
SMART_READER_LITE
LIVE PREVIEW

GPU on KVM Gabriel Laskar <gabriel@lse.epita.fr> Introduction - - PowerPoint PPT Presentation

GPU on KVM Gabriel Laskar <gabriel@lse.epita.fr> Introduction How can we have 3D acceleration on VMs? Goals: Portability Security and of course Quake ! Outline What is a GPU? How can we bring something to the


slide-1
SLIDE 1

GPU on KVM

Gabriel Laskar <gabriel@lse.epita.fr>

slide-2
SLIDE 2

Introduction

  • How can we have 3D acceleration on VMs?
  • Goals:

○ Portability ○ Security ○ and of course Quake !

slide-3
SLIDE 3

Outline

  • What is a GPU?
  • How can we bring something to the screen?
  • What is a VM?
  • A virtualized device?
  • How can we bring all this together?
slide-4
SLIDE 4

What is a Graphic Card?

  • Display
  • Video Playback
  • 2D & 3D Graphics
  • Computation
slide-5
SLIDE 5

GPUs are complex

State State Pixel Shader Vertex Shader Vertex Pipeline Rasterization Pixel Pipeline Framebuffer Vertex Data Texture Data

slide-6
SLIDE 6

GPU API

  • Specs unknown
  • Every GPU is different
  • State is enormous (>1GB size)
  • DMA & Computation
slide-7
SLIDE 7

Graphic Stack

Application Kernel KMS DRM Mesa3D libGL DRI, Mesa Classic State Tracker WinSys HW Driver libDRM

Classic Mesa Gallium

slide-8
SLIDE 8

Mesa3D

  • Provides High Level APIs

○ 3D Acceleration: OpenGL/OpenGLES ○ Video Acceleration: XVMC, VAAPI, VDPAU

  • Device dependant
  • Divided in 2 parts: Mesa classic & Gallium3D
slide-9
SLIDE 9

Gallium3D

  • New architecture for graphic devices
  • Allows code-sharing between drivers
  • Used by radeon, nouveau & others
  • Provides software fallback
slide-10
SLIDE 10

Gallium API

  • Screen: screen access, context & resource

creation

  • Resource: texture or buffer
  • Surface: resource binded as a framebuffer
  • Sampler view: resource for shader use
  • Context: constant state, resources
slide-11
SLIDE 11

Gallium Shaders: TGSI

  • Intermediate language for shaders
  • Text based
  • API not stable yet
slide-12
SLIDE 12

TGSI Example

VERT DCL IN[0] DCL IN[1] DCL OUT[0], POSITION DCL OUT[1], COLOR IMM FLT32 { 0.2, -0.1, 0.0, 0.0 } ADD OUT[0], IN[0], IMM[0] MOV OUT[1], IN[1] END

slide-13
SLIDE 13

EGL/GLX

  • Graphics context management
  • Surface/buffer binding
  • EGL is an interface between OpenGL and

the windowing system

slide-14
SLIDE 14

DRM

  • Low level access to the GPU
  • Perform Kernel Mode Setting
  • Export GPU Primitives

○ Context allocations ○ Command queues ○ VRAM management with GEM & TTM ○ Buffer sharing with GEM & DMA-buf

  • libDRM in userland wraps the interface
slide-15
SLIDE 15

KMS

  • In kernel API for modsetting
  • Allow modesetting without root access
  • Glitch-free boot
  • Fast VT-Switch
  • Kernel crash log
  • Better power management
slide-16
SLIDE 16

How can we have all of this inside a VM ?

slide-17
SLIDE 17

Qemu/KVM

  • Linux Hypervisor
  • Leverage existing Linux APIs
  • Use Qemu for VM Creation & Device

Emulation

slide-18
SLIDE 18

Qemu/KVM

Linux Kernel

KVM

Hardware

Virtualization Extensions

Qemu guest

driver virtual device

HW

Qemu guest

driver virtual device

Qemu guest

driver virtual device

slide-19
SLIDE 19

Device Virtualization

  • Emulated Devices

○ Too Slow ○ GPU are too complex

  • Virtualized Devices

○ Hard to do it right ○ What we want to do

  • Hardware Passthrough

○ Good performances ○ No sharing

slide-20
SLIDE 20

Virtualized OpenGL stack

  • API remoting
  • Virtual GPU
  • HW Sharing: XenGT, Grid
slide-21
SLIDE 21

API Remoting

3D API Redirector RPC Endpoint App App App GPU Driver 3D API GPU Guest Host

User-Level API Kernel Hardware API

slide-22
SLIDE 22

Device Emulation

3D API Rendering Backend App App App GPU Driver 3D API GPU Guest Host

User-Level API Kernel Hardware API

Virtual GPU Driver Virtual GPU

Kernel Hardware

State Management GPU Emulator Shared Memory

slide-23
SLIDE 23

Virtio Devices

  • Standard for virtualized devices
  • Already used for net, block & console
  • Easy code reuse
slide-24
SLIDE 24

Virgl

  • Virtio based virtual gpu
  • Developed by David Airlie
  • 2d and 3d version
  • Portability: no need for a specific gpu
slide-25
SLIDE 25

Virgl: What’s in it?

  • vga device in Qemu
  • Renderer Backend in Qemu (for 2D & 3D)
  • KMS kernel driver for the guest
  • Xorg DDX driver for guest
  • Mesa Gallium3D based driver for guest
slide-26
SLIDE 26

Virgl: virtio

  • Single virtio queue used to send commands

to the host

  • Protocol is based on Gallium3D
  • IRQ for Cursor & Fence IRQ
slide-27
SLIDE 27

Current Status

  • Error handling
  • Capabilities (OpenGL 3.0 for the moment)
  • GL versioning
  • GLES in guest or host
  • Not usable for production yet
slide-28
SLIDE 28

Want to try it? http://virgil3d.github.io/ Questions?