@@ -22,6 +22,7 @@ import (
22
22
"net/url"
23
23
"os"
24
24
"path/filepath"
25
+ "strings"
25
26
26
27
"golang.org/x/net/context"
27
28
@@ -42,6 +43,7 @@ import (
42
43
"sigs.k8s.io/node-feature-discovery/pkg/resourcemonitor"
43
44
"sigs.k8s.io/node-feature-discovery/pkg/topologypolicy"
44
45
"sigs.k8s.io/node-feature-discovery/pkg/utils"
46
+ "sigs.k8s.io/node-feature-discovery/pkg/utils/hostpath"
45
47
"sigs.k8s.io/node-feature-discovery/pkg/utils/kubeconf"
46
48
"sigs.k8s.io/node-feature-discovery/pkg/version"
47
49
"sigs.k8s.io/yaml"
@@ -337,6 +339,45 @@ func (w *nfdTopologyUpdater) updateNodeResourceTopology(zoneInfo v1alpha2.ZoneLi
337
339
return nil
338
340
}
339
341
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
+
340
381
func (w * nfdTopologyUpdater ) updateNRTTopologyManagerInfo (nrt * v1alpha2.NodeResourceTopology ) error {
341
382
policy , scope , err := w .detectTopologyPolicyAndScope ()
342
383
if err != nil {
@@ -349,6 +390,9 @@ func (w *nfdTopologyUpdater) updateNRTTopologyManagerInfo(nrt *v1alpha2.NodeReso
349
390
updateAttributes (& nrt .Attributes , tmAttributes )
350
391
nrt .TopologyPolicies = deprecatedTopologyPolicies
351
392
393
+ attrList := discoverCpuCores ()
394
+ updateAttributes (& nrt .Attributes , attrList )
395
+
352
396
return nil
353
397
}
354
398
0 commit comments