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 Aug 18, 2024
1 parent a851aae commit 0ae4fba
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 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,39 @@ func (w *nfdTopologyUpdater) updateNodeResourceTopology(zoneInfo v1alpha2.ZoneLi
return nil
}

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

cpu_atom, err := os.ReadFile(hostpath.SysfsDir.Path("sys/devices/cpu_atom", "cpus"))
if err != nil {
klog.ErrorS(err, "error reading cpu_atom/cpus file")
return v1alpha2.AttributeList{}
}

attrAtom := v1alpha2.AttributeInfo{
Name: "cpu_atom",
Value: strings.TrimSpace(string(cpu_atom)),
}

attrList = append(attrList, attrAtom)

cpu_core, err := os.ReadFile(hostpath.SysfsDir.Path("sys/devices/cpu_core", "cpus"))
if err != nil {
klog.ErrorS(err, "error reading cpu_core/cpus file")
return v1alpha2.AttributeList{}
}

attrCore := v1alpha2.AttributeInfo{
Name: "cpu_core",
Value: strings.TrimSpace(string(cpu_core)),
}

attrList = append(attrList, attrCore)

return attrList
}

func (w *nfdTopologyUpdater) updateNRTTopologyManagerInfo(nrt *v1alpha2.NodeResourceTopology) error {
policy, scope, err := w.detectTopologyPolicyAndScope()
if err != nil {
Expand All @@ -349,6 +384,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 0ae4fba

Please sign in to comment.