From: Matthew Dobson Patch 2/3: This patch defines a topology macro for ppc64, nr_cpus_node(node) which returns the number of CPUs on 'node'. This patch also adds code to compute and store these values in an array for quick lookup. Test compiled and booted by Andrew Theurer (habanero@us.ibm.com) on both x440 and ppc64. 25-akpm/arch/ppc64/mm/numa.c | 6 +++++- 25-akpm/include/asm-ppc64/mmzone.h | 1 + 25-akpm/include/asm-ppc64/topology.h | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff -puN arch/ppc64/mm/numa.c~sched_best_cpu-fix-02 arch/ppc64/mm/numa.c --- 25/arch/ppc64/mm/numa.c~sched_best_cpu-fix-02 Tue Jun 3 13:03:28 2003 +++ 25-akpm/arch/ppc64/mm/numa.c Tue Jun 3 13:03:28 2003 @@ -25,6 +25,7 @@ int numa_cpu_lookup_table[NR_CPUS] = { [ int numa_memory_lookup_table[MAX_MEMORY >> MEMORY_INCREMENT_SHIFT] = { [ 0 ... ((MAX_MEMORY >> MEMORY_INCREMENT_SHIFT) - 1)] = -1}; unsigned long numa_cpumask_lookup_table[MAX_NUMNODES]; +int nr_cpus_in_node[MAX_NUMNODES] = { [0 ... (MAX_NUMNODES -1)] = 0}; struct pglist_data node_data[MAX_NUMNODES]; bootmem_data_t plat_node_bdata[MAX_NUMNODES]; @@ -33,7 +34,10 @@ static inline void map_cpu_to_node(int c { dbg("cpu %d maps to domain %d\n", cpu, node); numa_cpu_lookup_table[cpu] = node; - numa_cpumask_lookup_table[node] |= 1UL << cpu; + if (!(numa_cpumask_lookup_table[node] & 1UL << cpu)) { + numa_cpumask_lookup_table[node] |= 1UL << cpu; + nr_cpus_in_node[node]++; + } } static int __init parse_numa_properties(void) diff -puN include/asm-ppc64/mmzone.h~sched_best_cpu-fix-02 include/asm-ppc64/mmzone.h --- 25/include/asm-ppc64/mmzone.h~sched_best_cpu-fix-02 Tue Jun 3 13:03:28 2003 +++ 25-akpm/include/asm-ppc64/mmzone.h Tue Jun 3 13:03:28 2003 @@ -21,6 +21,7 @@ extern struct pglist_data node_data[]; extern int numa_cpu_lookup_table[]; extern int numa_memory_lookup_table[]; extern unsigned long numa_cpumask_lookup_table[]; +extern int nr_cpus_in_node[]; #define MAX_MEMORY (1UL << 41) /* 256MB regions */ diff -puN include/asm-ppc64/topology.h~sched_best_cpu-fix-02 include/asm-ppc64/topology.h --- 25/include/asm-ppc64/topology.h~sched_best_cpu-fix-02 Tue Jun 3 13:03:28 2003 +++ 25-akpm/include/asm-ppc64/topology.h Tue Jun 3 13:03:28 2003 @@ -38,6 +38,8 @@ static inline int node_to_first_cpu(int #define pcibus_to_cpumask(bus) (cpu_online_map) +#define nr_cpus_node(node) (nr_cpus_in_node[node]) + /* Cross-node load balancing interval. */ #define NODE_BALANCE_RATE 10 _