Introduction

Laptops designed for high graphics performance, such as that required for gaming, are typically provisioned with a discrete GPU, in addition to one integrated into the CPU. Nvidia calls this technology Optimus, or Advanced Optimus, in newer versions which allows the Nvidia GPU to output directly to the built-in screen instead of routing output through the integrated GPU. The Optimus dual GPU hardware configuration is capable of operating in one of several modes Hybrid (or Dynamic), Discrete, or Integrated. These modes correspond, respectively, to operation in which the integrated card is used by default, with the discrete GPU activated on demand for a particular application; in which only the discrete Nvidia GPU is used; or one in which only the integrated GPU is used. The purpose of the dual GPU configuration is to provide applications which need it increased graphics capability, but reduce power consumption when these applications are not running.

History

For a long time Optimus on Linux required either using the integrated mode or the discrete mode. The switching between integrated mode and discrete mode was done either manually or by an Optimus management program. At some point, a Hybrid mode also became available, where the integrated GPU was used by default, with the discrete GPU being activated only on demand when launching a particular application requiring more graphics power. This mode did however require external methods to control the power state of the Nvidia GPU and to activate rendering by the GPU.

Since the release of the Turing generation of Nvidia GPU micro-architectures and the associated Nvidia driver versions (435.17 +), the external tools have not been necessary to manage the power state of the GPU in Hybrid mode, or to activate offloading. The proprietary driver and the GPU are capable of Run Time D3 Power Management, meaning that they can place the Nvidia card in the low power ACPI D3hot or D3cold (D3) device power states, or to put it simply, in a low power suspend mode (D3hot) or an effectively zero power use state (D3cold or D3) (see Nvidia Optimus on Linux). Also, in post Turing generation Optimus laptops, external tools, such as Bumblebee, have not been required to offload graphics rendering to the Nvidia GPU in Hybrid mode, as applications requiring the Nvidia card could be launched to use the Nvidia GPU by setting environment variables such as

__NV_PRIME_RENDER_OFFLOAD=1
__GLX_VENDOR_LIBRARY_NAME=nvidia

Now, there is a new development in the form of switcheroo-control, a D-Bus service that is able to determine the existence of multiple GPUs and provide a command to offload applications to the Nvidia graphics card in Hybrid mode. It also facilitates the capability in certain desktop environments to launch an application such that its graphics output is rendered with the discrete GPU. With switcheroo-control and the move towards Wayland away from the X Window System, the complicated history of using Nvidia on Linux is continuing with a new chapter. This complicated history and the current evolution can be reduced as shown in the following (non-authoritative and non-definitive) table, with historical periods defined by the methods that were/are available for:

  • switching the graphics modes
  • managing the power state of the Nvidia GPU
  • activating the Nvidia GPU to render graphics for a particular program while in Hybrid mode, i.e., offloading
Nvidia History on Linux
Period Modes Switching Methods Power Management Methods Offloading Methods in Hybrid Mode
Pre Turing Gen Discrete, Hybrid, Integrated Manual; Optimus management programs, e.g., Optimus Manager, Nvidia Prime, SUSEPrime bbswitch Bumblebee
Post Turing Gen Discrete, Hybrid, &dagger Manual; Optimus management programs, e.g., Optimus Manager, Nvidia Prime, SUSEPrime, EnvyControl external methods not necessary; managed internally by Nvidia driver and Nvidia GPU (RTD3 Power Management) external methods not necessary; set appropriate environment variables when launching applications to be offloaded
&dagger: an Integrated mode is possible, however in post Turing generation Nvidia GPU's, the GPU is not able to be placed in a complete poweroff state (the ACPI D) device power state)
Post Turing Gen (Current, with Wayland switcheroo-control) Hybrid switching to Discrete mode not favored, but individual applications can be launched to use the discrete GPU external methods not necessary; managed internally by Nvidia driver and Nvidia GPU (RTD3 Power Management) external methods not necessary; use switcherooctl to launch an application to use discrete GPU or set appropriate environment variables when launching applications to be offloaded

switcheroo-control

According to its GitLab repository readme, switcheroo-control is a "D-Bus service to check the availability of dual-GPU." This service allows the switcherooctl command to perform its actions, which are to list the available GPUs, and to run a program specifying which GPU will perform the graphics rendering. These commands are

switcherooctl list
and
switcherooctl launch [OPTION] COMMAND...
where OPTION is one of switcherooctl and COMMAND is the command of the application to run in PRIME offloading mode on the GPU. It uses the associated systemd service swithceroo-control.service.

The following image shows -- on openSUSE Tumbleweed on the Lenovo Legion 5i Pro with the graphics mode set to Hybrid by EnvyControl -- two panes of a Konsole window, where in the first pane, the outputs of envycontrol --query, systemctl status switcheroo-control.service, switcherooctl list, and switcherooctl launch smplayer are displayed; the right pane shows the outpus of nvidia-smi and nvtop. We see that the graphics mode is Hybrid, both GPUs are listed by switcherooctl, and that it successfully launches SMPlayer using the discrete GPU. This is confirmed by the output of nvidia-smi listing smplayer and its low level worker mpv as processes using the Nvidia GPU including 185MiB of its dedicated memory. The lower right pane also confirms this in the output of nvtop, showing that mpv is also using discrete GPU resources.

Image 1: Using switcherooctl to Launch SMPlayer Using the Discrete GPU

switcheroo-control not only allows launching applications in discrete mode on demand when the Optimus laptop is in Hybrid mode, but also provides the underlying functionality which allows the discrete GPU to be specified when launching applications from the graphical desktop environment. In GNOME and POPOS, users can right click on an application icon, and select the menu item corresponding to launching with the dedicated GPU. In the Plasma desktop, its a bit more complicated, requiring users to use KDE Menu Editor, one time, to specify that an application should always use the dedicated GPU (see Image 2a, below). After this one time action the application will always be launched with the discrete GPU providing graphics rendering. The second image in the following set confirms that KDEnlive launched in this way is properly offloading the graphics rendering for the application.

Currently switcheroo-control is quietly installed automatically by many distributions. openSUSE is more vocal in its adoption of switcheroo-control, while at the same time abandoning support for the Optimus management program SUSEPrime. The distribution favors switcheroo-control for the case when, as stated in its wiki page on switcheroo-control:

You have a laptop with an NVIDIA discrete graphics card and Intel or AMD integrated GPU (iGPU), otherwise known as NVIDIA Optimus technology. You may need to run programs using the discrete graphics card, but you don't want the discrete graphics active all the time, because that would cause the laptop to consume too much energy. You also are using either Gnome or the KDE desktop environment with Wayland, which both offer GUI integration for hybrid graphics

Other distributions, such as CachyOS also recommend switcheroo-control. In CachyOS's case, the distribution vaguely states:

please avoid using tools like optimus-manager. They may seem quite handy to you, but believe us, they can cause a lot of issues and you really don’t need them if your dGPU supports PRIME Offload and dynamic power management.

The Continuing Need for Optimus Management Programs

The current momentum is to only use Optimus laptops only in Hybrid mode (also with Wayland instead of X) using switcheroo-control to offload application graphics rendering to the Nvidia GPU on demand with switcheroo-control -- something we have seen is useful in the above discussion.

But for use cases outside of that described in openSUSE's wiki, an Optimus management program is still useful. Also, the problems suggested by the Arch based CachyOS could be due to the difference in behavior of some Optimus management programs, depending on whether the Nvidia GPU they are managing is capable of Runtime D3 Power Management (see Nvidia Optimus on Linux). In the case of the Arch specific Optimus Manager, the power state management method can be specified from a pre-configured set of choices. Users must select the appropriate method -- or no method for handling by post Turing generation GPUs' Run Time D3 Management capability -- for the specific generation of GPU, and ensure that if their laptop does not support Run Time D3 Management the appropriate external power management method is available on the system for use by Optimus Manager. CachyOS may be trying to spare their users of this complication.

So, as we saw in Image 1, Image 2bOptimus management programs can still be used alongside switcheroo-control to gain the full benefits of an Nvidia Optimus laptop. The Optimus management program can be used to set the graphics mode to

  • integrated mode to get the maximum power savings, but not have the ability to offload graphics rendering to the GPU, nor have the ability to use an external monitor connected to a port that is hard-wired to the Nvidia GPU, e.g., HDMI
  • discrete mode to get the maximum performance for all applications, including the desktop environment, using all of the resources of the Nvidia GPU, including its dedicated video memory that would otherwise be taken from the main system memory
  • hybrid mode to have the Nvidia GPU available such that application graphics rendering can be offloaded to the discrete GPU on demand through the use of the with the appropriate environment variables for PRIME offloading, with switcherooctl on the command line, or using the desktop environment through the capabilities provided by switcheroo-control.

The benefits of switcheroo-control can be realized in Hybrid mode, as set by the Optimus management program. But the other modes are available with their own benefits as described above.

The usefulness of the Discrete mode as set by an Optimus management program is further illustrated in the following set of images (Images 3a and 3b) which compare resource usage in Hybrid (Image 3a) and Discrete (Image 3b) modes. Image 3a shows openSUSE Tumbleweed running on a Lenovo Legion 5i Pro with an Nvidia GeForce RTX 3050 in Hybrid mode set by EnvyControl in an X11 session. The graphics portion of KDEnlive has been offloaded to the Nvidia GPU as indicated by nvidia-smi (the second process in its list of processes, which unfortunately is obscured here, but the obscured window is clearly visible in Image 2b). This is also indicated by the output of nvtop, which in case indicates that KDEnlive is using 46 MiB of dedicated GPU memory.

This can be contrasted with Image 3b, which shows openSUSE Tumbleweed running on a Lenovo Legion 5i Pro with an Nvidia GeForce RTX 3050 in Discrete mode as set by EnvyControl in an X11 session.

For distributions that do not have a Optimus management program (currently only Ubuntu's excellent Nvidia Prime, Optimus Manager for Arch, and openSUSE's deprecated SUSEPrime which provides a very good one; see Nvidia Optimus on Linux ) EnvyControl provides an alternative to the Hybrid only mode of the Switcherooctl/Wayland combination of using an Optimus laptop, for distributions such as Fedora, openSUSE, and Debian which do not provide an Optimus management program or do not have a third-party Optimus management program as in the case of Arch with Optimus Manager.

Also, some distributions do not provide their own Optimus management programs; as far as I know Debian does not. And Fedora, for example, required modification -- when using an X session -- to the X.org configuration to switch between the default mode of using Hybrid mode and to Discrete mode by making the Nvidia card the default.

Conclusion

In conclusion, I will describe my own use case.

On my secondary laptop, a Dell G5-5587 with a GeForce 1050 Ti, a pre Turing Nvidia GPU, I currently multi-boot Arch and Siduction. The laptop is plugged in all the time and does not require battery power saving. So I have used Optimus Manager on Arch and EnvyControl on Siduction to set the graphics mode to discrete. I get the full performance benefit of the Nvidia GPU for all applications and the desktop environment. The graphics portion of memory needed by the running applications and the desktop environment is not shared or taken from system memory, allowing more and larger applications to run with more and larger files. This type of usage makes the laptop a true desktop replacement.

On my primary laptop, a Lenovo Legion 5i Pro with a GeForce RTX 3050, a post Turing Nvidia GPU, I currently multi-boot Arch, openSUSE Tumbleweed, Siduction, Kubuntu, and Ultramarine. I typically use these distributions in Hybrid mode as set by Optimus Manager in Arch, EnvyControl in openSUSE, Siduction and Ultramarine, and the graphical interface to Ubuntu's Nvidia Prime integrated in Nvidia Settings. On all of these except Arch, in which the switcheroo-control package interferes with optimus-manager-git, switcherooctl and the capability it provides desktop environments is available to offload on demand on a per-application basis.

When I am truly mobile and want maximum battery, I can also switch to Integrated mode using EnvyControl. On the other distributions switching to Integrated mode, for some reason, the Nvidia GPU is not removed from PCI enumeration, a requirement of the ACPI D3cold device power state.

References

  1. Advanced Configuration and Power Interface (ACPI) Specification, Release 6.6
  2. Microsoft Learn: Device Power States
  3. Nvidia Driver README; Chapter 22. PCI-Express Runtime D3 (RTD3) Power Management
  4. openSUSE Online man Page for switcherooctl(1)
  5. Optimus Manager GitHub Wiki Main Page
  6. Optimus Manager GitHub Wiki; Nvidia GPU offloading for "hybrid" mode
  7. SUSEPrime Github Repository
  8. Debian Packages Web Portal: switcheroo-control
  9. freedesktop.org switcheroo-control GitLab Repository
  10. CachyOS Wiki: Dual GPU Setup Guide
  11. openSUSE News: GPU Switching: A Multi-GPU Game Changer
  12. openSUSE Wiki: SDB:NVIDIA Switcheroo Control
  13. endeavourOS Wiki (Discover): Switcheroo Control
  14. Nvidia Optimus on Linux
  15. Siduction Linux 2024.1.0 (Shine On) Review [KDE Plasma Edition]
  16. bayasdev / envycontrol GitHub Repository