aboutsummaryrefslogtreecommitdiffstats
path: root/extras/hs-test/cpu.go
diff options
context:
space:
mode:
authorAdrian Villin <avillin@cisco.com>2024-05-27 09:52:59 -0400
committerDave Wallace <dwallacelf@gmail.com>2024-05-30 15:58:18 +0000
commitb9464cde7d3288f8feeeaf945ce933b276f07d82 (patch)
tree81bd58c1a5f3736ea6e5d2be1534c49004bc8d84 /extras/hs-test/cpu.go
parent2b671aa3e9b9b23afd46854a4bdd144ed783e99e (diff)
hs-test: pin CPUs to containers
Type: test Change-Id: I412be2dec7ff352740e50e838e0ac466bf0a6674 Signed-off-by: Adrian Villin <avillin@cisco.com>
Diffstat (limited to 'extras/hs-test/cpu.go')
-rw-r--r--extras/hs-test/cpu.go26
1 files changed, 15 insertions, 11 deletions
diff --git a/extras/hs-test/cpu.go b/extras/hs-test/cpu.go
index 69b4cabd4e3..49a7dfb02f8 100644
--- a/extras/hs-test/cpu.go
+++ b/extras/hs-test/cpu.go
@@ -23,22 +23,26 @@ type CpuAllocatorT struct {
var cpuAllocator *CpuAllocatorT = nil
-func (c *CpuAllocatorT) Allocate(vppContainerCount int, nCpus int) (*CpuContext, error) {
+func (c *CpuAllocatorT) Allocate(containerCount int, nCpus int) (*CpuContext, error) {
var cpuCtx CpuContext
- maxCpu := GinkgoParallelProcess() * 2 * nCpus
- minCpu := (GinkgoParallelProcess() - 1) * 2 * nCpus
- if len(c.cpus) < maxCpu {
- vppContainerCount += 1
+
+ // splitting cpus into equal parts; this will over-allocate cores but it's good enough for now
+ maxContainerCount := 4
+ // skip CPU 0
+ minCpu := ((GinkgoParallelProcess() - 1) * maxContainerCount * nCpus) + 1
+ maxCpu := (GinkgoParallelProcess() * maxContainerCount * nCpus)
+
+ if len(c.cpus)-1 < maxCpu {
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)
+ nCpus*containerCount, len(c.cpus)-1, minCpu, maxCpu)
return nil, err
}
- if vppContainerCount == 0 {
- cpuCtx.cpus = c.cpus[minCpu : maxCpu-nCpus]
- } else if vppContainerCount == 1 {
- cpuCtx.cpus = c.cpus[minCpu+nCpus : maxCpu]
+ if containerCount == 1 {
+ cpuCtx.cpus = c.cpus[minCpu : minCpu+nCpus]
+ } else if containerCount > 1 && containerCount <= maxContainerCount {
+ cpuCtx.cpus = c.cpus[minCpu+(nCpus*(containerCount-1)) : minCpu+(nCpus*containerCount)]
} else {
- return nil, fmt.Errorf("too many VPP containers; CPU allocation for >2 VPP containers is not implemented yet")
+ return nil, fmt.Errorf("too many containers; CPU allocation for >%d containers is not implemented", maxContainerCount)
}
cpuCtx.cpuAllocator = c