[PATCH] [44/58] x86_64: extract helper function from e820_register_active_regions

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Andi Kleen
Date: Thursday, July 19, 2007 - 2:55 am

From: David Rientjes <rientjes@google.com>

The logic in e820_find_active_regions() for determining the true active
regions for an e820 entry given a range of PFN's is needed for
e820_hole_size() as well.

e820_hole_size() is called from the NUMA emulation code to determine the
reserved area within an address range on a per-node basis.  Its logic should
duplicate that of finding active regions in an e820 entry because these are
the only true ranges we may register anyway.

[akpm@linux-foundation.org: cleanup]
Cc: Mel Gorman <mel@csn.ul.ie>
Signed-off-by: David Rientjes <rientjes@google.com>
Signed-off-by: Andi Kleen <ak@suse.de>
Cc: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 arch/x86_64/kernel/e820.c |   82 ++++++++++++++++++++++++++--------------------
 1 file changed, 48 insertions(+), 34 deletions(-)

Index: linux/arch/x86_64/kernel/e820.c
===================================================================
--- linux.orig/arch/x86_64/kernel/e820.c
+++ linux/arch/x86_64/kernel/e820.c
@@ -289,47 +289,61 @@ void __init e820_mark_nosave_regions(voi
 	}
 }
 
+/*
+ * Finds an active region in the address range from start_pfn to end_pfn and
+ * returns its range in ei_startpfn and ei_endpfn for the e820 entry.
+ */
+static int __init e820_find_active_region(const struct e820entry *ei,
+					  unsigned long start_pfn,
+					  unsigned long end_pfn,
+					  unsigned long *ei_startpfn,
+					  unsigned long *ei_endpfn)
+{
+	*ei_startpfn = round_up(ei->addr, PAGE_SIZE) >> PAGE_SHIFT;
+	*ei_endpfn = round_down(ei->addr + ei->size, PAGE_SIZE) >> PAGE_SHIFT;
+
+	/* Skip map entries smaller than a page */
+	if (*ei_startpfn >= *ei_endpfn)
+		return 0;
+
+	/* Check if end_pfn_map should be updated */
+	if (ei->type != E820_RAM && *ei_endpfn > end_pfn_map)
+		end_pfn_map = *ei_endpfn;
+
+	/* Skip if map is outside the node */
+	if (ei->type != E820_RAM || *ei_endpfn <= start_pfn ||
+				    *ei_startpfn >= end_pfn)
+		return 0;
+
+	/* Check for overlaps */
+	if (*ei_startpfn < start_pfn)
+		*ei_startpfn = start_pfn;
+	if (*ei_endpfn > end_pfn)
+		*ei_endpfn = end_pfn;
+
+	/* Obey end_user_pfn to save on memmap */
+	if (*ei_startpfn >= end_user_pfn)
+		return 0;
+	if (*ei_endpfn > end_user_pfn)
+		*ei_endpfn = end_user_pfn;
+
+	return 1;
+}
+
 /* Walk the e820 map and register active regions within a node */
 void __init
 e820_register_active_regions(int nid, unsigned long start_pfn,
 							unsigned long end_pfn)
 {
+	unsigned long ei_startpfn;
+	unsigned long ei_endpfn;
 	int i;
-	unsigned long ei_startpfn, ei_endpfn;
-	for (i = 0; i < e820.nr_map; i++) {
-		struct e820entry *ei = &e820.map[i];
-		ei_startpfn = round_up(ei->addr, PAGE_SIZE) >> PAGE_SHIFT;
-		ei_endpfn = round_down(ei->addr + ei->size, PAGE_SIZE)
-								>> PAGE_SHIFT;
-
-		/* Skip map entries smaller than a page */
-		if (ei_startpfn >= ei_endpfn)
-			continue;
-
-		/* Check if end_pfn_map should be updated */
-		if (ei->type != E820_RAM && ei_endpfn > end_pfn_map)
-			end_pfn_map = ei_endpfn;
-
-		/* Skip if map is outside the node */
-		if (ei->type != E820_RAM ||
-				ei_endpfn <= start_pfn ||
-				ei_startpfn >= end_pfn)
-			continue;
-
-		/* Check for overlaps */
-		if (ei_startpfn < start_pfn)
-			ei_startpfn = start_pfn;
-		if (ei_endpfn > end_pfn)
-			ei_endpfn = end_pfn;
-
-		/* Obey end_user_pfn to save on memmap */
-		if (ei_startpfn >= end_user_pfn)
-			continue;
-		if (ei_endpfn > end_user_pfn)
-			ei_endpfn = end_user_pfn;
 
-		add_active_range(nid, ei_startpfn, ei_endpfn);
-	}
+	for (i = 0; i < e820.nr_map; i++)
+		if (e820_find_active_region(&e820.map[i],
+					    start_pfn, end_pfn,
+					    &ei_startpfn, &ei_endpfn))
+			add_active_range(nid, ei_startpfn, ei_endpfn);
 }
 
 /* 
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] [0/58] First batch of x86 patches for .23, Andi Kleen, (Thu Jul 19, 2:54 am)
[PATCH] [14/58] x86_64: Add on_cpu_single, Andi Kleen, (Thu Jul 19, 2:54 am)
[PATCH] [15/58] i386: Rewrite sched_clock, Andi Kleen, (Thu Jul 19, 2:54 am)
[PATCH] [20/58] x86: Always probe the NMI watchdog, Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [23/58] i386: remove pit_interrupt_hook, Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [25/58] x86_64: use generic cmos update, Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [26/58] x86_64: Use generic xtime init, Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [28/58] x86_64: Fix APIC typo, Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [29/58] x86_64: fiuxp pt_reqs leftovers, Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [30/58] x86: share hpet.h with i386, Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [34/58] x86_64: ia32entry adjustments, Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [39/58] i386: minor nx handling adjustment, Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [40/58] i386: remapped_pgdat_init() static, Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [42/58] i386: timer_irq_works() static again, Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [43/58] x86_64: Quicklist support for x86_64, Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [44/58] x86_64: extract helper function from e820_ ..., Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [48/58] x86_64: O_EXCL on /dev/mcelog, Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [51/58] i386: fix machine rebooting, Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [53/58] x86: PM_TRACE support, Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [55/58] i386: add reference to the arguments, Andi Kleen, (Thu Jul 19, 2:55 am)
[PATCH] [58/58] x86: remove support for the Rise CPU, Andi Kleen, (Thu Jul 19, 2:55 am)
Re: [PATCH] [33/58] x86_64: Avoid too many remote cpu refe ..., Christoph Hellwig, (Thu Jul 19, 3:21 am)
Re: [PATCH] [14/58] x86_64: Add on_cpu_single, Satyam Sharma, (Thu Jul 19, 4:09 am)
Re: [PATCH] [14/58] x86_64: Add on_cpu_single, Andi Kleen, (Thu Jul 19, 5:07 am)
Re: [PATCH] [34/58] x86_64: ia32entry adjustments, Jeff Garzik, (Thu Jul 19, 7:46 am)
Re: [PATCH] [15/58] i386: Rewrite sched_clock, Daniel Walker, (Thu Jul 19, 9:51 am)
Re: [PATCH] [15/58] i386: Rewrite sched_clock, Andi Kleen, (Thu Jul 19, 10:13 am)
Re: [PATCH] [15/58] i386: Rewrite sched_clock, Daniel Walker, (Thu Jul 19, 10:15 am)
Re: [PATCH] [15/58] i386: Rewrite sched_clock, Andi Kleen, (Thu Jul 19, 10:22 am)
Re: [PATCH] [15/58] i386: Rewrite sched_clock, Daniel Walker, (Thu Jul 19, 10:31 am)
Re: [PATCH] [15/58] i386: Rewrite sched_clock, Andi Kleen, (Thu Jul 19, 10:38 am)
Re: [PATCH] [15/58] i386: Rewrite sched_clock, Daniel Walker, (Thu Jul 19, 10:43 am)
Re: [PATCH] [15/58] i386: Rewrite sched_clock, Daniel Walker, (Thu Jul 19, 11:00 am)
Re: [PATCH] [15/58] i386: Rewrite sched_clock, Andi Kleen, (Thu Jul 19, 11:00 am)
Re: [PATCH] [15/58] i386: Rewrite sched_clock, Mathieu Desnoyers, (Thu Jul 19, 8:11 pm)
Re: [PATCH] [15/58] i386: Rewrite sched_clock, Mathieu Desnoyers, (Thu Jul 19, 8:47 pm)
Re: [PATCH] [15/58] i386: Rewrite sched_clock (cmpxchg8b), Mathieu Desnoyers, (Thu Jul 19, 9:18 pm)
Re: [PATCH] [15/58] i386: Rewrite sched_clock (cmpxchg8b), Mathieu Desnoyers, (Thu Jul 19, 10:47 pm)
Re: [PATCH] [15/58] i386: Rewrite sched_clock, Andi Kleen, (Fri Jul 20, 1:27 am)
Re: [PATCH] [15/58] i386: Rewrite sched_clock, Mathieu Desnoyers, (Fri Jul 20, 7:12 am)
Re: [PATCH] [15/58] i386: Rewrite sched_clock, Mathieu Desnoyers, (Fri Jul 20, 7:39 am)
Re: [PATCH] [15/58] i386: Rewrite sched_clock, Andi Kleen, (Fri Jul 20, 8:14 am)
Re: [PATCH] [15/58] i386: Rewrite sched_clock, Mathieu Desnoyers, (Fri Jul 20, 8:22 am)
[PATCH] 80386 and 80486 cmpxchg64 and cmpxchg64_local fallback, Mathieu Desnoyers, (Fri Jul 20, 9:49 am)
Re: [patches] [PATCH] [17/58] i386: Add L3 cache support t ..., Andreas Herrmann, (Fri Jul 20, 10:00 am)
Re: [patches] [PATCH] [17/58] i386: Add L3 cache support t ..., Andreas Herrmann, (Fri Jul 20, 10:15 am)
Re: [PATCH] [34/58] x86_64: ia32entry adjustments, Jan Beulich, (Mon Aug 6, 3:43 am)