BUG: cpu.Info() doesn't work on OpenBSD (7.5)
Describe the bug
cpu.Info() doesn't work on OpenBSD, version 7.5, MacBook Pro with M3 Pro chip (arm64).
To Reproduce
import "github.com/shirou/gopsutil/v4/cpu"
_, err := cpu.Info()
It reports error operation not supported.
Expected behavior
Expect it collects at least number of CPU cores.
Environment (please complete the following information):
- [ ] Windows: [paste the result of
ver] - [ ] Linux: [paste contents of
/etc/os-releaseand the result ofuname -a] - [ ] Mac OS: [paste the result of
sw_versanduname -a - [ ] FreeBSD: [paste the result of
freebsd-version -k -r -uanduname -a] - [x] OpenBSD: [paste the result of
uname -a]
# uname -a
OpenBSD ob75.localdomain 7.5 GENERIC#131 arm64
afaik, direct syscalls as done in https://github.com/shirou/gopsutil/blob/master/cpu/cpu_openbsd.go#L59 are forbidden
Sorry I don't reproduce on an openbsd 7.5 VM under VirtualBox
package main
import (
"log"
"github.com/shirou/gopsutil/v4/cpu"
)
func main() {
log.Println("cpu.Info()")
log.Println(cpu.Info())
}
openbsd75$ go run cpu.go
2024/09/15 16:59:55 cpu.Info()
2024/09/15 16:59:55 [{"cpu":0,"vendorId":"","family":"","model":"","stepping":0,"physicalId":"","coreId":"","cores":1,"modelName":"Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz","mhz":2506,"cacheSize":0,"flags":null,"microcode":""}] <nil>
Are you restricting your Go program with something like plegde/unveil maybe?
FYI https://github.com/golang/go/issues/63900
Same code doesn't work for me with Go 1.22.1 (the binary package installed via pkg_add go), OpenBSD 7.5 is running in VMware Fusion, hardware is MacBook Pro (M3 Pro CPU).
# uname -a
OpenBSD ob75.localdomain 7.5 GENERIC#131 arm64
# cat main.go
package main
import (
"log"
"github.com/shirou/gopsutil/v4/cpu"
)
func main() {
log.Println("cpu.Info()")
log.Println(cpu.Info())
}
# go run .
2024/09/16 01:13:54 cpu.Info()
2024/09/16 01:13:54 [] operation not supported
I was also testing with go version go1.22.1 openbsd/amd64, the difference is arm64 vs amd64.
What's the result of this shell oneliner (sysctl values from here)?
for I in hw.cpuspeed hw.ncpuonline hw.model; do printf "%s: " "$I"; sysctl "$I"; done
@Lomanic
Running on OpenBSD 7.6 (arm64), which is a VM guest inside VMware Fusion (MacBook Pro with Apple M3 Pro chip):
# for I in hw.cpuspeed hw.ncpuonline hw.model; do printf "%s: " "$I"; sysctl "$I"; done
hw.cpuspeed: sysctl: hw.cpuspeed: value is not available
hw.ncpuonline: hw.ncpuonline=1
hw.model: hw.model=Unknown
# uname -r -m
7.6 arm64