hs-test: fix numa node core retrieval 15/42315/4
authorSemir Sionek <[email protected]>
Thu, 6 Feb 2025 12:44:05 +0000 (07:44 -0500)
committerFlorin Coras <[email protected]>
Thu, 6 Feb 2025 17:24:17 +0000 (17:24 +0000)
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 <[email protected]>
extras/hs-test/infra/cpu.go

index e871c60..743a4ed 100644 (file)
@@ -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)