summaryrefslogtreecommitdiffstats
path: root/extras/hs-test/cpu.go
diff options
context:
space:
mode:
Diffstat (limited to 'extras/hs-test/cpu.go')
-rw-r--r--extras/hs-test/cpu.go28
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
}