Nvidia-xrun: Difference between revisions

From ArchWiki
(Fix style. See Help:Style.)
m (→‎Configuration: - whitespace)
 
(73 intermediate revisions by 32 users not shown)
Line 1: Line 1:
{{Lowercase title}}
[[Category:Graphics]]
[[Category:Graphics]]
[[zh-hans:nvidia-xrun]]
[[ja:nvidia-xrun]]
[https://github.com/Witko/nvidia-xrun nvidia-xrun] is a utility to run separate X with discrete nvidia graphics. This solution offers a bit more complicated procedure but offers a full GPU utilization(in terms of linux drivers).
[[ru:Nvidia-xrun]]
[[zh-hans:Nvidia-xrun]]
[https://github.com/Witko/nvidia-xrun nvidia-xrun] is a utility that allows NVIDIA Optimus-enabled laptops to run [[X server]] with discrete NVIDIA graphics on demand. This solution offers full GPU utilization, compatibility and better performance than [[Bumblebee]].
 
X server can only be used with integrated graphics or discrete NVIDIA graphics, but not both, so the user might want to switch to a separate [[Linux console|virtual console]] and start another X server using different graphics from what was used for the first X server.
 
== Installation ==


== installation ==
[[Install]]:
[[Install]]:
* {{Pkg|nvidia}}
* {{Pkg|nvidia}} - if using older drivers you have to edit nvidia-xrun's PKGBUILD and remove the NVIDIA depend
* {{Pkg|bbswitch}}
* {{AUR|nvidia-xrun-git}}(recommended) or {{AUR|nvidia-xrun}} (old method, uses bumblebee to switch off the dedicated card)
* {{AUR|nvidia-xrun}} or {{AUR|nvidia-xrun-git}}
* Any [[window manager]], since running application directly like with {{ic|nvidia-xrun ''application''}} is not recommended.
* a [[Window manager]], such as {{Pkg|openbox}} it only for running applications,becasue running some applications (such as Steam) directly with nvidia-xrun does not work well, use some window manager like openbox will be better.
 
== configuration ==
== Configuration ==
 
=== Setting the right bus id ===
=== Setting the right bus id ===
If you install nvidia-xrun from [[AUR]],you can skip this step,the bus id has been already setted in {{ic|/etc/X11/nvidia-xorg.conf}}


If you down nvidia-xrun form [nvidia-xrun github repo],perhaps you should set the bus id.
{{Note|If you installed package from [[AUR]], the bus id has been automatically set in {{ic|/etc/X11/nvidia-xorg.conf}}. Make sure the bus ID has been correctly set, otherwise change it (you can find correct bus ID using {{ic|lspci}} command). In some cases you need to convert the hex output from {{ic|lspci}} to decimal for {{ic|nvidia-xorg.conf}}, e.g. {{ic|3b:00.0}} becomes {{ic|"PCI:59:0:0"}}.}}
 
Find your display device bus id:


check your display device's bus id
$ lspci | grep -i nvidia | awk '{print $1}'
  $ lspci | grep NVIDIA


You will find your bus id.Usually the 1:0:0 bus is correct. If this is not your case(you can find out through lspci or bbswitch output mesages) you can create a conf script for example nano /etc/X11/nvidia-xorg.conf.d/30-nvidia.conf to set the proper bus id:
It might return something similar to {{ic|01:00.0}}. Then create a file (for example {{ic|/etc/X11/nvidia-xorg.conf.d/30-nvidia.conf}}) to set the proper bus id:


{{hc|/etc/X11/nvidia-xorg.conf.d/30-nvidia.conf|
{{hc|/etc/X11/nvidia-xorg.conf.d/30-nvidia.conf|
Line 24: Line 31:
     Identifier "nvidia"
     Identifier "nvidia"
     Driver "nvidia"
     Driver "nvidia"
     BusID "PCI:2:0:0"
     BusID "PCI:'''1:0:0'''"
    #  Option "DPI" "'''96 x 96'''"
EndSection}}
EndSection}}


Also this way you can adjust some nvidia settings if you encounter issues:
Also this way you can adjust some NVIDIA settings if you encounter issues:


{{hc|/etc/X11/nvidia-xorg.conf.d/30-nvidia.conf|
{{hc|/etc/X11/nvidia-xorg.conf.d/30-nvidia.conf|
Line 36: Line 44:
     #  Option "UseDisplayDevice" "none"
     #  Option "UseDisplayDevice" "none"
EndSection}}
EndSection}}
=== External GPU setup ===
You can also use this in an external GPU setup. Make sure to load the ''nvidia-modeset'' and ''nvidia-drm'' modules and add the option {{ic|Option "AllowExternalGpus" "true"}} to the ''"Device"'' section.
Change the auto-generated configuration to use the '''internal display''' on devices with multiple NVIDIA cards:
{{hc|/etc/X11/nvidia-xorg.conf.d/30-nvidia.conf|
Section "ServerLayout"
  Identifier "layout"
  Screen 0 "nvidia" 0 0
  Inactive "intel"
  Option  "AutoAddGPU" "false"
EndSection
Section "Device"
  Identifier "nvidia"
  Driver "nvidia"
  BusID "PCI:9:0:0"
  Option "AllowExternalGpus" "true"
  Option "ProbeAllGpus" "false"
  Option "HardDPMS" "false"
  Option "NoLogo" "true"
  Option "UseEDID" "false"
#    Option "UseDisplayDevice" "none"
EndSection
Section "Screen"
  Identifier "nvidia"
  Device "nvidia"
  Option "AllowEmptyInitialConfiguration" "Yes"
#  Option "UseDisplayDevice" "None"
EndSection}}
Remember to set the bus id to the correct graphics card.


=== Automatically run window manager ===
=== Automatically run window manager ===


For convenience you can create nano ~/.nvidia-xinitrc and put there your favourite window manager:
For convenience you can create an {{ic|$XDG_CONFIG_HOME/X11/nvidia-xinitrc}} file with your favorite window manager. (if using ''nvidia-xrun'' < v.0.3.79 create {{ic|$HOME/.nvidia-xinitrc}}) 
 
if [ $# -gt 0 ]; then
  $*
else
  ''your-window-manager''
fi
 
With it you do not need to specify the app and can simply execute:
 
$ nvidia-xrun
 
Since this method starts an isolated X server, it is also a good idea to get a copy of all the other configurations files that you have located at {{ic|/etc/X11/xorg.conf.d/}}, except for your prior standard integrated GPU configurations.
 
=== Use bbswitch to manage the NVIDIA card ===
 
{{Note|nvidia-xrun > 0.3.78 should disable the card automatically so this method is unneccessary}}
When the NVIDIA card is not needed, ''bbswitch'' can be used to turn it off. The ''nvidia-xrun'' script will automatically take care of running a window manager and waking up the NVIDIA card. To achieve that, you need to:


  openbox-session
Load the {{ic|bbswitch}} module on boot:


With this you do not need to specify the app and you can simply run:
# echo 'bbswitch' > /etc/modules-load.d/bbswitch.conf


  nvidia-xrun
Disable the {{ic|nvidia}} module on boot:


=== Use bbswitch to manage nvidia ===
# echo 'options bbswitch load_state=0 unload_state=1' > /etc/modprobe.d/bbswitch.conf
When do not need to use nvidia , use bbswitch to turn off it , and run application which need nvidia , nvidia-xrun will automatically run window manager and wake up nvidia.


* Load bbswitch module when boot
After a reboot, the NVIDIA card will be off. This can be seen by querying {{ic|bbswitch}}'s status:
  # echo 'bbswitch ' > /etc/modules-load.d/bbswitch


* Disable the nvidia on boot time.
$ cat /proc/acpi/bbswitch
  # echo 'options bbswitch load_state=0' > /etc/modprobe.d/bbswitch.conf


* Blacklisting nvidia modules
To force the card to turn on/off respectively run:


  $ lsmod | grep nvidia | cut -d ' ' -f 1 > /tmp/nvidia
  # echo OFF > /proc/acpi/bbswitch
$ lsmod | grep  nouveau | cut -d ' ' -f 1 > > /tmp/nvidia
  # echo ON > /proc/acpi/bbswitch
  $ sort -n /tmp/nvidia | uniq > /tmp/nvidia.conf
$ sed -i 's/^\w*$/blacklist &/g' /tmp/nvidia.conf
# cp /tmp/nvidia.conf /etc/modprobe.d/nvidia.conf


Reboot system , nvidia will be off , you can geet the status:
For more about bbswitch see [https://github.com/Bumblebee-Project/bbswitch Bumblebee-Project/bbswitch].


  $ cat /proc/acpi/bbswitch 
== Usage ==


turn the card off, respectively on:
=== Start  at boot ===


  # tee /proc/acpi/bbswitch <<<OFF
[[Enable]] {{ic|nvidia-xrun-pm.service}} - this shuts down the NVIDIA card during boot.
  # tee /proc/acpi/bbswitch <<<ON


more about bbswitch see [https://github.com/Bumblebee-Project/bbswitch Bumblebee-Project/bbswitch]
Once the system boots, from the virtual console, login to your user, and run {{ic|nvidia-xrun ''application''}}.


== usage ==
If above does not work, [[Keyboard shortcuts#Xorg and Wayland|switch]] to unused virtual console and try again.
#switch to free tty
 
#login
As mentioned before, running applications directly with {{ic|nvidia-xrun ''application''}} '''does not work well''', so it is best to create an {{ic|nvidia-xinitrc}} file as outlined earlier, and use {{ic|nvidia-xrun}} to launch your window manager.
#run {{ic|nvidia-xrun [app]}}


== Troubleshooting ==
== Troubleshooting ==
Running Steam directly with nvidia-xrun does not work well, use some window manager like openbox will be better.
 
=== NVIDIA GPU fails to switch off or is set to be default ===
 
See [[#Use bbswitch to manage the NVIDIA card]].
 
If NVIDIA GPU still fails to switch off, or is somehow set to be default whenever you use or not {{ic|nvidia-xrun}}, then you might likely need to blacklist specific modules (which were previously blacklisted by [[Bumblebee]]). Create this file and restart your system:
 
{{hc|/usr/lib/modprobe.d/nvidia-xrun.conf|
blacklist nvidia
blacklist nvidia-drm
blacklist nvidia-modeset
blacklist nvidia-uvm
blacklist nouveau
}}
 
There seems to be a race condition between {{ic|nvidia-xrun-pm.service}} and {{ic|systemd-modules-load.service}} which loads the {{ic|nvidia}} modules. If the latter runs first, {{ic|nvidia-xrun-pm}} will hang (actually the {{ic|tee}} command) during device removal. If on the other hand {{ic|nvidia-xrun-pm}} runs first then it will succeed, and later the modules will fail to load with an error (which is harmless but ugly). For this reason it might be better to always blacklist the above modules.
 
DRM kernel mode setting should be enabled for PRIME synchronization to work (for example on muxless devices where only the Intel GPU is connected to outputs). However, consider disabling it in case there is an issue. See [[NVIDIA#DRM kernel mode setting]]
 
On certain hardware, the NVIDIA GPU exposes two devices on the PCI bus: a 3D controller and an audio device. In this case, both devices need to be removed from the bus in order for the GPU  to fully power down. This can be done by simply adding a line for the audio device bus id in {{ic|/etc/default/nvidia-xrun}}, and the corresponding line in the function {{ic|turn_off_gpu}}  in {{ic|/usr/bin/nvidia-xrun}} to remove the second device.

Latest revision as of 20:12, 23 November 2022

nvidia-xrun is a utility that allows NVIDIA Optimus-enabled laptops to run X server with discrete NVIDIA graphics on demand. This solution offers full GPU utilization, compatibility and better performance than Bumblebee.

X server can only be used with integrated graphics or discrete NVIDIA graphics, but not both, so the user might want to switch to a separate virtual console and start another X server using different graphics from what was used for the first X server.

Installation

Install:

  • nvidia - if using older drivers you have to edit nvidia-xrun's PKGBUILD and remove the NVIDIA depend
  • nvidia-xrun-gitAUR(recommended) or nvidia-xrunAUR (old method, uses bumblebee to switch off the dedicated card)
  • Any window manager, since running application directly like with nvidia-xrun application is not recommended.

Configuration

Setting the right bus id

Note: If you installed package from AUR, the bus id has been automatically set in /etc/X11/nvidia-xorg.conf. Make sure the bus ID has been correctly set, otherwise change it (you can find correct bus ID using lspci command). In some cases you need to convert the hex output from lspci to decimal for nvidia-xorg.conf, e.g. 3b:00.0 becomes "PCI:59:0:0".

Find your display device bus id:

$ lspci | grep -i nvidia | awk '{print $1}'

It might return something similar to 01:00.0. Then create a file (for example /etc/X11/nvidia-xorg.conf.d/30-nvidia.conf) to set the proper bus id:

/etc/X11/nvidia-xorg.conf.d/30-nvidia.conf
Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
    BusID "PCI:1:0:0"
    #  Option "DPI" "96 x 96"
EndSection

Also this way you can adjust some NVIDIA settings if you encounter issues:

/etc/X11/nvidia-xorg.conf.d/30-nvidia.conf
Section "Screen"
    Identifier "nvidia"
    Device "nvidia"
    #  Option "AllowEmptyInitialConfiguration" "Yes"
    #  Option "UseDisplayDevice" "none"
EndSection

External GPU setup

You can also use this in an external GPU setup. Make sure to load the nvidia-modeset and nvidia-drm modules and add the option Option "AllowExternalGpus" "true" to the "Device" section.

Change the auto-generated configuration to use the internal display on devices with multiple NVIDIA cards:

/etc/X11/nvidia-xorg.conf.d/30-nvidia.conf
Section "ServerLayout"
  Identifier "layout"
  Screen 0 "nvidia" 0 0
  Inactive "intel"
  Option  "AutoAddGPU" "false"
EndSection

Section "Device"
  Identifier "nvidia"
  Driver "nvidia"
  BusID "PCI:9:0:0"
  Option "AllowExternalGpus" "true"
  Option "ProbeAllGpus" "false"
  Option "HardDPMS" "false"
  Option "NoLogo" "true"
  Option "UseEDID" "false"
#    Option "UseDisplayDevice" "none"
EndSection

Section "Screen"
  Identifier "nvidia"
  Device "nvidia"
  Option "AllowEmptyInitialConfiguration" "Yes"
#  Option "UseDisplayDevice" "None"
EndSection

Remember to set the bus id to the correct graphics card.

Automatically run window manager

For convenience you can create an $XDG_CONFIG_HOME/X11/nvidia-xinitrc file with your favorite window manager. (if using nvidia-xrun < v.0.3.79 create $HOME/.nvidia-xinitrc)

if [ $# -gt 0 ]; then
  $*
else
  your-window-manager
fi

With it you do not need to specify the app and can simply execute:

$ nvidia-xrun

Since this method starts an isolated X server, it is also a good idea to get a copy of all the other configurations files that you have located at /etc/X11/xorg.conf.d/, except for your prior standard integrated GPU configurations.

Use bbswitch to manage the NVIDIA card

Note: nvidia-xrun > 0.3.78 should disable the card automatically so this method is unneccessary

When the NVIDIA card is not needed, bbswitch can be used to turn it off. The nvidia-xrun script will automatically take care of running a window manager and waking up the NVIDIA card. To achieve that, you need to:

Load the bbswitch module on boot:

# echo 'bbswitch' > /etc/modules-load.d/bbswitch.conf

Disable the nvidia module on boot:

# echo 'options bbswitch load_state=0 unload_state=1' > /etc/modprobe.d/bbswitch.conf 

After a reboot, the NVIDIA card will be off. This can be seen by querying bbswitch's status:

$ cat /proc/acpi/bbswitch  

To force the card to turn on/off respectively run:

# echo OFF > /proc/acpi/bbswitch
# echo ON > /proc/acpi/bbswitch

For more about bbswitch see Bumblebee-Project/bbswitch.

Usage

Start at boot

Enable nvidia-xrun-pm.service - this shuts down the NVIDIA card during boot.

Once the system boots, from the virtual console, login to your user, and run nvidia-xrun application.

If above does not work, switch to unused virtual console and try again.

As mentioned before, running applications directly with nvidia-xrun application does not work well, so it is best to create an nvidia-xinitrc file as outlined earlier, and use nvidia-xrun to launch your window manager.

Troubleshooting

NVIDIA GPU fails to switch off or is set to be default

See #Use bbswitch to manage the NVIDIA card.

If NVIDIA GPU still fails to switch off, or is somehow set to be default whenever you use or not nvidia-xrun, then you might likely need to blacklist specific modules (which were previously blacklisted by Bumblebee). Create this file and restart your system:

/usr/lib/modprobe.d/nvidia-xrun.conf
blacklist nvidia
blacklist nvidia-drm
blacklist nvidia-modeset
blacklist nvidia-uvm
blacklist nouveau

There seems to be a race condition between nvidia-xrun-pm.service and systemd-modules-load.service which loads the nvidia modules. If the latter runs first, nvidia-xrun-pm will hang (actually the tee command) during device removal. If on the other hand nvidia-xrun-pm runs first then it will succeed, and later the modules will fail to load with an error (which is harmless but ugly). For this reason it might be better to always blacklist the above modules.

DRM kernel mode setting should be enabled for PRIME synchronization to work (for example on muxless devices where only the Intel GPU is connected to outputs). However, consider disabling it in case there is an issue. See NVIDIA#DRM kernel mode setting

On certain hardware, the NVIDIA GPU exposes two devices on the PCI bus: a 3D controller and an audio device. In this case, both devices need to be removed from the bus in order for the GPU to fully power down. This can be done by simply adding a line for the audio device bus id in /etc/default/nvidia-xrun, and the corresponding line in the function turn_off_gpu in /usr/bin/nvidia-xrun to remove the second device.