Skip to content

Commit

Permalink
Advertise RDT L3 num_closid
Browse files Browse the repository at this point in the history
Signed-off-by: PiotrProkop <[email protected]>
  • Loading branch information
PiotrProkop committed Mar 30, 2023
1 parent 821e042 commit d1ec296
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 22 deletions.
17 changes: 9 additions & 8 deletions docs/usage/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,15 @@ See the full list in [github.com/klauspost/cpuid][klauspost-cpuid].

#### Intel RDT flags

| Flag | Description |
| --------- | ---------------------------------------------------------------- |
| RDTMON | Intel RDT Monitoring Technology
| RDTCMT | Intel Cache Monitoring (CMT)
| RDTMBM | Intel Memory Bandwidth Monitoring (MBM)
| RDTL3CA | Intel L3 Cache Allocation Technology
| RDTl2CA | Intel L2 Cache Allocation Technology
| RDTMBA | Intel Memory Bandwidth Allocation (MBA) Technology
| Flag | Description |
| -------------------| ----------------------------------------------------------------------------------------------|
| RDTMON | Intel RDT Monitoring Technology
| RDTCMT | Intel Cache Monitoring (CMT)
| RDTMBM | Intel Memory Bandwidth Monitoring (MBM)
| RDTL3CA | Intel L3 Cache Allocation Technology
| RDTl2CA | Intel L2 Cache Allocation Technology
| RDTMBA | Intel Memory Bandwidth Allocation (MBA) Technology
| RDTL3CA_NUM_CLOSID | The number or available CLOSid(Class of service ID) for Intel L3 Cache Allocation Technology

### Kernel

Expand Down
6 changes: 3 additions & 3 deletions source/cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ func (s *cpuSource) GetLabels() (source.FeatureLabels, error) {
}

// RDT
for k := range features.Flags[RdtFeature].Elements {
labels["rdt."+k] = true
for k, v := range features.Attributes[RdtFeature].Elements {
labels["rdt."+k] = v
}

// Security
Expand Down Expand Up @@ -227,7 +227,7 @@ func (s *cpuSource) Discover() error {
s.features.Attributes[PstateFeature] = nfdv1alpha1.NewAttributeFeatures(pstate)

// Detect RDT features
s.features.Flags[RdtFeature] = nfdv1alpha1.NewFlagFeatures(discoverRDT()...)
s.features.Attributes[RdtFeature] = nfdv1alpha1.NewAttributeFeatures(discoverRDT())

// Detect SGX features
s.features.Attributes[SecurityFeature] = nfdv1alpha1.NewAttributeFeatures(discoverSecurity())
Expand Down
53 changes: 44 additions & 9 deletions source/cpu/rdt_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ limitations under the License.
package cpu

import (
"bytes"
"os"
"path/filepath"
"strconv"

"github.com/opencontainers/runc/libcontainer/intelrdt"

"sigs.k8s.io/node-feature-discovery/pkg/cpuid"
)

Expand All @@ -44,8 +51,8 @@ const (
RDT_ALLOCATION_EBX_MEMORY_BANDWIDTH_ALLOCATION = 1 << 3
)

func discoverRDT() []string {
features := []string{}
func discoverRDT() map[string]string {
attributes := map[string]string{}

// Read cpuid information
extFeatures := cpuid.Cpuid(LEAF_EXT_FEATURE_FLAGS, 0)
Expand All @@ -57,16 +64,16 @@ func discoverRDT() []string {
if extFeatures.EBX&EXT_FEATURE_FLAGS_EBX_RDT_M != 0 {
if rdtMonitoring.EDX&RDT_MONITORING_EDX_L3_MONITORING != 0 {
// Monitoring is supported
features = append(features, "RDTMON")
attributes["RDTMON"] = "true"

// Cache Monitoring Technology (L3 occupancy monitoring)
if rdtL3Monitoring.EDX&RDT_MONITORING_SUBLEAF_L3_EDX_L3_OCCUPANCY_MONITORING != 0 {
features = append(features, "RDTCMT")
attributes["RDTCMT"] = "true"
}
// Memore Bandwidth Monitoring (L3 local&total bandwidth monitoring)
if rdtL3Monitoring.EDX&RDT_MONITORING_SUBLEAF_L3_EDX_L3_TOTAL_BANDWIDTH_MONITORING != 0 &&
rdtL3Monitoring.EDX&RDT_MONITORING_SUBLEAF_L3_EDX_L3_LOCAL_BANDWIDTH_MONITORING != 0 {
features = append(features, "RDTMBM")
attributes["RDTMBM"] = "true"
}
}
}
Expand All @@ -75,17 +82,45 @@ func discoverRDT() []string {
if extFeatures.EBX&EXT_FEATURE_FLAGS_EBX_RDT_A != 0 {
// L3 Cache Allocation
if rdtAllocation.EBX&RDT_ALLOCATION_EBX_L3_CACHE_ALLOCATION != 0 {
features = append(features, "RDTL3CA")
attributes["RDTL3CA"] = "true"
numClosID := getNumClosID("L3")
if numClosID > -1 {
attributes["RDTL3CA_NUM_CLOSID"] = strconv.FormatInt(int64(numClosID), 10)
}
}
// L2 Cache Allocation
if rdtAllocation.EBX&RDT_ALLOCATION_EBX_L2_CACHE_ALLOCATION != 0 {
features = append(features, "RDTL2CA")
attributes["RDTL2CA"] = "true"
}
// Memory Bandwidth Allocation
if rdtAllocation.EBX&RDT_ALLOCATION_EBX_MEMORY_BANDWIDTH_ALLOCATION != 0 {
features = append(features, "RDTMBA")
attributes["RDTMBA"] = "true"
}
}

return features
return attributes
}

func getNumClosID(level string) int64 {
resctrlRootDir, err := intelrdt.Root()
if err != nil {
return -1
}

if _, err := os.Stat(filepath.Join(resctrlRootDir, "info", level, "num_closids")); err != nil {
return -1
}

closidsBytes, err := os.ReadFile(filepath.Join(resctrlRootDir, "info", level, "num_closids"))
if err != nil {
return -1
}

numClosIDs, err := strconv.ParseInt(string(bytes.TrimSpace(closidsBytes)), 10, 64)
if err != nil {
return -1
}

// subtract 1 for default control group
return numClosIDs - 1
}
4 changes: 2 additions & 2 deletions source/cpu/rdt_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ limitations under the License.

package cpu

func discoverRDT() []string {
return []string{}
func discoverRDT() map[string]string {
return map[string]string{}
}

0 comments on commit d1ec296

Please sign in to comment.