Merge pull request #377 from bilibili/fix/cpu_nums

fix possible cpus
pull/386/head
Tony 5 years ago committed by GitHub
commit 8a0fee6cd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      pkg/stat/sys/cpu/cgroup.go
  2. 18
      pkg/stat/sys/cpu/cgroupCPU.go

@ -56,7 +56,10 @@ func (c *cgroup) CPUAcctUsagePerCPU() ([]uint64, error) {
if u, err = parseUint(v); err != nil { if u, err = parseUint(v); err != nil {
return nil, err return nil, err
} }
usage = append(usage, u) // fix possible_cpu:https://www.ibm.com/support/knowledgecenter/en/linuxonibm/com.ibm.linux.z.lgdd/lgdd_r_posscpusparm.html
if u != 0 {
usage = append(usage, u)
}
} }
return usage, nil return usage, nil
} }

@ -8,6 +8,7 @@ import (
"strings" "strings"
"github.com/pkg/errors" "github.com/pkg/errors"
pscpu "github.com/shirou/gopsutil/cpu"
) )
type cgroupCPU struct { type cgroupCPU struct {
@ -21,12 +22,17 @@ type cgroupCPU struct {
} }
func newCgroupCPU() (cpu *cgroupCPU, err error) { func newCgroupCPU() (cpu *cgroupCPU, err error) {
cpus, err := perCPUUsage() var cores int
if err != nil { cores, err = pscpu.Counts(true)
err = errors.Errorf("perCPUUsage() failed!err:=%v", err) if err != nil || cores == 0 {
return var cpus []uint64
cpus, err = perCPUUsage()
if err != nil {
err = errors.Errorf("perCPUUsage() failed!err:=%v", err)
return
}
cores = len(cpus)
} }
cores := uint64(len(cpus))
sets, err := cpuSets() sets, err := cpuSets()
if err != nil { if err != nil {
@ -61,7 +67,7 @@ func newCgroupCPU() (cpu *cgroupCPU, err error) {
cpu = &cgroupCPU{ cpu = &cgroupCPU{
frequency: maxFreq, frequency: maxFreq,
quota: quota, quota: quota,
cores: cores, cores: uint64(cores),
preSystem: preSystem, preSystem: preSystem,
preTotal: preTotal, preTotal: preTotal,
} }

Loading…
Cancel
Save