Optimus.mdwn 6.9 KB
Newer Older
1
<meta name="google-translate-customization" content="38b387022ed0f4d4-a4eb7ef5c10c8ae0-g2870fab75904ce51-18"></meta>
2
3
<div id="google_translate_element"></div>
<script type="text/javascript" src="/wiki/translate.js"></script>
4

Joe Rayhawk's avatar
Joe Rayhawk committed
5
6
7
8
# Nvidia Optimus

'Optimus technology' is a software [and possibly hardware] solution for automatically switching between an integrated graphics chip or IGP (such as on onboard intel chip) and a more powerful [nvidia] graphics chip. This technology is intended specifically for laptops. The precursor to this technology was 'switchable graphics,' in which the user could manually switch between the graphics card. It may require that the Nvidia GPU has the PCOPY engine. 

mperes's avatar
mperes committed
9
The graphics system in a laptop has a GPU with some memory, in the case of an IGP, this memory may be a piece of system memory, but otherwise it is usually dedicated memory living on the GPU. This GPU connects to a laptop display, or output port. There are two main problems to solve in order to support optimus under linux: 
Joe Rayhawk's avatar
Joe Rayhawk committed
10

mperes's avatar
mperes committed
11
1) Currently we do not have a way to a priori know what outputs (displays) are connected to what GPU's.  
Joe Rayhawk's avatar
Joe Rayhawk committed
12

mperes's avatar
mperes committed
13
2) The supposed optimus software, should perform the task of switching between the which of the two graphics processors drives your display. Ideally this would be done by directly flipping a hardware switch, called a mux ([[multiplexer|http://en.wikipedia.org/wiki/Multiplexer]]). However such a mux does not always exist! 
Joe Rayhawk's avatar
Joe Rayhawk committed
14

mperes's avatar
mperes committed
15
If a hardware mux does not exist, there there is no physical way to perform this GPU switching. Thus Optimus is used to effectively "implement" a software mux. Specifically it ensures that relevant data is sent to and processed on the right GPU then the data needed for display is copied to the device that displays the image. 
Joe Rayhawk's avatar
Joe Rayhawk committed
16

mperes's avatar
mperes committed
17
When it comes to how a specific machine is configured, there are a number of possibilities. Again, if the hardware mux exists it would be used to select which GPU drives the internal panel, or the external monitor, or possibly both. It is also possible, that a GPU is hardwired to the internal panel, so the other GPU cannot possibly drive the internal panel. The same goes for external monitor output. In the worst case we have that the:the Intel GPU hardwired to the internal panel and the Nvidia GPU hardwired to the external output! The best case scenario is a mux, which can select which GPU drivers control which outputs. 
Joe Rayhawk's avatar
Joe Rayhawk committed
18

mperes's avatar
mperes committed
19
Basically, you can have _any_ combination of these possibilities. There is no standard on how to wire things. There should be ways to detect the wirings and whether there is a mux and where, but the documentation is not available to the developers (maybe you can help us figure out how to do this, have any ideas? You can also 'petition' nvidia for releasing these specs: [[nvidia customer help|http://nvidia.custhelp.com/]] ? ) 
Joe Rayhawk's avatar
Joe Rayhawk committed
20
21


mperes's avatar
mperes committed
22
## Switcheroo - Using one card at a time
Joe Rayhawk's avatar
Joe Rayhawk committed
23

mperes's avatar
mperes committed
24
If your laptop has a hardware mux, the kernel switcheroo driver may be able to set the wanted GPU at boot. There are also hacks based on the switcheroo, like asus-switcheroo, but they offer no extra value. If one of the hacks happens to work, and the switcheroo does not, the switcheroo has a bug. There might already be pending patches waiting to go towards the mainline kernel. 
Joe Rayhawk's avatar
Joe Rayhawk committed
25

mperes's avatar
mperes committed
26
In all other cases, you are stuck with what happens to work by default. No switching, no framebuffer copying. Yet. 
Joe Rayhawk's avatar
Joe Rayhawk committed
27

mperes's avatar
mperes committed
28
## Using Optimus/Prime
Joe Rayhawk's avatar
Joe Rayhawk committed
29

mperes's avatar
mperes committed
30
'PRIME GPU offloading' is an attempt to support muxless hybrid graphics in the Linux kernel. It requires:
Joe Rayhawk's avatar
Joe Rayhawk committed
31

mperes's avatar
mperes committed
32
33
34
* An updated graphic stack (Kernel, xserver and mesa);
* KMS drivers for both GPUs loaded;
* DDX drivers for both GPUs loaded.
Joe Rayhawk's avatar
Joe Rayhawk committed
35

mperes's avatar
mperes committed
36
If everything went well, *xrandr --listproviders* should list two providers. In my case, this gives:
Joe Rayhawk's avatar
Joe Rayhawk committed
37

mperes's avatar
mperes committed
38
39
40
41
    $ xrandr --listproviders 
    Providers: number : 2
    Provider 0: id: 0x8a cap: 0xb, Source Output, Sink Output, Sink Offload crtcs: 2 outputs: 2 associated providers: 1 name:Intel
    Provider 1: id: 0x66 cap: 0x7, Source Output, Sink Output, Source Offload crtcs: 2 outputs: 5 associated providers: 1 name:nouveau
Joe Rayhawk's avatar
Joe Rayhawk committed
42

mperes's avatar
mperes committed
43
It is then important to tell Prime what card should be used for offloading. In my case, I would like to use Nouveau for offloading the Intel card:
Joe Rayhawk's avatar
Joe Rayhawk committed
44

mperes's avatar
mperes committed
45
    $ xrandr --setprovideroffloadsink nouveau Intel
Joe Rayhawk's avatar
Joe Rayhawk committed
46

mperes's avatar
mperes committed
47
48
When this is done, it becomes very easy to select which card should be used. If you want to offload an application to a GPU, use DRI_PRIME=1. When the application is launched, it will use the second card to do its rendering. If you want to use
the "regular" GPU, set DRI_PRIME to 0 or omit it. The behaviour can be seen in the following example:
Joe Rayhawk's avatar
Joe Rayhawk committed
49

mperes's avatar
mperes committed
50
51
52
53
    $ DRI_PRIME=0 glxinfo | grep "OpenGL vendor string"
    OpenGL vendor string: Intel Open Source Technology Center
    $ DRI_PRIME=1 glxinfo | grep "OpenGL vendor string"
    OpenGL vendor string: nouveau
Joe Rayhawk's avatar
Joe Rayhawk committed
54

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
### Power management

When an application is using 'PRIME GPU offloading', both the discrete and the integrated GPUs are active and aside from optimizations at the driver level, nothing else can be done. However, when no application is making use of the discrete GPU, the default behaviour should be for the card to automatically power down entirely after 5 seconds.

This dynamic power management feature has been added in Linux 3.12 but requires Linux 3.13 to work properly with Nouveau. If you cannot make use of this feature and do not mind not using your NVIDIA GPU, it is recommended to blacklist the 'nouveau' module and to use bbswitch to turn off the NVIDIA GPU. Look onto your distribution's wiki for more information.

#### Checking the current power state

You can query the current power state and policy by running as root:

     # cat /sys/kernel/debug/vgaswitcheroo/switch
     0:DIS: :DynOff:0000:01:00.0
     1:IGD:+:Pwr:0000:00:02.0
     2:DIS-Audio: :Off:0000:01:00.1

Each line of the output is of the following format:

 * A number: not important
 * A string:
  * DIS: Discrete GPU (your AMD or NVIDIA GPU)
  * IGD: Integrated Graphics (your Intel card?)
  * DIS-Audio: The audio device exported by your discrete GPU for HDMI sound playback
 * A power state:
  * OFF: The device is powered off
  * ON: The device is powered on
  * DynOff: The device will be powered on when needed and powered off when unused for some time
 * The PCI-ID of the device

#### U

mperes's avatar
mperes committed
85
### Known issues
Joe Rayhawk's avatar
Joe Rayhawk committed
86

mperes's avatar
mperes committed
87
88
89
90
#### Everything seems to work but the output is black

Try using a re-parenting compositor. Those compositors usually provide 3D effects.

91
*WARNING*: Currently, Kwin only works when using the desktop effects. In the case where the window would be pure black, please try minimizing/maximizing or redimensioning the window. This bug is being investigated.
mperes's avatar
mperes committed
92
93

#### Poor performance when using the Nouveau card
Joe Rayhawk's avatar
Joe Rayhawk committed
94

mperes's avatar
mperes committed
95
Right now, Nouveau does not support reclocking and other power management feature. This cripples the performance of the GPU a lot along with increasing the power consumption compared to the proprietary driver.
Joe Rayhawk's avatar
Joe Rayhawk committed
96

mperes's avatar
mperes committed
97
Using Prime with Nouveau may not result in any performance gain right now, but it should in a not-so-distant future.