From 2946157c6f7d8903307da737bc5a6c48172891be Mon Sep 17 00:00:00 2001 From: Oleg Zhurakivskyy Date: Sun, 18 Aug 2024 19:30:33 +0300 Subject: [PATCH] nfd-topology-updater: Detect E/P cores and expose through attributes Signed-off-by: Oleg Zhurakivskyy --- .../nfd-topology-updater.go | 31 +++++++++++++++++++ source/cpu/cpu.go | 10 ++++++ 2 files changed, 41 insertions(+) diff --git a/pkg/nfd-topology-updater/nfd-topology-updater.go b/pkg/nfd-topology-updater/nfd-topology-updater.go index e65edbea2..9d625e5ee 100644 --- a/pkg/nfd-topology-updater/nfd-topology-updater.go +++ b/pkg/nfd-topology-updater/nfd-topology-updater.go @@ -22,6 +22,7 @@ import ( "net/url" "os" "path/filepath" + "strings" "golang.org/x/net/context" @@ -42,6 +43,7 @@ import ( "sigs.k8s.io/node-feature-discovery/pkg/resourcemonitor" "sigs.k8s.io/node-feature-discovery/pkg/topologypolicy" "sigs.k8s.io/node-feature-discovery/pkg/utils" + "sigs.k8s.io/node-feature-discovery/pkg/utils/hostpath" "sigs.k8s.io/node-feature-discovery/pkg/utils/kubeconf" "sigs.k8s.io/node-feature-discovery/pkg/version" "sigs.k8s.io/yaml" @@ -337,6 +339,32 @@ func (w *nfdTopologyUpdater) updateNodeResourceTopology(zoneInfo v1alpha2.ZoneLi return nil } +// Discover E/P cores +func discoverCpuCores() v1alpha2.AttributeList { + attrList := v1alpha2.AttributeList{} + + cpusPathGlob := hostpath.SysfsDir.Path("sys/devices/cpu_*/cpus") + cpuPaths, err := filepath.Glob(cpusPathGlob) + if err != nil { + klog.ErrorS(err, "error reading cpu entries", "cpusPathGlob", cpusPathGlob) + return attrList + } + + for _, entry := range cpuPaths { + cpus, err := os.ReadFile(entry) + if err != nil { + klog.ErrorS(err, "error reading cpu entry file", "entry", entry) + } else { + attrList = append(attrList, v1alpha2.AttributeInfo{ + Name: filepath.Base(filepath.Dir(entry)), + Value: strings.TrimSpace(string(cpus)), + }) + } + } + + return attrList +} + func (w *nfdTopologyUpdater) updateNRTTopologyManagerInfo(nrt *v1alpha2.NodeResourceTopology) error { policy, scope, err := w.detectTopologyPolicyAndScope() if err != nil { @@ -349,6 +377,9 @@ func (w *nfdTopologyUpdater) updateNRTTopologyManagerInfo(nrt *v1alpha2.NodeReso updateAttributes(&nrt.Attributes, tmAttributes) nrt.TopologyPolicies = deprecatedTopologyPolicies + attrList := discoverCpuCores() + updateAttributes(&nrt.Attributes, attrList) + return nil } diff --git a/source/cpu/cpu.go b/source/cpu/cpu.go index 8b889cd7e..1dfd8068c 100644 --- a/source/cpu/cpu.go +++ b/source/cpu/cpu.go @@ -198,6 +198,16 @@ func (s *cpuSource) GetLabels() (source.FeatureLabels, error) { labels["coprocessor.nx_gzip"] = v } + _, err := os.ReadFile(hostpath.SysfsDir.Path("sys/devices/cpu_atom/cpus")) + if err == nil { + labels["cpu_atom"] = true + } + + _, err = os.ReadFile(hostpath.SysfsDir.Path("sys/devices/cpu_core/cpus")) + if err == nil { + labels["cpu_core"] = true + } + return labels, nil }