Skip to content

Commit

Permalink
topology,sysfs: implement partial hint resolution.
Browse files Browse the repository at this point in the history
Add functions for resolving partial, NUMA-only topology
hints to fully defined CPU-specific ones using a sysfs
instance.

Signed-off-by: Krisztian Litkey <[email protected]>
  • Loading branch information
klihub committed Nov 30, 2024
1 parent a8e482d commit 36f72ed
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/sysfs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ type System interface {

Offlined() cpuset.CPUSet
Isolated() cpuset.CPUSet

NodeHintToCPUs(string) string
}

// System devices
Expand Down Expand Up @@ -742,6 +744,24 @@ func (sys *system) Isolated() cpuset.CPUSet {
return sys.IsolatedCPUs()
}

// Resolve given node topology hints to CPUs.
func (sys *system) NodeHintToCPUs(nodes string) string {
mset, err := cpuset.Parse(nodes)
if err != nil {
log.Error("failed to resolve nodes %q to CPUs: %v", nodes, err)
return ""
}

cset := cpuset.New()
for _, id := range mset.List() {
if n, ok := sys.nodes[id]; ok {
cset = cset.Union(n.CPUSet())
}
}

return cset.Intersection(sys.OnlineCPUs()).String()
}

// Discover Cpus present in the system.
func (sys *system) discoverCPUs() error {
if sys.cpus != nil {
Expand Down
11 changes: 11 additions & 0 deletions pkg/topology/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,17 @@ func MergeTopologyHints(org, hints Hints) (res Hints) {
return
}

// ResolvePartialHints resolves NUMA-only hints to CPU hints using the given function.
func (hints Hints) ResolvePartialHints(resolve func(NUMAs string) string) {
for k, h := range hints {
if h.CPUs == "" && h.NUMAs != "" {
h.CPUs = resolve(h.NUMAs)
log.Debugf("partial NUMA hint %q resolved to CPUs %q", h.NUMAs, h.CPUs)
hints[k] = h
}
}
}

// String returns the hints as a string.
func (h *Hint) String() string {
cpus, nodes, sockets, sep := "", "", "", ""
Expand Down

0 comments on commit 36f72ed

Please sign in to comment.