Skip to content

Commit

Permalink
config_cpu: use lscpu for identifying CPU information
Browse files Browse the repository at this point in the history
On arm64 we don't have the CPU information in /proc/cpuinfo as expected
by our config_cpu, so its output is broken:

| # awk -F: '/^processor/{printf "        Processor"$2" is"};/^model name/{printf $2};/^vendor_id/{printf vendor};/^cpu MHz/{printf " %dMHz",int($2)};/^cache size/{printf ","$2" Cache"};/^$/{print ""}' /proc/cpuinfo
|         Processor 0 is
|         Processor 1 is
| [...]
|         Processor 13 is
|         Processor 14 is
|         Processor 15 is

FTR:

| # head /proc/cpuinfo
| processor       : 0
| BogoMIPS        : 50.00
| Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp ssbs
| CPU implementer : 0x41
| CPU architecture: 8
| CPU variant     : 0x3
| CPU part        : 0xd0c
| CPU revision    : 1
|
| processor       : 1

While with lspcu we get the information we're interested in:

| # lscpu | grep 'Model name:'
| Model name:                      Neoverse-N1
| BIOS Model name:                 virt-5.2  CPU @ 2.0GHz

So instead of having some hackish /proc/cpuinfo parsing, let's rely on
util-linux's lscpu(1).

While at it, let's output only the number of present CPUs instead of
listing every single one of them, given that there exist systems with
>100 CPUs nowadays. :)

Thanks: Christopher Bock and András Korn for feedback
  • Loading branch information
mika committed Sep 8, 2023
1 parent bd414ee commit 74eef77
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions autoconfig.functions
Original file line number Diff line number Diff line change
Expand Up @@ -905,19 +905,23 @@ fi # -z $INSTALLED

# {{{ CPU-detection
config_cpu(){
if checkbootparam 'nocpu'; then
ewarn "Skipping CPU detection as requested on boot commandline." ; eend 0
return 0
fi
if checkbootparam 'nocpu'; then
ewarn "Skipping CPU detection as requested on boot commandline." ; eend 0
return 0
fi

if [[ $(grep -c processor /proc/cpuinfo) -gt 1 ]] ; then
einfo "Found CPU:"
CPU=$(awk -F: '/^processor/{printf " Processor"$2" is"};/^model name/{printf $2};/^vendor_id/{printf vendor};/^cpu MHz/{printf " %dMHz",int($2)};/^cache size/{printf ","$2" Cache"};/^$/{print ""}' /proc/cpuinfo 2>>$DEBUG)
echo $CPU | sed 's/ \{1,\}/ /g'
eend 0
else
einfo "Found CPU: `awk -F: '/^processor/{printf " Processor"$2" is"};/^model name/{printf $2};/^vendor_id/{printf vendor};/^cpu MHz/{printf " %dMHz",int($2)};/^cache size/{printf ","$2" Cache"};/^$/{print ""}' /proc/cpuinfo 2>>$DEBUG` " ; eend 0
fi
if ! [ -x "$(which lscpu)" ] ; then
ewarn "Skipping CPU detection due to lack of lscpu."; eend 0
return 0
fi

local cpu_info num_cpus

cpu_info="$(lscpu | sed -n '/^Model name:/s/[^:]*:\s*//p')"
num_cpus=$(grep -c processor /proc/cpuinfo)

einfo "Found ${num_cpus} CPU(s): ${cpu_info}"
eend 0
}
# }}}

Expand Down

0 comments on commit 74eef77

Please sign in to comment.