Skip to content

Commit 3c4c811

Browse files
committed
libcontainer/intelrdt: fix CMT feature 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]>
1 parent 44f221e commit 3c4c811

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

libcontainer/intelrdt/cmt.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ func IsCMTEnabled() bool {
1212
func getCMTNumaNodeStats(numaPath string) (*CMTNumaNodeStats, error) {
1313
stats := &CMTNumaNodeStats{}
1414

15-
llcOccupancy, err := getIntelRdtParamUint(numaPath, "llc_occupancy")
16-
if err != nil {
17-
return nil, err
15+
if enabledMonFeatures.llcOccupancy {
16+
llcOccupancy, err := getIntelRdtParamUint(numaPath, "llc_occupancy")
17+
if err != nil {
18+
return nil, err
19+
}
20+
stats.LLCOccupancy = llcOccupancy
1821
}
19-
stats.LLCOccupancy = llcOccupancy
2022

2123
return stats, nil
2224
}

libcontainer/intelrdt/intelrdt.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,18 @@ func init() {
229229
}
230230
}
231231

232-
if flagsSet.MBMTotal || flagsSet.MBMLocal {
232+
if flagsSet.MBMTotal || flagsSet.MBMLocal || flagsSet.CMT {
233233
if _, err := os.Stat(filepath.Join(intelRdtRoot, "info", "L3_MON")); err == nil {
234-
mbmEnabled = true
235-
cmtEnabled = true
236-
}
237-
238-
enabledMonFeatures, err = getMonFeatures(intelRdtRoot)
239-
if err != nil {
240-
return
234+
enabledMonFeatures, err = getMonFeatures(intelRdtRoot)
235+
if err != nil {
236+
return
237+
}
238+
if enabledMonFeatures.mbmTotalBytes || enabledMonFeatures.mbmLocalBytes {
239+
mbmEnabled = true
240+
}
241+
if enabledMonFeatures.llcOccupancy {
242+
cmtEnabled = true
243+
}
241244
}
242245
}
243246
}
@@ -305,6 +308,8 @@ type cpuInfoFlags struct {
305308
// Memory Bandwidth Monitoring related.
306309
MBMTotal bool
307310
MBMLocal bool
311+
312+
CMT bool // Cache Monitoring Technology
308313
}
309314

310315
func parseCpuInfoFile(path string) (cpuInfoFlags, error) {
@@ -334,6 +339,8 @@ func parseCpuInfoFile(path string) (cpuInfoFlags, error) {
334339
infoFlags.MBMTotal = true
335340
case "cqm_mbm_local":
336341
infoFlags.MBMLocal = true
342+
case "cqm_occup_llc":
343+
infoFlags.CMT = true
337344
}
338345
}
339346
return infoFlags, nil
@@ -651,9 +658,11 @@ func (m *IntelRdtManager) GetStats() (*Stats, error) {
651658
}
652659
}
653660

654-
err = getMonitoringStats(containerPath, stats)
655-
if err != nil {
656-
return nil, err
661+
if IsMBMEnabled() || IsCMTEnabled() {
662+
err = getMonitoringStats(containerPath, stats)
663+
if err != nil {
664+
return nil, err
665+
}
657666
}
658667

659668
return stats, nil

0 commit comments

Comments
 (0)