Files
TA-ProxMenu/inc/cpu-compat.inc
T
David Schroeder 8bd60e2f52 update
2026-07-29 17:17:56 -05:00

97 lines
2.8 KiB
Bash

#!/usr/bin/env bash
# Parse the per-node rows printed by ProxCLMC. Fields are separated with an
# ASCII unit separator so processor descriptions can safely contain spaces.
TAPM_PROXCLMC_HOST_ROWS() {
awk -F '|' '
function trim(value) {
gsub(/^[[:space:]]+|[[:space:]]+$/, "", value)
return value
}
{
node = trim($1)
address = trim($2)
level = trim($3)
if (node ~ /^[[:alnum:]_.-]+$/ && level ~ /^x86-64-v(1|2-AES|3|4)$/) {
printf "%s\034%s\034%s\n", node, address, level
}
}
'
}
# Produce a conservative generation label from the processor name exposed by
# Proxmox. Ambiguous products are described as a family instead of being given
# a potentially incorrect codename.
TAPM_CPU_GENERATION_FROM_NAME() {
local cpu_name="${1:-}"
local normalized
local generation=""
local model_number=""
normalized="$(printf '%s' "$cpu_name" | tr '[:upper:]' '[:lower:]')"
if [[ "$normalized" =~ xeon.*e5-[[:digit:]]+[[:space:]]+v([1-4]) ]]; then
generation="${BASH_REMATCH[1]}"
case "$generation" in
1) printf '%s\n' "Sandy Bridge-EP" ;;
2) printf '%s\n' "Ivy Bridge-EP" ;;
3) printf '%s\n' "Haswell-EP" ;;
4) printf '%s\n' "Broadwell-EP" ;;
esac
return 0
fi
if [[ "$normalized" =~ xeon.*(bronze|silver|gold|platinum)[[:space:]]+([[:digit:]]{4}) ]]; then
model_number="${BASH_REMATCH[2]}"
generation="${model_number:1:1}"
case "$generation" in
1) printf '%s\n' "1st Gen Xeon Scalable (Skylake-SP)" ;;
2) printf '%s\n' "2nd Gen Xeon Scalable (Cascade Lake)" ;;
3) printf '%s\n' "3rd Gen Xeon Scalable (Ice Lake)" ;;
4) printf '%s\n' "4th Gen Xeon Scalable (Sapphire Rapids)" ;;
5) printf '%s\n' "5th Gen Xeon Scalable (Emerald Rapids)" ;;
*) printf '%s\n' "Intel Xeon Scalable family" ;;
esac
return 0
fi
if [[ "$normalized" =~ epyc[[:space:]]+([[:digit:]]{4}) ]]; then
model_number="${BASH_REMATCH[1]}"
generation="${model_number:3:1}"
case "$generation" in
1) printf '%s\n' "1st Gen EPYC (Naples / Zen)" ;;
2) printf '%s\n' "2nd Gen EPYC (Rome / Zen 2)" ;;
3) printf '%s\n' "3rd Gen EPYC (Milan / Zen 3)" ;;
4) printf '%s\n' "4th Gen EPYC (Zen 4 family)" ;;
5) printf '%s\n' "5th Gen EPYC (Zen 5 family)" ;;
*) printf '%s\n' "AMD EPYC family" ;;
esac
return 0
fi
if [[ "$normalized" =~ core.*i[3579]-([[:digit:]]{4,5}) ]]; then
model_number="${BASH_REMATCH[1]}"
if (( ${#model_number} == 4 )); then
generation="${model_number:0:1}"
else
generation="${model_number:0:2}"
fi
printf '%s\n' "Intel Core Gen ${generation}"
return 0
fi
if [[ "$normalized" =~ ryzen.*[[:space:]]([[:digit:]]{4,5}) ]]; then
model_number="${BASH_REMATCH[1]}"
printf '%s\n' "AMD Ryzen ${model_number:0:1}000 family"
return 0
fi
case "$normalized" in
*intel*) printf '%s\n' "Intel generation unknown" ;;
*amd*) printf '%s\n' "AMD generation unknown" ;;
*) printf '%s\n' "Generation unknown" ;;
esac
}