Upload
anne-nicolas
View
913
Download
5
Tags:
Embed Size (px)
DESCRIPTION
The Linux graphics stack is constantly evolving to add support for new hardware. This evolution and new software specifications have forced the X graphical server to be split into several components including a now rotates in the Linux kernel, the Direct Rendering Manager (DRM). A quick presentation of these components and their role will be carried out before looking at new major change in the common code, the NVIDIA Optimus technology. One equipped with Optimus technology laptop has two graphics processing units (GPUs), one from Intel and one from NVIDIA. This technology combines the low power Intel GPU when the machine is not used to the performance of NVIDIA GPUs when the user plays. This technology, however, is a nightmare to manage kernel-side although the final building blocks necessary for its complete management are being finalized. Further explanation of this issue will be made and we’ll see how this new software architecture has added graphics acceleration on embedded processor SoCs like Tegra. The case of open source NVIDIA driver, called “New” will then be studied. This is the graphics driver community as it is developed without the help of NVIDIA and attracted several regular contributors, including myself! We’ll take a quick history of the project before talking about the current developments and issues related to the lack of documentation. The end of this presentation will then be left to the participants so they can ask more general questions about the graphics stack, if they wish. Martin Peres, Laboratoire Bordelais de Recherche en Informatique
Citation preview
The Linux graphics stack, Optimus and theNouveau driver
Cooperative rendering across GPUs on Linux
Martin Peres
Nouveau developerPhD student at LaBRI
X.Org Foundation board member
September 26, 2014
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Summary
1 Introduction to the Linux graphics stackGeneral overviewKernel spaceUser space
2 Optimus
3 Prime
4 Nouveau
5 Q&A
1 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
General overview of the Linux Graphics stack
The graphics stack before 2005
The X-Server provided everything:
Modesetting (CRTC & plane management);2D/3D acceleration;Video rendering acceleration;Input management.
The X-Server talked to the GPU directly, as root.
The current graphics stack
The X-Server got split into more than 200 components:
Privileged operations moved to the kernel;2D drivers got put into different shared objects;3D acceleration got put in mesa;The list is too long (and boring) ;)
2 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Mesa: APIs+DRI/Gallium3D driverlibGL-mesa-swx11 (libGL)libGL-mesa-glxlibOpenVG-mesalibGLES-mesalibEGL-mesalibEGL-mesa-drivers (Wayland)libGBMlibGL-mesa-DRI (Modules)
X-server (X.Org)
X.Org Server display driverxserver-xorg-video-nouveauxserver-xorg-video-nvidiaxserver-xorg-video-radeon
DRM Linux kernel
libDRM-intellibDRM-radeonlibDRM-nouveaulibDRM-freedreno
hardware specificUserspace interface tohardware specificdirect rendering manager
CPU & registers & L1 & L2 & L3 & L4 & main memoryGPU & registers & L1 & L2 (& graphic memory)
ApplicationsToolkits
lib
DR
M
3D-game engine
DD
X-
dri
ver
libX / libXCB
Proprietary OpenGL 4.2 driverlibGL-nvidia-glxlibGL-fglrx-glx"l
ibG
L"
Rendering APIs: OpenGL
OpenGL|ESOpenVG
X 11R7.8
blob
Displayserver
libwayland-client
Wayland 1.5
framebuffer
DIX driver
hardware-specific
by Shmuel Csaba Otto Traian; CC-BY-SA 4.0 intl; created 2013-08-24; last updated 2014-03-25
KMS
Kernel Mode Setting
Waylandobsoletes
2D drivers inthe display server
Wayland compositor
API: EGL
API: EGL
Window manager
KWinMutterWestonEnlightment
KWinCompizOpenBoxMetacityMutter
Figure: General overview of the Linux graphics stack
3 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
The kernel space
Direct Rendering Manager (DRM) : The common code
This common code provides:
Kernel ModeSetting (KMS): CRTC & plane management;Video memory management via GEM (with a TTM backend?);Nodes with different capabilities (master or render nodes).
DRM open source drivers
i810/i915: Intel;
nouveau: NVIDIA;
radeon: AMD/ATI;
vmwgfx: VMware;
many SoC GPUs (armada, exynos, msm, omap, tegra, ...).
4 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Architecture of the X-Server
Client
Server
DDX
Acceleration Architectures
DIX
ExtensionsHardware devices
Cairo
OpenGLXlib or xcb
Pango
MesaDispatch
Toolkit
Event_Queue Input Drivers
Xinput
Video Drivers
Acceleration_2DAcceleration_VideoDisplay
Pixman
Render RandR GLXKeyboardMouse Gallium
FrameBuffer
Figure: General overview of the X-Server’s internal architecture
5 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Architecture of Mesa
Applications
Mesa
Gallium
State trackers
drivers (compilers)
Mesa Classics (simplified)
X-Server
xorg
Wine
Nine
Weston
EGL
Xonotic
libgl
Qt
OpenGL
Gallium
nvc0
GPU
r300gr600g nv30nv50softpipe
CPU
llvmpipe
LLVM
intel radeon nouveau_vieux swrast
(throughlibdrm)
Figure: General overview of Mesa’s internal architecture
6 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Summary
1 Introduction to the Linux graphics stack
2 OptimusIntroductionTurning the dGPU on/offDriving the right outputsHow to share buffers across drivers?
3 Prime
4 Nouveau
5 Q&A
7 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Great performance, great battery-life
Optimus
Laptops can be equipped with two GPUs;
The Intel IGP is great for battery-life;
NVIDIA’s discrete GPU (dGPU) is great for performance;
Dynamic switch between the 2: get the best of both worlds!
Challenges
When/How the dGPU should be turned on/off?
Who drives the outputs?
How to copy buffers from one driver to another?
How should we do application migration?
How should we handle the HDMI “sound card”?
8 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Turning the dGPU on/off
How
Optimus laptops have ACPI functions to do that;
Two ways of calling them:
bbswitch: Old kernel module for manual management;vgaswitcheroo: Manual or automatic power management.
When: The case of vgaswitcheroo
Turn off the dGPU when it has been idle for 5 seconds;
Idle?:
no graphics context allocated;no output is being used;no sound interface used (not done);no call to the drm driver has been made;
9 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Handling the outputs : Hardware multiplexer
Figure: Switchable graphics10 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Handling the outputs : Software multiplexer
Figure: The “real” Optimus architecture11 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Sharing buffers across drivers
Cross-driver BO sharing : Challenges
The memory representation for buffers is different fromhardware to hardware:
pitch: number of pixels per row;tiling: technique that increases the spatial locality.
Synchronising rendering across drivers.
Solutions
VirtualGL: Remote rendering solution. Redirects drawingcommands to a distant GPU, read back the rendered frame;
Primus: Same solution as VirtualGL except in a morelightweight fashion!
DMA-Buf: A Linux-only solution that allows sharing buffersbetween different GPUs without copies.
12 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Sharing buffers across drivers : VirtualGL
13 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Sharing buffers across drivers : DMA-Buf
Driver roles
Exporter: Being able to export a buffer;
User: Being able to import a buffer.
General overview
No standardised memory allocation: It’s up to the exporter;
An arbitrary buffer can be wrapped into a DMA buffer;
An fd can be returned to the userspace to reference this buffer;
The fd can be passed to another process;
The fd can be mmapped and accessed by the CPU;
The fd can be imported by any driver supporting the user role.
14 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
dma_buf usage flow
Videodecoder
Graphicsstack
dma_buf
User
Kernel
CMA(optional)
1
2
3
4
5
6
1) allocation (CMA usage is optional).
2) dma_buf_export(): request the creation of a dma_buf for previously allocated memory.
3) dma_buf_fd(): provides a fd to return to userspace.
4) fd passed to video decoder.
5) dma_buf_get(fd): takes ref and returns 'struct dma_buf'.
6) dma_buf_attach() + dma_buf_map_attachment(): to get info for dma
a) dev->dma_parms should be expanded to tell if receiving device needs contiguous memory or any other special requirements
b) allocation of backing pages could be deferred by exporting driver until it is known if importing driver requires contiguous memory.. to make things a bit easier on systems without IOMMU
15 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
How should we do application migration?
Short answer
We don’t!
Why?
The context is hardware-dependent;
The context can be HUGE (hundreds of MB);
The best way is to ask the application to re-upload itscontext: GL ARB robustness.
16 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Optimus : How windows does it
Figure: The global hardware/software infrastructure
17 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Summary
1 Introduction to the Linux graphics stack
2 Optimus
3 PrimeIntroductionHow toDemos
4 Nouveau
5 Q&A
18 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Prime
Prime
Prime is the name for all the ustream open source technologiesthat make hybrid graphics possible:
DMA-Buf: sharing buffers across drivers (Linux 3.3);
vgaswitcheroo: switching graphics (Linux 3.12);
Cross-device fence mechanism: make a driver wait on anotherdriver to complete a task (Linux 3.17);
DMA-Buf synchronisation: Wait for rendering completion of aDMA-Buf before compositing to avoid tearing (Linux 3.19?).
List of requirements
running nouveau/radeon drm;
running the nouveau/radeon ddx;
19 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Prime: Simplified how-to for Nouveau
vgaswitcheroo
# cd /sys/kernel/debug/vgaswitcheroo/
# cat switch
# echo (DIGD|DDIS) > switch
(Re)start your desktop environment.
XRandr
$ xrandr −−listproviders
$ xrandr −−setprovideroffloadsink nouveau Intel
This sets the order: Nouveau == offload, Intel == default
20 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Prime: Simplified how-to for Nouveau
Usage
DRI PRIME=1 glxgears # Use the NVIDIA GPU
DRI PRIME=0 glxgears # Use the Intel GPU
glxgears # Use the Intel GPU
Longer How-to for Nouveau
http://nouveau.freedesktop.org/wiki/Optimus
21 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Prime: Demos
Current setup
This is an Optimus laptop (Sandy Bridge + NVIDIA NVD9);
All the outputs are connected to the Intel IGP.
List of demos
Selecting the GPU and checking with glxinfo;
Performance difference in glxgears;
Video decoding with VDPAU on the NVIDIA GPU.
22 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Summary
1 Introduction to the Linux graphics stack
2 Optimus
3 Prime
4 NouveauIntroductionCurrent workInvolvement from NVIDIA
5 Q&A
23 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Nouveau: Introduction
Nouveau: An Open Source Linux driver for NVIDIA GPUs
Merged in Linux 2.6.33 & left staging on Linux 3.4;
Mostly developed by Red Hat and students.
Current features
Modesetting support for almost all NVIDIA GPUs;
2D, 3D and video-rendering accel on NV04-;
Video decoding accel on NV40-NV117 (non-free).
24 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Nouveau: Current developments
Current work
Maxwell support:
Released in two times (March then September);Modesetting: DONE;2D/3D support: MOSTLY DONE;Video decoding: TODOOpen source firmware: WIP
Manual reclocking support:
nv40-a3: crude support, disabled by default;nva3-ac: good chances of working;Fermi: crude support, disabled by default;Kepler: WIP, good chances of partial support;Maxwell: TODO
Adding new OpenGL extensions:
Everything is done up to Fermi;OpenGL 4 for the other GPUs.
25 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Involvement from NVIDIA
NV
1998(?): NVIDIA releases “nv”, a Linux OSS 2D driver;
1998: Obfuscation commit, release only pre-processed source.
Little hope of NVIDIA ever working again on an OSS driver
“It’s so hard to write a graphics driver that open-sourcing it wouldnot help [...] In addition, customers aren’t asking for opensourcedrivers.”Andrew Fear, NVIDIA software product manager, April 2006
26 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Short history of Nouveau
Nouveau
2005: Stephane Marchesin improves nv and works on 3D
2008: Open Arena runs on nv40
2009: KMS driver based on TTM for memory management
2010: Merged in Linux 2.6.33
2010: Nv is deprecated by NVIDIA, “use VESA”.
A new hope from NVIDIA
September 2013: NVIDIA releases some vbios documentation;
January 2014: NVIDIA starts adding support for their TegraK1 in Nouveau, as requested by its clients;
Full support for the Tegra K1 expected by the end of 2014.
27 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Summary
1 Introduction to the Linux graphics stack
2 Optimus
3 Prime
4 Nouveau
5 Q&A
28 / 29
Introduction to the Linux graphics stack Optimus Prime Nouveau Q&A
Questions?
Thank you for listening! Questions?
Martin Peres: [email protected]
29 / 29