Skip to content

Commit

Permalink
Remove unncessary SMT detection
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissnell committed Feb 4, 2022
1 parent e0ec1b9 commit cb2abbf
Showing 1 changed file with 2 additions and 34 deletions.
36 changes: 2 additions & 34 deletions cpu/cpu_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"runtime"
"strconv"
"strings"
"syscall"

"github.com/shirou/gopsutil/v3/internal/common"
"github.com/tklauser/go-sysconf"
Expand All @@ -31,8 +30,6 @@ var (
// sys/sysctl.h
const (
ctlKern = 1 // "high kernel": proc, limits
ctlHw = 6 // CTL_HW
sMT = 24 // HW_sMT
kernCptime = 40 // KERN_CPTIME
kernCptime2 = 71 // KERN_CPTIME2
)
Expand Down Expand Up @@ -64,22 +61,6 @@ func init() {
}()
}

func smt() (bool, error) {
mib := []int32{ctlHw, sMT}
buf, _, err := common.CallSyscall(mib)
if err != nil {
return false, err
}

var ret bool
br := bytes.NewReader(buf)
if err := binary.Read(br, binary.LittleEndian, &ret); err != nil {
return false, err
}

return ret, nil
}

func Times(percpu bool) ([]TimesStat, error) {
return TimesWithContext(context.Background(), percpu)
}
Expand All @@ -94,25 +75,12 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
ncpu = 1
}

smt, err := smt()
if err == syscall.EOPNOTSUPP {
// if hw.smt is not applicable for this platform (e.g. i386),
// pretend it's enabled
smt = true
} else if err != nil {
return nil, err
}

for i := 0; i < ncpu; i++ {
j := i
if !smt {
j *= 2
}

cpuTimes := make([]int32, cpUStates)
var mib []int32
if percpu {
mib = []int32{ctlKern, kernCptime2, int32(j)}
mib = []int32{ctlKern, kernCptime2, int32(i)}
} else {
mib = []int32{ctlKern, kernCptime}
}
Expand All @@ -134,7 +102,7 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
Irq: float64(cpuTimes[cpIntr]) / ClocksPerSec,
}
if percpu {
c.CPU = fmt.Sprintf("cpu%d", j)
c.CPU = fmt.Sprintf("cpu%d", i)
} else {
c.CPU = "cpu-total"
}
Expand Down

0 comments on commit cb2abbf

Please sign in to comment.