Skip to content
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

cgroup: improve test to find cgroup compatibility issues #41347

Merged
merged 10 commits into from
Feb 13, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix
hawkingrei committed Feb 13, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 32c740191291b9a5a115ac7b82a38a15f835d7f8
13 changes: 11 additions & 2 deletions util/cgroup/cgroup_cpu.go
Original file line number Diff line number Diff line change
@@ -25,7 +25,16 @@ var noCPUControllerDetected = errors.New("no cpu controller detected")

// Helper function for getCgroupCPU. Root is always "/", except in tests.
func getCgroupCPU(root string) (CPUUsage, error) {
path, err := detectControlPath(filepath.Join(root, procPathCGroup), "cpu,cpuacct")
cu, err := getCgroupCPUInternal(root, "cpu,cpuacct")
if err == nil {
return cu, nil
}
return getCgroupCPUInternal(root, "cpuacct,cpu")
}

// getCgroupCPUInternal is to deal with different control keyword
func getCgroupCPUInternal(root, controlKeyword string) (CPUUsage, error) {
path, err := detectControlPath(filepath.Join(root, procPathCGroup), controlKeyword)
if err != nil {
return CPUUsage{}, err
}
@@ -35,7 +44,7 @@ func getCgroupCPU(root string) (CPUUsage, error) {
return CPUUsage{}, noCPUControllerDetected
}

mount, ver, err := getCgroupDetails(filepath.Join(root, procPathMountInfo), path, "cpu,cpuacct")
mount, ver, err := getCgroupDetails(filepath.Join(root, procPathMountInfo), path, controlKeyword)
if err != nil {
return CPUUsage{}, err
}