Skip to content

Commit 54fe54d

Browse files
committed
getCpuInfo: Add support for arm64
As the content of /proc/cpuinfo for arm64 is different from x86, which the current getCpuInfo implementation based on, the getCpuInfo function is basically deficient for arm64. Refer to the id definitions in linux kernel header file for arm64 cpu, Convert the corresponding parsing fileds(like 'Features' vs 'flags') and add the vendor id translation to support getCpuInfo for arm64. The code logic of the non-arm64 architecture remains unchanged. Arm64 cpu vender id References: Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/include/asm/cputype.h?h=v6.13-rc5 Signed-off-by: Zengkai163 <[email protected]>
1 parent 3c0715b commit 54fe54d

File tree

1 file changed

+163
-10
lines changed

1 file changed

+163
-10
lines changed

UnixBench/Run

Lines changed: 163 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ use FindBin;
5858
# 2007.10.14 IS Set and report LANG. Added "grep" and "sysexec".
5959
# 2007.12.22 IS Tiny fixes; see README.
6060
# 2011.01.13 KDL Fix for parallel compilation.
61+
# 2025.01.02 ZZK Improve getCpuInfo() function for arm64 CPUs.
6162

6263

6364
############################################################################
@@ -512,6 +513,115 @@ my $x86CpuFlags = {
512513
'svm' => "AMD virtualization",
513514
};
514515

516+
my $armCpuImplementers = {
517+
'0x41' => "ARM",
518+
'0x42' => "Broadcom",
519+
'0x43' => "Cavium",
520+
'0x46' => "FUJITSU",
521+
'0x48' => "HiSilicon",
522+
'0x4e' => "NVIDIA",
523+
'0x50' => "APM",
524+
'0x51' => "Qualcomm",
525+
'0x61' => "Apple",
526+
'0x6d' => "Microsoft",
527+
'0xc0' => "Ampere",
528+
};
529+
530+
my $armCpuParts = {
531+
"ARM" => {
532+
"0xd00" => "Foundation",
533+
"0xd03" => "Cortex-A53",
534+
"0xd04" => "Cortex-A35",
535+
"0xd05" => "Cortex-A55",
536+
"0xd07" => "Cortex-A57",
537+
"0xd08" => "Cortex-A72",
538+
"0xd09" => "Cortex-A73",
539+
"0xd0a" => "Cortex-A75",
540+
"0xd0b" => "Cortex-A76",
541+
"0xd0c" => "Neoverse-N1",
542+
"0xd0d" => "Cortex-A77",
543+
"0xd0f" => "AEMv8",
544+
"0xd40" => "Neoverse-V1",
545+
"0xd41" => "Cortex-A78",
546+
"0xd42" => "Cortex-A78AE",
547+
"0xd44" => "Cortex-X1",
548+
"0xd46" => "Cortex-A510",
549+
"0xd47" => "Cortex-A710",
550+
"0xd48" => "Cortex-X2",
551+
"0xd49" => "Neoverse-N2",
552+
"0xd4b" => "Cortex-A78C",
553+
"0xd4c" => "Cortex-X1C",
554+
"0xd4d" => "Cortex-A715",
555+
"0xd4e" => "Cortex-X3",
556+
"0xd4f" => "Neoverse-V2",
557+
"0xd80" => "Cortex-A520",
558+
"0xd81" => "Cortex-A720",
559+
"0xd82" => "Cortex-X4",
560+
"0xd84" => "Neoverse-V3",
561+
"0xd85" => "Cortex-X925",
562+
"0xd87" => "Cortex-A725",
563+
"0xd8e" => "Neoverse-N3",
564+
},
565+
"APM" => {
566+
"0x000" => "X-Gene",
567+
},
568+
"Cavium" => {
569+
"0x0a1" => "ThunderX",
570+
"0x0a2" => "ThunderX-81XX",
571+
"0x0a3" => "ThunderX-83XX",
572+
"0x0af" => "ThunderX2",
573+
"0x0b1" => "OcteonTX2-98XX",
574+
"0x0b2" => "OcteonTX2-96XX",
575+
"0x0b3" => "OcteonTX2-95XX",
576+
"0x0b4" => "OcteonTX2-95XXN",
577+
"0x0b5" => "OcteonTX2-95XXMM",
578+
"0x0b6" => "OcteonTX2-95XXO",
579+
},
580+
"Broadcom" => {
581+
"0x100" => "Brahma-B53",
582+
"0x516" => "Vulcan",
583+
},
584+
"Qualcomm" => {
585+
"0x200" => "Kryo",
586+
"0xc00" => "Falkor",
587+
"0x800" => "Falkor-V1/Kryo-2XX-Gold",
588+
"0x801" => "Kryo-2XX-Silver",
589+
"0x803" => "Kryo-3XX-Silver",
590+
"0x804" => "Kryo-4XX-Gold",
591+
"0x805" => "Kryo-4XX-Silver",
592+
},
593+
"NVIDIA" => {
594+
"0x003" => "Denver",
595+
"0x004" => "Carmel",
596+
},
597+
"FUJITSU" => {
598+
"0x001" => "A64FX",
599+
},
600+
"HiSilicon" => {
601+
"0xd01" => "TaiShan-v110",
602+
},
603+
"Apple" => {
604+
"0x022" => "Icestorm-M1",
605+
"0x023" => "Firestorm-M1",
606+
"0x024" => "Icestorm-M1-Pro",
607+
"0x025" => "Firestorm-M1-Pro",
608+
"0x028" => "Icestorm-M1-Max",
609+
"0x029" => "Firestorm-M1-Max",
610+
"0x032" => "Blizzard-M2",
611+
"0x033" => "Avalanche-M2",
612+
"0x034" => "Blizzard-M2-Pro",
613+
"0x035" => "Avalanche-M2-Pro",
614+
"0x038" => "Blizzard-M2-Max",
615+
"0x039" => "Avalanche-M2-Max",
616+
},
617+
"Ampere" => {
618+
"0xac3" => "Ampere-1",
619+
"0xac4" => "Ampere-1a",
620+
},
621+
"Microsoft" => {
622+
"0xd49" => "Azure-Cobalt-100",
623+
},
624+
};
515625

516626
############################################################################
517627
# UTILITIES
@@ -675,6 +785,26 @@ sub mergeParams {
675785
# SYSTEM ANALYSIS
676786
############################################################################
677787

788+
sub parseArmCpuImplementer {
789+
my ( $implementerIdStr ) = @_;
790+
my $CpuImplementer = $armCpuImplementers->{$implementerIdStr};
791+
if (defined($CpuImplementer)) {
792+
$CpuImplementer;
793+
} else {
794+
"CPU implementer $implementerIdStr";
795+
}
796+
}
797+
798+
sub parseArmCpuPart {
799+
my ( $implementerIdStr, $partIdStr ) = @_;
800+
my $CpuPart = $armCpuParts->{$implementerIdStr}->{$partIdStr};
801+
if (defined($CpuPart)) {
802+
$CpuPart;
803+
} else {
804+
"CPU part $partIdStr";
805+
}
806+
}
807+
678808
# Extract interesting flags from the given processor flags string and
679809
# convert them to descriptive names.
680810
sub processCpuFlags {
@@ -698,25 +828,48 @@ sub processCpuFlags {
698828
# future: on systems without /proc/cpuinfo, might check for Perl modules:
699829
# Sys::Info::Device::CPU or Sys::CpuAffinity
700830
sub getCpuInfo {
831+
my $mach = $^O ne "aix"
832+
? getCmdOutput("uname -m")
833+
: getCmdOutput("uname -p");
834+
701835
if (!("$^O" eq "darwin")) {
702836
open(my $fd, "<", "/proc/cpuinfo") || return undef;
703837

704838
my $cpus = [ ];
705839
my $cpu = 0;
840+
my $armCpuImplementer="";
706841
while (<$fd>) {
707842
chomp;
708843
my ( $field, $val ) = split(/[ \t]*:[ \t]*/);
709844
next if (!$field || !$val);
710-
if ($field eq "processor") {
711-
$cpu = $val;
712-
} elsif ($field eq "model name") {
713-
my $model = $val;
714-
$model =~ s/ +/ /g;
715-
$cpus->[$cpu]{'model'} = $model;
716-
} elsif ($field eq "bogomips" || $field eq "BogoMIPS") {
717-
$cpus->[$cpu]{'bogo'} = $val;
718-
} elsif ($field eq "flags") {
719-
$cpus->[$cpu]{'flags'} = processCpuFlags($val);
845+
if ($mach eq "aarch64") {
846+
if ($field eq "processor") {
847+
$cpu = $val;
848+
} elsif ($field eq "CPU implementer") {
849+
my $model = $val;
850+
$model =~ s/ +/ /g;
851+
$armCpuImplementer = parseArmCpuImplementer($model);
852+
$cpus->[$cpu]{'model'} = $armCpuImplementer;
853+
} elsif ($field eq "CPU part" && $armCpuImplementer ne "") {
854+
my $armCpuPart = parseArmCpuPart($armCpuImplementer, $val);
855+
$cpus->[$cpu]{'model'} = "$armCpuImplementer $armCpuPart";
856+
} elsif ($field eq "BogoMIPS") {
857+
$cpus->[$cpu]{'bogo'} = $val;
858+
} elsif ($field eq "Features") {
859+
$cpus->[$cpu]{'flags'} = "CPU Features: $val";
860+
}
861+
} else {
862+
if ($field eq "processor") {
863+
$cpu = $val;
864+
} elsif ($field eq "model name") {
865+
my $model = $val;
866+
$model =~ s/ +/ /g;
867+
$cpus->[$cpu]{'model'} = $model;
868+
} elsif ($field eq "bogomips" || $field eq "BogoMIPS") {
869+
$cpus->[$cpu]{'bogo'} = $val;
870+
} elsif ($field eq "flags") {
871+
$cpus->[$cpu]{'flags'} = processCpuFlags($val);
872+
}
720873
}
721874
}
722875

0 commit comments

Comments
 (0)