Skip to content

Commit 2946157

Browse files
committed
nfd-topology-updater: Detect E/P cores and expose through attributes
Signed-off-by: Oleg Zhurakivskyy <[email protected]>
1 parent 86d2809 commit 2946157

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

pkg/nfd-topology-updater/nfd-topology-updater.go

+31
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"net/url"
2323
"os"
2424
"path/filepath"
25+
"strings"
2526

2627
"golang.org/x/net/context"
2728

@@ -42,6 +43,7 @@ import (
4243
"sigs.k8s.io/node-feature-discovery/pkg/resourcemonitor"
4344
"sigs.k8s.io/node-feature-discovery/pkg/topologypolicy"
4445
"sigs.k8s.io/node-feature-discovery/pkg/utils"
46+
"sigs.k8s.io/node-feature-discovery/pkg/utils/hostpath"
4547
"sigs.k8s.io/node-feature-discovery/pkg/utils/kubeconf"
4648
"sigs.k8s.io/node-feature-discovery/pkg/version"
4749
"sigs.k8s.io/yaml"
@@ -337,6 +339,32 @@ func (w *nfdTopologyUpdater) updateNodeResourceTopology(zoneInfo v1alpha2.ZoneLi
337339
return nil
338340
}
339341

342+
// Discover E/P cores
343+
func discoverCpuCores() v1alpha2.AttributeList {
344+
attrList := v1alpha2.AttributeList{}
345+
346+
cpusPathGlob := hostpath.SysfsDir.Path("sys/devices/cpu_*/cpus")
347+
cpuPaths, err := filepath.Glob(cpusPathGlob)
348+
if err != nil {
349+
klog.ErrorS(err, "error reading cpu entries", "cpusPathGlob", cpusPathGlob)
350+
return attrList
351+
}
352+
353+
for _, entry := range cpuPaths {
354+
cpus, err := os.ReadFile(entry)
355+
if err != nil {
356+
klog.ErrorS(err, "error reading cpu entry file", "entry", entry)
357+
} else {
358+
attrList = append(attrList, v1alpha2.AttributeInfo{
359+
Name: filepath.Base(filepath.Dir(entry)),
360+
Value: strings.TrimSpace(string(cpus)),
361+
})
362+
}
363+
}
364+
365+
return attrList
366+
}
367+
340368
func (w *nfdTopologyUpdater) updateNRTTopologyManagerInfo(nrt *v1alpha2.NodeResourceTopology) error {
341369
policy, scope, err := w.detectTopologyPolicyAndScope()
342370
if err != nil {
@@ -349,6 +377,9 @@ func (w *nfdTopologyUpdater) updateNRTTopologyManagerInfo(nrt *v1alpha2.NodeReso
349377
updateAttributes(&nrt.Attributes, tmAttributes)
350378
nrt.TopologyPolicies = deprecatedTopologyPolicies
351379

380+
attrList := discoverCpuCores()
381+
updateAttributes(&nrt.Attributes, attrList)
382+
352383
return nil
353384
}
354385

source/cpu/cpu.go

+10
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ func (s *cpuSource) GetLabels() (source.FeatureLabels, error) {
198198
labels["coprocessor.nx_gzip"] = v
199199
}
200200

201+
_, err := os.ReadFile(hostpath.SysfsDir.Path("sys/devices/cpu_atom/cpus"))
202+
if err == nil {
203+
labels["cpu_atom"] = true
204+
}
205+
206+
_, err = os.ReadFile(hostpath.SysfsDir.Path("sys/devices/cpu_core/cpus"))
207+
if err == nil {
208+
labels["cpu_core"] = true
209+
}
210+
201211
return labels, nil
202212
}
203213

0 commit comments

Comments
 (0)