-
Notifications
You must be signed in to change notification settings - Fork 1
/
nv-xrun.sh
executable file
·103 lines (81 loc) · 2.21 KB
/
nv-xrun.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
DRY_RUN=0
function execute {
if [ ${DRY_RUN} -eq 1 ]
then
echo ">>Dry run. Command: $*"
else
eval $*
fi
}
# calculate current VT
LVT=`fgconsole`
# calculate first usable display
XNUM="-1"
SOCK="something"
while [ ! -z "$SOCK" ]
do
XNUM=$(( $XNUM + 1 ))
SOCK=$(ls -A -1 /tmp/.X11-unix | grep "X$XNUM" )
done
NEWDISP=":$XNUM"
if [ ! -z "$*" ] # generate exec line if arguments are given
then
# test if executable exists in path
if [ -x "$(which $1 2> /dev/null)" ]
then
# generate exec line
EXECL="$(which $1)"
# test if executable exists on disk
elif [ -e "$(realpath "$1")" ]
then
# generate exec line
EXECL="$(realpath "$1")"
else
echo "$1: No such executable!"
exit 1
fi
shift 1
EXECL="$EXECL $*"
else # prepare to start new X sessions if no arguments passed
EXECL=""
fi
#EXECL="/etc/X11/xinit/nvidia-xinitrc $EXECL"
COMMAND="xinit $EXECL -- $NEWDISP vt$LVT -nolisten tcp -br" # -config nvidia-xorg.conf -configdir nvidia-xorg.conf.d"
# --------- TURNING ON GPU -----------
echo 'Waking up nvidia GPU'
execute "sudo /root/gpu-ctl n"
sleep 1
execute "sudo /root/gpu-ctl s"
echo "Rescan PCI devices"
execute "echo 1 | sudo tee /sys/bus/pci/rescan"
sleep 1
execute "sudo lspci | grep VGA"
# ---------- LOADING MODULES ----------
echo 'Loading nvidia module'
execute "sudo modprobe nvidia"
echo 'Loading nvidia_uvm module'
execute "sudo modprobe nvidia_uvm"
echo 'Loading nvidia_modeset module'
execute "sudo modprobe nvidia_modeset"
echo 'Loading nvidia_drm module'
execute "sudo modprobe nvidia_drm"
echo "Switch gmux to Nvidia GPU"
execute "sudo /root/gpu-ctl d"
# ---------- EXECUTING COMMAND --------
execute ${COMMAND}
# ---------- UNLOADING MODULES --------
echo 'Unloading nvidia_drm module'
execute "sudo rmmod nvidia_drm"
echo 'Unloading nvidia_modeset module'
execute "sudo rmmod nvidia_modeset"
echo 'Unloading nvidia_uvm module'
execute "sudo rmmod nvidia_uvm"
echo 'Unloading nvidia module'
execute "sudo rmmod nvidia"
# --------- TURNING OFF GPU ----------
echo 'Turning off nvidia GPU'
execute "echo 1 | sudo tee /sys/bus/pci/devices/0000:01:00.0/remove"
execute "sudo /root/gpu-ctl f"
echo "Switch gmux to Intel GPU"
execute "sudo /root/gpu-ctl i"