Skip to content

Fix cpu discovery on custom kernel builds #2677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions machine/testdata/cpu1/online
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
1 change: 1 addition & 0 deletions machine/testdata/cpu3/topology/core_id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
1 change: 1 addition & 0 deletions machine/testdata/cpu3/topology/physical_package_id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
2 changes: 1 addition & 1 deletion machine/topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down