Skip to content

Commit 0ae4fba

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

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

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

+38
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,39 @@ func (w *nfdTopologyUpdater) updateNodeResourceTopology(zoneInfo v1alpha2.ZoneLi
337339
return nil
338340
}
339341

342+
// Dicsover E/P cores
343+
func discoverCpuCores() v1alpha2.AttributeList {
344+
attrList := v1alpha2.AttributeList{}
345+
346+
cpu_atom, err := os.ReadFile(hostpath.SysfsDir.Path("sys/devices/cpu_atom", "cpus"))
347+
if err != nil {
348+
klog.ErrorS(err, "error reading cpu_atom/cpus file")
349+
return v1alpha2.AttributeList{}
350+
}
351+
352+
attrAtom := v1alpha2.AttributeInfo{
353+
Name: "cpu_atom",
354+
Value: strings.TrimSpace(string(cpu_atom)),
355+
}
356+
357+
attrList = append(attrList, attrAtom)
358+
359+
cpu_core, err := os.ReadFile(hostpath.SysfsDir.Path("sys/devices/cpu_core", "cpus"))
360+
if err != nil {
361+
klog.ErrorS(err, "error reading cpu_core/cpus file")
362+
return v1alpha2.AttributeList{}
363+
}
364+
365+
attrCore := v1alpha2.AttributeInfo{
366+
Name: "cpu_core",
367+
Value: strings.TrimSpace(string(cpu_core)),
368+
}
369+
370+
attrList = append(attrList, attrCore)
371+
372+
return attrList
373+
}
374+
340375
func (w *nfdTopologyUpdater) updateNRTTopologyManagerInfo(nrt *v1alpha2.NodeResourceTopology) error {
341376
policy, scope, err := w.detectTopologyPolicyAndScope()
342377
if err != nil {
@@ -349,6 +384,9 @@ func (w *nfdTopologyUpdater) updateNRTTopologyManagerInfo(nrt *v1alpha2.NodeReso
349384
updateAttributes(&nrt.Attributes, tmAttributes)
350385
nrt.TopologyPolicies = deprecatedTopologyPolicies
351386

387+
attrList := discoverCpuCores()
388+
updateAttributes(&nrt.Attributes, attrList)
389+
352390
return nil
353391
}
354392

0 commit comments

Comments
 (0)