From 12d92847cfd6a4bd572925239fdfa7d290e2d54d Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Wed, 13 Mar 2019 11:03:17 +0100 Subject: [PATCH] Get hw.ncpuonline without unix.SysctlUint32 unix.Sysctl always return an error when asking for hw.ncpuonline, so revert to a direct unix.Syscall6 to get the cpu count. --- cpu/cpu_openbsd.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cpu/cpu_openbsd.go b/cpu/cpu_openbsd.go index 9ede291..d224a1b 100644 --- a/cpu/cpu_openbsd.go +++ b/cpu/cpu_openbsd.go @@ -28,6 +28,8 @@ var ( // sys/sysctl.h const ( CTLKern = 1 // "high kernel": proc, limits + CTLHw = 6 // CTL_HW + NCpuOnline = 25 // HW_NCPUONLINE KernCptime = 40 // KERN_CPTIME KernCptime2 = 71 // KERN_CPTIME2 ) @@ -134,10 +136,19 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { } c.Mhz = float64(u32) - if u32, err = unix.SysctlUint32("hw.ncpuonline"); err != nil { + mib := []int32{CTLHw, NCpuOnline} + buf, _, err := common.CallSyscall(mib) + if err != nil { return nil, err } - c.Cores = int32(u32) + + var ncpu int32 + br := bytes.NewReader(buf) + err = binary.Read(br, binary.LittleEndian, &ncpu) + if err != nil { + return nil, err + } + c.Cores = ncpu if c.ModelName, err = unix.Sysctl("hw.model"); err != nil { return nil, err