NVIDIA Optimus: Difference between revisions

From ArchWiki
(added tip on thermal monitor tools keeping gpu awake)
 
(56 intermediate revisions by 22 users not shown)
Line 1: Line 1:
[[Category:Graphics]]
[[Category:Graphics]]
[[es:NVIDIA Optimus]]
[[fr:NVIDIA Optimus]]
[[ja:NVIDIA Optimus]]
[[ja:NVIDIA Optimus]]
[[ru:NVIDIA Optimus]]
[[ru:NVIDIA Optimus]]
[[zh-hans:NVIDIA Optimus]]
[[zh-hans:NVIDIA Optimus]]
{{Related articles start}}
{{Related articles start}}
{{Related|PRIME}}
{{Related|Bumblebee}}
{{Related|Bumblebee}}
{{Related|Nouveau}}
{{Related|Nouveau}}
{{Related|NVIDIA}}
{{Related|NVIDIA}}
{{Related|nvidia-xrun}}
{{Related|nvidia-xrun}}
{{Related|External GPU}}
{{Related articles end}}
{{Related articles end}}


[[Wikipedia:NVIDIA Optimus|NVIDIA Optimus]] is a technology that allows an Intel integrated GPU and discrete NVIDIA GPU to be built into and accessed by a laptop.
[[Wikipedia:NVIDIA Optimus|NVIDIA Optimus]] is a technology that allows an integrated GPU and discrete NVIDIA GPU to be built into and accessed by a laptop.


== Available methods ==
== Available methods ==
Line 16: Line 20:
There are several methods available:
There are several methods available:


* [[#Use Intel graphics only]] - saves power, because NVIDIA GPU will be completely powered off.
* [[#Use integrated graphics only]] - saves power, because NVIDIA GPU will be completely powered off.
* [[#Use NVIDIA graphics only]] - gives more performance than Intel graphics, but drains more battery (which is not welcome for mobile devices). This utilizes the same underlying process as the [[#Using optimus-manager|optimus-manager]] and [[#Using nvidia-xrun|nvidia-xrun]] options, it should be utilized for troubleshooting and verifying general functionality, before opting for one of the more automated approaches.
* [[#Use NVIDIA graphics only]] - gives more performance than integrated graphics, but drains more battery (which is not welcome for mobile devices). This utilizes the same underlying process as the [[#Using optimus-manager|optimus-manager]] and [[#Using nvidia-xrun|nvidia-xrun]] options, it should be utilized for troubleshooting and verifying general functionality, before opting for one of the more automated approaches.
* Using both (use NVIDIA GPU when needed and keep it powered off to save power):
* Using both (use NVIDIA GPU when needed and keep it powered off to save power):
** [[#Using PRIME render offload]] - official method supported by NVIDIA.
** [[#Using PRIME render offload]] - official method supported by NVIDIA.
** [[#Using optimus-manager]] - switches graphics with a single command (logout and login required to take effect). It achieves maximum performance out of NVIDIA GPU and switches it off if not in use.
** [[#Using optimus-manager]] - switches graphics with a single command (logout and login required to take effect). Also supports hybrid mode with PRIME render offload. It achieves maximum performance out of NVIDIA GPU and switches it off if not in use. Since the 1.4 release AMD+NVIDIA combination is also supported.
** [[#Using nvidia-xrun]] - run separate X session on different TTY with NVIDIA graphics. It achieves maximum performance out of NVIDIA GPU and switches it off if not in use.
** [[#Using nvidia-xrun]] - run separate X session on different TTY with NVIDIA graphics. It achieves maximum performance out of NVIDIA GPU and switches it off if not in use.
** [[#Using Bumblebee]] - provides Windows-like functionality by allowing to run selected applications with NVIDIA graphics while using Intel graphics for everything else. Has significant performance issues.
** [[#Using Bumblebee]] - provides Windows-like functionality by allowing to run selected applications with NVIDIA graphics while using Intel graphics for everything else. Has significant performance issues.
** [[#Using switcheroo-control]] - Similar to Bumblebee, but specifically for [[GNOME]] users. Allows applications to specify if they prefer the dedicated GPU in their [[desktop entry]] file, and lets you manually run any application on the NVIDIA GPU from the right-click menu.
** [[#Using nouveau]] - offers poorer performance (compared to the proprietary NVIDIA driver) and may cause issues with sleep and hibernate. Does not work with latest NVIDIA GPUs.
** [[#Using nouveau]] - offers poorer performance (compared to the proprietary NVIDIA driver) and may cause issues with sleep and hibernate. Does not work with latest NVIDIA GPUs.
** [[#Using EnvyControl]] - Similar to optimus-manager but does not require extensive configuration or having a daemon running in the background as well as having to install a patched version of GDM if you are a GNOME user.
** [[#Using NVidia-eXec]] - Similar to Bumblebee, but without the performance impact. It works on both Xorg and Wayland. This package is experimental, and is currently being tested only under GNOME/GDM.
** [[#Using nvidia-switch]] - Similar to nvidia-xrun, but not needing to change TTY, the switches will be done by login and logouts in your display manager. This package is being tested on Debian based system, but, like nvidia-xrun, it must work in all Linux systems.


{{Note|All of these options are mutually exclusive, if you test one approach and decide for another, you must ensure to revert any configuration changes done by following one approach before attempting another method, otherwise file conflicts and undefined behaviours may arise.}}
{{Note|All of these options are mutually exclusive, if you test one approach and decide for another, you must ensure to revert any configuration changes done by following one approach before attempting another method, otherwise file conflicts and undefined behaviours may arise.}}


== Use Intel graphics only ==
== Use integrated graphics only ==


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 just one of the cards.
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 just one of the cards.


If your BIOS does not allow to disable Nvidia graphics, you can disable it from the Linux kernel itself. See [[Hybrid graphics#Fully Power Down Discrete GPU]].
If your BIOS does not allow to disable Nvidia graphics, you can disable it from the Linux kernel itself. See [[Hybrid graphics#Fully power down discrete GPU]].


=== Use CUDA without switching the rendering provider ===
=== Use CUDA without switching the rendering provider ===


You can use CUDA without switching rendering to the Nvidia graphics. All you need to do is ensure that the Nvidia card is powered on before starting a CUDA application, see [[Hybrid graphics#Fully Power Down Discrete GPU]] for details.
You can use CUDA without switching rendering to the Nvidia graphics. All you need to do is ensure that the Nvidia card is powered on before starting a CUDA application, see [[Hybrid graphics#Fully power down discrete GPU]] for details.


Now when you start a CUDA application, it will automatically load all necessary kernel modules. Before turning off the Nvidia card after using CUDA, the {{ic|nvidia}} kernel modules have to be unloaded first:
Now when you start a CUDA application, it will automatically load all necessary kernel modules. Before turning off the Nvidia card after using CUDA, the {{ic|nvidia}} kernel modules have to be unloaded first:
Line 66: Line 74:
     ModulePath "/usr/lib/xorg/modules"
     ModulePath "/usr/lib/xorg/modules"
EndSection
EndSection
}}
}}


Line 82: Line 89:
  xrandr --dpi 96
  xrandr --dpi 96


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


=== Display managers ===
=== 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 {{ic|~/.xinitrc}}.
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 {{ic|~/.xinitrc}}.


==== LightDM ====
==== LightDM ====
Line 98: Line 105:
}}
}}


Make the script executable:
Make the script [[executable]].  
 
# chmod +x /etc/lightdm/display_setup.sh


Now configure lightdm to run the script by editing the {{ic|[Seat:*]}} section in {{ic|/etc/lightdm/lightdm.conf}}:
Now configure lightdm to run the script by editing the {{ic|[Seat:*]}} section in {{ic|/etc/lightdm/lightdm.conf}}:
Line 112: Line 117:


==== SDDM ====
==== SDDM ====
For the [[SDDM]] display manager (SDDM is the default DM for [[KDE]]):
For the [[SDDM]] display manager (SDDM is the default DM for [[KDE]]):


Line 133: Line 139:
}}
}}


Make sure that GDM use [[GDM#Use_Xorg_backend|X as default backend]].
Make sure that GDM use [[GDM#Use Xorg backend|X as default backend]].


=== Checking 3D ===
=== Checking 3D ===


You can check if the NVIDIA graphics are being used by installing {{Pkg|mesa-demos}} and running
You can check if the NVIDIA graphics are being used by installing {{Pkg|mesa-utils}} and running


  $ glxinfo | grep NVIDIA
  $ glxinfo | grep NVIDIA


=== Further Information ===
=== Further information ===


For more information, look at NVIDIA's official page on the topic [http://us.download.nvidia.com/XFree86/Linux-x86/370.28/README/randr14.html].
For more information, look at NVIDIA's official page on the topic [http://us.download.nvidia.com/XFree86/Linux-x86/370.28/README/randr14.html].
== Use switchable graphics ==
=== Using PRIME render offload ===
This is the official NVIDIA method to support switchable graphics.
See [[PRIME#PRIME render offload]] for details.
=== Using nouveau ===
See [[PRIME]] for graphics switching and [[nouveau]] for open-source NVIDIA driver.
=== Using Bumblebee ===
See [[Bumblebee]].
=== Using switcheroo-control ===
See [[PRIME#Gnome integration]].
=== Using nvidia-xrun ===
See [[nvidia-xrun]].
=== Using optimus-manager ===
See [https://github.com/Askannz/optimus-manager Optimus-manager] upstream documentation. It covers both installation and configuration in Arch Linux systems.
=== Using EnvyControl ===
See [https://github.com/geminis3/envycontrol EnvyControl] upstream documentation. It covers both installation and usage instructions.
=== Using NVidia-eXec ===
See [https://github.com/pedro00dk/nvidia-exec NVidia-eXec] upstream documentation. It covers both installation and usage instructions.
=== Using nvidia-switch ===
See [https://github.com/nvidiaswitch/nvidia-switch nvidia-switch] upstream documentation. It covers both installation and usage instructions.


== Troubleshooting ==
== Troubleshooting ==
{{Style|If this is relevant only for [[#Use NVIDIA graphics only]], it should be a subsection. Otherwise it should be the last section on the page.}}


=== Tearing/Broken VSync ===
=== Tearing/Broken VSync ===


This requires {{pkg|xorg-server}} 1.19 or higher, {{pkg|linux}} kernel 4.5 or higher, and {{pkg|nvidia}} 370.23 or higher. Then enable [[NVIDIA#DRM_kernel_mode_setting|DRM kernel mode setting]], which will in turn enable the PRIME synchronization and fix the tearing.
Enable [[NVIDIA#DRM kernel mode setting|DRM kernel mode setting]], which will in turn enable the PRIME synchronization and fix the tearing.


You can read the official [https://devtalk.nvidia.com/default/topic/957814/linux/prime-and-prime-synchronization/ forum thread] for details.
You can read the official [https://devtalk.nvidia.com/default/topic/957814/linux/prime-and-prime-synchronization/ forum thread] for details.
It has been [https://bbs.archlinux.org/viewtopic.php?id=251032 reported] that {{pkg|linux}} kernel 5.4 breaks PRIME synchronization but this has since been fixed.


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


Add {{ic|1=rcutree.rcu_idle_gp_delay=1}} to the kernel parameters. Original topic can be found in [https://github.com/Bumblebee-Project/Bumblebee/issues/455#issuecomment-22497464] and [https://bbs.archlinux.org/viewtopic.php?id=169742].
Add {{ic|1=rcutree.gp_init_delay=1}} to the kernel parameters. Original topic can be found in [https://github.com/Bumblebee-Project/Bumblebee/issues/455#issuecomment-22497464] and [https://bbs.archlinux.org/viewtopic.php?id=169742].


=== Resolution, screen scan wrong. EDID errors in Xorg.log ===
=== Resolution, screen scan wrong. EDID errors in Xorg.log ===
Line 176: Line 218:
}}
}}


If Xorg wont start try swapping out all references of CRT to DFB.
If Xorg will not 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.
{{ic|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 {{ic|/sys/class/drm}}.


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


=== Wrong resolution without EDID errors ===
=== Wrong resolution without EDID errors ===
Using ''nvidia-xconfig'', incorrect information might be generated in Xorg.conf and in particular wrong monitor refresh rates that restruct the possible resolutions. Try commenting out the {{ic|HorizSync}}/{{ic|VertRefresh}} lines. If this helps, you can probably also remove everything else not mentioned in this article.
 
Using ''nvidia-xconfig'', incorrect information might be generated in {{ic|xorg.conf}} and in particular wrong monitor refresh rates that restrict the possible resolutions. Try commenting out the {{ic|HorizSync}}/{{ic|VertRefresh}} lines. If this helps, you can probably also remove everything else not mentioned in this article.


=== Lockup issue (lspci hangs) ===
=== Lockup issue (lspci hangs) ===
Symptoms: lspci hangs, system suspend fails, shutdown hangs, optirun hangs.
Symptoms: lspci hangs, system suspend fails, shutdown hangs, optirun hangs.


Line 199: Line 243:
=== No screens found on a laptop/NVIDIA Optimus ===
=== No screens found on a laptop/NVIDIA Optimus ===


Check if {{ic|<nowiki>$ lspci | grep VGA</nowiki>}}
Check if the output is something similar to:
outputs something similar to:
 
00:02.0 VGA compatible controller: Intel Corporation Core Processor Integrated Graphics Controller (rev 02)
{{hc|$ lspci {{!}} grep VGA|
01:00.0 VGA compatible controller: nVidia Corporation Device 0df4 (rev a1)
00:02.0 VGA compatible controller: Intel Corporation Core Processor Integrated Graphics Controller (rev 02)
01:00.0 VGA compatible controller: nVidia Corporation Device 0df4 (rev a1)
}}


NVIDIA drivers now offer Optimus support since 319.12 Beta [http://www.nvidia.com/object/linux-display-amd64-319.12-driver.html] with kernels above and including 3.9.
NVIDIA drivers now offer Optimus support since 319.12 Beta [https://www.nvidia.com/object/linux-display-amd64-319.12-driver.html] with kernels above and including 3.9.


Another solution is to install the [[Intel]] driver to handle the screens, then if you want 3D software you should run them through [[Bumblebee]] to tell them to use the NVIDIA card.
Another solution is to install the [[Intel]] driver to handle the screens, then if you want 3D software you should run them through [[Bumblebee]] to tell them to use the NVIDIA card.


== Use switchable graphics ==
=== Random freezes "(EE) NVIDIA(GPU-0): WAIT" ===
 
Using the proprietary drivers on a setup with an integrated AMD card and with the dedicated NVIDIA card set as the only one in use, users report freezes for up to 10 seconds, with the following errors in the Xorg logs:
 
[  219.796] (EE) NVIDIA(GPU-0): WAIT (2, 8, 0x8000, 0x0002e1c4, 0x0002e1cc)
[  226.796] (EE) NVIDIA(GPU-0): WAIT (1, 8, 0x8000, 0x0002e1c4, 0x0002e1cc)
 
While this is not root-caused yet, it seems linked to a conflict in how the integrated and dedicated cards interact with Xorg.
 
The workaround is to use switchable graphics, see [[PRIME#PRIME render offload]] for details.
 
=== "No Devices detected" with optimus-manager ===
 
There are cases where ''lspci'' will show the PCI domain as first output column, making ''optimus-manager'' generated files break while trying to map {{ic|BusID}} on multiple laptop models.
 
If you face a black screen that never ends to load your GUI, GUI partially loading with console artifacts or Xorg crashing with {{ic|(EE) - No Devices detected}}, the workaround and bug reports are available at the [https://github.com/Askannz/optimus-manager/issues/471#issuecomment-1315628537 upstream GitHub].


=== Using PRIME render offload ===
=== Xorg: external monitor updates only when the mouse is moving ===


This is the official NVIDIA method to support switchable graphics.
A workaround for the issue is to uninstall the Xorg driver of the iGPU (e.g. {{Pkg|xf86-video-amdgpu}} or {{Pkg|xf86-video-intel}}) [https://bbs.archlinux.org/viewtopic.php?id=284651]. This should work as long as the external monitor port (HDMI/DP/USB-C) is connected directly to the Nvidia dGPU.


See [[PRIME#PRIME render offload]] for details.
{{Tip|The desktop behavior may become quirky (e.g. switching virtual desktops or Alt-Tab'ing freezes the image on the external monitor), which can be also worked around by disabling the laptop's monitor.}}


=== Using nouveau ===
=== Low power usage (TDP) ===


See [[PRIME]] for graphics switching and [[nouveau]] for open-source NVIDIA driver.
Since the 530.41 driver version, cases of cards locked at low power consumption limits appeared (see [https://github.com/NVIDIA/open-gpu-kernel-modules/issues/483 GitHub issue 483]). The NVIDIA driver has disabled the ability to manually set the power limit using {{ic|nvidia-smi}} command, so many laptops are stuck with low power usage and bad performance.  


=== Using Bumblebee ===
To workaround this problem (for the Ampere generation or newer), [[start/enable]] {{ic|nvidia-powerd.service}}, which enables [https://download.nvidia.com/XFree86/Linux-x86_64/535.54.03/README/dynamicboost.html DynamicBoost].


See [[Bumblebee]].
=== NVIDIA GPU will not turn off or stay deactivated ===


=== Using nvidia-xrun ===
If you use a thermal monitor that is probing your GPU temperature, it typically calls {{ic|nvidia-smi}} to get this temperature, which will wake up your GPU and keep it in an active state. This causes significantly increased power usage, lower battery life, and higher temperatures.


See [[nvidia-xrun]].
Check if your GPU is in an active state or suspended


=== Using optimus-manager ===
$ cat /sys/bus/pci/devices/0000\:01\:00.0/power/runtime_status


See [https://github.com/Askannz/optimus-manager Optimus-manager] upstream documentation. It covers both installation and configuration in Arch Linux systems.
and if the state is {{ic|active}}, ensure you are not using a thermal monitoring tool or widget that is calling {{ic|nvidia-smi}}.

Latest revision as of 17:58, 12 March 2024

NVIDIA Optimus is a technology that allows an integrated GPU and discrete NVIDIA GPU to be built into and accessed by a laptop.

Available methods

There are several methods available:

  • #Use integrated graphics only - saves power, because NVIDIA GPU will be completely powered off.
  • #Use NVIDIA graphics only - gives more performance than integrated graphics, but drains more battery (which is not welcome for mobile devices). This utilizes the same underlying process as the optimus-manager and nvidia-xrun options, it should be utilized for troubleshooting and verifying general functionality, before opting for one of the more automated approaches.
  • Using both (use NVIDIA GPU when needed and keep it powered off to save power):
    • #Using PRIME render offload - official method supported by NVIDIA.
    • #Using optimus-manager - switches graphics with a single command (logout and login required to take effect). Also supports hybrid mode with PRIME render offload. It achieves maximum performance out of NVIDIA GPU and switches it off if not in use. Since the 1.4 release AMD+NVIDIA combination is also supported.
    • #Using nvidia-xrun - run separate X session on different TTY with NVIDIA graphics. It achieves maximum performance out of NVIDIA GPU and switches it off if not in use.
    • #Using Bumblebee - provides Windows-like functionality by allowing to run selected applications with NVIDIA graphics while using Intel graphics for everything else. Has significant performance issues.
    • #Using switcheroo-control - Similar to Bumblebee, but specifically for GNOME users. Allows applications to specify if they prefer the dedicated GPU in their desktop entry file, and lets you manually run any application on the NVIDIA GPU from the right-click menu.
    • #Using nouveau - offers poorer performance (compared to the proprietary NVIDIA driver) and may cause issues with sleep and hibernate. Does not work with latest NVIDIA GPUs.
    • #Using EnvyControl - Similar to optimus-manager but does not require extensive configuration or having a daemon running in the background as well as having to install a patched version of GDM if you are a GNOME user.
    • #Using NVidia-eXec - Similar to Bumblebee, but without the performance impact. It works on both Xorg and Wayland. This package is experimental, and is currently being tested only under GNOME/GDM.
    • #Using nvidia-switch - Similar to nvidia-xrun, but not needing to change TTY, the switches will be done by login and logouts in your display manager. This package is being tested on Debian based system, but, like nvidia-xrun, it must work in all Linux systems.
Note: All of these options are mutually exclusive, if you test one approach and decide for another, you must ensure to revert any configuration changes done by following one approach before attempting another method, otherwise file conflicts and undefined behaviours may arise.

Use integrated graphics only

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 just one of the cards.

If your BIOS does not allow to disable Nvidia graphics, you can disable it from the Linux kernel itself. See Hybrid graphics#Fully power down discrete GPU.

Use CUDA without switching the rendering provider

You can use CUDA without switching rendering to the Nvidia graphics. All you need to do is ensure that the Nvidia card is powered on before starting a CUDA application, see Hybrid graphics#Fully power down discrete GPU for details.

Now when you start a CUDA application, it will automatically load all necessary kernel modules. Before turning off the Nvidia card after using CUDA, the nvidia kernel modules have to be unloaded first:

# rmmod nvidia_uvm
# rmmod nvidia

Use NVIDIA graphics only

The proprietary NVIDIA driver can be configured to be the primary rendering provider. It also has notable screen-tearing issues unless you enable prime sync by enabling NVIDIA#DRM kernel mode setting, see [1] for further information. It does allow use of the discrete GPU and has (as of January 2017) a marked edge in performance over the nouveau driver.

First, install the NVIDIA driver and xorg-xrandr. Then, configure /etc/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf the options of which will be combined with the package provided /usr/share/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf to provide compatibility with this setup.

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.
/etc/X11/xorg.conf.d/10-nvidia-drm-outputclass.conf
Section "OutputClass"
    Identifier "intel"
    MatchDriver "i915"
    Driver "modesetting"
EndSection

Section "OutputClass"
    Identifier "nvidia"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "AllowEmptyInitialConfiguration"
    Option "PrimaryGPU" "yes"
    ModulePath "/usr/lib/nvidia/xorg"
    ModulePath "/usr/lib/xorg/modules"
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 the 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.

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
#!/bin/sh
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto

Make the script executable.

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

/etc/lightdm/lightdm.conf
[Seat:*]
display-setup-script=/etc/lightdm/display_setup.sh

Now reboot and your display manager should start.

SDDM

For the SDDM display manager (SDDM is the default DM for KDE):

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

GDM

For the GDM display manager create two new .desktop files:

/usr/share/gdm/greeter/autostart/optimus.desktop
/etc/xdg/autostart/optimus.desktop
[Desktop Entry]
Type=Application
Name=Optimus
Exec=sh -c "xrandr --setprovideroutputsource modesetting NVIDIA-0; xrandr --auto"
NoDisplay=true
X-GNOME-Autostart-Phase=DisplayServer

Make sure that GDM use X as default backend.

Checking 3D

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

$ glxinfo | grep NVIDIA

Further information

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

Use switchable graphics

Using PRIME render offload

This is the official NVIDIA method to support switchable graphics.

See PRIME#PRIME render offload for details.

Using nouveau

See PRIME for graphics switching and nouveau for open-source NVIDIA driver.

Using Bumblebee

See Bumblebee.

Using switcheroo-control

See PRIME#Gnome integration.

Using nvidia-xrun

See nvidia-xrun.

Using optimus-manager

See Optimus-manager upstream documentation. It covers both installation and configuration in Arch Linux systems.

Using EnvyControl

See EnvyControl upstream documentation. It covers both installation and usage instructions.

Using NVidia-eXec

See NVidia-eXec upstream documentation. It covers both installation and usage instructions.

Using nvidia-switch

See nvidia-switch upstream documentation. It covers both installation and usage instructions.

Troubleshooting

Tearing/Broken VSync

Enable DRM kernel mode setting, which will in turn enable the PRIME synchronization and fix the tearing.

You can read the official forum thread for details.

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

Add rcutree.gp_init_delay=1 to the kernel parameters. Original topic can be found in [3] and [4].

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 will not 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.

Wrong resolution without EDID errors

Using nvidia-xconfig, incorrect information might be generated in xorg.conf and in particular wrong monitor refresh rates that restrict the possible resolutions. Try commenting out the HorizSync/VertRefresh lines. If this helps, you can probably also remove everything else not mentioned in this article.

Lockup issue (lspci hangs)

Symptoms: lspci hangs, system suspend fails, shutdown hangs, optirun hangs.

Applies to: newer laptops with GTX 965M or alike when bbswitch (e.g. via Bumblebee) or nouveau is in use.

When the dGPU power resource is turned on, it may fail to do so and hang in ACPI code (kernel bug 156341).

When using nouveau, disabling runtime power-management stops it from changing the power state, thus avoiding this issue. To disable runtime power-management, add nouveau.runpm=0 to the kernel parameters.

For known model-specific workarounds, see this issue. In other cases you can try to boot with acpi_osi="!Windows 2015" or acpi_osi=! acpi_osi="Windows 2009" added to your Kernel parameters. (Consider reporting your laptop to that issue.)

No screens found on a laptop/NVIDIA Optimus

Check if the output is something similar to:

$ lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Core Processor Integrated Graphics Controller (rev 02)
01:00.0 VGA compatible controller: nVidia Corporation Device 0df4 (rev a1)

NVIDIA drivers now offer Optimus support since 319.12 Beta [5] with kernels above and including 3.9.

Another solution is to install the Intel driver to handle the screens, then if you want 3D software you should run them through Bumblebee to tell them to use the NVIDIA card.

Random freezes "(EE) NVIDIA(GPU-0): WAIT"

Using the proprietary drivers on a setup with an integrated AMD card and with the dedicated NVIDIA card set as the only one in use, users report freezes for up to 10 seconds, with the following errors in the Xorg logs:

[   219.796] (EE) NVIDIA(GPU-0): WAIT (2, 8, 0x8000, 0x0002e1c4, 0x0002e1cc)
[   226.796] (EE) NVIDIA(GPU-0): WAIT (1, 8, 0x8000, 0x0002e1c4, 0x0002e1cc)

While this is not root-caused yet, it seems linked to a conflict in how the integrated and dedicated cards interact with Xorg.

The workaround is to use switchable graphics, see PRIME#PRIME render offload for details.

"No Devices detected" with optimus-manager

There are cases where lspci will show the PCI domain as first output column, making optimus-manager generated files break while trying to map BusID on multiple laptop models.

If you face a black screen that never ends to load your GUI, GUI partially loading with console artifacts or Xorg crashing with (EE) - No Devices detected, the workaround and bug reports are available at the upstream GitHub.

Xorg: external monitor updates only when the mouse is moving

A workaround for the issue is to uninstall the Xorg driver of the iGPU (e.g. xf86-video-amdgpu or xf86-video-intel) [6]. This should work as long as the external monitor port (HDMI/DP/USB-C) is connected directly to the Nvidia dGPU.

Tip: The desktop behavior may become quirky (e.g. switching virtual desktops or Alt-Tab'ing freezes the image on the external monitor), which can be also worked around by disabling the laptop's monitor.

Low power usage (TDP)

Since the 530.41 driver version, cases of cards locked at low power consumption limits appeared (see GitHub issue 483). The NVIDIA driver has disabled the ability to manually set the power limit using nvidia-smi command, so many laptops are stuck with low power usage and bad performance.

To workaround this problem (for the Ampere generation or newer), start/enable nvidia-powerd.service, which enables DynamicBoost.

NVIDIA GPU will not turn off or stay deactivated

If you use a thermal monitor that is probing your GPU temperature, it typically calls nvidia-smi to get this temperature, which will wake up your GPU and keep it in an active state. This causes significantly increased power usage, lower battery life, and higher temperatures.

Check if your GPU is in an active state or suspended

$ cat /sys/bus/pci/devices/0000\:01\:00.0/power/runtime_status

and if the state is active, ensure you are not using a thermal monitoring tool or widget that is calling nvidia-smi.