Refactor the CPU associativity lookup logic to reduce code nesting and improve readability. Previously, the code had separate paths for VPHN and device tree lookups with duplicated processing logic.
Consolidate the lookup into a unified flow: 1. Try VPHN associativity if firmware supports it 2. Fall back to device tree associativity if VPHN fails or unavailable 3. Process the associativity information once, regardless of source No functional change is intended. Both VPHN and device tree paths continue to work as before, with the common associativity processing performed in one place. Signed-off-by: Srikar Dronamraju <[email protected]> --- arch/powerpc/mm/numa.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c index ffdb07b995a8..c2aefb60ed5a 100644 --- a/arch/powerpc/mm/numa.c +++ b/arch/powerpc/mm/numa.c @@ -920,6 +920,7 @@ static int detect_and_enable_coregroup(const __be32 *associativity, int index) static int __init parse_numa_properties(void) { + bool vphn = firmware_has_feature(FW_FEATURE_VPHN); struct device_node *memory, *pci; int default_nid = 0, index = 0; const __be32 *associativity; @@ -951,17 +952,16 @@ static int __init parse_numa_properties(void) */ for_each_present_cpu(i) { __be32 vphn_assoc[VPHN_ASSOC_BUFSIZE]; + struct device_node *cpu = NULL; int nid = NUMA_NO_NODE; - memset(vphn_assoc, 0, VPHN_ASSOC_BUFSIZE * sizeof(__be32)); - - if (vphn_get_associativity(i, vphn_assoc) == 0) { - nid = associativity_to_nid(vphn_assoc); - initialize_form1_numa_distance(vphn_assoc); - index = detect_and_enable_coregroup(vphn_assoc, index); - } else { - struct device_node *cpu; - + associativity = NULL; + if (vphn) { + memset(vphn_assoc, 0, VPHN_ASSOC_BUFSIZE * sizeof(__be32)); + if (vphn_get_associativity(i, vphn_assoc) == 0) + associativity = vphn_assoc; + } + if (!associativity) { /* * Don't fall back to default_nid yet -- we will plug * cpus into nodes once the memory scan has discovered @@ -971,13 +971,14 @@ static int __init parse_numa_properties(void) BUG_ON(!cpu); associativity = of_get_associativity(cpu); - if (associativity) { - nid = associativity_to_nid(associativity); - index = detect_and_enable_coregroup(associativity, index); - initialize_form1_numa_distance(associativity); - } - of_node_put(cpu); } + if (associativity) { + nid = associativity_to_nid(associativity); + initialize_form1_numa_distance(associativity); + index = detect_and_enable_coregroup(associativity, index); + } + if (cpu) + of_node_put(cpu); /* node_set_online() is an UB if 'nid' is negative */ if (likely(nid >= 0) && numa_enabled) -- 2.47.1
