Skip to content

Commit d16169d

Browse files
committed
[Dependency: opencontainers#2643] 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 f4440f9 commit d16169d

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
@@ -237,16 +237,20 @@ func init() {
237237
}
238238
}
239239

240-
if flagsSet.MBMTotal || flagsSet.MBMLocal {
241-
if _, err := os.Stat(filepath.Join(intelRdtRoot, "info", "L3_MON")); err == nil {
242-
mbmEnabled = true
243-
cmtEnabled = true
240+
if flagsSet.MBMTotal || flagsSet.MBMLocal || flagsSet.CMT {
241+
if _, err := os.Stat(filepath.Join(intelRdtRoot, "info", "L3_MON")); err != nil {
242+
return
244243
}
245-
246244
enabledMonFeatures, err = getMonFeatures(intelRdtRoot)
247245
if err != nil {
248246
return
249247
}
248+
if enabledMonFeatures.mbmTotalBytes || enabledMonFeatures.mbmLocalBytes {
249+
mbmEnabled = true
250+
}
251+
if enabledMonFeatures.llcOccupancy {
252+
cmtEnabled = true
253+
}
250254
}
251255
}
252256

@@ -313,6 +317,8 @@ type cpuInfoFlags struct {
313317
// Memory Bandwidth Monitoring related.
314318
MBMTotal bool
315319
MBMLocal bool
320+
321+
CMT bool // Cache Monitoring Technology
316322
}
317323

318324
func parseCpuInfoFile(path string) (cpuInfoFlags, error) {
@@ -342,6 +348,8 @@ func parseCpuInfoFile(path string) (cpuInfoFlags, error) {
342348
infoFlags.MBMTotal = true
343349
case "cqm_mbm_local":
344350
infoFlags.MBMLocal = true
351+
case "cqm_occup_llc":
352+
infoFlags.CMT = true
345353
}
346354
}
347355
return infoFlags, nil
@@ -659,9 +667,11 @@ func (m *intelRdtManager) GetStats() (*Stats, error) {
659667
}
660668
}
661669

662-
err = getMonitoringStats(containerPath, stats)
663-
if err != nil {
664-
return nil, err
670+
if IsMBMEnabled() || IsCMTEnabled() {
671+
err = getMonitoringStats(containerPath, stats)
672+
if err != nil {
673+
return nil, err
674+
}
665675
}
666676

667677
return stats, nil

0 commit comments

Comments
 (0)