Skip to content

Commit

Permalink
Merge pull request #1265 from fidencio/topic/cpu-misc-cgroups-take-cg…
Browse files Browse the repository at this point in the history
…roupsv1-into-account

cpu: Take cgroupsv1 into account when reading misc.capacity
  • Loading branch information
k8s-ci-robot committed Jul 19, 2023
2 parents 5f181cc + 7532ac3 commit fd0ba3f
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions source/cpu/security_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,10 @@ func sevParameterEnabled(parameter string) bool {
return false
}

func getCgroupMiscCapacity(resource string) int64 {
func retrieveCgroupMiscCapacityValue(miscCgroupPath *os.File, resource string) int64 {
var totalResources int64 = -1

miscCgroups := hostpath.SysfsDir.Path("fs/cgroup/misc.capacity")
f, err := os.Open(miscCgroups)
if err != nil {
return totalResources
}
defer f.Close()

r := bufio.NewReader(f)
r := bufio.NewReader(miscCgroupPath)
for {
line, _, err := r.ReadLine()
if err != nil {
Expand All @@ -158,3 +151,18 @@ func getCgroupMiscCapacity(resource string) int64 {

return totalResources
}

func getCgroupMiscCapacity(resource string) int64 {
miscCgroupsPaths := []string{"fs/cgroup/misc.capacity", "fs/cgroup/misc/misc.capacity"}
for _, miscCgroupsPath := range miscCgroupsPaths {
miscCgroups := hostpath.SysfsDir.Path(miscCgroupsPath)
f, err := os.Open(miscCgroups)
if err == nil {
defer f.Close()

return retrieveCgroupMiscCapacityValue(f, resource)
}
}

return -1
}

0 comments on commit fd0ba3f

Please sign in to comment.