From 221e85f6f2e11455cdeeb5b2d4cfd93b51b575c1 Mon Sep 17 00:00:00 2001 From: Nicholas Orlowsky Date: Fri, 31 Mar 2023 00:36:12 -0500 Subject: [PATCH] added version detecting --- pkg/util/runtime/cpu_linux.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/util/runtime/cpu_linux.go b/pkg/util/runtime/cpu_linux.go index a69a4432c..431691a7e 100644 --- a/pkg/util/runtime/cpu_linux.go +++ b/pkg/util/runtime/cpu_linux.go @@ -62,8 +62,12 @@ func NumCPU() int { } func getCgroupVersion() int64 { - // TODO: detect version - return 2; + // /sys/fs/cgroup/cgroup.controllers will not exist with cgroupsv1 + if _, err := os.Stat("/sys/fs/cgroup/cgroup.controllers"); err == nil { + return 2; + } else { + return 1; + } } func readCgroup2FileToInt64Tuple(cgroupPath, cgroupFile string) (int64, int64) { @@ -75,6 +79,7 @@ func readCgroup2FileToInt64Tuple(cgroupPath, cgroupFile string) (int64, int64) { // file contents looks like: $MAX $PERIOD // $MAX can have value "max" indicating no limit + // it is possible for $PERIOD to be unset values := strings.Fields(string(contents));