From 21ceb9a12bf91f309316a431e40538d24eea5d16 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Sat, 8 Aug 2020 03:49:41 +0000 Subject: [PATCH 1/5] Create powersaving guide --- POWERSAVING.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 POWERSAVING.md diff --git a/POWERSAVING.md b/POWERSAVING.md new file mode 100644 index 0000000..a28a445 --- /dev/null +++ b/POWERSAVING.md @@ -0,0 +1,33 @@ +# Asus Zephyrus G14 GPU powersaving + +In order to get the best battery life, the dedicated GPU must be disabled. + +Simply unloading the driver or enabling powersaving feaures isn't enough. + +In the future, the nvidia driver may allow for entering D3 (full power off) on it's own, but for now, there's another solution: acpi calls. This requires the `acpi_call` kernel module, on Arch this can be installed with the `acpi_call` or `acpi_call-dkms` package. + +Thanks to /u/FailSpai on reddit for finding the correct ACPI call. The GPU can be powered off and on with the call "\\_SB.PCI0.GPP0.PG00". For example, to turn off the GPU completely, run `sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._OFF" > /proc/acpi/call'`. Similarly, to turn it back on, `sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._ON" > /proc/acpi/call'`. You can verify the state of the GPU by running `sudo sh -c 'echo "\\_SB.PCI0.GPP0.PEGP.SGST" > /proc/acpi/call'`, then running `sudo cat /proc/acpi/call`. 0x0 means off, and anything above 0 means on. Alternatively, just look at the power draw, `cat /sys/class/power_supply/BAT0/power_now` and if it's under 10-11w then it's off. + +This allows for the same, or better, idle power draw than Windows, as long as you have done other tweaks (disable boost, change CPU governor, etc). + +If the GPU is powered off during suspend, the system will hang. This can be solved by using a systemd hook to turn the GPU back on before suspend, then turning it back off after. For example, place this script in an executable file in `/usr/lib/systemd/system-sleep/`: + +``` +#!/bin/bash + +if [ "${1}" == "pre" ]; then + sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._ON" > /proc/acpi/call' + sleep 1 # The GPU needs a bit of time to ensure that it's on before suspend +elif [ "${1}" == "post" ]; then + if xrandr --listproviders | grep NVIDIA; then + echo "GPU is in use for PRIME, keeping on" + else + sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._OFF" > /proc/acpi/call' + echo "GPU powered off" + fi +fi +``` + +As the script suggests, you can't power off the GPU while it's in use. I would recommend using optimus-manager-amd (available on the AUR as optimus-manager-amd-git) to automatically handle switching Xorg sessions and automatically depowering the GPU when it's not used. You can see my config files for optimus-manager-amd [here](https://git.deck.sh/shark/g14gpu/-/tree/master/etc/optimus-manager). When in `amd` mode, I only draw 5.5-6w on idle, and it bounces around up to 10w when using firefox with the second half of the cores disabled. + +Again, thanks to /u/FailSpai for digging through the ACPI tables to find the right call, you can find his comment about it [here](https://www.reddit.com/r/VFIO/comments/hx5j8q/success_with_laptop_gpu_passthrough_on_asus_rog/g0m3kvh/). From 2f23879bc165ac0100ccb0ad105358616099d992 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Sat, 8 Aug 2020 03:50:58 +0000 Subject: [PATCH 2/5] Update systemd suspend hook --- acpigpu | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/acpigpu b/acpigpu index 4a1b654..f81cd6f 100755 --- a/acpigpu +++ b/acpigpu @@ -1,15 +1,13 @@ #!/bin/bash -#case "$1" in -# pre) -# /home/cole/g14gpu/gpuon.sh ;; -# post) -# /home/cole/g14gpu/gpuoff.sh ;; -#esac - - if [ "${1}" == "pre" ]; then - bash /home/cole/g14gpu/gpuon.sh + sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._ON" > /proc/acpi/call' + sleep 1 # The GPU needs a bit of time to ensure that it's on before suspend elif [ "${1}" == "post" ]; then - bash /home/cole/g14gpu/gpuoff.sh -fi + if xrandr --listproviders | grep NVIDIA; then + echo "GPU is in use for PRIME, keeping on" + else + sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._OFF" > /proc/acpi/call' + echo "GPU powered off" + fi +fi \ No newline at end of file From b5d92144a14cf0890c9f33edce69877bc1602bf7 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Sat, 8 Aug 2020 03:52:47 +0000 Subject: [PATCH 3/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e9f72b7..442b1b9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ This is a collection of scripts for managing the GPU in the Asus Zephyrus G14. -The setup involves using bumblebee, bbswitch, and GPU passthrough to a Windows 10 vm. bbswitch is unable to wake the GPU up at this time, so for now I'm not using it. However it was able to completely depower the GPU, allowing idle power usage of 5-7w just like on windows. +The setup originally involved using bumblebee, bbswitch, and GPU passthrough to a Windows 10 vm. bbswitch is unable to wake the GPU up at this time, so for now I'm not using it. I am now using optimus-manager with some acpi calls to fully depower and wake the GPU. `startvm` unbinds from nvidia, binds to vfio-pci, runs the vm, then when you type 'stop' it shuts it down and gives the GPU back to the nvidia driver for use with bumblebee. From 975471706cc7d048f62e3cb11a80778b01e01f47 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Sat, 8 Aug 2020 04:18:15 +0000 Subject: [PATCH 4/5] Update POWERSAVING.md - fix suspend script --- POWERSAVING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/POWERSAVING.md b/POWERSAVING.md index a28a445..329ab76 100644 --- a/POWERSAVING.md +++ b/POWERSAVING.md @@ -17,7 +17,7 @@ If the GPU is powered off during suspend, the system will hang. This can be solv if [ "${1}" == "pre" ]; then sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._ON" > /proc/acpi/call' - sleep 1 # The GPU needs a bit of time to ensure that it's on before suspend + sleep 2 # The GPU needs a bit of time to ensure that it's on before suspend elif [ "${1}" == "post" ]; then if xrandr --listproviders | grep NVIDIA; then echo "GPU is in use for PRIME, keeping on" From 58d7254f6c571456d130609db81e116a4d8b4fe2 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Sat, 8 Aug 2020 04:19:23 +0000 Subject: [PATCH 5/5] Fix formatting --- POWERSAVING.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/POWERSAVING.md b/POWERSAVING.md index 329ab76..3f67c87 100644 --- a/POWERSAVING.md +++ b/POWERSAVING.md @@ -16,13 +16,13 @@ If the GPU is powered off during suspend, the system will hang. This can be solv #!/bin/bash if [ "${1}" == "pre" ]; then - sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._ON" > /proc/acpi/call' + sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._ON" > /proc/acpi/call' sleep 2 # The GPU needs a bit of time to ensure that it's on before suspend elif [ "${1}" == "post" ]; then - if xrandr --listproviders | grep NVIDIA; then - echo "GPU is in use for PRIME, keeping on" + if xrandr --listproviders | grep NVIDIA; then + echo "GPU is in use for PRIME, keeping on" else - sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._OFF" > /proc/acpi/call' + sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._OFF" > /proc/acpi/call' echo "GPU powered off" fi fi