Skip to content
Open
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: 3 additions & 0 deletions docs/usage/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ feature.node.kubernetes.io/<feature> = <value>
| **`cpu-model.vendor_id`** | string | Comparable CPU vendor ID. |
| **`cpu-model.family`** | int | CPU family. |
| **`cpu-model.id`** | int | CPU model number. |
| **`cpu-cores.physical `** | int | Number of CPU physical cores. |
| **`cpu-cores.threads_per_core`** | int | Number of threads per CPU core. |
| **`cpu-cores.logical`** | int | Number of CPU physical cores. |

The CPU label source is configurable, see
[worker configuration](nfd-worker.md#worker-configuration) and
Expand Down
18 changes: 18 additions & 0 deletions source/cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const Name = "cpu"

const (
CpuidFeature = "cpuid"
Cpucores = "cpu_cores"
Cpumodel = "model"
CstateFeature = "cstate"
PstateFeature = "pstate"
Expand Down Expand Up @@ -161,6 +162,11 @@ func (s *cpuSource) GetLabels() (source.FeatureLabels, error) {
labels["model."+k] = v
}

// CPU cores
for k, v := range features.Attributes[Cpucores].Elements {
labels["cores."+k] = v
}

// Cstate
for k, v := range features.Attributes[CstateFeature].Elements {
labels["cstate."+k] = v
Expand Down Expand Up @@ -226,6 +232,9 @@ func (s *cpuSource) Discover() error {
// Detect CPU model
s.features.Attributes[Cpumodel] = nfdv1alpha1.NewAttributeFeatures(getCPUModel())

// Detect CPU cores
s.features.Attributes[Cpucores] = nfdv1alpha1.NewAttributeFeatures(getCPUCores())

// Detect cstate configuration
cstate, err := detectCstate()
if err != nil {
Expand Down Expand Up @@ -299,6 +308,15 @@ func getCPUModel() map[string]string {
return cpuModelInfo
}

func getCPUCores() map[string]string {
cpuCoresInfo := make(map[string]string)
cpuCoresInfo["physical"] = strconv.Itoa(cpuid.CPU.PhysicalCores)
cpuCoresInfo["threads_per_core"] = strconv.Itoa(cpuid.CPU.ThreadsPerCore)
cpuCoresInfo["logical"] = strconv.Itoa(cpuid.CPU.LogicalCores)

return cpuCoresInfo
}

// getHypervisor detects the hypervisor on s390x by reading /proc/sysinfo
// and on x86_64/arm64 using the cpuid library.
// Returns normalized hypervisor string, "unknown" for unknown vendor, or "none" for bare metal.
Expand Down