Skip to content

Commit

Permalink
Add function to node utils to fetch Core Siblings (#403)
Browse files Browse the repository at this point in the history
GetCoreSiblings function fetches core siblings per
numa Node

Signed-off-by: Niranjan M.R <mrniranjan@redhat.com>

Co-authored-by: Niranjan M.R <mrniranjan@redhat.com>
  • Loading branch information
mrniranjan and Niranjan M.R committed Aug 9, 2022
1 parent 20a1d1c commit 0441499
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions test/e2e/performanceprofile/functests/utils/nodes/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ type NumaNodes struct {

// NodeCPU Structure
type NodeCPU struct {
CPU string `json:"cpu"`
Node string `json:"node"`
Core string `json:"core"`
CPU string `json:"cpu"`
}

// GetByRole returns all nodes with the specified role
Expand Down Expand Up @@ -275,7 +276,7 @@ func GetSMTLevel(cpuID int, node *corev1.Node) int {

// GetNumaNodes returns the number of numa nodes and the associated cpus as list on the node
func GetNumaNodes(node *corev1.Node) (map[int][]int, error) {
lscpuCmd := []string{"lscpu", "-e=cpu,node", "-J"}
lscpuCmd := []string{"lscpu", "-e=node,core,cpu", "-J"}
cmdout, err := ExecCommandOnNode(lscpuCmd, node)
var numaNode, cpu int
if err != nil {
Expand All @@ -299,6 +300,29 @@ func GetNumaNodes(node *corev1.Node) (map[int][]int, error) {
return numaCpus, err
}

// GetCoreSiblings returns the siblings of core per numa node
func GetCoreSiblings(node *corev1.Node) (map[int]map[int][]int, error) {
lscpuCmd := []string{"lscpu", "-e=node,core,cpu", "-J"}
out, err := ExecCommandOnNode(lscpuCmd, node)
var result NumaNodes
var numaNode, core, cpu int
coreSiblings := make(map[int]map[int][]int)
err = json.Unmarshal([]byte(out), &result)
if err != nil {
return nil, err
}
for _, value := range result.Cpus {
if numaNode, err = strconv.Atoi(value.Node); err != nil {
break
}
if coreSiblings[numaNode] == nil {
coreSiblings[numaNode] = make(map[int][]int)
}
coreSiblings[numaNode][core] = append(coreSiblings[numaNode][core], cpu)
}
return coreSiblings, err
}

//TunedForNode find tuned pod for appropriate node
func TunedForNode(node *corev1.Node, sno bool) *corev1.Pod {

Expand Down

0 comments on commit 0441499

Please sign in to comment.