From 705f307a03c49d6cdd93ff1592c6ed10b8096234 Mon Sep 17 00:00:00 2001 From: Cole Deck Date: Fri, 7 Aug 2020 22:07:32 -0500 Subject: [PATCH] Add optimus manager and full GPU power off config --- acpigpu | 15 +++++++++++++ bind => binddev | 3 ++- etc/optimus-manager/nvidia-disable.sh | 1 + etc/optimus-manager/nvidia-enable.sh | 1 + etc/optimus-manager/optimus-manager.conf | 12 +++++++++++ etc/optimus-manager/xorg-amd.conf | 9 ++++++++ etc/optimus-manager/xorg-intel.conf | 9 ++++++++ etc/optimus-manager/xorg-nvidia.conf | 9 ++++++++ etc/optimus-manager/xsetup-amd.sh | 4 ++++ etc/optimus-manager/xsetup-intel.sh | 3 +++ etc/optimus-manager/xsetup-nvidia.sh | 5 +++++ gpuoff.sh | 27 +++++++++++++++++++----- gpuon.sh | 3 ++- startvm | 14 ++++++------ unbind => unbinddev | 8 ++++--- vm | 9 ++++---- 16 files changed, 112 insertions(+), 20 deletions(-) create mode 100755 acpigpu rename bind => binddev (87%) create mode 100755 etc/optimus-manager/nvidia-disable.sh create mode 100755 etc/optimus-manager/nvidia-enable.sh create mode 100644 etc/optimus-manager/optimus-manager.conf create mode 100644 etc/optimus-manager/xorg-amd.conf create mode 100644 etc/optimus-manager/xorg-intel.conf create mode 100644 etc/optimus-manager/xorg-nvidia.conf create mode 100755 etc/optimus-manager/xsetup-amd.sh create mode 100755 etc/optimus-manager/xsetup-intel.sh create mode 100755 etc/optimus-manager/xsetup-nvidia.sh rename unbind => unbinddev (64%) diff --git a/acpigpu b/acpigpu new file mode 100755 index 0000000..4a1b654 --- /dev/null +++ b/acpigpu @@ -0,0 +1,15 @@ +#!/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 +elif [ "${1}" == "post" ]; then + bash /home/cole/g14gpu/gpuoff.sh +fi diff --git a/bind b/binddev similarity index 87% rename from bind rename to binddev index 16599bb..73249f8 100755 --- a/bind +++ b/binddev @@ -3,6 +3,7 @@ modprobe vfio-pci for dev in "$@"; do vendor=$(cat /sys/bus/pci/devices/$dev/vendor) device=$(cat /sys/bus/pci/devices/$dev/device) + echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id if [ -e /sys/bus/pci/devices/$dev/driver ]; then #echo $dev > /sys/bus/pci/devices/$dev/driver/unbind rmmod nvidia_drm @@ -10,6 +11,6 @@ for dev in "$@"; do rmmod nvidia echo "Unbound old driver" fi - echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id + #echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id echo "Bound VFIO driver" done diff --git a/etc/optimus-manager/nvidia-disable.sh b/etc/optimus-manager/nvidia-disable.sh new file mode 100755 index 0000000..a2822d4 --- /dev/null +++ b/etc/optimus-manager/nvidia-disable.sh @@ -0,0 +1 @@ +sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._OFF" > /proc/acpi/call' diff --git a/etc/optimus-manager/nvidia-enable.sh b/etc/optimus-manager/nvidia-enable.sh new file mode 100755 index 0000000..1114ccb --- /dev/null +++ b/etc/optimus-manager/nvidia-enable.sh @@ -0,0 +1 @@ +sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._ON" > /proc/acpi/call' diff --git a/etc/optimus-manager/optimus-manager.conf b/etc/optimus-manager/optimus-manager.conf new file mode 100644 index 0000000..732bb82 --- /dev/null +++ b/etc/optimus-manager/optimus-manager.conf @@ -0,0 +1,12 @@ +[optimus] +switching=none +pci_power_control=no +pci_remove=no +pci_reset=no +auto_logout=yes +startup_mode=amd + +[nvidia] +modeset=yes +PAT=yes +options=overclocking diff --git a/etc/optimus-manager/xorg-amd.conf b/etc/optimus-manager/xorg-amd.conf new file mode 100644 index 0000000..f5ce420 --- /dev/null +++ b/etc/optimus-manager/xorg-amd.conf @@ -0,0 +1,9 @@ +# You can use this file to add Xorg options which are not covered in the configuration file. +# +# Everything you put here will go to the "Device" section corresponding +# to the AMD GPU in the Xorg configuration. +# Lines starting with # are ignored. +# +# Example : +# +# Option "Backlight" "amdgpu_bl1" diff --git a/etc/optimus-manager/xorg-intel.conf b/etc/optimus-manager/xorg-intel.conf new file mode 100644 index 0000000..64dd8ca --- /dev/null +++ b/etc/optimus-manager/xorg-intel.conf @@ -0,0 +1,9 @@ +# You can use this file to add Xorg options which are not covered in the configuration file. +# +# Everything you put here will go to the "Device" section corresponding +# to the Intel GPU in the Xorg configuration. +# Lines starting with # are ignored. +# +# Example : +# +# Option "Backlight" "intel_backlight" diff --git a/etc/optimus-manager/xorg-nvidia.conf b/etc/optimus-manager/xorg-nvidia.conf new file mode 100644 index 0000000..1e2baa2 --- /dev/null +++ b/etc/optimus-manager/xorg-nvidia.conf @@ -0,0 +1,9 @@ +# You can use this file to add Xorg options which are not covered in the configuration file. +# +# Everything you put here will go to the "Device" section corresponding +# to the Nvidia GPU in the Xorg configuration. +# Lines starting with # are ignored. +# +# Example : +# +# Option "ConnectToAcpid" "0" diff --git a/etc/optimus-manager/xsetup-amd.sh b/etc/optimus-manager/xsetup-amd.sh new file mode 100755 index 0000000..e16479a --- /dev/null +++ b/etc/optimus-manager/xsetup-amd.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +# Everything you write here will be executed by the display manager when setting up the login screen in AMD mode. +#sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._OFF" > /proc/acpi/call' diff --git a/etc/optimus-manager/xsetup-intel.sh b/etc/optimus-manager/xsetup-intel.sh new file mode 100755 index 0000000..53f3c7f --- /dev/null +++ b/etc/optimus-manager/xsetup-intel.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +# Everything you write here will be executed by the display manager when setting up the login screen in Intel mode. diff --git a/etc/optimus-manager/xsetup-nvidia.sh b/etc/optimus-manager/xsetup-nvidia.sh new file mode 100755 index 0000000..b2860b4 --- /dev/null +++ b/etc/optimus-manager/xsetup-nvidia.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +# Everything you write here will be executed by the display manager when setting up the login screen in Nvidia mode. +# (but before optimus-manager sets up PRIME with xrandr commands). +#sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._ON" > /proc/acpi/call' diff --git a/gpuoff.sh b/gpuoff.sh index af7f889..1f335a8 100755 --- a/gpuoff.sh +++ b/gpuoff.sh @@ -1,7 +1,24 @@ #!/bin/bash -sudo rmmod nvidia_drm -sudo rmmod nvidia_modeset -sudo rmmod nvidia -sudo tee /proc/acpi/bbswitch << /sys/bus/pci/devices/0000:01:00.0/remove; echo '\\_SB.PCI0.PEG0.PEGP._OFF' > /proc/acpi/call" +#output=$(optimus-manager --print-mode) +#echo $output +if [ $(sudo -u cole 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 $(sudo cat /proc/acpi/call) + echo "GPU POWERED OFF" +fi +#if [ "$(optimus-manager --print-mode)" = " +# +#Current GPU mode : amd" ]; then +# sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._OFF" > /proc/acpi/call' +# echo $(sudo cat /proc/acpi/call) +# echo "GPU POWERED OFF" +#fi +#echo "script finished" diff --git a/gpuon.sh b/gpuon.sh index 995124e..6bbea35 100755 --- a/gpuon.sh +++ b/gpuon.sh @@ -4,4 +4,5 @@ #sudo rmmod nvidia #sudo tee /proc/acpi/bbswitch << /proc/acpi/call; echo 1 > /sys/bus/pci/rescan" +sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._ON" > /proc/acpi/call' +sleep 2 diff --git a/startvm b/startvm index 694e069..7aea276 100755 --- a/startvm +++ b/startvm @@ -1,8 +1,10 @@ #!/bin/bash -if [ `which-driver-for-gpu` == "nvidia" ]; then - sudo systemctl stop bumblebeed - sleep 1 - sudo bind 0000:01:00.0 0000:01:00.1 0000:01:00.2 0000:01:00.3 -fi +#export PATH=/bedrock/cross/pin/bin:/bedrock/bin:/usr/local/bin:/usr/local/sbin:/opt/bin:/opt/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/snap/bin:/bedrock/cross/bin:/home/cole/g14gpu +cd /home/cole/g14gpu +#if [ `which-driver-for-gpu` == "nvidia" ]; then +sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._ON" > /proc/acpi/call' +sleep 1 +sudo binddev 0000:01:00.0 0000:01:00.1 0000:01:00.2 0000:01:00.3 +#fi vm -#sudo unbind 0000:01:00.0 0000:01:00.1 0000:01:00.2 0000:01:00.3 +#sudo unbinddev 0000:01:00.0 0000:01:00.1 0000:01:00.2 0000:01:00.3 diff --git a/unbind b/unbinddev similarity index 64% rename from unbind rename to unbinddev index 0913655..a69069c 100755 --- a/unbind +++ b/unbinddev @@ -1,18 +1,20 @@ #!/bin/bash +#sudo rmmod vfio-pci for dev in "$@"; do vendor=$(cat /sys/bus/pci/devices/$dev/vendor) device=$(cat /sys/bus/pci/devices/$dev/device) echo "Removing ${dev} from vfio-pci id list" - echo "${vendor} ${device}" > /sys/bus/pci/drivers/vfio-pci/remove_id + echo "${vendor} ${device}" | sudo tee /sys/bus/pci/drivers/vfio-pci/remove_id sleep 0.1 echo "Remove PCI device" - echo 1 > /sys/bus/pci/devices/${dev}/remove + echo 1 | sudo tee /sys/bus/pci/devices/${dev}/remove while [[ -e "/sys/bus/pci/devices/${dev}" ]]; do sleep 0.1 done echo "Rescanning..." - echo 1 > /sys/bus/pci/rescan + echo 1 | sudo tee /sys/bus/pci/rescan while [[ ! -e "/sys/bus/pci/devices/${dev}" ]]; do sleep 0.1 done done +sudo rmmod vfio-pci diff --git a/vm b/vm index 7b40f34..b4fe0ca 100755 --- a/vm +++ b/vm @@ -38,12 +38,13 @@ echo "VM is off" echo "Freeing up memory" echo 0 | sudo tee /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages echo "Unbinding from vfio-pci" -sudo unbind 0000:01:00.0 0000:01:00.1 0000:01:00.2 0000:01:00.3 +unbinddev 0000:01:00.0 0000:01:00.1 0000:01:00.2 0000:01:00.3 sleep 1 echo "Enabling GPU power management" -sudo modprobe nvidia NVreg_DynamicPowerManagement=0x02 +#sudo modprobe nvidia NVreg_DynamicPowerManagement=0x02 +sudo sh -c 'echo "\\_SB.PCI0.GPP0.PG00._OFF" > /proc/acpi/call' sleep 2 -sudo systemctl start bumblebeed +#sudo systemctl start bumblebeed sudo systemctl stop smb nmb sleep 1 -clrgpu +#clrgpu