-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2292 from Creatone/creatone/extend-intelrdt
Add RDT Memory Bandwidth Monitoring (MBM) and Cache Monitoring Technology (CMT) statistics.
- Loading branch information
Showing
10 changed files
with
463 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package intelrdt | ||
|
||
var ( | ||
cmtEnabled bool | ||
) | ||
|
||
// Check if Intel RDT/CMT is enabled. | ||
func IsCMTEnabled() bool { | ||
return cmtEnabled | ||
} | ||
|
||
func getCMTNumaNodeStats(numaPath string) (*CMTNumaNodeStats, error) { | ||
stats := &CMTNumaNodeStats{} | ||
|
||
llcOccupancy, err := getIntelRdtParamUint(numaPath, "llc_occupancy") | ||
if err != nil { | ||
return nil, err | ||
} | ||
stats.LLCOccupancy = llcOccupancy | ||
|
||
return stats, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package intelrdt | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestGetCMTNumaNodeStats(t *testing.T) { | ||
mocksNUMANodesToCreate := []string{"mon_l3_00", "mon_l3_01"} | ||
|
||
mocksFilesToCreate := map[string]uint64{ | ||
"llc_occupancy": 9123911, | ||
} | ||
|
||
mockedL3_MON, err := mockResctrlL3_MON(mocksNUMANodesToCreate, mocksFilesToCreate) | ||
|
||
defer func() { | ||
err := os.RemoveAll(mockedL3_MON) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}() | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
t.Run("Gather mbm", func(t *testing.T) { | ||
enabledMonFeatures.llcOccupancy = true | ||
|
||
stats := make([]CMTNumaNodeStats, 0, len(mocksNUMANodesToCreate)) | ||
for _, numa := range mocksNUMANodesToCreate { | ||
other, err := getCMTNumaNodeStats(filepath.Join(mockedL3_MON, "mon_data", numa)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
stats = append(stats, *other) | ||
} | ||
|
||
expectedStats := CMTNumaNodeStats{ | ||
LLCOccupancy: mocksFilesToCreate["llc_occupancy"], | ||
} | ||
|
||
checkCMTStatCorrection(stats[0], expectedStats, t) | ||
checkCMTStatCorrection(stats[1], expectedStats, t) | ||
}) | ||
} | ||
|
||
func checkCMTStatCorrection(got CMTNumaNodeStats, expected CMTNumaNodeStats, t *testing.T) { | ||
if got.LLCOccupancy != expected.LLCOccupancy { | ||
t.Fatalf("Wrong value of `llc_occupancy`. Expected: %v but got: %v", | ||
expected.LLCOccupancy, | ||
got.LLCOccupancy) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// +build linux | ||
|
||
package intelrdt | ||
|
||
var ( | ||
// The flag to indicate if Intel RDT/MBM is enabled | ||
mbmEnabled bool | ||
) | ||
|
||
// Check if Intel RDT/MBM is enabled. | ||
func IsMBMEnabled() bool { | ||
return mbmEnabled | ||
} | ||
|
||
func getMBMNumaNodeStats(numaPath string) (*MBMNumaNodeStats, error) { | ||
stats := &MBMNumaNodeStats{} | ||
if enabledMonFeatures.mbmTotalBytes { | ||
mbmTotalBytes, err := getIntelRdtParamUint(numaPath, "mbm_total_bytes") | ||
if err != nil { | ||
return nil, err | ||
} | ||
stats.MBMTotalBytes = mbmTotalBytes | ||
} | ||
|
||
if enabledMonFeatures.mbmLocalBytes { | ||
mbmLocalBytes, err := getIntelRdtParamUint(numaPath, "mbm_local_bytes") | ||
if err != nil { | ||
return nil, err | ||
} | ||
stats.MBMLocalBytes = mbmLocalBytes | ||
} | ||
|
||
return stats, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// +build linux | ||
|
||
package intelrdt | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestGetMBMNumaNodeStats(t *testing.T) { | ||
mocksNUMANodesToCreate := []string{"mon_l3_00", "mon_l3_01"} | ||
|
||
mocksFilesToCreate := map[string]uint64{ | ||
"mbm_total_bytes": 9123911, | ||
"mbm_local_bytes": 2361361, | ||
} | ||
|
||
mockedL3_MON, err := mockResctrlL3_MON(mocksNUMANodesToCreate, mocksFilesToCreate) | ||
|
||
defer func() { | ||
err := os.RemoveAll(mockedL3_MON) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
}() | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
t.Run("Gather mbm", func(t *testing.T) { | ||
enabledMonFeatures.mbmTotalBytes = true | ||
enabledMonFeatures.mbmLocalBytes = true | ||
|
||
stats := make([]MBMNumaNodeStats, 0, len(mocksNUMANodesToCreate)) | ||
for _, numa := range mocksNUMANodesToCreate { | ||
other, err := getMBMNumaNodeStats(filepath.Join(mockedL3_MON, "mon_data", numa)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
stats = append(stats, *other) | ||
} | ||
|
||
expectedStats := MBMNumaNodeStats{ | ||
MBMTotalBytes: mocksFilesToCreate["mbm_total_bytes"], | ||
MBMLocalBytes: mocksFilesToCreate["mbm_local_bytes"], | ||
} | ||
|
||
checkMBMStatCorrection(stats[0], expectedStats, t) | ||
checkMBMStatCorrection(stats[1], expectedStats, t) | ||
}) | ||
} | ||
|
||
func checkMBMStatCorrection(got MBMNumaNodeStats, expected MBMNumaNodeStats, t *testing.T) { | ||
if got.MBMTotalBytes != expected.MBMTotalBytes { | ||
t.Fatalf("Wrong value of mbm_total_bytes. Expected: %v but got: %v", | ||
expected.MBMTotalBytes, | ||
got.MBMTotalBytes) | ||
} | ||
|
||
if got.MBMLocalBytes != expected.MBMLocalBytes { | ||
t.Fatalf("Wrong value of mbm_local_bytes. Expected: %v but got: %v", | ||
expected.MBMLocalBytes, | ||
got.MBMLocalBytes) | ||
} | ||
|
||
} |
Oops, something went wrong.