Skip to content

Commit ada0313

Browse files
committed
PPC: skip comparing ProcessorCore.Index between NUMA cores
ProcessorCore.Index indicates the zero-based index of the core in the Cores slice. While core might be shown in a different order, they can still be equivalent. See: jaypipes/ghw#346. Adjust the equality check to skip this field to fix this: ``` Error: targeted nodes differ: nodes host1.development.lab and host2.development.lab have different topology: the CPU cores differ: processor core #20 (2 threads), logical processors [2 66] vs processor core #20 (2 threads), logical processors [2 66] ``` And add a unit test to cover this scenario. Signed-off-by: Shereen Haj <[email protected]>
1 parent 1e9a589 commit ada0313

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

pkg/performanceprofile/profilecreator/profilecreator.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,8 @@ func EnsureNodesHaveTheSameHardware(nodeHandlers []*GHWHandler) error {
708708
}
709709

710710
func ensureSameTopology(topology1, topology2 *topology.Info) error {
711+
// the assumption here is that both topologies are deep sorted (e.g. slices of numa nodes, cores, processors ..);
712+
// see handle.SortedTopology()
711713
if topology1.Architecture != topology2.Architecture {
712714
return fmt.Errorf("the architecture is different: %v vs %v", topology1.Architecture, topology2.Architecture)
713715
}
@@ -730,8 +732,16 @@ func ensureSameTopology(topology1, topology2 *topology.Info) error {
730732
}
731733

732734
for j, core1 := range cores1 {
733-
if !reflect.DeepEqual(core1, cores2[j]) {
734-
return fmt.Errorf("the CPU corres differ: %v vs %v", core1, cores2[j])
735+
// skip comparing index because it's fine if they deffer; see https://github.com/jaypipes/ghw/issues/345#issuecomment-1620274077
736+
// ghw.ProcessorCore.Index is completely removed starting v0.11.0
737+
if core1.ID != cores2[j].ID {
738+
return fmt.Errorf("the CPU core ids in NUMA node %d differ: %d vs %d", node1.ID, core1.ID, cores2[j].ID)
739+
}
740+
if core1.NumThreads != cores2[j].NumThreads {
741+
return fmt.Errorf("number of threads for CPU %d in NUMA node %d differs: %d vs %d", core1.ID, node1.ID, core1.NumThreads, cores2[j].NumThreads)
742+
}
743+
if !reflect.DeepEqual(core1.LogicalProcessors, cores2[j].LogicalProcessors) {
744+
return fmt.Errorf("logical processors for CPU %d in NUMA node %d differs: %d vs %d", core1.ID, node1.ID, core1.NumThreads, cores2[j].NumThreads)
735745
}
736746
}
737747
}

pkg/performanceprofile/profilecreator/profilecreator_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,12 @@ var _ = Describe("PerformanceProfileCreator: Test Helper Function ensureSameTopo
14741474
err := ensureSameTopology(&topology1, &topology2)
14751475
Expect(err).To(HaveOccurred())
14761476
})
1477+
It("same cores with different indices should still considered equivalent", func() {
1478+
topology2.Nodes[0].Cores[0].Index = 1
1479+
topology2.Nodes[0].Cores[1].Index = 0
1480+
err := ensureSameTopology(&topology1, &topology2)
1481+
Expect(err).ToNot(HaveOccurred())
1482+
})
14771483
})
14781484
})
14791485

0 commit comments

Comments
 (0)