hs-test: fix CPU alloc when running in parallel
Type: test Change-Id: I6062eddffb938880d9ec004c8418a9a731891989 Signed-off-by: Adrian Villin <avillin@cisco.com>
This commit is contained in:

committed by
Florin Coras

parent
f5df854389
commit
0df582e8ec
@@ -4,6 +4,7 @@ import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
@@ -16,26 +17,31 @@ type CpuContext struct {
|
||||
cpus []int
|
||||
}
|
||||
|
||||
func (c *CpuContext) Release() {
|
||||
c.cpuAllocator.cpus = append(c.cpuAllocator.cpus, c.cpus...)
|
||||
c.cpus = c.cpus[:0] // empty the list
|
||||
}
|
||||
|
||||
type CpuAllocatorT struct {
|
||||
cpus []int
|
||||
}
|
||||
|
||||
var cpuAllocator *CpuAllocatorT = nil
|
||||
|
||||
func (c *CpuAllocatorT) Allocate(nCpus int) (*CpuContext, error) {
|
||||
func (c *CpuAllocatorT) Allocate(vppContainerCount int, nCpus int) (*CpuContext, error) {
|
||||
var cpuCtx CpuContext
|
||||
|
||||
if len(c.cpus) < nCpus {
|
||||
return nil, fmt.Errorf("could not allocate %d CPUs; available: %d", nCpus, len(c.cpus))
|
||||
maxCpu := GinkgoParallelProcess() * 2 * nCpus
|
||||
minCpu := (GinkgoParallelProcess() - 1) * 2 * nCpus
|
||||
if len(c.cpus) < maxCpu {
|
||||
vppContainerCount += 1
|
||||
err := fmt.Errorf("could not allocate %d CPUs; available: %d; attempted to allocate cores %d-%d",
|
||||
nCpus*vppContainerCount, len(c.cpus), minCpu, minCpu+nCpus*vppContainerCount)
|
||||
return nil, err
|
||||
}
|
||||
cpuCtx.cpus = c.cpus[0:nCpus]
|
||||
if vppContainerCount == 0 {
|
||||
cpuCtx.cpus = c.cpus[minCpu : maxCpu-nCpus]
|
||||
} else if vppContainerCount == 1 {
|
||||
cpuCtx.cpus = c.cpus[minCpu+nCpus : maxCpu]
|
||||
} else {
|
||||
return nil, fmt.Errorf("too many VPP containers; CPU allocation for >2 VPP containers is not implemented yet")
|
||||
}
|
||||
|
||||
cpuCtx.cpuAllocator = c
|
||||
c.cpus = c.cpus[nCpus:]
|
||||
return &cpuCtx, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user