NVIDIA Optimus

From ArchWiki
(Redirected from Optimus)
Jump to: navigation, search

Related articles

NVIDIA Optimus is a technology that allows an Intel integrated GPU and discrete NVIDIA GPU to be built into and accessed by a laptop. Getting Optimus graphics to work on Arch Linux requires a few somewhat complicated steps, explained below. There are several methods available:

  • disabling one of the devices in BIOS, which may result in improved battery life if the NVIDIA device is disabled, but may not be available with all BIOSes and does not allow GPU switching
  • using the official Optimus support included with the proprietary NVIDIA driver, which offers the best NVIDIA performance but does not allow GPU switching and can be more buggy than the open-source driver
  • using the PRIME functionality of the open-source nouveau driver, which allows GPU switching but offers poor performance compared to the proprietary NVIDIA driver and does not currently implement any powersaving
  • using the third-party Bumblebee program to implement Optimus-like functionality, which offers GPU switching and powersaving but requires extra configuration

These options are explained in detail below.

Disabling switchable graphics

If you only care to use a certain GPU without switching, check the options in your system's BIOS. There should be an option to disable one of the cards. Some laptops only allow disabling of the discrete card, or vice-versa, but it is worth checking if you only plan to use one of the cards. If you want to use both cards, or cannot disable the card you do not want, see the options below.

Using nvidia

The proprietary NVIDIA driver does not support dynamic switching like the nouveau driver (meaning it can only use the NVIDIA device). It also has notable screen-tearing issues that NVIDIA recognizes but has not fixed. However, it does allow use of the discrete GPU and has (as of October 2013) a marked edge in performance over the nouveau driver.

First, install nvidia, nvidia-libgl and xorg-xrandr from the official repositories.

Then, configure xorg.conf. You will need to know the PCI address of the NVIDIA card, which you can find by issuing

$ lspci | grep -E "VGA|3D"

The PCI address is the first 7 characters of the line that mentions NVIDIA. It will look something like 01:00.0. In the xorg.conf, you will need to format it as #:#:#; e.g. 01:00.0 would be formatted as 1:0:0.

Note: Since Xorg-server 1.17-1 FS#43830 related to the modesetting module persists for Optimus configurations. A work-around for some systems is to set the Option "AccelMethod" to "none", as in the configuration below. Other systems require it set to "sna", see #Alternative configuration.
Note: On some setups this setup breaks automatic detection of the values of the display by the nvidia driver through the EDID file. As a work-around see #Resolution, screen scan wrong. EDID errors in Xorg.log.

If X.Org X server version 1.17.2 or higher is installed ([1])

/etc/X11/xorg.conf
Section "Module"
    Load "modesetting"
EndSection

Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
    BusID "<BusID for NVIDIA device here>"
    Option "AllowEmptyInitialConfiguration"
EndSection

For older X servers

/etc/X11/xorg.conf
Section "ServerLayout"
    Identifier "layout"
    Screen 0 "nvidia"
    Inactive "intel"
EndSection

Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
    # Change BusID if necessary. Tips: (lspci | grep 3D) (Change 01:00.0 to 1:0:0)
    BusID "PCI:1:0:0"
EndSection

Section "Screen"
    Identifier "nvidia"
    Device "nvidia"
    Option "AllowEmptyInitialConfiguration" "Yes"
EndSection

Section "Device"
    Identifier "intel"
    Driver "modesetting"
    # Change BusID if necessary. Tips: (lspci | grep VGA) (Change 00:02.0 to 0:2:0)
    BusID "PCI:0:2:0"
    Option "AccelMethod"  "none"
EndSection

Section "Screen"
    Identifier "intel"
    Device "intel"
EndSection

Next, add the following two lines to the beginning of your ~/.xinitrc:

~/.xinitrc
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto

Now reboot to load the drivers, and X should start.

If your display dpi is not correct add following line:

xrandr --dpi 96

If you get a black screen when starting X, make sure that there are no ampersands after the two xrandr commands in ~/.xinitrc. If there are ampersands, it seems that the window manager can run before the xrandr commands finish executing, leading to a black screen.

If the black screen persists, see the #Alternative configuration below.

Alternative configuration

If you experience Xorg-server crashes since release 1.17.1 with above configuration, modify the section for the Intel device in /etc/X11/xorg.conf as follows:

# nano /etc/X11/xorg.conf
Section "Device"
    Identifier  "intel"
    Driver      "modesetting"
    BusID       "PCI:0:2:0"
    Option      "AccelMethod"  "sna"
    #Option      "TearFree" "True"
    #Option      "Tiling" "True"
    #Option      "SwapbuffersWait" "True"
EndSection

As above, the BusID must match for the output of the lspci command. Search for the line with "VGA compatible controller", that contains something Intel. For example:

$ lspci |grep VGA
00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 0b)
Tip: The three last commented out options may (without #) result in positive effects on the tearing, but exchange for some performance cost. Note the TearFree option may be used for "sna" acceleration only, see Intel graphics. You can use either "sna" or "uxa" in "AccelMethod" option. For further experimenting, a working xorg.conf from a Lenovo Ideapad Z50-70 59-432128 is here: [2].

If X starts but nothing appears on the screen, check if /var/log/xorg.conf contains a following line or similar:

/var/log/xorg.conf
[ 16112.937] (EE) Screen 1 deleted because of no matching config section.

If so, the problem may disappear when you change your ServerLayout section of /etc/X11/xorg.conf:

/etc/X11/xorg.conf
Section "ServerLayout"
    Identifier "layout"
    Screen 1 "nvidia"
    Inactive "intel"
EndSection

Display Managers

If you are using a display manager then you will need to create or edit a display setup script for your display manager instead of using ~/.xinitrc.

LightDM

For the LightDM display manager:

/etc/lightdm/display_setup.sh
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto

Make the script executable:

# chmod +x /etc/lightdm/display_setup.sh

Now configure lightdm to run the script by editing the [SeatDefaults] section in /etc/lightdm/lightdm.conf:

/etc/lightdm/lightdm.conf
[SeatDefaults]
display-setup-script=/etc/lightdm/display_setup.sh

Now reboot and your display manager should start.

SDDM

For the SDDM display manager:

/usr/share/sddm/scripts/Xsetup
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto

GDM

For the GDM display manager create a new .desktop file:

/usr/share/gdm/greeter/autostart/display_setup.desktop
[Desktop Entry]
Type=Application
Name=Display setup
Exec=sh -c "xrandr --setprovideroutputsource modesetting NVIDIA-0; xrandr --auto"
NoDisplay=true
X-GNOME-AutoRestart=true

If it is not working, you must add a script to /etc/X11/xinit/xinitrc.d directory, as below:

/etc/X11/xinit/xinitrc.d/nvidia-optimus.sh
#!/bin/sh
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto

Then run:

# chmod +x /etc/X11/xinit/xinitrc.d/nvidia-optimus.sh

And make sure that GDM use X as default backend.

KDM

For KDE's KDM, add the xrandr lines into /usr/share/config/kdm/Xsetup.

Checking 3D

You can check if the NVIDIA graphics are being used by installing mesa-demos and running

$ glxinfo | grep NVIDIA

Further Information

For more information, look at NVIDIA's official page on the topic [3].

Troubleshooting

Tearing/Broken VSync

Unfortunately, this is an issue which currently has no solution, and is known to NVIDIA.

Failed to initialize the NVIDIA GPU at PCI:1:0:0 (GPU fallen off the bus / RmInitAdapter failed!)

Add rcutree.rcu_idle_gp_delay=1 to the kernel parameters. Original topic can be found here.

Resolution, screen scan wrong. EDID errors in Xorg.log

This is due to the NVIDIA driver not detecting the EDID for the display. You need to manually specify the path to an EDID file or provide the same information in a similar way.

To provide the path to the EDID file edit the Device Section for the NVIDIA card in Xorg.conf, adding these lines and changing parts to reflect your own system:

/etc/X11/xorg.conf
Section "Device"
       	Option		"ConnectedMonitor" "CRT-0"
       	Option		"CustomEDID" "CRT-0:/sys/class/drm/card0-LVDS-1/edid"
	Option		"IgnoreEDID" "false"
	Option		"UseEDID" "true"
EndSection

If Xorg wont start try swapping out all references of CRT to DFB. card0 is the identifier for the intel card to which the display is connected via LVDS. The edid binary is in this directory. If the hardware arrangement is different, the value for CustomEDID might vary but yet this has to be confirmed. The path will start in any case with /sys/class/drm.

Alternatively you can generate your edid with tools like read-edid and point the driver to this file. Even modelines can be used, but then be sure to change "UseEDID" and "IgnoreEDID".

Using nouveau

The open-source nouveau driver (xf86-video-nouveau) can dynamically switch with the Intel driver (xf86-video-intel) using a technology called PRIME. For more information, see the wiki article on PRIME.

Using Bumblebee

If you wish to use Bumblebee, which will implement powersaving and some other useful features, see the wiki article on Bumblebee.