Offloading Nvidia GPU

Hi all,

I’m STRUGGLING a bit with my Nivida GPU attachment. I’m running Arch newest everything, and for the life of me I can’t get the NVIDIA GPU to shut down when on battery. I feel like I’ve tried everything on the Arch Linux wiki and it still refuses to shut down.

This leads to a a usage of 20-30W on battery which drains the battery in about 2 hours (if I’m lucky).

I can use EnvyControl to disable the dGPU until reboot, which is quite annoying process. However with the dGPU disabled my usage drops to 9-13W, which is what is expected.

Please help!

I don’t know what you’ve tried or how you’re testing this, but I’ve got a few tips. Note though, that I have the RX 7700s module, not the 5070. I used to have a Razer laptop running Arch with a 3070 though.

  1. Don’t use tools like nvtop to check whether the dGPU is on or not. These tools wake the device up and they themselves will prevent the dGPU from turning on. It’s better to run a command like cat /sys/class/drm/card1/device/power_state and check to see if the dGPU is in D0 (on) or d3Cold (off). This doesn’t wake the dGPU.
  2. Some apps (e.g. Discord, Steam, some web browsers) will turn the dGPU on for a moment but then it will re-enter sleep on it’s own. If you have a tool running that’s watching for dGPU activity, when these other apps turn on the dGPU, that measurement tool could then latch onto it and prevent it from turning on. For example, I have modified the firmware on my keyboard to turn one of the lights red when the dGPU is on. When the dGPU is on, I have to change the sampling rate so that I don’t accidentally keep it on through the act of observing it. RGB Keyboard Custom Firmware - PC Utilization Stats
  3. You can use nvtop to figure out which processes are binding to the dGPU, and then configure the env variables/launch options for that application to prefer a given GPU. For example, these env variables I use when I want to force an app onto the iGPU.
    1. DRI_PRIME=0 DXVK_FILTER_DEVICE_NAME="AMD Radeon 780M Graphics (RADV PHOENIX)"
    2. Technically, only DRI_PRIME or the filter variable should be needed, but I like to be certain.
    3. You can get the name needed by the filter variable with vulkaninfo e.g., vulkaninfo | grep 5070
    4. If those don’t work, you can also try loading the game with gamescope and making use of it’s --perfer-vk-device parameter. Unfortunately, I’ve deleted my sample of that command though.
  4. If you’re trying to run an application/game with mangohud and on the iGPU, you’ll need to toggle mangohud off temporarily. I’ve noticed that if I successfully launch a game on the iGPU with mangohud running, mangohud will latch onto the dGPU rather than the GPU in use and then mangohud itself will report the dGPU’s stats and keep the dGPU online. I can get around this by hitting shift + f12 to toggle the overlay off, wait ~10 seconds, then turn it back on.

That’s all I can think of off the top of my head. I’ll make another comment if I think of more.

1 Like

Is there a piece of software that checks whether the dGPU is asleep without waking the dGPU itself?

I use btop on a laptop (not a Framework) with Nvidia GPU, if btop starts immediately, the Nvidia dGPU is awake, if btop needs half a second to start, the GPU was asleep and btopwoke it, I’ll then turn off btop and the Nvidia dGPU will sleep within 10 seconds.

The only 2 reliable ways I’ve found to do it are A) the cat command I cited above, and B) the custom keyboard firmware I developed, as I wrote it with that feature specifically in mind.

I have a simple script in my home folder called gpu_state.sh that checks the state of both GPUs.

#! /bin/sh
cat /sys/class/drm/card1/device/power_state
cat /sys/class/drm/card2/device/power_state

Both said D0. Which I think read as “are active”

I check my wattage using Powertop. It doesnt force the NVIDIA GPU on.

855        root   0  Graphic   0%      4MiB   0%     0%    108MiB /usr/lib/Xorg -nolisten tcp -background none -background none -seat seat0 vt2 -auth /run/sddm/xauth_Venqyf -noreset -displayfd 16

Using NVTOP that is the only entry using the Nvidia card. Also why is my dGPU device Zero and not 1? Regardless, I’m not sure why this is forcing it on.

I had that issue in the past. Unfortunately, I only remember it being a real pain to resolve and not how I resolved it :frowning:

I was able to fix that problem. I forced SDDM to use wayland and not X11.

I think maybe the energy is discharging at the right rate? Not sure.

I think that was how I may have resolved it as well, but I thought you said you were on the latest? IIRC both Gnome and Plasma have done away with X11.

Yeah I’m not sure why its using X11. I’m on Wayland, I guess the SDDM wants to use X11 for log in.

Sorry for kinda hijacking this thread, but I have a question regarding the same topic:

I want to use only my iGPU instead of dGPU for a certain game. (Slay the Spire 2)
I tried everything in step 3., my commandline for the game in steam looks like this:
MESA_VK_DEVICE_SELECT=1002:15bf! DRI_PRIME=0 DXVK_FILTER_DEVICE_NAME=“AMD Radeon 780M Graphics (RADV PHOENIX)” %command%
But still, the game is primarily using the iGPU, but still somehow latches onto the dGPU thus keeping it awake…
I know that because the power usage isnt ~20W but ~60W, cat /sys/class/drm/card1/device/power_state= D0 and amdgpu_top shows this:

Where would I go from here? I just want the game to ignore the dGPU :sob:

EDIT: Oops, sorry, forgot to mention, I got the RX7700S, but as far as I could find out, the commands should work for both Nvidia and AMD

Temporary solution would be to force iGPU only one start up.

But for now you probably should first confirm the dgpu is running Slay but running nvtop as you run the program and see if it says GPU 1. If not, check to see if its another program running it.

This is keeping it awake I bet. Be aware that most monitoring tools will wake it up and hold it awake.

Thank you, that gave me the idea that led to a solution!

I checked all possible culprits and think I managed to configure it the way I want:

  • Discord wakes up the dGPU twice on startup
  • Steam wakes up the dGPU on startup and for some time afterwards, unless I tab into other windows
  • Waiting for Steam to stop waking up the dGPU and only then Slay the Spire 2 uses only the iGPU (with MESA_VK_DEVICE_SELECT=1002:15bf! %command% )!

Now I only wonder how I can force Steam to never wake up the dGPU at all, because then I should be able to start any game using only the iGPU…

The difference is huge: If I play StS2 with the dGPU I get maybe 45 minutes of playtime with lowest display brightness, CPU clocks and WIFI turned off. But with the iGPU I can watch a stream at the same time with a bright display and still get ~2 hours :slight_smile: