Skip to content

Commit

Permalink
nfd-topology-updater: Detect E/P cores and expose through attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Zhurakivskyy <[email protected]>
  • Loading branch information
ozhuraki committed Nov 8, 2024
1 parent 566a945 commit b4f2eca
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pkg/nfd-topology-updater/nfd-topology-updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"net/url"
"os"
"path/filepath"
"strings"

"golang.org/x/net/context"

Expand All @@ -42,6 +43,7 @@ import (
"sigs.k8s.io/node-feature-discovery/pkg/resourcemonitor"
"sigs.k8s.io/node-feature-discovery/pkg/topologypolicy"
"sigs.k8s.io/node-feature-discovery/pkg/utils"
"sigs.k8s.io/node-feature-discovery/pkg/utils/hostpath"
"sigs.k8s.io/node-feature-discovery/pkg/utils/kubeconf"
"sigs.k8s.io/node-feature-discovery/pkg/version"
"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -337,6 +339,46 @@ func (w *nfdTopologyUpdater) updateNodeResourceTopology(zoneInfo v1alpha2.ZoneLi
return nil
}

func readAttributeFromFile(entry string) (v1alpha2.AttributeInfo, error) {
cpus, err := os.ReadFile(entry)
if err != nil {
return v1alpha2.AttributeInfo{}, err
}

dir, _ := filepath.Split(entry)
kind := filepath.Base(dir)

attr := v1alpha2.AttributeInfo{
Name: kind,
Value: strings.TrimSpace(string(cpus)),
}

return attr, nil
}

// Dicsover E/P cores
func discoverCpuCores() v1alpha2.AttributeList {
attrList := v1alpha2.AttributeList{}

cpusPathGlob := hostpath.SysfsDir.Path("sys/devices/cpu_*/cpus")
cpuPaths, err := filepath.Glob(cpusPathGlob)
if err != nil {
klog.ErrorS(err, "error reading cpu entries", "cpusPathGlob", cpusPathGlob)
return attrList
}

for _, entry := range cpuPaths {
attr, err := readAttributeFromFile(entry)
if err != nil {
klog.ErrorS(err, "error reading cpu entry file", "entry", entry)
} else {
attrList = append(attrList, attr)
}
}

return attrList
}

func (w *nfdTopologyUpdater) updateNRTTopologyManagerInfo(nrt *v1alpha2.NodeResourceTopology) error {
policy, scope, err := w.detectTopologyPolicyAndScope()
if err != nil {
Expand All @@ -349,6 +391,9 @@ func (w *nfdTopologyUpdater) updateNRTTopologyManagerInfo(nrt *v1alpha2.NodeReso
updateAttributes(&nrt.Attributes, tmAttributes)
nrt.TopologyPolicies = deprecatedTopologyPolicies

attrList := discoverCpuCores()
updateAttributes(&nrt.Attributes, attrList)

return nil
}

Expand Down

0 comments on commit b4f2eca

Please sign in to comment.