<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
From: Matthew Dobson &lt;colpatch@us.ibm.com&gt;

3/10 - Replace numnodes with node_online_map for i386

[mcd@arrakis node_online_map]$ diffstat arch-i386.patch

-Matt


Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
---

 25-akpm/arch/i386/kernel/mpparse.c              |    4 +--
 25-akpm/arch/i386/kernel/numaq.c                |   10 +++----
 25-akpm/arch/i386/kernel/srat.c                 |   32 +++++++++++++-----------
 25-akpm/arch/i386/mm/discontig.c                |   28 ++++++++++++---------
 25-akpm/arch/i386/pci/numa.c                    |    7 +++--
 25-akpm/include/asm-i386/mach-numaq/mach_apic.h |   10 ++++---
 6 files changed, 51 insertions(+), 40 deletions(-)

diff -puN arch/i386/kernel/mpparse.c~replace-numnodes-with-node_online_map-i386 arch/i386/kernel/mpparse.c
--- 25/arch/i386/kernel/mpparse.c~replace-numnodes-with-node_online_map-i386	Thu Dec 23 15:21:55 2004
+++ 25-akpm/arch/i386/kernel/mpparse.c	Thu Dec 23 15:21:55 2004
@@ -309,8 +309,8 @@ static void __init MP_translation_info (
 		printk(KERN_ERR "MAX_MPC_ENTRY exceeded!\n");
 	else
 		translation_table[mpc_record] = m; /* stash this for later */
-	if (m-&gt;trans_quad+1 &gt; numnodes)
-		numnodes = m-&gt;trans_quad+1;
+	if (m-&gt;trans_quad &lt; MAX_NUMNODES &amp;&amp; !node_online(m-&gt;trans_quad))
+		node_set_online(m-&gt;trans_quad);
 }
 
 /*
diff -puN arch/i386/kernel/numaq.c~replace-numnodes-with-node_online_map-i386 arch/i386/kernel/numaq.c
--- 25/arch/i386/kernel/numaq.c~replace-numnodes-with-node_online_map-i386	Thu Dec 23 15:21:55 2004
+++ 25-akpm/arch/i386/kernel/numaq.c	Thu Dec 23 15:21:55 2004
@@ -40,8 +40,7 @@ extern long node_start_pfn[], node_end_p
  * Function: smp_dump_qct()
  *
  * Description: gets memory layout from the quad config table.  This
- * function also increments numnodes with the number of nodes (quads)
- * present.
+ * function also updates node_online_map with the nodes (quads) present.
  */
 static void __init smp_dump_qct(void)
 {
@@ -50,11 +49,10 @@ static void __init smp_dump_qct(void)
 	struct sys_cfg_data *scd =
 		(struct sys_cfg_data *)__va(SYS_CFG_DATA_PRIV_ADDR);
 
-	numnodes = 0;
-	for(node = 0; node &lt; MAX_NUMNODES; node++) {
-		if(scd-&gt;quads_present31_0 &amp; (1 &lt;&lt; node)) {
+	nodes_clear(node_online_map);
+	for_each_node(node) {
+		if (scd-&gt;quads_present31_0 &amp; (1 &lt;&lt; node)) {
 			node_set_online(node);
-			numnodes++;
 			eq = &amp;scd-&gt;eq[node];
 			/* Convert to pages */
 			node_start_pfn[node] = MB_TO_PAGES(
diff -puN arch/i386/kernel/srat.c~replace-numnodes-with-node_online_map-i386 arch/i386/kernel/srat.c
--- 25/arch/i386/kernel/srat.c~replace-numnodes-with-node_online_map-i386	Thu Dec 23 15:21:55 2004
+++ 25-akpm/arch/i386/kernel/srat.c	Thu Dec 23 15:21:55 2004
@@ -232,18 +232,22 @@ static int __init acpi20_parse_srat(stru
 	 * a set of sequential node IDs starting at zero.  (ACPI doesn't seem
 	 * to specify the range of _PXM values.)
 	 */
-	numnodes = 0;		/* init total nodes in system */
+	/*
+	 * MCD - we no longer HAVE to number nodes sequentially.  PXM domain
+	 * numbers could go as high as 256, and MAX_NUMNODES for i386 is typically
+	 * 32, so we will continue numbering them in this manner until MAX_NUMNODES
+	 * approaches MAX_PXM_DOMAINS for i386.
+	 */
+	nodes_clear(node_online_map);
 	for (i = 0; i &lt; MAX_PXM_DOMAINS; i++) {
 		if (BMAP_TEST(pxm_bitmap, i)) {
-			pxm_to_nid_map[i] = numnodes;
-			nid_to_pxm_map[numnodes] = i;
-			node_set_online(numnodes);
-			++numnodes;
+			nid = num_online_nodes();
+			pxm_to_nid_map[i] = nid;
+			nid_to_pxm_map[nid] = i;
+			node_set_online(nid);
 		}
 	}
-
-	if (numnodes == 0)
-		BUG();
+	BUG_ON(num_online_nodes() == 0);
 
 	/* set cnode id in memory chunk structure */
 	for (i = 0; i &lt; num_memory_chunks; i++)
@@ -254,7 +258,7 @@ static int __init acpi20_parse_srat(stru
 		printk("%02X ", pxm_bitmap[i]);
 	}
 	printk("\n");
-	printk("Number of logical nodes in system = %d\n", numnodes);
+	printk("Number of logical nodes in system = %d\n", num_online_nodes());
 	printk("Number of memory chunks in system = %d\n", num_memory_chunks);
 
 	for (j = 0; j &lt; num_memory_chunks; j++){
@@ -265,7 +269,7 @@ static int __init acpi20_parse_srat(stru
 	}
  
 	/*calculate node_start_pfn/node_end_pfn arrays*/
-	for (nid = 0; nid &lt; numnodes; nid++) {
+	for_each_online_node(nid) {
 		int been_here_before = 0;
 
 		for (j = 0; j &lt; num_memory_chunks; j++){
@@ -397,7 +401,7 @@ static void __init get_zholes_init(void)
 	int first;
 	unsigned long end = 0;
 
-	for (nid = 0; nid &lt; numnodes; nid++) {
+	for_each_online_node(nid) {
 		first = 1;
 		for (c = 0; c &lt; num_memory_chunks; c++){
 			if (node_memory_chunk[c].nid == nid) {
@@ -425,8 +429,8 @@ unsigned long * __init get_zholes_size(i
 		zholes_size_init++;
 		get_zholes_init();
 	}
-	if((nid &gt;= numnodes) | (nid &gt;= MAX_NUMNODES))
-		printk("%s: nid = %d is invalid. numnodes = %d",
-		       __FUNCTION__, nid, numnodes);
+	if (nid &gt;= MAX_NUMNODES || !node_online(nid))
+		printk("%s: nid = %d is invalid/offline. num_online_nodes = %d",
+		       __FUNCTION__, nid, num_online_nodes());
 	return &amp;zholes_size[nid * MAX_NR_ZONES];
 }
diff -puN arch/i386/mm/discontig.c~replace-numnodes-with-node_online_map-i386 arch/i386/mm/discontig.c
--- 25/arch/i386/mm/discontig.c~replace-numnodes-with-node_online_map-i386	Thu Dec 23 15:21:55 2004
+++ 25-akpm/arch/i386/mm/discontig.c	Thu Dec 23 15:21:55 2004
@@ -41,7 +41,7 @@ bootmem_data_t node0_bdata;
  * numa interface - we expect the numa architecture specfic code to have
  *                  populated the following initialisation.
  *
- * 1) numnodes         - the total number of nodes configured in the system
+ * 1) node_online_map  - the map of all nodes configured (online) in the system
  * 2) physnode_map     - the mapping between a pfn and owning node
  * 3) node_start_pfn   - the starting page frame number for a node
  * 3) node_end_pfn     - the ending page fram number for a node
@@ -93,12 +93,12 @@ int __init get_memcfg_numa_flat(void)
 
 	/* Run the memory configuration and find the top of memory. */
 	find_max_pfn();
-	node_start_pfn[0]  = 0;
-	node_end_pfn[0]	  = max_pfn;
+	node_start_pfn[0] = 0;
+	node_end_pfn[0] = max_pfn;
 
         /* Indicate there is one node available. */
+	nodes_clear(node_online_map);
 	node_set_online(0);
-	numnodes = 1;
 	return 1;
 }
 
@@ -183,7 +183,9 @@ void __init remap_numa_kva(void)
 	unsigned long pfn;
 	int node;
 
-	for (node = 1; node &lt; numnodes; ++node) {
+	for_each_online_node(node) {
+		if (node == 0)
+			continue;
 		for (pfn=0; pfn &lt; node_remap_size[node]; pfn += PTRS_PER_PTE) {
 			vaddr = node_remap_start_vaddr[node]+(pfn&lt;&lt;PAGE_SHIFT);
 			set_pmd_pfn((ulong) vaddr, 
@@ -198,7 +200,9 @@ static unsigned long calculate_numa_rema
 	int nid;
 	unsigned long size, reserve_pages = 0;
 
-	for (nid = 1; nid &lt; numnodes; nid++) {
+	for_each_online_node(nid) {
+		if (nid == 0)
+			continue;
 		/* calculate the size of the mem_map needed in bytes */
 		size = (node_end_pfn[nid] - node_start_pfn[nid] + 1) 
 			* sizeof(struct page) + sizeof(pg_data_t);
@@ -248,7 +252,7 @@ unsigned long __init setup_memory(void)
 	get_memcfg_numa();
 
 	/* Fill in the physnode_map */
-	for (nid = 0; nid &lt; numnodes; nid++) {
+	for_each_online_node(nid) {
 		printk("Node: %d, start_pfn: %ld, end_pfn: %ld\n",
 				nid, node_start_pfn[nid], node_end_pfn[nid]);
 		printk("  Setting physnode_map array to node %d for pfns:\n  ",
@@ -285,7 +289,7 @@ unsigned long __init setup_memory(void)
 
 	printk("Low memory ends at vaddr %08lx\n",
 			(ulong) pfn_to_kaddr(max_low_pfn));
-	for (nid = 0; nid &lt; numnodes; nid++) {
+	for_each_online_node(nid) {
 		node_remap_start_vaddr[nid] = pfn_to_kaddr(
 			(highstart_pfn + reserve_pages) - node_remap_offset[nid]);
 		allocate_pgdat(nid);
@@ -297,7 +301,7 @@ unsigned long __init setup_memory(void)
 	printk("High memory starts at vaddr %08lx\n",
 			(ulong) pfn_to_kaddr(highstart_pfn));
 	vmalloc_earlyreserve = reserve_pages * PAGE_SIZE;
-	for (nid = 0; nid &lt; numnodes; nid++)
+	for_each_online_node(nid)
 		find_max_pfn_node(nid);
 
 	NODE_DATA(0)-&gt;bdata = &amp;node0_bdata;
@@ -375,14 +379,16 @@ void __init zone_sizes_init(void)
 	 * Clobber node 0's links and NULL out pgdat_list before starting.
 	 */
 	pgdat_list = NULL;
-	for (nid = numnodes - 1; nid &gt;= 0; nid--) {       
+	for (nid = MAX_NUMNODES - 1; nid &gt;= 0; nid--) {
+		if (!node_online(nid))
+			continue;
 		if (nid)
 			memset(NODE_DATA(nid), 0, sizeof(pg_data_t));
 		NODE_DATA(nid)-&gt;pgdat_next = pgdat_list;
 		pgdat_list = NODE_DATA(nid);
 	}
 
-	for (nid = 0; nid &lt; numnodes; nid++) {
+	for_each_online_node(nid) {
 		unsigned long zones_size[MAX_NR_ZONES] = {0, 0, 0};
 		unsigned long *zholes_size;
 		unsigned int max_dma;
diff -puN arch/i386/pci/numa.c~replace-numnodes-with-node_online_map-i386 arch/i386/pci/numa.c
--- 25/arch/i386/pci/numa.c~replace-numnodes-with-node_online_map-i386	Thu Dec 23 15:21:55 2004
+++ 25-akpm/arch/i386/pci/numa.c	Thu Dec 23 15:21:55 2004
@@ -112,14 +112,15 @@ static int __init pci_numa_init(void)
 		return 0;
 
 	pci_root_bus = pcibios_scan_root(0);
-	if (numnodes &gt; 1) {
-		for (quad = 1; quad &lt; numnodes; ++quad) {
+	if (num_online_nodes() &gt; 1)
+		for_each_online_node(quad) {
+			if (quad == 0)
+				continue;
 			printk("Scanning PCI bus %d for quad %d\n", 
 				QUADLOCAL2BUS(quad,0), quad);
 			pci_scan_bus(QUADLOCAL2BUS(quad,0), 
 				&amp;pci_root_ops, NULL);
 		}
-	}
 	return 0;
 }
 
diff -puN include/asm-i386/mach-numaq/mach_apic.h~replace-numnodes-with-node_online_map-i386 include/asm-i386/mach-numaq/mach_apic.h
--- 25/include/asm-i386/mach-numaq/mach_apic.h~replace-numnodes-with-node_online_map-i386	Thu Dec 23 15:21:55 2004
+++ 25-akpm/include/asm-i386/mach-numaq/mach_apic.h	Thu Dec 23 15:21:55 2004
@@ -112,13 +112,15 @@ static inline int mpc_apic_id(struct mpc
 
 static inline void setup_portio_remap(void)
 {
-	if (numnodes &lt;= 1)
+	int num_quads = num_online_nodes();
+
+	if (num_quads &lt;= 1)
        		return;
 
-	printk("Remapping cross-quad port I/O for %d quads\n", numnodes);
-	xquad_portio = ioremap (XQUAD_PORTIO_BASE, numnodes*XQUAD_PORTIO_QUAD);
+	printk("Remapping cross-quad port I/O for %d quads\n", num_quads);
+	xquad_portio = ioremap(XQUAD_PORTIO_BASE, num_quads*XQUAD_PORTIO_QUAD);
 	printk("xquad_portio vaddr 0x%08lx, len %08lx\n",
-		(u_long) xquad_portio, (u_long) numnodes*XQUAD_PORTIO_QUAD);
+		(u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
 }
 
 static inline int check_phys_apicid_present(int boot_cpu_physical_apicid)
_
</pre></body></html>