diff --git a/machine/machine.go b/machine/machine.go index 4330d69502..dfbe08eec5 100644 --- a/machine/machine.go +++ b/machine/machine.go @@ -249,19 +249,21 @@ func getUniqueCPUPropertyCount(cpuBusPath string, propertyName string) int { for _, sysCPUPath := range sysCPUPaths { onlinePath := filepath.Join(sysCPUPath, "online") onlineVal, err := ioutil.ReadFile(onlinePath) - if err != nil { + // If linux is compiled with CONFIG_HOTPLUG_CPU=n the online/offline file does not exist + if err != nil && !os.IsNotExist(err) { klog.Warningf("Cannot determine CPU %s online state, skipping", sysCPUPath) continue - } - onlineVal = bytes.TrimSpace(onlineVal) - if len(onlineVal) == 0 || onlineVal[0] != 49 { - klog.Warningf("CPU %s is offline, skipping", sysCPUPath) - continue + } else if err == nil { + onlineVal = bytes.TrimSpace(onlineVal) + if len(onlineVal) == 0 || onlineVal[0] != byte('1') { + klog.Warningf("CPU %s is offline, skipping", sysCPUPath) + continue + } } propertyPath := filepath.Join(sysCPUPath, sysFsCPUTopology, propertyName) propertyVal, err := ioutil.ReadFile(propertyPath) if err != nil { - klog.Errorf("Cannot open %s, number of unique %s set to 0", propertyPath, propertyName) + klog.Errorf("Cannot open %s, number of unique %s set to 0", propertyPath, propertyName) return 0 } uniques[string(propertyVal)] = true diff --git a/machine/testdata/cpu1/online b/machine/testdata/cpu1/online new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/machine/testdata/cpu1/online @@ -0,0 +1 @@ +0 diff --git a/machine/testdata/cpu3/topology/core_id b/machine/testdata/cpu3/topology/core_id new file mode 100644 index 0000000000..00750edc07 --- /dev/null +++ b/machine/testdata/cpu3/topology/core_id @@ -0,0 +1 @@ +3 diff --git a/machine/testdata/cpu3/topology/physical_package_id b/machine/testdata/cpu3/topology/physical_package_id new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/machine/testdata/cpu3/topology/physical_package_id @@ -0,0 +1 @@ +0 diff --git a/machine/topology_test.go b/machine/topology_test.go index e94030070d..0b944f2f64 100644 --- a/machine/topology_test.go +++ b/machine/topology_test.go @@ -48,7 +48,7 @@ func TestPhysicalCoresReadingFromCpuBus(t *testing.T) { assert.NotNil(t, testcpuinfo) numPhysicalCores := GetPhysicalCores(testcpuinfo) - assert.Equal(t, 2, numPhysicalCores) + assert.Equal(t, 3, numPhysicalCores) } func TestPhysicalCoresFromWrongSysFs(t *testing.T) {