Fix CPU core/frequency reading on Linux/SPARC systems (#1643)

This commit is contained in:
Koakuma 2021-06-11 14:42:46 +07:00 committed by GitHub
parent 07ae57453a
commit 70ad34e919
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2213,17 +2213,50 @@ get_cpu() {
speed="$((speed / 1000))"
else
case $kernel_machine in
"sparc"*)
# SPARC systems use a different file to expose clock speed information.
speed_file="/sys/devices/system/cpu/cpu0/clock_tick"
speed="$(($(< "$speed_file") / 1000000))"
;;
*)
speed="$(awk -F ': |\\.' '/cpu MHz|^clock/ {printf $2; exit}' "$cpu_file")"
speed="${speed/MHz}"
;;
esac
fi
# Get CPU temp.
[[ -f "$temp_dir" ]] && deg="$(($(< "$temp_dir") * 100 / 10000))"
# Get CPU cores.
case $kernel_machine in
"sparc"*)
case $cpu_cores in
"logical" | "on") cores="$(grep -c "^processor" "$cpu_file")" ;;
"physical") cores="$(awk '/^core id/&&!a[$0]++{++i} END {print i}' "$cpu_file")" ;;
# SPARC systems doesn't expose detailed topology information in
# /proc/cpuinfo so I have to use lscpu here.
"logical" | "on")
cores="$(lscpu | awk -F ': *' '/^CPU\(s\)/ {print $2}')"
;;
"physical")
cores="$(lscpu | awk -F ': *' '/^Core\(s\) per socket/ {print $2}')"
sockets="$(lscpu | awk -F ': *' '/^Socket\(s\)/ {print $2}')"
cores="$((sockets * cores))"
;;
esac
;;
*)
case $cpu_cores in
"logical" | "on")
cores="$(grep -c "^processor" "$cpu_file")"
;;
"physical")
cores="$(awk '/^core id/&&!a[$0]++{++i} END {print i}' "$cpu_file")"
;;
esac
;;
esac
;;