diff --git a/test/e2e/performanceprofile/functests/2_performance_update/memorymanager.go b/test/e2e/performanceprofile/functests/2_performance_update/memorymanager.go index 7142db3f1b..3c9c0f1282 100644 --- a/test/e2e/performanceprofile/functests/2_performance_update/memorymanager.go +++ b/test/e2e/performanceprofile/functests/2_performance_update/memorymanager.go @@ -27,6 +27,7 @@ import ( "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" + "k8s.io/utils/cpuset" "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -54,7 +55,7 @@ var _ = Describe("[rfe_id: 43186][memorymanager] Memorymanager feature", Label(s Context("Group Both Numa Nodes with restricted topology", Ordered, Label(string(label.Tier2)), func() { var numaCoreSiblings map[int]map[int][]int - var reserved, isolated []string + var reserved, isolated cpuset.CPUSet // Number of hugepages of size 2M created on both numa nodes const hpCount = 20 testutils.CustomBeforeAll(func() { @@ -82,18 +83,16 @@ var _ = Describe("[rfe_id: 43186][memorymanager] Memorymanager feature", Label(s // Get cpu siblings from core 0, 1 for reservedCores := 0; reservedCores < 2; reservedCores++ { cpusiblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaCoreSiblings, reservedCores) - reserved = append(reserved, cpusiblings...) + reserved = reserved.Union(cpusiblings) } - reservedCpus := strings.Join(reserved, ",") for key := range numaCoreSiblings { for k := range numaCoreSiblings[key] { cpusiblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaCoreSiblings, k) - isolated = append(isolated, cpusiblings...) + isolated = isolated.Union(cpusiblings) } } - isolatedCpus := strings.Join(isolated, ",") - reservedSet := performancev2.CPUSet(reservedCpus) - isolatedSet := performancev2.CPUSet(isolatedCpus) + reservedSet := performancev2.CPUSet(reserved.String()) + isolatedSet := performancev2.CPUSet(isolated.String()) hpSize1G := performancev2.HugePageSize("1G") hpSize2M := performancev2.HugePageSize("2M") @@ -156,7 +155,7 @@ var _ = Describe("[rfe_id: 43186][memorymanager] Memorymanager feature", Label(s mm2.hpgSize = profile.Spec.HugePages.Pages[0].Size targetNode := &workerRTNodes[0] mm2.memory = "200Mi" - mm2.cpu = fmt.Sprintf("%d", len(isolated)-2) + mm2.cpu = fmt.Sprintf("%d", isolated.Size()-2) // no. of hugepages is 20 * 2 (numazones). 40Mi // we are asking for 30Mi, so it needs 2 numazones combined to // satisfy the requirement @@ -177,7 +176,7 @@ var _ = Describe("[rfe_id: 43186][memorymanager] Memorymanager feature", Label(s mm2.hpgSize = profile.Spec.HugePages.Pages[0].Size targetNode := &workerRTNodes[0] mm2.memory = "200Mi" - mm2.cpu = fmt.Sprintf("%d", len(isolated)-2) + mm2.cpu = fmt.Sprintf("%d", isolated.Size()-2) mm2.noOfhpgs = "8Mi" testPod := mm2.createPodTemplate(profile, false, targetNode) // Initialize test pod, check if the pod uses both numa node 0 and 1 @@ -211,10 +210,10 @@ var _ = Describe("[rfe_id: 43186][memorymanager] Memorymanager feature", Label(s Context("Numa Nodes of same Hugepage size with different hugepages count and restricted policy", Ordered, Label(string(label.Tier2)), func() { var numaCoreSiblings map[int]map[int][]int - var reserved, isolated, available_node0_cpus, available_node1_cpus []string + var reserved, isolated, available_node0_cpus, available_node1_cpus cpuset.CPUSet var numaZone0HugepagesCount int = 10 var numaZone1HugepagesCount int = 20 - numaZone := make(map[int]map[int][]string) + numaZone := make(map[int]map[int]cpuset.CPUSet) testutils.CustomBeforeAll(func() { var policy = "restricted" workerRTNodes = getUpdatedNodes() @@ -251,19 +250,18 @@ var _ = Describe("[rfe_id: 43186][memorymanager] Memorymanager feature", Label(s break } cpusiblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaCoreSiblings, reservedCores) - reserved = append(reserved, cpusiblings...) + reserved = reserved.Union(cpusiblings) count++ } - reservedCpus := strings.Join(reserved, ",") for key := range numaCoreSiblings { if numaZone[key] == nil { - numaZone[key] = make(map[int][]string) + numaZone[key] = make(map[int]cpuset.CPUSet) } for k := range numaCoreSiblings[key] { cpusiblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaCoreSiblings, k) - isolated = append(isolated, cpusiblings...) - numaZone[key][k] = append(numaZone[key][k], cpusiblings...) + isolated = isolated.Union(cpusiblings) + numaZone[key][k] = numaZone[key][k].Union(cpusiblings) } } @@ -272,16 +270,15 @@ var _ = Describe("[rfe_id: 43186][memorymanager] Memorymanager feature", Label(s // are assigned to reserved. // Get available cpus in numa node 0 and numa node 1 for core := range numaZone[0] { - available_node0_cpus = append(available_node0_cpus, numaZone[0][core]...) + available_node0_cpus = available_node0_cpus.Union(numaZone[0][core]) } for core := range numaZone[1] { - available_node1_cpus = append(available_node1_cpus, numaZone[1][core]...) + available_node1_cpus = available_node1_cpus.Union(numaZone[1][core]) } - isolatedCpus := strings.Join(isolated, ",") - reservedSet := performancev2.CPUSet(reservedCpus) - isolatedSet := performancev2.CPUSet(isolatedCpus) + reservedSet := performancev2.CPUSet(reserved.String()) + isolatedSet := performancev2.CPUSet(isolated.String()) // Enable Hugepages hpSize2M := performancev2.HugePageSize("2M") @@ -326,7 +323,7 @@ var _ = Describe("[rfe_id: 43186][memorymanager] Memorymanager feature", Label(s // cpus of numa zone1 will be greater than numa zone0 because we used 4 cpus from numa zone0 for reserved. // so number of cpus will be total number of available cpus on numazone0 + 2 // which can be satisfied by cpus of numa zone 1 only. - mm1.cpu = fmt.Sprintf("%d", len(available_node0_cpus)+2) + mm1.cpu = fmt.Sprintf("%d", available_node0_cpus.Size()+2) // we are requesting 14Mi hugepages which again can be satisfied by numa zone 1 // since numa zone 0 has only 10Mi hugepages mm1.noOfhpgs = "14Mi" @@ -349,11 +346,11 @@ var _ = Describe("[rfe_id: 43186][memorymanager] Memorymanager feature", Label(s targetNode := &workerRTNodes[0] mm1.memory = "200Mi" mm1.hpgSize = profile.Spec.HugePages.Pages[1].Size - var availableCpusOnZone1 = len(available_node1_cpus) + var availableCpusOnZone1 = available_node1_cpus.Size() // cpus of numa zone1 will be greater than numa zone0 because we used 4 cpus from numa zone0 for reserved. // so number of cpus will be total number of available cpus on numazone 0 + 2 // which can be satisfied by cpus of numa zone 1 only. - mm1.cpu = fmt.Sprintf("%d", len(available_node0_cpus)+2) + mm1.cpu = fmt.Sprintf("%d", available_node0_cpus.Size()+2) // Reduce the cpus taken for testPod1 from availablecpus on numa zone1 availableCpusOnZone1 = availableCpusOnZone1 - 2 // we are requesting 14Mi hugepages which again can be satisfed by numa zone 1 @@ -407,7 +404,7 @@ var _ = Describe("[rfe_id: 43186][memorymanager] Memorymanager feature", Label(s Context("Group Both Numa Nodes with single-numa-node topology", Ordered, Label(string(label.Tier2)), func() { var numaCoreSiblings map[int]map[int][]int - var reserved, isolated []string + var reserved, isolated cpuset.CPUSet var err error // Number of hugepages of size 2M const hpCount = 20 @@ -435,18 +432,16 @@ var _ = Describe("[rfe_id: 43186][memorymanager] Memorymanager feature", Label(s // Get cpu siblings from core 0, 1 for reservedCores := 0; reservedCores < 2; reservedCores++ { cpusiblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaCoreSiblings, reservedCores) - reserved = append(reserved, cpusiblings...) + reserved = reserved.Union(cpusiblings) } - reservedCpus := strings.Join(reserved, ",") for key := range numaCoreSiblings { for k := range numaCoreSiblings[key] { cpusiblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaCoreSiblings, k) - isolated = append(isolated, cpusiblings...) + isolated = isolated.Union(cpusiblings) } } - isolatedCpus := strings.Join(isolated, ",") - reservedSet := performancev2.CPUSet(reservedCpus) - isolatedSet := performancev2.CPUSet(isolatedCpus) + reservedSet := performancev2.CPUSet(reserved.String()) + isolatedSet := performancev2.CPUSet(isolated.String()) // Enable Hugepages hpSize2M := performancev2.HugePageSize("2M") @@ -516,11 +511,11 @@ var _ = Describe("[rfe_id: 43186][memorymanager] Memorymanager feature", Label(s Context("Numa Nodes with different hugepage size and single-numa-node policy", Ordered, Label(string(label.Tier2)), func() { var numaCoreSiblings map[int]map[int][]int - var reserved, isolated, available_node0_cpus, available_node1_cpus []string + var reserved, isolated, available_node0_cpus, available_node1_cpus cpuset.CPUSet var numaZone0HugepagesCount int = 10 var numaZone1HugepagesCount int = 10 var err error - numaZone := make(map[int]map[int][]string) + numaZone := make(map[int]map[int]cpuset.CPUSet) testutils.CustomBeforeAll(func() { var policy = "single-numa-node" workerRTNodes = getUpdatedNodes() @@ -546,18 +541,17 @@ var _ = Describe("[rfe_id: 43186][memorymanager] Memorymanager feature", Label(s // Get cpu siblings from core 0, 1 for reservedCores := 0; reservedCores < 2; reservedCores++ { cpusiblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaCoreSiblings, reservedCores) - reserved = append(reserved, cpusiblings...) + reserved = reserved.Union(cpusiblings) } - reservedCpus := strings.Join(reserved, ",") for key := range numaCoreSiblings { if numaZone[key] == nil { - numaZone[key] = make(map[int][]string) + numaZone[key] = make(map[int]cpuset.CPUSet) } for k := range numaCoreSiblings[key] { cpusiblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaCoreSiblings, k) - isolated = append(isolated, cpusiblings...) - numaZone[key][k] = append(numaZone[key][k], cpusiblings...) + isolated = isolated.Union(cpusiblings) + numaZone[key][k] = numaZone[key][k].Union(cpusiblings) } } @@ -566,16 +560,15 @@ var _ = Describe("[rfe_id: 43186][memorymanager] Memorymanager feature", Label(s // are assigned to reserved. // Get available cpus in numa node 0 and numa node 1 for core := range numaZone[0] { - available_node0_cpus = append(available_node0_cpus, numaZone[0][core]...) + available_node0_cpus = available_node0_cpus.Union(numaZone[0][core]) } for core := range numaZone[1] { - available_node1_cpus = append(available_node1_cpus, numaZone[1][core]...) + available_node1_cpus = available_node0_cpus.Union(numaZone[1][core]) } - isolatedCpus := strings.Join(isolated, ",") - reservedSet := performancev2.CPUSet(reservedCpus) - isolatedSet := performancev2.CPUSet(isolatedCpus) + reservedSet := performancev2.CPUSet(reserved.String()) + isolatedSet := performancev2.CPUSet(isolated.String()) // Enable Hugepages hpSize2M := performancev2.HugePageSize("2M") @@ -617,7 +610,7 @@ var _ = Describe("[rfe_id: 43186][memorymanager] Memorymanager feature", Label(s mm1.memory = "200Mi" mm1.hpgSize = profile.Spec.HugePages.Pages[0].Size targetNode := &workerRTNodes[0] - mm1.cpu = fmt.Sprintf("%d", len(available_node0_cpus)-2) + mm1.cpu = fmt.Sprintf("%d", available_node0_cpus.Size()-2) mm1.hpgSize = "2M" // we are requesting 8Mi hugepages which again can be satisfied by numa zone 0 mm1.noOfhpgs = "8Mi" @@ -635,7 +628,7 @@ var _ = Describe("[rfe_id: 43186][memorymanager] Memorymanager feature", Label(s mm2.noOfhpgs = "4Gi" mm2.memory = "200Mi" mm2.hpgSize = profile.Spec.HugePages.Pages[1].Size - mm2.cpu = fmt.Sprintf("%d", len(available_node1_cpus)-2) + mm2.cpu = fmt.Sprintf("%d", available_node1_cpus.Size()-2) testPod2 := mm2.createPodTemplate(profile, true, targetNode) // Initialize test pod, check if the pod uses Numa node 1 err = initializePod(context.TODO(), testPod2) @@ -781,7 +774,7 @@ func GetMemoryNodes(ctx context.Context, testPod *corev1.Pod, targetNode *corev1 } containerCgroup, err = cgroup.PidParser(out) Expect(err).ToNot(HaveOccurred()) - fmt.Println("Container Cgroup = ", containerCgroup) + testlog.Infof("cgroup path = %s", containerCgroup) cgroupv2, err := cgroup.IsVersion2(context.TODO(), testclient.DataPlaneClient) if err != nil { return "", err diff --git a/test/e2e/performanceprofile/functests/2_performance_update/updating_profile.go b/test/e2e/performanceprofile/functests/2_performance_update/updating_profile.go index bf02c77ead..ccfb199df8 100644 --- a/test/e2e/performanceprofile/functests/2_performance_update/updating_profile.go +++ b/test/e2e/performanceprofile/functests/2_performance_update/updating_profile.go @@ -625,7 +625,7 @@ var _ = Describe("[rfe_id:28761][performance] Updating parameters in performance }) It("[test_id:50964] Offline Higher CPUID's", func() { - var reserved, isolated, offline []string + var reserved, isolated, offline cpuset.CPUSet numaTopology := copyNumaCoreSiblings(numaCoreSiblings) for numaNode := range numaTopology { cores := make([]int, 0) @@ -637,30 +637,30 @@ var _ = Describe("[rfe_id:28761][performance] Updating parameters in performance higherCoreIds := cores[len(cores)-1] // Get cpu siblings from the selected cores and delete the selected cores from the map cpusiblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaTopology, higherCoreIds) - offline = append(offline, cpusiblings...) + //offline = append(offline, cpusiblings...) + offline = offline.Union(cpusiblings) } - offlineCpus := strings.Join(offline, ",") // Get reserved core siblings from 0, 1 for reservedCores := 0; reservedCores < 2; reservedCores++ { // Get the cpu siblings from the selected core and delete the siblings // from the map. Selected siblings of cores are saved in reservedCpus cpusiblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaTopology, reservedCores) - reserved = append(reserved, cpusiblings...) + //reserved = append(reserved, cpusiblings...) + reserved = reserved.Union(cpusiblings) } - reservedCpus := strings.Join(reserved, ",") + // Remaining core siblings available in the // numaTopology map is used in isolatedCpus for key := range numaTopology { for k := range numaTopology[key] { cpusiblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaTopology, k) - isolated = append(isolated, cpusiblings...) + //isolated = append(isolated, cpusiblings...) + isolated = isolated.Union(cpusiblings) } } - isolatedCpus := strings.Join(isolated, ",") - // Create new performance with offlined - reservedSet := performancev2.CPUSet(reservedCpus) - isolatedSet := performancev2.CPUSet(isolatedCpus) - offlinedSet := performancev2.CPUSet(offlineCpus) + reservedSet := performancev2.CPUSet(reserved.String()) + isolatedSet := performancev2.CPUSet(isolated.String()) + offlinedSet := performancev2.CPUSet(offline.String()) profile, err := profiles.GetByNodeLabels(testutils.NodeSelectorLabels) Expect(err).ToNot(HaveOccurred()) @@ -695,7 +695,7 @@ var _ = Describe("[rfe_id:28761][performance] Updating parameters in performance }) It("[test_id:50965]Offline Middle CPUID's", func() { - var reserved, isolated, offline []string + var reserved, isolated, offline cpuset.CPUSet numaTopology := copyNumaCoreSiblings(numaCoreSiblings) for key := range numaTopology { cores := make([]int, 0) @@ -705,29 +705,26 @@ var _ = Describe("[rfe_id:28761][performance] Updating parameters in performance sort.Ints(cores) middleCoreIds := cores[len(cores)/2] siblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaTopology, middleCoreIds) - offline = append(offline, siblings...) + offline = offline.Union(siblings) } - offlineCpus := strings.Join(offline, ",") for reservedCores := 0; reservedCores < 2; reservedCores++ { // Get the cpu siblings from the selected core and delete the siblings // from the map. Selected siblings of cores are saved in reservedCpus siblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaTopology, reservedCores) - reserved = append(reserved, siblings...) + reserved = reserved.Union(siblings) } - reservedCpus := strings.Join(reserved, ",") // Remaining core siblings available in the // numaTopology map is used in isolatedCpus for key := range numaTopology { for k := range numaTopology[key] { siblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaTopology, k) - isolated = append(isolated, siblings...) + isolated = isolated.Union(siblings) } } - isolatedCpus := strings.Join(isolated, ",") // Create new performance with offlined - reservedSet := performancev2.CPUSet(reservedCpus) - isolatedSet := performancev2.CPUSet(isolatedCpus) - offlinedSet := performancev2.CPUSet(offlineCpus) + reservedSet := performancev2.CPUSet(reserved.String()) + isolatedSet := performancev2.CPUSet(isolated.String()) + offlinedSet := performancev2.CPUSet(offline.String()) profile, err := profiles.GetByNodeLabels(testutils.NodeSelectorLabels) Expect(err).ToNot(HaveOccurred()) @@ -761,7 +758,7 @@ var _ = Describe("[rfe_id:28761][performance] Updating parameters in performance }) It("[test_id:50966]verify offlined parameter accepts multiple ranges of cpuid's", func() { - var reserved, isolated, offlined []string + var reserved, isolated, offlined cpuset.CPUSet numaTopology := copyNumaCoreSiblings(numaCoreSiblings) if len(numaCoreSiblings) < 2 { Skip(fmt.Sprintf("This test need 2 NUMA nodes, available only %d", len(numaCoreSiblings))) @@ -774,9 +771,8 @@ var _ = Describe("[rfe_id:28761][performance] Updating parameters in performance // Get the cpu siblings from the selected core and delete the siblings // from the map. Selected siblings of cores are saved in reservedCpus siblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaTopology, reservedCores) - reserved = append(reserved, siblings...) + reserved = reserved.Union(siblings) } - reservedCpus := strings.Join(reserved, ",") //Get Offline Core siblings . We take the total cores and //from the middle we take core ids for calculating the ranges. for key := range numaTopology { @@ -787,23 +783,21 @@ var _ = Describe("[rfe_id:28761][performance] Updating parameters in performance sort.Ints(cores) for i := 0; i < len(cores)/2; i++ { siblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaTopology, cores[i]) - offlined = append(offlined, siblings...) + offlined = offlined.Union(siblings) } } - offlinedCpus := nodes.GetNumaRanges(strings.Join(offlined, ",")) // Remaining core siblings available in the numaTopology // map is used in isolatedCpus for key := range numaTopology { for k := range numaTopology[key] { siblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaTopology, k) - isolated = append(isolated, siblings...) + isolated = isolated.Union(siblings) } } - isolatedCpus := strings.Join(isolated, ",") // Create new performance with offlined - reservedSet := performancev2.CPUSet(reservedCpus) - isolatedSet := performancev2.CPUSet(isolatedCpus) - offlinedSet := performancev2.CPUSet(offlinedCpus) + reservedSet := performancev2.CPUSet(reserved.String()) + isolatedSet := performancev2.CPUSet(isolated.String()) + offlinedSet := performancev2.CPUSet(offlined.String()) profile, err := profiles.GetByNodeLabels(testutils.NodeSelectorLabels) Expect(err).ToNot(HaveOccurred()) @@ -837,7 +831,7 @@ var _ = Describe("[rfe_id:28761][performance] Updating parameters in performance }) It("[test_id:50968]verify cpus mentioned in reserved or isolated cannot be offline", func() { - var reserved, isolated []string + var reserved, isolated, offlined cpuset.CPUSet numaTopology := copyNumaCoreSiblings(numaCoreSiblings) if len(numaCoreSiblings) < 2 { Skip(fmt.Sprintf("This test need 2 NUMA nodes, available only %d", len(numaCoreSiblings))) @@ -847,28 +841,26 @@ var _ = Describe("[rfe_id:28761][performance] Updating parameters in performance // Get the cpu siblings from the selected core and delete the siblings // from the map. Selected siblings of cores are saved in reservedCpus siblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaTopology, reservedCores) - reserved = append(reserved, siblings...) + reserved = reserved.Union(siblings) } - reservedCpus := strings.Join(reserved, ",") // Remaining core siblings available in the // numaTopology map is used in isolatedCpus for key := range numaTopology { for k := range numaTopology[key] { siblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaTopology, k) - isolated = append(isolated, siblings...) + isolated = isolated.Union(siblings) } } - isolatedCpus := strings.Join(isolated, ",") //combine both isolated and reserved - totalCpus := fmt.Sprintf("%s,%s", reservedCpus, isolatedCpus) - totalCpuSlice := strings.Split(totalCpus, ",") + totalCpuSlice := cpuset.CPUSet.Union(reserved, isolated) // get partial cpus from the combined cpus - partialCpulist := totalCpuSlice[:len(totalCpuSlice)/2] - offlineCpus := strings.Join(partialCpulist, ",") + totalList := totalCpuSlice.List() + offlineCpuList := totalList[:totalCpuSlice.Size()/2] + offlined = cpuset.New(offlineCpuList...) // Create new performance with offlined - reservedSet := performancev2.CPUSet(reservedCpus) - isolatedSet := performancev2.CPUSet(isolatedCpus) - offlinedSet := performancev2.CPUSet(offlineCpus) + reservedSet := performancev2.CPUSet(reserved.String()) + isolatedSet := performancev2.CPUSet(isolated.String()) + offlinedSet := performancev2.CPUSet(offlined.String()) profile, err := profiles.GetByNodeLabels(testutils.NodeSelectorLabels) Expect(err).ToNot(HaveOccurred()) @@ -904,7 +896,7 @@ var _ = Describe("[rfe_id:28761][performance] Updating parameters in performance }) It("[test_id:50970]Offline CPUID's from multiple numa nodes", func() { - var reserved, isolated, offlined []string + var reserved, isolated, offlined cpuset.CPUSet numaTopology := copyNumaCoreSiblings(numaCoreSiblings) if len(numaCoreSiblings) < 2 { Skip(fmt.Sprintf("This test need 2 NUMA nodes, available only %d", len(numaCoreSiblings))) @@ -914,27 +906,24 @@ var _ = Describe("[rfe_id:28761][performance] Updating parameters in performance // Get the cpu siblings from the selected core and delete the siblings // from the map. Selected siblings of cores are saved in reservedCpus siblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaTopology, reservedCores) - reserved = append(reserved, siblings...) + reserved = reserved.Union(siblings) } - reservedCpus := strings.Join(reserved, ",") discreteCores := []int{3, 13, 15, 24, 29} for _, v := range discreteCores { siblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaTopology, v) - offlined = append(offlined, siblings...) + offlined = offlined.Union(siblings) } - offlineCpus := strings.Join(offlined, ",") for key := range numaTopology { for k := range numaTopology[key] { cpusiblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaTopology, k) - isolated = append(isolated, cpusiblings...) + isolated = isolated.Union(cpusiblings) } } - isolatedCpus := strings.Join(isolated, ",") // Create new performance with offlined - reservedSet := performancev2.CPUSet(reservedCpus) - isolatedSet := performancev2.CPUSet(isolatedCpus) - offlinedSet := performancev2.CPUSet(offlineCpus) + reservedSet := performancev2.CPUSet(reserved.String()) + isolatedSet := performancev2.CPUSet(isolated.String()) + offlinedSet := performancev2.CPUSet(offlined.String()) profile, err := profiles.GetByNodeLabels(testutils.NodeSelectorLabels) Expect(err).ToNot(HaveOccurred()) @@ -1033,7 +1022,7 @@ var _ = Describe("[rfe_id:28761][performance] Updating parameters in performance }) It("[test_id:56006]Verify systemd unit file gets updated when the reserved cpus are modified", func() { - var reserved, isolated []string + var reserved, isolated cpuset.CPUSet var onlineCPUInt int for _, node := range workerRTNodes { out, err := nodes.ExecCommand(context.TODO(), &node, []string{"nproc", "--all"}) @@ -1060,19 +1049,17 @@ var _ = Describe("[rfe_id:28761][performance] Updating parameters in performance Expect(len(coreids)).ToNot(Equal(0)) middleCoreIds := coreids[len(coreids)/2] coresiblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaCoreSiblings, middleCoreIds) - reserved = append(reserved, coresiblings...) + reserved = reserved.Union(coresiblings) } - reservedCpus := strings.Join(reserved, ",") for numaNode := range numaCoreSiblings { for coreids := range numaCoreSiblings[numaNode] { coresiblings := nodes.GetAndRemoveCpuSiblingsFromMap(numaCoreSiblings, coreids) - isolated = append(isolated, coresiblings...) + isolated = isolated.Union(coresiblings) } } - isolatedCpus := strings.Join(isolated, ",") // Update performance profile - reservedSet := performancev2.CPUSet(reservedCpus) - isolatedSet := performancev2.CPUSet(isolatedCpus) + reservedSet := performancev2.CPUSet(reserved.String()) + isolatedSet := performancev2.CPUSet(isolated.String()) By("Update reserved, isolated parameters") profile.Spec.CPU = &performancev2.CPU{ diff --git a/test/e2e/performanceprofile/functests/utils/nodes/nodes.go b/test/e2e/performanceprofile/functests/utils/nodes/nodes.go index 629a3a6c48..f2d9bd85e1 100644 --- a/test/e2e/performanceprofile/functests/utils/nodes/nodes.go +++ b/test/e2e/performanceprofile/functests/utils/nodes/nodes.go @@ -386,22 +386,20 @@ func GetByCpuCapacity(nodesList []corev1.Node, cpuQty int) []corev1.Node { // GetAndRemoveCpuSiblingsFromMap function returns the cpus siblings associated with core // Also updates the map by deleting the cpu siblings returned -func GetAndRemoveCpuSiblingsFromMap(numaCoreSiblings map[int]map[int][]int, coreId int) []string { - var cpuSiblings []string +func GetAndRemoveCpuSiblingsFromMap(numaCoreSiblings map[int]map[int][]int, coreId int) cpuset.CPUSet { + var cpuSiblings []int // Iterate over the Numa node in the map for node := range numaCoreSiblings { // Check if the coreId exists in the Numa node _, ok := numaCoreSiblings[node][coreId] if ok { // Iterate over the siblings of the coreId - for _, sibling := range numaCoreSiblings[node][coreId] { - cpuSiblings = append(cpuSiblings, strconv.Itoa(sibling)) - } - // Delete the cpusiblings of that particular coreid - delete(numaCoreSiblings[node], coreId) + cpuSiblings = append(cpuSiblings, numaCoreSiblings[node][coreId]...) } + // Delete the cpusiblings of that particular coreid + delete(numaCoreSiblings[node], coreId) } - return cpuSiblings + return cpuset.New(cpuSiblings...) } // GetNumaRanges function Splits the numa Siblings in to multiple Ranges