@@ -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,45 @@ func (w *nfdTopologyUpdater) updateNodeResourceTopology(zoneInfo v1alpha2.ZoneLi
337339 return nil
338340}
339341
342+ func getCPUCoreAttribute (entry string ) (v1alpha2.AttributeInfo , error ) {
343+ cpus , err := os .ReadFile (entry )
344+ if err != nil {
345+ klog .ErrorS (err , "error reading cpu entry file" , "entry" , entry )
346+ return v1alpha2.AttributeInfo {}, err
347+ }
348+
349+ dir , _ := filepath .Split (entry )
350+ kind := filepath .Base (dir )
351+
352+ attr := v1alpha2.AttributeInfo {
353+ Name : kind ,
354+ Value : strings .TrimSpace (string (cpus )),
355+ }
356+
357+ return attr , nil
358+ }
359+
360+ // Dicsover E/P cores
361+ func discoverCpuCores () v1alpha2.AttributeList {
362+ attrList := v1alpha2.AttributeList {}
363+
364+ cpusPathGlob := hostpath .SysfsDir .Path ("sys/devices/cpu_*/cpus" )
365+ cpuPaths , err := filepath .Glob (cpusPathGlob )
366+ if err != nil {
367+ klog .ErrorS (err , "error reading cpu entries" , "cpusPathGlob" , cpusPathGlob )
368+ return attrList
369+ }
370+
371+ for _ , entry := range cpuPaths {
372+ attr , err := getCPUCoreAttribute (entry )
373+ if err == nil {
374+ attrList = append (attrList , attr )
375+ }
376+ }
377+
378+ return attrList
379+ }
380+
340381func (w * nfdTopologyUpdater ) updateNRTTopologyManagerInfo (nrt * v1alpha2.NodeResourceTopology ) error {
341382 policy , scope , err := w .detectTopologyPolicyAndScope ()
342383 if err != nil {
@@ -349,6 +390,9 @@ func (w *nfdTopologyUpdater) updateNRTTopologyManagerInfo(nrt *v1alpha2.NodeReso
349390 updateAttributes (& nrt .Attributes , tmAttributes )
350391 nrt .TopologyPolicies = deprecatedTopologyPolicies
351392
393+ attrList := discoverCpuCores ()
394+ updateAttributes (& nrt .Attributes , attrList )
395+
352396 return nil
353397}
354398
0 commit comments