forked from amoghmunikote/cmpunlocker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify.sh
More file actions
executable file
·147 lines (130 loc) · 4.8 KB
/
Copy pathverify.sh
File metadata and controls
executable file
·147 lines (130 loc) · 4.8 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
KVER="$(uname -r)"
INSTALL_MOD_DIR="/lib/modules/${KVER}/updates/cmpunlocker"
INVENTORY_FILE="${INSTALL_MOD_DIR}/gpu_inventory"
source "${SCRIPT_DIR}/common/lib.sh"
is_unlocked_memory() {
local profile="$1"
local mem_mib="$2"
[[ "${mem_mib}" =~ ^[0-9]+$ ]] || return 1
case "${profile}" in
8gb)
(( mem_mib >= 60000 )) && return 0
;;
10gb)
(( mem_mib >= 35000 && mem_mib < 60000 )) && return 0
;;
esac
return 1
}
is_stock_memory() {
local profile="$1"
local mem_mib="$2"
[[ "${mem_mib}" =~ ^[0-9]+$ ]] || return 1
case "${profile}" in
8gb)
(( mem_mib >= 7680 && mem_mib <= 8704 )) && return 0
;;
10gb)
(( mem_mib >= 9728 && mem_mib <= 10752 )) && return 0
;;
esac
return 1
}
banner
step_init 3
step "Locating GPU inventory"
command -v nvidia-smi &>/dev/null || die "nvidia-smi not found"
SMI_MEM_CACHE="$(nvidia-smi --query-gpu=pci.bus_id,memory.total --format=csv,noheader,nounits 2>/dev/null || true)"
[[ -n "${SMI_MEM_CACHE}" ]] || die "nvidia-smi returned no GPU memory data"
GPU_BDFS=()
GPU_DEVIDS=()
GPU_PROFILES=()
GPU_EXPECTED=()
if [[ -r "${INVENTORY_FILE}" ]] && [[ -s "${INVENTORY_FILE}" ]]; then
info "Using inventory: ${INVENTORY_FILE}"
while read -r bdf devid profile expected || [[ -n "${bdf:-}" ]]; do
[[ -n "${bdf:-}" ]] || continue
[[ "${bdf}" =~ ^# ]] && continue
GPU_BDFS+=("$(normalize_bus_id "${bdf}")")
GPU_DEVIDS+=("${devid}")
GPU_PROFILES+=("${profile}")
GPU_EXPECTED+=("${expected}")
done < "${INVENTORY_FILE}"
else
info "No installed gpu_inventory; enumerating via lspci"
mapfile -t PCI_LINES < <(lspci -nn 2>/dev/null | grep -iE '10de:20c2|10de:2082' || true)
[[ ${#PCI_LINES[@]} -gt 0 ]] || die "No unlockable CMP 170HX GPU found (10de:20c2 / 10de:2082)"
for PCI_LINE in "${PCI_LINES[@]}"; do
PCI="$(echo "${PCI_LINE}" | awk '{print $1}')"
PCI_FULL="$(normalize_bus_id "${PCI}")"
DEVID="$(echo "${PCI_LINE}" | grep -oE '10de:[0-9a-fA-F]{4}' | head -1 | cut -d: -f2 | tr '[:upper:]' '[:lower:]')"
PROF="$(profile_from_devid "${DEVID}")"
[[ "${PROF}" != "unsupported" ]] || continue
EXP="$(expected_mib_for_profile "${PROF}")"
GPU_BDFS+=("${PCI_FULL}")
GPU_DEVIDS+=("${DEVID}")
GPU_PROFILES+=("${PROF}")
GPU_EXPECTED+=("${EXP}")
done
fi
[[ ${#GPU_BDFS[@]} -gt 0 ]] || die "No unlockable GPUs to verify"
step "Checking memory unlock status"
failures=0
printf "\n%-16s %-8s %-8s %-12s %-12s %s\n" "BDF" "PCI ID" "Variant" "Expect" "Actual" "Status"
for i in "${!GPU_BDFS[@]}"; do
bdf="${GPU_BDFS[$i]}"
devid="${GPU_DEVIDS[$i]}"
profile="${GPU_PROFILES[$i]}"
expected="${GPU_EXPECTED[$i]}"
actual="$(smi_memory_for_bus "${bdf}" || true)"
[[ -n "${actual}" ]] || actual="?"
status="FAIL"
if is_unlocked_memory "${profile}" "${actual}"; then
status="OK"
ok "${bdf}: ${actual} MiB (unlocked ${profile})"
elif is_stock_memory "${profile}" "${actual}"; then
status="STOCK"
err "${bdf}: still stock ${actual} MiB (expect ~${expected})"
failures=$((failures + 1))
elif [[ "${actual}" == "?" ]]; then
status="MISSING"
err "${bdf}: not found in nvidia-smi"
failures=$((failures + 1))
else
status="UNEXPECTED"
err "${bdf}: unexpected ${actual} MiB (expect ~${expected} for ${profile})"
failures=$((failures + 1))
fi
printf "%-16s %-8s %-8s ~%-11s %-12s %s\n" "${bdf}" "${devid}" "${profile}" "${expected}" "${actual}" "${status}"
done
step "Checking unlock logs and installed profile"
sec2_logs="$(dmesg 2>/dev/null | grep 'SEC2_DEBUG' || true)"
if [[ -n "${sec2_logs}" ]]; then
ok "dmesg contains SEC2_DEBUG unlock logs"
info "Sample:"
printf '%s\n' "${sec2_logs}" | tail -n 8 | sed 's/^/ /'
else
warn "No SEC2_DEBUG lines in dmesg (logs may have rotated; unlock can still be OK if memory is unlocked)"
fi
echo ""
if [[ -r "${INSTALL_MOD_DIR}/card_profile" ]]; then
info "Installed profile: $(cat "${INSTALL_MOD_DIR}/card_profile") / geometry: $(cat "${INSTALL_MOD_DIR}/unlock_geometry" 2>/dev/null || echo '?')"
fi
if (( failures > 0 )); then
echo ""
die "${failures} GPU(s) failed unlock verification. Cold reboot if modules were just installed."
fi
echo ""
ok "All ${#GPU_BDFS[@]} unlockable GPU(s) report unlocked memory"
if [[ -x "${SCRIPT_DIR}/tools/service.sh" ]]; then
echo ""
info "Checking negotiated PCIe generation"
if ! "${SCRIPT_DIR}/tools/service.sh" verify; then
warn "Memory unlock is healthy, but PCIe Gen2 is not active"
exit 1
fi
fi
exit 0