Report a CPU model on ARM boards (Raspberry Pi 5 and others)
x86's /proc/cpuinfo has a per-core "model name" line; most 64-bit ARM kernels don't. Raspberry Pi's kernel instead puts a single friendly "Model" line at the end of /proc/cpuinfo (e.g. "Raspberry Pi 5 Model B Rev 1.0"), and /proc/device-tree/model has the same string on any device-tree-based board as a further fallback if even that's missing. Try each in turn, matching real Pi 5 /proc/cpuinfo formatting. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ae41a02864
commit
1a054d6c2f
1 file changed
+12
-4
@@ -191,10 +191,18 @@ collect_system_info() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local cpu_model="" cpu_cores=0 cpu_load_percent="null"
|
local cpu_model="" cpu_cores=0 cpu_load_percent="null"
|
||||||
# Some ARM kernels (e.g. Raspberry Pi) have no "model name" line in
|
# x86 /proc/cpuinfo has a per-core "model name" line. Most 64-bit ARM
|
||||||
# /proc/cpuinfo at all — grep then finds no match and exits 1, which is not
|
# kernels (Raspberry Pi included) don't — they instead have a single
|
||||||
# a real error here, just an absent field.
|
# "Model" line at the very end, or nothing at all, in which case
|
||||||
cpu_model=$(grep -m1 "model name" /proc/cpuinfo 2>/dev/null | cut -d: -f2- | sed 's/^ *//' || true)
|
# /proc/device-tree/model (present on any device-tree/SBC board) has the
|
||||||
|
# board's friendly name. Try each in turn; leave blank if none exist.
|
||||||
|
cpu_model=$(grep -m1 "^model name" /proc/cpuinfo 2>/dev/null | cut -d: -f2- | sed 's/^ *//' || true)
|
||||||
|
if [[ -z "$cpu_model" ]]; then
|
||||||
|
cpu_model=$(grep -m1 "^Model" /proc/cpuinfo 2>/dev/null | cut -d: -f2- | sed 's/^ *//' || true)
|
||||||
|
fi
|
||||||
|
if [[ -z "$cpu_model" && -r /proc/device-tree/model ]]; then
|
||||||
|
cpu_model=$(tr -d '\0' < /proc/device-tree/model 2>/dev/null || true)
|
||||||
|
fi
|
||||||
cpu_cores=$(nproc 2>/dev/null || echo 0)
|
cpu_cores=$(nproc 2>/dev/null || echo 0)
|
||||||
if [[ -r /proc/loadavg && "$cpu_cores" -gt 0 ]]; then
|
if [[ -r /proc/loadavg && "$cpu_cores" -gt 0 ]]; then
|
||||||
local load1
|
local load1
|
||||||
|
|||||||
Reference in new issue
Block a user