commit | 32788e5e6e5811f58b1cd5d8c57e942501114a4c | [log] [tgz] |
---|---|---|
author | Ruoyu Zhong <zhongruoyu@outlook.com> | Wed Apr 05 06:55:20 2023 +0800 |
committer | GitHub <noreply@github.com> | Tue Apr 04 17:55:20 2023 -0500 |
tree | c39909f52b558e49da4adcfc04170f83c4ac9c6b | |
parent | d0606a03406c5269ba5819145b55f017a1392eda [diff] |
m1cpu: handle `kIOMainPortDefault` for macOS < 12 (#6) `kIOMainPortDefault` was renamed from `kIOMasterPortDefault` in macOS Monterey. This patch makes sure m1cpu can be built on Big Sur, too. Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
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 M1 and M2 CPUs.
go get github.com/shoenig/go-m1cpu@latest
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.
Simple Go program to print Apple Silicon M1/M2 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)
Open source under the MPL