Skip to content

Commit ea06d03

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 d8bfd6c commit ea06d03

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
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: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,20 @@ func init() {
229229
}
230230
}
231231

232-
if flagsSet.MBMTotal || flagsSet.MBMLocal {
233-
if _, err := os.Stat(filepath.Join(intelRdtRoot, "info", "L3_MON")); err == nil {
234-
mbmEnabled = true
235-
cmtEnabled = true
232+
if flagsSet.MBMTotal || flagsSet.MBMLocal || flagsSet.CMT {
233+
if _, err := os.Stat(filepath.Join(intelRdtRoot, "info", "L3_MON")); err != nil {
234+
return
236235
}
237-
238236
enabledMonFeatures, err = getMonFeatures(intelRdtRoot)
239237
if err != nil {
240238
return
241239
}
240+
if enabledMonFeatures.mbmTotalBytes || enabledMonFeatures.mbmLocalBytes {
241+
mbmEnabled = true
242+
}
243+
if enabledMonFeatures.llcOccupancy {
244+
cmtEnabled = true
245+
}
242246
}
243247
}
244248

@@ -305,6 +309,8 @@ type cpuInfoFlags struct {
305309
// Memory Bandwidth Monitoring related.
306310
MBMTotal bool
307311
MBMLocal bool
312+
313+
CMT bool // Cache Monitoring Technology
308314
}
309315

310316
func parseCpuInfoFile(path string) (cpuInfoFlags, error) {
@@ -334,6 +340,8 @@ func parseCpuInfoFile(path string) (cpuInfoFlags, error) {
334340
infoFlags.MBMTotal = true
335341
case "cqm_mbm_local":
336342
infoFlags.MBMLocal = true
343+
case "cqm_occup_llc":
344+
infoFlags.CMT = true
337345
}
338346
}
339347
return infoFlags, nil
@@ -651,9 +659,11 @@ func (m *IntelRdtManager) GetStats() (*Stats, error) {
651659
}
652660
}
653661

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

659669
return stats, nil

0 commit comments

Comments
 (0)