1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-15 13:07:48 +00:00

Advertise RDT L3 num_closid

Signed-off-by: PiotrProkop <pprokop@nvidia.com>
This commit is contained in:
PiotrProkop 2023-04-06 09:53:25 +02:00
parent 60f052f086
commit 0e78eba40e
4 changed files with 62 additions and 15 deletions

View file

@ -601,8 +601,9 @@ The following features are available for matching:
| | | **`status`** | string | Status of the driver, possible values are 'active' and 'passive' | | | **`status`** | string | Status of the driver, possible values are 'active' and 'passive'
| | | **`turbo`** | bool | 'true' if turbo frequencies are enabled, otherwise 'false' | | | **`turbo`** | bool | 'true' if turbo frequencies are enabled, otherwise 'false'
| | | **`scaling`** | string | Active scaling_governor, possible values are 'powersave' or 'performance'. | | | **`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 | | | **`<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 | **`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 | | | **`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 | | | **`se.enabled`** | bool | `true` if IBM Secure Execution for Linux is available and has been enabled, otherwise does not exist

View file

@ -164,8 +164,12 @@ func (s *cpuSource) GetLabels() (source.FeatureLabels, error) {
} }
// RDT // RDT
for k := range features.Flags[RdtFeature].Elements { for k, v := range features.Attributes[RdtFeature].Elements {
labels["rdt."+k] = true if k == "RDTL3CA_NUM_CLOSID" {
continue
}
labels["rdt."+k] = v
} }
// Security // Security
@ -227,7 +231,7 @@ func (s *cpuSource) Discover() error {
s.features.Attributes[PstateFeature] = nfdv1alpha1.NewAttributeFeatures(pstate) s.features.Attributes[PstateFeature] = nfdv1alpha1.NewAttributeFeatures(pstate)
// Detect RDT features // 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 // Detect available guest protection(SGX,TDX,SEV) features
s.features.Attributes[SecurityFeature] = nfdv1alpha1.NewAttributeFeatures(discoverSecurity()) s.features.Attributes[SecurityFeature] = nfdv1alpha1.NewAttributeFeatures(discoverSecurity())

View file

@ -20,6 +20,14 @@ limitations under the License.
package cpu package cpu
import ( import (
"bytes"
"os"
"path/filepath"
"strconv"
"github.com/opencontainers/runc/libcontainer/intelrdt"
"k8s.io/klog/v2"
"sigs.k8s.io/node-feature-discovery/pkg/cpuid" "sigs.k8s.io/node-feature-discovery/pkg/cpuid"
) )
@ -44,8 +52,8 @@ const (
RDT_ALLOCATION_EBX_MEMORY_BANDWIDTH_ALLOCATION = 1 << 3 RDT_ALLOCATION_EBX_MEMORY_BANDWIDTH_ALLOCATION = 1 << 3
) )
func discoverRDT() []string { func discoverRDT() map[string]string {
features := []string{} attributes := map[string]string{}
// Read cpuid information // Read cpuid information
extFeatures := cpuid.Cpuid(LEAF_EXT_FEATURE_FLAGS, 0) extFeatures := cpuid.Cpuid(LEAF_EXT_FEATURE_FLAGS, 0)
@ -57,16 +65,16 @@ func discoverRDT() []string {
if extFeatures.EBX&EXT_FEATURE_FLAGS_EBX_RDT_M != 0 { if extFeatures.EBX&EXT_FEATURE_FLAGS_EBX_RDT_M != 0 {
if rdtMonitoring.EDX&RDT_MONITORING_EDX_L3_MONITORING != 0 { if rdtMonitoring.EDX&RDT_MONITORING_EDX_L3_MONITORING != 0 {
// Monitoring is supported // Monitoring is supported
features = append(features, "RDTMON") attributes["RDTMON"] = "true"
// Cache Monitoring Technology (L3 occupancy monitoring) // Cache Monitoring Technology (L3 occupancy monitoring)
if rdtL3Monitoring.EDX&RDT_MONITORING_SUBLEAF_L3_EDX_L3_OCCUPANCY_MONITORING != 0 { 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) // Memore Bandwidth Monitoring (L3 local&total bandwidth monitoring)
if rdtL3Monitoring.EDX&RDT_MONITORING_SUBLEAF_L3_EDX_L3_TOTAL_BANDWIDTH_MONITORING != 0 && 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 { rdtL3Monitoring.EDX&RDT_MONITORING_SUBLEAF_L3_EDX_L3_LOCAL_BANDWIDTH_MONITORING != 0 {
features = append(features, "RDTMBM") attributes["RDTMBM"] = "true"
} }
} }
} }
@ -75,17 +83,51 @@ func discoverRDT() []string {
if extFeatures.EBX&EXT_FEATURE_FLAGS_EBX_RDT_A != 0 { if extFeatures.EBX&EXT_FEATURE_FLAGS_EBX_RDT_A != 0 {
// L3 Cache Allocation // L3 Cache Allocation
if rdtAllocation.EBX&RDT_ALLOCATION_EBX_L3_CACHE_ALLOCATION != 0 { 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 // L2 Cache Allocation
if rdtAllocation.EBX&RDT_ALLOCATION_EBX_L2_CACHE_ALLOCATION != 0 { if rdtAllocation.EBX&RDT_ALLOCATION_EBX_L2_CACHE_ALLOCATION != 0 {
features = append(features, "RDTL2CA") attributes["RDTL2CA"] = "true"
} }
// Memory Bandwidth Allocation // Memory Bandwidth Allocation
if rdtAllocation.EBX&RDT_ALLOCATION_EBX_MEMORY_BANDWIDTH_ALLOCATION != 0 { 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 {
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 {
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
} }

View file

@ -19,6 +19,6 @@ limitations under the License.
package cpu package cpu
func discoverRDT() []string { func discoverRDT() map[string]string {
return []string{} return map[string]string{}
} }