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