mirror of
https://github.com/QuixiAI/nvdriver.git
synced 2026-12-06 06:28:39 +00:00
* tools: reboot-free dev mode (dev_mode/dev_reload/dev_health) and udev rule Root-only nvdriver nodes so no desktop process pins nvidia_rs, a reload script that unbinds GPUs before rmmod, and a pre/post health gate. Adds the AGENTS.md personal-laptop override that allows no-reboot tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * tools: address review of dev mode scripts - dev_health: scan threads (ps -L) so a D-state non-leader thread is caught - dev_reload: keep module parameters as separate quoted words (no glob expansion) - dev_reload: restart nvidia-persistenced when a holder refuses the teardown - dev_reload: drop and rebind the /dev/nvidia* aliases around the reload - dev_reload: enumerate bound PCI devices of every domain Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * dev tools: drop personal override and invalid reload defaults - AGENTS.md: restore upstream text (the laptop reboot/rmmod override is local, not repo-wide) - dev_reload.sh: remove rm_api / experimental_r620_ada / dyndbg defaults (not parameters of this module) - dev_reload.sh: require NV_RS_DEV_RELOAD_BDF, refuse if nvidia_rs is bound to any other device Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
94 lines
4.3 KiB
Bash
Executable File
94 lines
4.3 KiB
Bash
Executable File
#!/bin/sh
|
|
# Replaces the loaded nvidia_rs with a fresh build, without a reboot.
|
|
#
|
|
# NV_RS_DEV_RELOAD_BDF=0000:01:00.0 sh tools/dev_reload.sh [path/to/nvidia_rs.ko] [extra module parameters...]
|
|
#
|
|
# NV_RS_DEV_RELOAD_BDF is required and names the only GPU this script may unbind; it also becomes
|
|
# pci_target. Nothing else is bound or reset. Extra parameters are passed to insmod as given
|
|
# (for example dyndbg=+p, which needs CONFIG_DYNAMIC_DEBUG).
|
|
#
|
|
# Needs development mode (tools/dev_mode.sh on): any process holding a node pins the module.
|
|
# The runtime thread keeps a module reference while a GPU is bound, so the script first
|
|
# unbinds the GPU from nvidia_rs (the driver's own remove/teardown path) and then rmmods.
|
|
# Only pci_target and runtime_engines are defaulted (modprobe.d is not read); pass overrides as
|
|
# arguments, with or without a leading module path.
|
|
# A wedged GSP-RM makes unbind/rmmod wait forever; the script then reports it and leaves
|
|
# the stuck command behind.
|
|
set -u
|
|
cd "$(dirname "$0")/.." || exit 2
|
|
# Opt-in: the reload unbinds a GPU from nvidia_rs, so it must be told which single device it may touch.
|
|
# On a multi-GPU or data-center host this script never runs unless that is set deliberately.
|
|
NV_RS_DEV_RELOAD_BDF=${NV_RS_DEV_RELOAD_BDF:-}
|
|
case "$NV_RS_DEV_RELOAD_BDF" in
|
|
*:*:*.*) ;;
|
|
*) echo "refusing: set NV_RS_DEV_RELOAD_BDF=<domain:bus:dev.fn> (the one GPU this reload may unbind)"; exit 2 ;;
|
|
esac
|
|
for d in /sys/bus/pci/drivers/nvidia_rs/*:*:*.*; do
|
|
[ -e "$d" ] || continue
|
|
[ "${d##*/}" = "$NV_RS_DEV_RELOAD_BDF" ] || { echo "refusing: nvidia_rs is also bound to ${d##*/}; only $NV_RS_DEV_RELOAD_BDF is allowed"; exit 2; }
|
|
done
|
|
KO=kernel-open/nvidia_rs.ko
|
|
# A leading name=value is a module parameter, not the module path.
|
|
case "${1:-}" in ""|*=*) ;; *) KO=$1; shift ;; esac
|
|
set -- "pci_target=$NV_RS_DEV_RELOAD_BDF" runtime_engines=1 "$@"
|
|
STAMP=$(date '+%Y-%m-%d %H:%M:%S')
|
|
|
|
[ -f "$KO" ] || { echo "missing $KO (make CONFIG_DEBUG_INFO_BTF_MODULES= modules)"; exit 2; }
|
|
sh tools/dev_health.sh pre || { echo "health check failed: no reload attempted"; exit 1; }
|
|
|
|
holders() {
|
|
for p in /proc/[0-9]*; do
|
|
if sudo ls -l "$p/fd" 2>/dev/null | grep -q 'nvidia-rs'; then
|
|
echo " ${p#/proc/} $(cat "$p/comm" 2>/dev/null)"
|
|
fi
|
|
done
|
|
}
|
|
|
|
REBIND=0
|
|
if [ -e /sys/module/nvidia_rs ]; then
|
|
PERSISTED=0
|
|
systemctl is-active --quiet nvidia-persistenced 2>/dev/null && PERSISTED=1
|
|
sudo systemctl stop nvidia-persistenced 2>/dev/null
|
|
H=$(holders)
|
|
if [ -n "$H" ]; then
|
|
echo "these processes hold nvidia_rs nodes; close them first:"
|
|
echo "$H"
|
|
# Nothing was torn down yet: put the service back.
|
|
[ "$PERSISTED" -eq 0 ] || sudo systemctl start nvidia-persistenced 2>/dev/null
|
|
exit 1
|
|
fi
|
|
# The standard-path aliases keep the old inodes across a reload; drop them now and rebind after insmod.
|
|
mountpoint -q /dev/nvidiactl 2>/dev/null && REBIND=1
|
|
sudo bash tools/bind_dev_nodes.sh --unbind
|
|
# Every PCI domain, not only 0000.
|
|
for d in /sys/bus/pci/drivers/nvidia_rs/*:*:*.*; do
|
|
[ -e "$d" ] || continue
|
|
echo "${d##*/}" | sudo tee /sys/bus/pci/drivers/nvidia_rs/unbind >/dev/null &
|
|
UNBIND=$!
|
|
i=0
|
|
while kill -0 "$UNBIND" 2>/dev/null && [ "$i" -lt 60 ]; do sleep 1; i=$((i + 1)); done
|
|
if kill -0 "$UNBIND" 2>/dev/null; then
|
|
echo "unbind of ${d##*/} has not returned after 60 s; not attempting rmmod or insmod."
|
|
sudo journalctl -k --no-pager --since "$STAMP" | tail -20
|
|
exit 1
|
|
fi
|
|
done
|
|
sudo rmmod nvidia_rs &
|
|
RMMOD=$!
|
|
i=0
|
|
while kill -0 "$RMMOD" 2>/dev/null && [ "$i" -lt 60 ]; do sleep 1; i=$((i + 1)); done
|
|
if kill -0 "$RMMOD" 2>/dev/null; then
|
|
echo "rmmod nvidia_rs has not returned after 60 s (GSP-RM did not stop)."
|
|
sudo journalctl -k --no-pager --since "$STAMP" | tail -20
|
|
exit 1
|
|
fi
|
|
[ -e /sys/module/nvidia_rs ] && { echo "nvidia_rs is still loaded"; exit 1; }
|
|
fi
|
|
|
|
sudo insmod "$KO" "$@" || { echo "insmod failed"; sudo journalctl -k --no-pager --since "$STAMP" | tail -30; exit 1; }
|
|
sudo udevadm settle
|
|
[ "$REBIND" -eq 0 ] || sudo bash tools/bind_dev_nodes.sh --bind
|
|
sudo journalctl -k --no-pager --since "$STAMP" -g 'nvidia_rs' | grep -v 'TRACE' | tail -40
|
|
ls -l /dev/nvidiactl /dev/nvidia0 /dev/nvidia-uvm 2>&1
|
|
sh tools/dev_health.sh post
|