...
1 package intelrdt
2
3 import (
4 "bufio"
5 "io"
6 "os"
7 "path/filepath"
8
9 "github.com/sirupsen/logrus"
10 )
11
12 var enabledMonFeatures monFeatures
13
14 type monFeatures struct {
15 mbmTotalBytes bool
16 mbmLocalBytes bool
17 llcOccupancy bool
18 }
19
20 func getMonFeatures(intelRdtRoot string) (monFeatures, error) {
21 file, err := os.Open(filepath.Join(intelRdtRoot, "info", "L3_MON", "mon_features"))
22 if err != nil {
23 return monFeatures{}, err
24 }
25 defer file.Close()
26 return parseMonFeatures(file)
27 }
28
29 func parseMonFeatures(reader io.Reader) (monFeatures, error) {
30 scanner := bufio.NewScanner(reader)
31
32 monFeatures := monFeatures{}
33
34 for scanner.Scan() {
35 switch feature := scanner.Text(); feature {
36 case "mbm_total_bytes":
37 monFeatures.mbmTotalBytes = true
38 case "mbm_local_bytes":
39 monFeatures.mbmLocalBytes = true
40 case "llc_occupancy":
41 monFeatures.llcOccupancy = true
42 default:
43 logrus.Warnf("Unsupported Intel RDT monitoring feature: %s", feature)
44 }
45 }
46
47 return monFeatures, scanner.Err()
48 }
49
50 func getMonitoringStats(containerPath string, stats *Stats) error {
51 numaFiles, err := os.ReadDir(filepath.Join(containerPath, "mon_data"))
52 if err != nil {
53 return err
54 }
55
56 var mbmStats []MBMNumaNodeStats
57 var cmtStats []CMTNumaNodeStats
58
59 for _, file := range numaFiles {
60 if file.IsDir() {
61 numaPath := filepath.Join(containerPath, "mon_data", file.Name())
62 if IsMBMEnabled() {
63 numaMBMStats, err := getMBMNumaNodeStats(numaPath)
64 if err != nil {
65 return err
66 }
67 mbmStats = append(mbmStats, *numaMBMStats)
68 }
69 if IsCMTEnabled() {
70 numaCMTStats, err := getCMTNumaNodeStats(numaPath)
71 if err != nil {
72 return err
73 }
74 cmtStats = append(cmtStats, *numaCMTStats)
75 }
76 }
77 }
78
79 stats.MBMStats = &mbmStats
80 stats.CMTStats = &cmtStats
81
82 return err
83 }
84
View as plain text