Skip to content

Commit

Permalink
lxd/devices: extract getNumaCPUs() from deviceTaskBalance()
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
  • Loading branch information
mihalicyn committed Jan 20, 2025
1 parent e7ed9b3 commit 0b7b0f6
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions lxd/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,22 @@ func getNumaNodeToCPUMap() (numaNodeToCPU map[int64][]int64, err error) {
return numaNodeToCPU, err
}

func getNumaCPUs(numaNodeToCPU map[int64][]int64, cpuNodes string) ([]int64, error) {
var numaCpus []int64
if cpuNodes != "" {
numaNodeSet, err := resources.ParseNumaNodeSet(cpuNodes)
if err != nil {
return nil, err
}

for _, numaNode := range numaNodeSet {
numaCpus = append(numaCpus, numaNodeToCPU[numaNode]...)
}
}

return numaCpus, nil
}

// deviceTaskBalance is used to balance the CPU load across instances running on a host.
// It first checks if CGroup support is available and returns if it isn't.
// It then retrieves the effective CPU list (the CPUs that are guaranteed to be online) and isolates any isolated CPUs.
Expand Down Expand Up @@ -479,17 +495,10 @@ func deviceTaskBalance(s *state.State) {
for _, c := range instances {
conf := c.ExpandedConfig()
cpuNodes := conf["limits.cpu.nodes"]
var numaCpus []int64
if cpuNodes != "" {
numaNodeSet, err := resources.ParseNumaNodeSet(cpuNodes)
if err != nil {
logger.Error("Error parsing numa node set", logger.Ctx{"numaNodes": cpuNodes, "err": err})
return
}

for _, numaNode := range numaNodeSet {
numaCpus = append(numaCpus, numaNodeToCPU[numaNode]...)
}
numaCpus, err := getNumaCPUs(numaNodeToCPU, cpuNodes)
if err != nil {
logger.Error("Error parsing numa node set", logger.Ctx{"numaNodes": cpuNodes, "err": err})
return
}

cpulimit, ok := conf["limits.cpu"]
Expand Down

0 comments on commit 0b7b0f6

Please sign in to comment.