gopsutil icon indicating copy to clipboard operation
gopsutil copied to clipboard

BUG: cpu.Info() doesn't work on OpenBSD (7.5)

Open iredmail opened this issue 1 year ago • 5 comments

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-release and the result of uname -a]
  • [ ] Mac OS: [paste the result of sw_vers and uname -a
  • [ ] FreeBSD: [paste the result of freebsd-version -k -r -u and uname -a]
  • [x] OpenBSD: [paste the result of uname -a]
# uname -a
OpenBSD ob75.localdomain 7.5 GENERIC#131 arm64

iredmail avatar Sep 13 '24 09:09 iredmail

afaik, direct syscalls as done in https://github.com/shirou/gopsutil/blob/master/cpu/cpu_openbsd.go#L59 are forbidden

landryb avatar Sep 13 '24 10:09 landryb

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?

Lomanic avatar Sep 15 '24 13:09 Lomanic

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

iredmail avatar Sep 16 '24 04:09 iredmail

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 avatar Oct 18 '24 23:10 Lomanic

@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

iredmail avatar Oct 19 '24 01:10 iredmail