diff options
author | Adrian Villin <avillin@cisco.com> | 2024-05-22 09:26:47 -0400 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2024-05-23 15:48:50 +0000 |
commit | 0df582e8ecbe6a4d45c9b2a8b822dcbe039eec29 (patch) | |
tree | 50d144223e990663b0149680552659c362e66167 /extras/hs-test/cpu.go | |
parent | f5df854389b8f2f2602d2aac8fec33fefdc45e59 (diff) |
hs-test: fix CPU alloc when running in parallel
Type: test
Change-Id: I6062eddffb938880d9ec004c8418a9a731891989
Signed-off-by: Adrian Villin <avillin@cisco.com>
Diffstat (limited to 'extras/hs-test/cpu.go')
-rw-r--r-- | extras/hs-test/cpu.go | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/extras/hs-test/cpu.go b/extras/hs-test/cpu.go index a976f47d8a5..69b4cabd4e3 100644 --- a/extras/hs-test/cpu.go +++ b/extras/hs-test/cpu.go @@ -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 } |