Add CPU family for Apple’s M1 SoC

According to reports, XNU’s CPU family identifier previously used for
the Westmere family (which Homebrew mislabels as the Arrandale family)
is now being reused for one of Apple’s M1 SoC models.

Resolve the conflict by splitting the list of CPU families and adding a
microarchitecture check.

Sources for the values:

- https://github.com/Homebrew/brew/issues/7857#issuecomment-728739049
- https://en.wikipedia.org/wiki/Comparison_of_ARMv8-A_cores
- Direct messages
This commit is contained in:
Claudia 2020-11-17 09:34:00 +01:00
parent de1afcbfc5
commit 2a197af076
No known key found for this signature in database
GPG Key ID: 246AC3C0F10BE51F
2 changed files with 70 additions and 27 deletions

View File

@ -22,33 +22,10 @@ module Hardware
end end
def family def family
case sysctl_int("hw.cpufamily") if arm?
when 0x73d67300 # Yonah: Core Solo/Duo arm_family
:core elsif intel?
when 0x426f69ef # Merom: Core 2 Duo intel_family
:core2
when 0x78ea4fbc # Penryn
:penryn
when 0x6b5a4cd2 # Nehalem
:nehalem
when 0x573B5EEC # Arrandale
:arrandale
when 0x5490B78C # Sandy Bridge
:sandybridge
when 0x1F65E835 # Ivy Bridge
:ivybridge
when 0x10B282DC # Haswell
:haswell
when 0x582ed09c # Broadwell
:broadwell
when 0x37fc219f # Skylake
:skylake
when 0x0f817246 # Kaby Lake
:kabylake
when 0x38435547 # Ice Lake
:icelake
when 0x07d34b9f # ARMv8.3-A (Vortex, Tempest)
:arm_vortex_tempest
else else
:dunno :dunno
end end
@ -124,6 +101,48 @@ module Hardware
private private
def arm_family
case sysctl_int("hw.cpufamily")
when 0x07d34b9f # ARMv8.3-A (Vortex, Tempest)
:arm_vortex_tempest
when 0x573b5eec, 0x1b588bb3 # ARMv8.4-A (Firestorm, Icestorm)
:arm_firestorm_icestorm
else
:dunno
end
end
def intel_family
case sysctl_int("hw.cpufamily")
when 0x73d67300 # Yonah: Core Solo/Duo
:core
when 0x426f69ef # Merom: Core 2 Duo
:core2
when 0x78ea4fbc # Penryn
:penryn
when 0x6b5a4cd2 # Nehalem
:nehalem
when 0x573b5eec # Arrandale
:arrandale
when 0x5490b78c # Sandy Bridge
:sandybridge
when 0x1f65e835 # Ivy Bridge
:ivybridge
when 0x10b282dc # Haswell
:haswell
when 0x582ed09c # Broadwell
:broadwell
when 0x37fc219f # Skylake
:skylake
when 0x0f817246 # Kaby Lake
:kabylake
when 0x38435547 # Ice Lake
:icelake
else
:dunno
end
end
def sysctl_bool(key) def sysctl_bool(key)
sysctl_int(key) == 1 sysctl_int(key) == 1
end end

View File

@ -22,6 +22,7 @@ describe Hardware::CPU do
describe "::family" do describe "::family" do
let(:cpu_families) { let(:cpu_families) {
[ [
:arm_firestorm_icestorm,
:arm_vortex_tempest, :arm_vortex_tempest,
:arrandale, :arrandale,
:atom, :atom,
@ -48,5 +49,28 @@ describe Hardware::CPU do
it "returns the current CPU's family name as a symbol, or :dunno if it cannot be detected" do it "returns the current CPU's family name as a symbol, or :dunno if it cannot be detected" do
expect(cpu_families).to include described_class.family expect(cpu_families).to include described_class.family
end end
context "when hw.cpufamily is 0x573b5eec on a Mac", :needs_macos do
before do
allow(described_class)
.to receive(:sysctl_int)
.with("hw.cpufamily")
.and_return(0x573b5eec)
end
it "returns :arm_firestorm_icestorm on ARM" do
allow(described_class).to receive(:arm?).and_return(true)
allow(described_class).to receive(:intel?).and_return(false)
expect(described_class.family).to eq(:arm_firestorm_icestorm)
end
it "returns :westmere on Intel" do
allow(described_class).to receive(:arm?).and_return(false)
allow(described_class).to receive(:intel?).and_return(true)
expect(described_class.family).to eq(:westmere)
end
end
end end
end end