From 7fa13b27737650e846995512245bbf1b2bbf64ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Szulik?= Date: Wed, 8 Apr 2020 23:03:36 +0200 Subject: [PATCH] intelrdt: change parseCpuInfoFile to return struct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Szulik --- libcontainer/intelrdt/intelrdt.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/libcontainer/intelrdt/intelrdt.go b/libcontainer/intelrdt/intelrdt.go index b19580f1c..d40ae6442 100644 --- a/libcontainer/intelrdt/intelrdt.go +++ b/libcontainer/intelrdt/intelrdt.go @@ -191,8 +191,7 @@ type intelRdtData struct { // Check if Intel RDT sub-features are enabled in init() func init() { // 1. Check if hardware and kernel support Intel RDT sub-features - // "cat_l3" flag for CAT and "mba" flag for MBA - isCatFlagSet, isMbaFlagSet, err := parseCpuInfoFile("/proc/cpuinfo") + flagsSet, err := parseCpuInfoFile("/proc/cpuinfo") if err != nil { return } @@ -207,7 +206,7 @@ func init() { // "resource control" filesystem. Intel RDT sub-features can be // selectively disabled or enabled by kernel command line // (e.g., rdt=!l3cat,mba) in 4.14 and newer kernel - if isCatFlagSet { + if flagsSet.CAT { if _, err := os.Stat(filepath.Join(intelRdtRoot, "info", "L3")); err == nil { isCatEnabled = true } @@ -217,7 +216,7 @@ func init() { // MBA should be enabled because MBA Software Controller // depends on MBA isMbaEnabled = true - } else if isMbaFlagSet { + } else if flagsSet.MBA { if _, err := os.Stat(filepath.Join(intelRdtRoot, "info", "MB")); err == nil { isMbaEnabled = true } @@ -298,13 +297,17 @@ func isIntelRdtMounted() bool { return true } -func parseCpuInfoFile(path string) (bool, bool, error) { - isCatFlagSet := false - isMbaFlagSet := false +type cpuInfoFlags struct { + CAT bool // Cache Allocation Technology + MBA bool // Memory Bandwidth Allocation +} + +func parseCpuInfoFile(path string) (cpuInfoFlags, error) { + infoFlags := cpuInfoFlags{} f, err := os.Open(path) if err != nil { - return false, false, err + return infoFlags, err } defer f.Close() @@ -319,19 +322,19 @@ func parseCpuInfoFile(path string) (bool, bool, error) { for _, flag := range flags { switch flag { case "cat_l3": - isCatFlagSet = true + infoFlags.CAT = true case "mba": - isMbaFlagSet = true + infoFlags.MBA = true } } - return isCatFlagSet, isMbaFlagSet, nil + return infoFlags, nil } } if err := s.Err(); err != nil { - return false, false, err + return infoFlags, err } - return isCatFlagSet, isMbaFlagSet, nil + return infoFlags, nil } func parseUint(s string, base, bitSize int) (uint64, error) {