@@ -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,38 @@ func (w *nfdTopologyUpdater) updateNodeResourceTopology(zoneInfo v1alpha2.ZoneLi
337339 return nil
338340}
339341
342+ func getCPUCoreAttribute (coreKind string ) (error , v1alpha2.AttributeInfo ) {
343+ cpu , err := os .ReadFile (hostpath .SysfsDir .Path ("sys/devices/" + coreKind , "cpus" ))
344+ if os .IsNotExist (err ) {
345+ klog .ErrorS (err , "error reading cpu entry file" , "coreKind" , coreKind )
346+ return err , v1alpha2.AttributeInfo {}
347+ }
348+
349+ attr := v1alpha2.AttributeInfo {
350+ Name : coreKind ,
351+ Value : strings .TrimSpace (string (cpu )),
352+ }
353+
354+ return nil , attr
355+ }
356+
357+ // Dicsover E/P cores
358+ func discoverCpuCores () v1alpha2.AttributeList {
359+ attrList := v1alpha2.AttributeList {}
360+
361+ err , attrAtom := getCPUCoreAttribute ("cpu_atom" )
362+ if err == nil {
363+ attrList = append (attrList , attrAtom )
364+ }
365+
366+ err , attrCore := getCPUCoreAttribute ("cpu_core" )
367+ if err == nil {
368+ attrList = append (attrList , attrCore )
369+ }
370+
371+ return attrList
372+ }
373+
340374func (w * nfdTopologyUpdater ) updateNRTTopologyManagerInfo (nrt * v1alpha2.NodeResourceTopology ) error {
341375 policy , scope , err := w .detectTopologyPolicyAndScope ()
342376 if err != nil {
@@ -349,6 +383,9 @@ func (w *nfdTopologyUpdater) updateNRTTopologyManagerInfo(nrt *v1alpha2.NodeReso
349383 updateAttributes (& nrt .Attributes , tmAttributes )
350384 nrt .TopologyPolicies = deprecatedTopologyPolicies
351385
386+ attrList := discoverCpuCores ()
387+ updateAttributes (& nrt .Attributes , attrList )
388+
352389 return nil
353390}
354391
0 commit comments