-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cpu.Info() errors on Apple Silicon M1 (darwin/arm64) #1000
Comments
looks like this will be fixed with #999 |
This PR updates gopsutil to v3, given v2 is incompatible with Darwin arm64 (dep issue on github: shirou/gopsutil#1000).
@BitesPotatoBacks commented in giampaolo/psutil#1892 (comment)
From a quick glance at the linked function, sadly it needs some inline assembly, which looks quite hard to port to go or cgo. |
@Lomanic I compiled a binary for my script as well...since porting the code over to GO would be hard, perhaps gopsutil could just use that binary, and execute it using the GO exec package. If you guys want to be able to fetch the current CPU speed on Apple Silicon, this method would (probably) be the only way to do that here (unless GO has a secret inline assembly capability hidden somewhere). Though, this method would require you guys to bundle my binary within gopsutil's source, and I don't know how the devs feel about doing that sort of thing... |
I cannot wait for #1192 (a partial fix for this issue) to be merged. Will it make it into the December release? We are using this package to get the CPU brand and the number of cores so to us not returning an error when the CPU frequency is not available but most other information is makes sense. |
Sadly, there are no response other than kind Lomanic, so I did not merge. but from your comment, I will merge it. |
#1192 is only partial fix. reopen it until more good solution implemented. @BitesPotatoBacks 's great work should fix. I think we can implement by using asm in go world, but not yet implemented. |
See shirou/gopsutil#1000 Closes #95800. Signed-off-by: Sean Molenaar <1484494+SMillerDev@users.noreply.github.com> Signed-off-by: BrewTestBot <1589480+BrewTestBot@users.noreply.github.com>
Current enjoyer of this fine library here Anything I could do to PR this in and resolve this issue? Have an M1 so happy to test and write, but I think we should be able to just pull CPU info from /usr/bin/powermetrics?
|
@BitesPotatoBacks' newer released binary is functional now on M1 + M1 Pro. Would it be reasonable to bundle the binary as part of this library, calling it in the M1 case (or using the powermetrics method)? |
If my project was to been implemented in this library, I could compile a special barebones version of my binary with minimal output formatting, (to make it easier for gopsutil to parse the output of the frequency metrics) as well, if desired. My binary also doesn't require |
Including a compiled binary in a prevalent Go library would be suspect, at best. Perhaps that binary could be shipped via homebrew, and gopsutil could be smart enough to look for its existence in the standard location, but that is still some out-in-the-weeds requirement just for looking up CPU frequency. It's not impossible to do this with CGO, e.g. printing out a serial number below. But someone with more knowledge / patience than me is needed to dig through the docs / other examples to get the CPU info. I believe we need the equivalent of this oshi implementation.
|
FWIW I also got the naive implementation working, but it basically amounts to a PRNG between [0, max_freq]
|
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 shirou#1000
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 shirou#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 ```
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 shirou#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 ```
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 shirou#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 ```
Getting "no such file or directory", from here:
gopsutil/cpu/cpu_darwin.go
Lines 94 to 98 in 340db11
I confirmed this sysctl is not present on M1:
It only appears under Rosetta 2:
The text was updated successfully, but these errors were encountered: