Merge pull request #932 from tklauser/openbsd-cpu

Use unix.SysctlUint32("hw.ncpuonline") on OpenBSD
This commit is contained in:
Lomanic 2020-09-01 15:23:21 +02:00 committed by GitHub
commit ffaff45e9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 13 deletions

View File

@ -32,7 +32,6 @@ const (
CTLKern = 1 // "high kernel": proc, limits CTLKern = 1 // "high kernel": proc, limits
CTLHw = 6 // CTL_HW CTLHw = 6 // CTL_HW
SMT = 24 // HW_SMT SMT = 24 // HW_SMT
NCpuOnline = 25 // HW_NCPUONLINE
KernCptime = 40 // KERN_CPTIME KernCptime = 40 // KERN_CPTIME
KernCptime2 = 71 // KERN_CPTIME2 KernCptime2 = 71 // KERN_CPTIME2
) )
@ -163,25 +162,17 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
c := InfoStat{} c := InfoStat{}
var u32 uint32 mhz, err := unix.SysctlUint32("hw.cpuspeed")
if u32, err = unix.SysctlUint32("hw.cpuspeed"); err != nil {
return nil, err
}
c.Mhz = float64(u32)
mib := []int32{CTLHw, NCpuOnline}
buf, _, err := common.CallSyscall(mib)
if err != nil { if err != nil {
return nil, err return nil, err
} }
c.Mhz = float64(mhz)
var ncpu int32 ncpu, err := unix.SysctlUint32("hw.ncpuonline")
br := bytes.NewReader(buf)
err = binary.Read(br, binary.LittleEndian, &ncpu)
if err != nil { if err != nil {
return nil, err return nil, err
} }
c.Cores = ncpu c.Cores = int32(ncpu)
if c.ModelName, err = unix.Sysctl("hw.model"); err != nil { if c.ModelName, err = unix.Sysctl("hw.model"); err != nil {
return nil, err return nil, err