Skip to content

Commit

Permalink
[Dependency: opencontainers#2643] libcontainer/intelrdt: fix CMT feat…
Browse files Browse the repository at this point in the history
…ure check

Intel RDT sub-features can be selectively disabled or enabled by kernel
command line. See "rdt=" option details in kernel document:
https://www.kernel.org/doc/Documentation/admin-guide/kernel-parameters.txt

But Cache Monitoring Technology (CMT) feature is not correctly checked
in init() and getCMTNumaNodeStats() now. If CMT is disabled by kernel
command line (e.g., rdt=!cmt,mbmtotal,mbmlocal,l3cat,mba) while hardware
supports CMT, we may get following error when getting Intel RDT stats:
  runc run c1
  runc events c1
  ERRO[0005] container_linux.go:200: getting container's Intel RDT stats
  caused: open /sys/fs/resctrl/c1/mon_data/mon_L3_00/llc_occupancy: no
  such file or directory

Fix CMT feature check in init() and GetStats() call paths.

Signed-off-by: Xiaochen Shen <[email protected]>
  • Loading branch information
xiaochenshen committed Nov 10, 2020
1 parent f4440f9 commit d16169d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
10 changes: 6 additions & 4 deletions libcontainer/intelrdt/cmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ func IsCMTEnabled() bool {
func getCMTNumaNodeStats(numaPath string) (*CMTNumaNodeStats, error) {
stats := &CMTNumaNodeStats{}

llcOccupancy, err := getIntelRdtParamUint(numaPath, "llc_occupancy")
if err != nil {
return nil, err
if enabledMonFeatures.llcOccupancy {
llcOccupancy, err := getIntelRdtParamUint(numaPath, "llc_occupancy")
if err != nil {
return nil, err
}
stats.LLCOccupancy = llcOccupancy
}
stats.LLCOccupancy = llcOccupancy

return stats, nil
}
26 changes: 18 additions & 8 deletions libcontainer/intelrdt/intelrdt.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,20 @@ func init() {
}
}

if flagsSet.MBMTotal || flagsSet.MBMLocal {
if _, err := os.Stat(filepath.Join(intelRdtRoot, "info", "L3_MON")); err == nil {
mbmEnabled = true
cmtEnabled = true
if flagsSet.MBMTotal || flagsSet.MBMLocal || flagsSet.CMT {
if _, err := os.Stat(filepath.Join(intelRdtRoot, "info", "L3_MON")); err != nil {
return
}

enabledMonFeatures, err = getMonFeatures(intelRdtRoot)
if err != nil {
return
}
if enabledMonFeatures.mbmTotalBytes || enabledMonFeatures.mbmLocalBytes {
mbmEnabled = true
}
if enabledMonFeatures.llcOccupancy {
cmtEnabled = true
}
}
}

Expand Down Expand Up @@ -313,6 +317,8 @@ type cpuInfoFlags struct {
// Memory Bandwidth Monitoring related.
MBMTotal bool
MBMLocal bool

CMT bool // Cache Monitoring Technology
}

func parseCpuInfoFile(path string) (cpuInfoFlags, error) {
Expand Down Expand Up @@ -342,6 +348,8 @@ func parseCpuInfoFile(path string) (cpuInfoFlags, error) {
infoFlags.MBMTotal = true
case "cqm_mbm_local":
infoFlags.MBMLocal = true
case "cqm_occup_llc":
infoFlags.CMT = true
}
}
return infoFlags, nil
Expand Down Expand Up @@ -659,9 +667,11 @@ func (m *intelRdtManager) GetStats() (*Stats, error) {
}
}

err = getMonitoringStats(containerPath, stats)
if err != nil {
return nil, err
if IsMBMEnabled() || IsCMTEnabled() {
err = getMonitoringStats(containerPath, stats)
if err != nil {
return nil, err
}
}

return stats, nil
Expand Down

0 comments on commit d16169d

Please sign in to comment.