From d2932dbcbe1e8d98754dc34620e122adf6f39c97 Mon Sep 17 00:00:00 2001 From: Lou MassKonFuzion Herard <6656037+masskonfuzion@users.noreply.github.com> Date: Wed, 21 Aug 2019 01:58:13 -0500 Subject: [PATCH] Replace sleep BUS_RESCAN_WAIT_SEC with lspci-based GPU check; tweak MODULES_LOAD in config --- config/nvidia-xrun | 11 +++++++---- nvidia-xrun | 25 +++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/config/nvidia-xrun b/config/nvidia-xrun index c13363e..a241bc1 100644 --- a/config/nvidia-xrun +++ b/config/nvidia-xrun @@ -19,11 +19,14 @@ CONTROLLER_BUS_ID=0000:00:01.0 # Bus ID of the graphic card DEVICE_BUS_ID=0000:01:00.0 -# Seconds to wait before turning on the card after PCI devices rescan -BUS_RESCAN_WAIT_SEC=1 - # Ordered list of modules to load before running the command -MODULES_LOAD=(nvidia nvidia_uvm nvidia_modeset "nvidia_drm modeset=1") +# >>>>> ORIGINAL +#MODULES_LOAD=(nvidia nvidia_uvm nvidia_modeset "nvidia_drm modeset=1") + +# >>>>> MASSKONFUZION: "nvidia_drm modeset=1" seems to cause sporadic general +# protection faults on my machine. At a minimum, perhaps the "modeset=1" +# option can be documented as a parameter to tweak? +MODULES_LOAD=(nvidia nvidia_uvm nvidia_modeset nvidia_drm) # Ordered list of modules to unload after the command exits MODULES_UNLOAD=(nvidia_drm nvidia_modeset nvidia_uvm nvidia) diff --git a/nvidia-xrun b/nvidia-xrun index 56d9855..ae5d602 100755 --- a/nvidia-xrun +++ b/nvidia-xrun @@ -41,8 +41,27 @@ function turn_on_gpu { if [[ ! -d /sys/bus/pci/devices/${DEVICE_BUS_ID} ]]; then echo 'Rescanning PCI devices' execute "sudo tee /sys/bus/pci/rescan <<<1" - echo "Waiting ${BUS_RESCAN_WAIT_SEC} second for rescan" - execute "sleep ${BUS_RESCAN_WAIT_SEC}" + + # >>>>> MASSKONFUZION: This comment for review; feel free to delete: + # This change proposes to do away with BUS_RESCAN_WAIT_SEC, in favor of + # waiting for the NVIDIA GPU to appear in lspci. The code, as written, + # assumes the GPU will appear. But perhaps a more robust solution (not + # implemented as of yet) would be to fail if the GPU does not appear + # after a given timeout interval. + if [[ ${DRY_RUN} -eq 1 ]]; then + echo '>> Dry run. Waiting for NVIDIA video device' + else + echo 'Waiting for NVIDIA video device' + RESULT="1" + while [[ ${RESULT} -ne 0 ]]; do + echo -n '.' + lspci | grep -v Audio | grep NVIDIA > /dev/null + RESULT=$? + sleep 1 + done + echo 'Woo-hoo! Got it :fist pump:' + lspci | grep -v Audio | grep NVIDIA + fi fi echo 'Turning the card on' @@ -54,6 +73,7 @@ function load_modules { do echo "Loading module ${module}" execute "sudo modprobe ${module}" + sleep 1 done } @@ -62,6 +82,7 @@ function unload_modules { do echo "Unloading module ${module}" execute "sudo modprobe -r ${module}" + sleep 1 done }