fix handling of M5 Pro and Max handling (#37)

This patch detects the clock speeds of the two different M5 Pro and Max
cores correctly. Without this fix only the "Super" core clock speed is
read.

I'm not entirely sure what to do with the weird trick Apple pulled with
M5 Pro and Max CPUs. There's still 2 tiers of cores, but instead of
being Performance and Efficiency, they're *Super* and Performance.

The route I chose was:

 * M5 Pro/Max Super Core => PCore
 * M5 Pro/Max Performance Core => ECore

This is based on the idea that the important thing is that there's 2
*tiers* of cores. What those tiers is called is up to marketing.

Sadly that's not entirely true as these cores do have architectural
differences. However I think for the purposes of this library it's
preferable to take advantage of the BIG.little high/low mapping to keep
the API stable. If consumers want to use specific architectural features
of various M cores, this library wouldn't suffice anyway.

Changes are 100% ai driven. This is my first time working on Apple
hardware and their system interfaces are a nightmare.
5 files changed
tree: 8b27af24aa6a01bf39d39001f098a3bb5820b4c6
  1. .github/
  2. .gitignore
  3. cpu.go
  4. cpu_test.go
  5. examples_test.go
  6. frequency.go
  7. frequency_test.go
  8. generation.go
  9. generation_test.go
  10. go.mod
  11. go.sum
  12. incompatible.go
  13. incompatible_test.go
  14. Justfile
  15. LICENSE
  16. README.md
README.md

m1cpu

Go Reference MPL License Run CI Tests

The go-m1cpu module is a library for inspecting Apple Silicon CPUs in Go.

Use the m1cpu Go package for looking up the CPU frequency for Apple Silicon M-series CPUs, M1 and later.

Install

go get github.com/shoenig/go-m1cpu@latest

CGO

This package requires the use of CGO.

Extracting the CPU properties is done via Apple's IOKit framework, which is accessible only through system C libraries.

Example

Simple Go program to print Apple Silicon CPU speeds.

package main

import (
	"fmt"

	"github.com/shoenig/go-m1cpu"
)

func main() {
	fmt.Println("Apple Silicon", m1cpu.IsAppleSilicon())

	fmt.Println("pCore GHz", m1cpu.PCoreGHz())
	fmt.Println("eCore GHz", m1cpu.ECoreGHz())

	fmt.Println("pCore Hz", m1cpu.PCoreHz())
	fmt.Println("eCore Hz", m1cpu.ECoreHz())
}

Using go test to print out available information.

➜ go test -v -run Show
=== RUN   Test_Show
    cpu_test.go:42: pCore Hz 3504000000
    cpu_test.go:43: eCore Hz 2424000000
    cpu_test.go:44: pCore GHz 3.504
    cpu_test.go:45: eCore GHz 2.424
    cpu_test.go:46: pCore count 8
    cpu_test.go:47: eCoreCount 4
    cpu_test.go:50: pCore Caches 196608 131072 16777216
    cpu_test.go:53: eCore Caches 131072 65536 4194304
--- PASS: Test_Show (0.00s)

License

Open source under the MPL