From cb0a6fca5311517531009e71ee70fd11532a7a5b Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Arango Gutierrez Date: Mon, 28 Mar 2022 05:51:23 -0400 Subject: [PATCH] Add cpu-model feature detection (#792) * Add cpu-model feature detection Signed-off-by: Carlos Eduardo Arango Gutierrez * Apply suggestions from code review Co-authored-by: Markus Lehtonen Co-authored-by: Markus Lehtonen --- docs/advanced/customization-guide.md | 4 ++++ docs/get-started/features.md | 3 +++ source/cpu/cpu.go | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/docs/advanced/customization-guide.md b/docs/advanced/customization-guide.md index 949a82c54..2374c3357 100644 --- a/docs/advanced/customization-guide.md +++ b/docs/advanced/customization-guide.md @@ -478,6 +478,10 @@ The following features are available for matching: | | | **``** | | CPUID flag is present | **`cpu.cstate`** | attribute | | | Status of cstates in the intel_idle cpuidle driver | | | **`enabled`** | bool | 'true' if cstates are set, otherwise 'false'. Does not exist of intel_idle driver is not active. +| **`cpu.model`** | attribute | | | CPU model related attributes +| | | **`family`** | int | CPU family +| | | **`vendor_id`** | string | CPU vendor ID +| | | **`id`** | int | CPU model ID | **`cpu.pstate`** | attribute | | | State of the Intel pstate driver. Does not exist if the driver is not enabled. | | | **`status`** | string | Status of the driver, possible values are 'active' and 'passive' | | | **`turbo`** | bool | 'true' if turbo frequencies are enabled, otherwise 'false' diff --git a/docs/get-started/features.md b/docs/get-started/features.md index c38b90991..f0bb1b2b2 100644 --- a/docs/get-started/features.md +++ b/docs/get-started/features.md @@ -51,6 +51,9 @@ such as restricting discovered features with the -label-whitelist option.* | **`cpu-cstate.enabled`** | bool | Set to 'true' if cstates are set in the intel_idle driver, otherwise set to 'false'. Unset if intel_idle cpuidle driver is not active. | **`cpu-rdt.`** | true | [Intel RDT][intel-rdt] capability is supported. See [RDT flags](#intel-rdt-flags) for details. | **`cpu-sgx.enabled`** | true | Set to 'true' if Intel SGX is enabled in BIOS (based a non-zero sum value of SGX EPC section sizes). +| **`cpu-model.vendor_id`** | string | Comparable CPU vendor ID. +| **`cpu-model.family`** | int | CPU family. +| **`cpu-model.id`** | int | CPU model number. The CPU label source is configurable, see [worker configuration](deployment-and-usage#worker-configuration) and diff --git a/source/cpu/cpu.go b/source/cpu/cpu.go index 5c0fd8b85..5367026ac 100644 --- a/source/cpu/cpu.go +++ b/source/cpu/cpu.go @@ -22,6 +22,8 @@ import ( "k8s.io/klog/v2" + "github.com/klauspost/cpuid/v2" + "sigs.k8s.io/node-feature-discovery/pkg/api/feature" "sigs.k8s.io/node-feature-discovery/pkg/utils" "sigs.k8s.io/node-feature-discovery/source" @@ -32,6 +34,7 @@ const Name = "cpu" const ( CpuidFeature = "cpuid" + Cpumodel = "model" CstateFeature = "cstate" PstateFeature = "pstate" RdtFeature = "rdt" @@ -141,6 +144,11 @@ func (s *cpuSource) GetLabels() (source.FeatureLabels, error) { } } + // CPU model + for k, v := range features.Values[Cpumodel].Elements { + labels["model."+k] = v + } + // Cstate for k, v := range features.Values[CstateFeature].Elements { labels["cstate."+k] = v @@ -181,6 +189,9 @@ func (s *cpuSource) Discover() error { // Detect CPUID s.features.Keys[CpuidFeature] = feature.NewKeyFeatures(getCpuidFlags()...) + // Detect CPU model + s.features.Values[Cpumodel] = feature.NewValueFeatures(getCPUModel()) + // Detect cstate configuration cstate, err := detectCstate() if err != nil { @@ -221,6 +232,15 @@ func (s *cpuSource) GetFeatures() *feature.DomainFeatures { return s.features } +func getCPUModel() map[string]string { + cpuModelInfo := make(map[string]string) + cpuModelInfo["vendor_id"] = cpuid.CPU.VendorID.String() + cpuModelInfo["family"] = strconv.Itoa(cpuid.CPU.Family) + cpuModelInfo["id"] = strconv.Itoa(cpuid.CPU.Model) + + return cpuModelInfo +} + func discoverTopology() map[string]string { features := make(map[string]string)