Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advertise RDT L3 num_closid #1100

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/usage/customization-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,9 @@ The following features are available for matching:
| | | **`status`** | string | Status of the driver, possible values are 'active' and 'passive'
| | | **`turbo`** | bool | 'true' if turbo frequencies are enabled, otherwise 'false'
| | | **`scaling`** | string | Active scaling_governor, possible values are 'powersave' or 'performance'.
| **`cpu.rdt`** | flag | | | Intel RDT capabilities supported by the system
| **`cpu.rdt`** | attribute | | | Intel RDT capabilities supported by the system
| | | **`<rdt-flag>`** | | RDT capability is supported, see [RDT flags](#intel-rdt-flags) for details
| | | **`RDTL3CA_NUM_CLOSID`** | int | The number or available CLOSID (Class of service ID) for Intel L3 Cache Allocation Technology
| **`cpu.security`** | attribute | | | Features related to security and trusted execution environments
| | | **`sgx.enabled`** | bool | `true` if Intel SGX (Software Guard Extensions) has been enabled, otherwise does not exist
| | | **`se.enabled`** | bool | `true` if IBM Secure Execution for Linux is available and has been enabled, otherwise does not exist
Expand Down
10 changes: 7 additions & 3 deletions source/cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,12 @@ 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 {
if k == "RDTL3CA_NUM_CLOSID" {
continue
}

labels["rdt."+k] = v
}

// Security
Expand Down Expand Up @@ -227,7 +231,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 available guest protection(SGX,TDX,SEV) features
s.features.Attributes[SecurityFeature] = nfdv1alpha1.NewAttributeFeatures(discoverSecurity())
Expand Down
60 changes: 51 additions & 9 deletions source/cpu/rdt_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ limitations under the License.
package cpu

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

"github.com/opencontainers/runc/libcontainer/intelrdt"
"k8s.io/klog/v2"

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

Expand All @@ -44,8 +52,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 +65,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 +83,51 @@ 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 {
PiotrProkop marked this conversation as resolved.
Show resolved Hide resolved
klog.V(4).ErrorS(err, "can't find resctrl filesystem")
return -1
}

closidFile := filepath.Join(resctrlRootDir, "info", level, "num_closids")

if _, err := os.Stat(closidFile); err != nil {
klog.V(4).ErrorS(err, "failed to stat file", "fileName", closidFile)
return -1
}

closidsBytes, err := os.ReadFile(filepath.Join(resctrlRootDir, "info", level, "num_closids"))
if err != nil {
klog.V(4).ErrorS(err, "failed to read file", "fileName", closidFile)
return -1
}

numClosIDs, err := strconv.ParseInt(string(bytes.TrimSpace(closidsBytes)), 10, 64)
if err != nil {
marquiz marked this conversation as resolved.
Show resolved Hide resolved
klog.V(4).ErrorS(err, "failed to ParseInt", "num_closids", string(bytes.TrimSpace(closidsBytes)))
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{}
}