From 7276e963eb08a0f0b4bddbea38b4a13a442d4218 Mon Sep 17 00:00:00 2001 From: Antoine Jacoutot Date: Wed, 2 Jan 2019 17:06:46 +0100 Subject: [PATCH 1/2] cpu: implement Mhz and Cores Adapted from the FreeBSD code. Successfully tested with Nomad. --- cpu/cpu_openbsd.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cpu/cpu_openbsd.go b/cpu/cpu_openbsd.go index 7a3c2a6..923fa44 100644 --- a/cpu/cpu_openbsd.go +++ b/cpu/cpu_openbsd.go @@ -124,14 +124,24 @@ func Info() ([]InfoStat, error) { func InfoWithContext(ctx context.Context) ([]InfoStat, error) { var ret []InfoStat + var err error c := InfoStat{} - v, err := unix.Sysctl("hw.model") - if err != nil { + var u32 uint32 + if u32, err = unix.SysctlUint32("hw.cpuspeed"); err != nil { + return nil, err + } + c.Mhz = float64(u32) + + if u32, err = unix.SysctlUint32("hw.ncpu"); err != nil { + return nil, err + } + c.Cores = int32(u32) + + if c.ModelName, err = unix.Sysctl("hw.model"); err != nil { return nil, err } - c.ModelName = v return append(ret, c), nil } From 67297c879129bb84bc55717282641750a5f979f2 Mon Sep 17 00:00:00 2001 From: Antoine Jacoutot Date: Wed, 2 Jan 2019 17:10:02 +0100 Subject: [PATCH 2/2] cpu: prefer cpuonline on OpenBSD This gives us the value of actual online CPUs (as opposed to the found ones which may not be able active). --- cpu/cpu_openbsd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/cpu_openbsd.go b/cpu/cpu_openbsd.go index 923fa44..0177626 100644 --- a/cpu/cpu_openbsd.go +++ b/cpu/cpu_openbsd.go @@ -134,7 +134,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { } c.Mhz = float64(u32) - if u32, err = unix.SysctlUint32("hw.ncpu"); err != nil { + if u32, err = unix.SysctlUint32("hw.ncpuonline"); err != nil { return nil, err } c.Cores = int32(u32)