intelrdt: change parseCpuInfoFile to return struct
Signed-off-by: Paweł Szulik <pawel.szulik@intel.com>
This commit is contained in:
parent
9a93b7378c
commit
7fa13b2773
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue