UshakovVasilii / gnome-shell-extension-freon

Shows CPU temperature, disk temperature, video card temperature (NVIDIA/Catalyst/Bumblebee&NVIDIA), voltage and fan RPM
https://extensions.gnome.org/extension/841/freon
GNU General Public License v2.0
424 stars 77 forks source link

Feature request: Poll nvidia temperature status only if GPU is awake #250

Closed andrewmackrodt closed 1 year ago

andrewmackrodt commented 1 year ago

With Optimus laptops the nvidia dGPU can be suspended to enhance battery life. nvidia-smi causes the GPU to wake-up, thus consuming more power. This feature request is for Freon to support an option where nvidia-smi is only polled if the dGPU is already awake.

The power_state can be queried via /sys/devices/../../power_state, e.g.:

find /sys/module/nvidia/drivers/pci\:nvidia/ -mindepth 1 -maxdepth 1 -type l -name '*:*' | xargs -I@ sh -c 'echo $(basename "@") $(cat "@/power_state")'

When power_state = D3cold, temperature should not be queried.

Alternatively, disabling nvidia temperature reporting if using battery could work well as well.

Edit: allowing to disable polling on battery is probably the better solution. I tried a quick implementation of checking for GPU power_state by editing nvidiaUtil.js so the constructor is like this:

var NvidiaUtil = class extends CommandLineUtil.CommandLineUtil {

    constructor() {
        super();
        let path = GLib.find_program_in_path('nvidia-smi');
        this._argv = path ? [
            '/bin/sh',
            '-c',
            `find /sys/module/nvidia/drivers/pci\\:nvidia/ -mindepth 1 -maxdepth 1 -type l -name '*:*' \
                | xargs -I@ sh -c 'echo $(basename "@") $(cat "@/power_state")' \
                | grep -qv D3cold && '${path}' --query-gpu=name,temperature.gpu --format=csv,noheader`
        ] : null;
    }

While this works, if Freon's poll rate is too low (e.g. less than 10 seconds), it will keep the GPU awake.

maniacx commented 1 year ago

Wow. First thing it do when i install ubuntu is install extension and freon. Never realised it was keeping dgpu awake. I installed supergfxctl because of this to manually switch OFF dgpu. Today yesterday I disable freon for some reason and I noticed supergfxctl was showing dgpu is suspended in hybrid mode. It is then i remembered reading your issue. I thought my laptop didnt have optimus... :) But is does have it , and it was freon keeping it awake

antonio-petricca commented 1 year ago

Well tought, I just disabled NVIDIA sensor check.

Any news about this fix?

retrixe commented 1 year ago

This will probably need some heuristics, I'm thinking of submitting a PR which initially does this check using /proc/driver/nvidia/gpus/<ID>/power (which isn't enough on its own unless you slow down your polling), and a follow up commit which checks nvidia-smi running processes and slows down polling to every 30 seconds (for me, the GPU sleeps 20 seconds after running nvidia-smi on Wayland) if gnome-shell, Xorg or neither are running.

retrixe commented 1 year ago

I've created a PR which fixes this without any need to reduce the poll rate :^) feel free to test it out.

Side note: nouveau doesn't exhibit this issue because it doesn't wake the GPU when the temperature is polled, it simply returns N/A. Of course, nouveau is not a viable option for people at the moment, just worth mentioning.