You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gopsutil/cpu
Seth Hoenig 8617ff654a cpu: add frequency support for apple silicon m1/m2 cpus
This PR adds support for reading the frequency of Apple Silicon
M1/M2 CPUs. We do so by reading the values out of the IOKit
framework, as a few other projects have now demonstrated to be
possible. This requires the use of CGO. The library provides a
convenience IsAppleSilicon() guard to detect whether the values
can be read.

Currently gopsutil does not support the big.LITTLE CPU architectures
(i think?) - in fact the P and E cores have different max frequencies.
For now, just read the P core frequency. The E core data is readily
available if we want to read it in the future.

Closes #1000

Small example program

```go
package main

import (
        "fmt"

        "github.com/shoenig/go-m1cpu"

        "github.com/shirou/gopsutil/v3/cpu"
)

func main() {
        fmt.Println("is Apple Silicon:", m1cpu.IsAppleSilicon())
        fmt.Println("model name", m1cpu.ModelName())
        fmt.Println("pCore GHz", m1cpu.PCoreGHz())
        fmt.Println("eCore GHz", m1cpu.ECoreGHz())
        fmt.Println("pCore Hz", m1cpu.PCoreHz())
        fmt.Println("eCore Hz", m1cpu.ECoreHz())

        fmt.Println("----- gopsutil ----")

        infos, err := cpu.Info()
        if err != nil {
                panic(err)
        }

        for _, info := range infos {
                fmt.Println("info.Mhz", info.Mhz)
        }
}
```

```shell
go run main.go
is Apple Silicon: true
model name Apple M2 Pro
pCore GHz 3.504
eCore GHz 2.424
pCore Hz 3504000000
eCore Hz 2424000000
----- gopsutil ----
info.Mhz 3.504e+09
```
2 years ago
..
testdata fix dependabot v2 deletion. 3 years ago
cpu.go fix(cpu): fix cpu total and busy calc 3 years ago
cpu_aix.go aix: split code, that uses perfstat, to _cgo and _nocgo files 3 years ago
cpu_aix_cgo.go fix go build flags for aix/cpu 3 years ago
cpu_aix_nocgo.go fix lint 2 years ago
cpu_darwin.go cpu: add frequency support for apple silicon m1/m2 cpus 2 years ago
cpu_darwin_cgo.go gofumpt 3 years ago
cpu_darwin_nocgo.go gofumpt 3 years ago
cpu_darwin_test.go cpu: add frequency support for apple silicon m1/m2 cpus 2 years ago
cpu_dragonfly.go gofumpt 3 years ago
cpu_dragonfly_amd64.go cpu: support for DragonflyBSD 5 years ago
cpu_fallback.go gofumpt 3 years ago
cpu_freebsd.go gofumpt 3 years ago
cpu_freebsd_386.go Eliminate use of sysctl command on FreeBSD 8 years ago
cpu_freebsd_amd64.go Eliminate use of sysctl command on FreeBSD 8 years ago
cpu_freebsd_arm.go add FreeBSD ARM support. copied from i386 6 years ago
cpu_freebsd_arm64.go Add support for freebsd/arm64 5 years ago
cpu_freebsd_test.go gofumpt 3 years ago
cpu_linux.go Merge pull request #1414 from jeffweiss/bugfix/get_tests_working_on_s390x 2 years ago
cpu_linux_test.go get tests passing on s390x 2 years ago
cpu_openbsd.go avoid cgo for cpu_openbsd 3 years ago
cpu_openbsd_386.go avoid cgo for cpu_openbsd 3 years ago
cpu_openbsd_amd64.go avoid cgo for cpu_openbsd 3 years ago
cpu_openbsd_arm.go host: add support for OpenBSD/armv7 3 years ago
cpu_openbsd_arm64.go Fix telegraf 1.22.0 build on OpenBSD/arm64: 3 years ago
cpu_plan9.go gofumpt 3 years ago
cpu_plan9_test.go test: use `T.Setenv` to set env vars in tests 2 years ago
cpu_solaris.go refactor: remove unnecessary exec.LookPath calls 3 years ago
cpu_solaris_test.go gofumpt 3 years ago
cpu_test.go gofumpt 3 years ago
cpu_windows.go cpu: use windows.GetActiveProcessorCount 2 years ago