From 119ae0a10a990c0c4212c043f0a446b0af362652 Mon Sep 17 00:00:00 2001 From: Semir Sionek Date: Thu, 6 Feb 2025 07:44:05 -0500 Subject: [PATCH] hs-test: fix numa node core retrieval In CpuAllocator, the default assumption of two node core ranges seems to not be fully correct. Added handling of multiple ranges and singular cores. Type: fix Change-Id: Id50147c5360baa4035fcd87e3717b0d6c9ea7e5f Signed-off-by: Semir Sionek --- extras/hs-test/infra/cpu.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/extras/hs-test/infra/cpu.go b/extras/hs-test/infra/cpu.go index e871c60af80..743a4eddc67 100644 --- a/extras/hs-test/infra/cpu.go +++ b/extras/hs-test/infra/cpu.go @@ -93,7 +93,7 @@ func (c *CpuAllocatorT) readCpus() error { c.cpus = iterateAndAppend(first, second, c.cpus) c.cpus = iterateAndAppend(third, fourth, c.cpus) } else if NumaAwareCpuAlloc { - var fifth, sixth int + var range1, range2 int var tmpCpus []int file, err := os.Open("/sys/devices/system/node/online") @@ -122,22 +122,28 @@ func (c *CpuAllocatorT) readCpus() error { sc := bufio.NewScanner(file) sc.Scan() line := sc.Text() - _, err = fmt.Sscanf(line, "%d-%d,%d-%d", &third, &fourth, &fifth, &sixth) - if err != nil { - return err - } - // get numa node cores from first range - tmpCpus = iterateAndAppend(third, fourth, tmpCpus) + for _, coreRange := range strings.Split(line, ",") { + if strings.IndexRune(coreRange, '-') != -1 { + _, err = fmt.Sscanf(coreRange, "%d-%d", &range1, &range2) + if err != nil { + return err + } + tmpCpus = iterateAndAppend(range1, range2, tmpCpus) + } else { + _, err = fmt.Sscanf(coreRange, "%d", &range1) + if err != nil { + return err + } + tmpCpus = append(tmpCpus, range1) + } + } // discard cpu 0 if tmpCpus[0] == 0 && !*UseCpu0 { tmpCpus = tmpCpus[1:] } - // get numa node cores from second range - tmpCpus = iterateAndAppend(fifth, sixth, tmpCpus) - // make c.cpus divisible by maxContainerCount * nCpus, so we don't have to check which numa will be used // and we can use offsets countToRemove := len(tmpCpus) % (c.maxContainerCount * *NConfiguredCpus) -- 2.16.6