1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

Add cpu-model feature detection (#792)

* Add cpu-model feature detection

Signed-off-by: Carlos Eduardo Arango Gutierrez <carangog@redhat.com>

* Apply suggestions from code review

Co-authored-by: Markus Lehtonen <markus.lehtonen@intel.com>

Co-authored-by: Markus Lehtonen <markus.lehtonen@intel.com>
This commit is contained in:
Carlos Eduardo Arango Gutierrez 2022-03-28 05:51:23 -04:00 committed by GitHub
parent f952b9feed
commit cb0a6fca53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View file

@ -478,6 +478,10 @@ The following features are available for matching:
| | | **`<cpuid-flag>`** | | 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'

View file

@ -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.<rdt-flag>`** | 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

View file

@ -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)