From: Ingo Molnar <mingo@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Andy Lutomirski <luto@amacapital.net>,
Borislav Petkov <bp@alien8.de>, "H . Peter Anvin" <hpa@zytor.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Yinghai Lu <yinghai@kernel.org>
Subject: [PATCH 3/5] x86/boot/e820: Simplify e820__update_table()
Date: Wed, 1 Feb 2017 10:51:15 +0100 [thread overview]
Message-ID: <1485942677-19973-4-git-send-email-mingo@kernel.org> (raw)
In-Reply-To: <1485942677-19973-1-git-send-email-mingo@kernel.org>
- Remove the now unnecessary __e820__update_table() wrappery
- Move statics out from function scope, to make the logic clearer
- Rename local variables to be more in line with the rest of 820.c
- Remove unnecessary local variables: old_nr, *nr_entries
No change in functionality.
Cc: Alex Thorlton <athorlton@sgi.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Huang, Ying <ying.huang@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul Jackson <pj@sgi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
arch/x86/kernel/e820.c | 70 +++++++++++++++++++++++++++++++---------------------------------------
1 file changed, 31 insertions(+), 39 deletions(-)
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 2da2f7238a72..e2fb20ac5135 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -235,6 +235,11 @@ struct change_member {
unsigned long long addr;
};
+static struct change_member change_point_list[2*E820_MAX_ENTRIES] __initdata;
+static struct change_member *change_point[2*E820_MAX_ENTRIES] __initdata;
+static struct e820_entry *overlap_list[E820_MAX_ENTRIES] __initdata;
+static struct e820_entry new_entries[E820_MAX_ENTRIES] __initdata;
+
static int __init cpcompare(const void *a, const void *b)
{
struct change_member * const *app = a, * const *bpp = b;
@@ -252,51 +257,46 @@ static int __init cpcompare(const void *a, const void *b)
return (ap->addr != ap->entry->addr) - (bp->addr != bp->entry->addr);
}
-static int __init __e820__update_table(struct e820_entry *entries, u32 max_nr_entries, u32 *nr_entries)
+int __init e820__update_table(struct e820_table *table)
{
- static struct change_member change_point_list[2*E820_MAX_ENTRIES] __initdata;
- static struct change_member *change_point[2*E820_MAX_ENTRIES] __initdata;
- static struct e820_entry *overlap_list[E820_MAX_ENTRIES] __initdata;
- static struct e820_entry new_entries[E820_MAX_ENTRIES] __initdata;
+ struct e820_entry *entries = table->entries;
+ u32 max_nr_entries = ARRAY_SIZE(table->entries);
enum e820_type current_type, last_type;
unsigned long long last_addr;
- u32 chgidx;
- u32 overlap_entries;
- u32 new_nr_entries;
- u32 old_nr, new_nr, chg_nr;
- u32 i;
+ u32 new_nr_entries, overlap_entries;
+ u32 i, chg_idx, chg_nr;
/* If there's only one memory region, don't bother: */
- if (*nr_entries < 2)
+ if (table->nr_entries < 2)
return -1;
- old_nr = *nr_entries;
- BUG_ON(old_nr > max_nr_entries);
+ table->nr_entries = table->nr_entries;
+ BUG_ON(table->nr_entries > max_nr_entries);
/* Bail out if we find any unreasonable addresses in the map: */
- for (i = 0; i < old_nr; i++) {
+ for (i = 0; i < table->nr_entries; i++) {
if (entries[i].addr + entries[i].size < entries[i].addr)
return -1;
}
/* Create pointers for initial change-point information (for sorting): */
- for (i = 0; i < 2 * old_nr; i++)
+ for (i = 0; i < 2 * table->nr_entries; i++)
change_point[i] = &change_point_list[i];
/*
* Record all known change-points (starting and ending addresses),
* omitting empty memory regions:
*/
- chgidx = 0;
- for (i = 0; i < old_nr; i++) {
+ chg_idx = 0;
+ for (i = 0; i < table->nr_entries; i++) {
if (entries[i].size != 0) {
- change_point[chgidx]->addr = entries[i].addr;
- change_point[chgidx++]->entry = &entries[i];
- change_point[chgidx]->addr = entries[i].addr + entries[i].size;
- change_point[chgidx++]->entry = &entries[i];
+ change_point[chg_idx]->addr = entries[i].addr;
+ change_point[chg_idx++]->entry = &entries[i];
+ change_point[chg_idx]->addr = entries[i].addr + entries[i].size;
+ change_point[chg_idx++]->entry = &entries[i];
}
}
- chg_nr = chgidx;
+ chg_nr = chg_idx;
/* Sort change-point list by memory addresses (low -> high): */
sort(change_point, chg_nr, sizeof(*change_point), cpcompare, NULL);
@@ -308,15 +308,15 @@ static int __init __e820__update_table(struct e820_entry *entries, u32 max_nr_en
last_addr = 0; /* Start with 0 as last starting address */
/* Loop through change-points, determining effect on the new map: */
- for (chgidx = 0; chgidx < chg_nr; chgidx++) {
+ for (chg_idx = 0; chg_idx < chg_nr; chg_idx++) {
/* Keep track of all overlapping entries */
- if (change_point[chgidx]->addr == change_point[chgidx]->entry->addr) {
+ if (change_point[chg_idx]->addr == change_point[chg_idx]->entry->addr) {
/* Add map entry to overlap list (> 1 entry implies an overlap) */
- overlap_list[overlap_entries++] = change_point[chgidx]->entry;
+ overlap_list[overlap_entries++] = change_point[chg_idx]->entry;
} else {
/* Remove entry from list (order independent, so swap with last): */
for (i = 0; i < overlap_entries; i++) {
- if (overlap_list[i] == change_point[chgidx]->entry)
+ if (overlap_list[i] == change_point[chg_idx]->entry)
overlap_list[i] = overlap_list[overlap_entries-1];
}
overlap_entries--;
@@ -335,7 +335,7 @@ static int __init __e820__update_table(struct e820_entry *entries, u32 max_nr_en
/* Continue building up new map based on this information: */
if (current_type != last_type || current_type == E820_TYPE_PRAM) {
if (last_type != 0) {
- new_entries[new_nr_entries].size = change_point[chgidx]->addr - last_addr;
+ new_entries[new_nr_entries].size = change_point[chg_idx]->addr - last_addr;
/* Move forward only if the new size was non-zero: */
if (new_entries[new_nr_entries].size != 0)
/* No more space left for new entries? */
@@ -343,29 +343,21 @@ static int __init __e820__update_table(struct e820_entry *entries, u32 max_nr_en
break;
}
if (current_type != 0) {
- new_entries[new_nr_entries].addr = change_point[chgidx]->addr;
+ new_entries[new_nr_entries].addr = change_point[chg_idx]->addr;
new_entries[new_nr_entries].type = current_type;
- last_addr = change_point[chgidx]->addr;
+ last_addr = change_point[chg_idx]->addr;
}
last_type = current_type;
}
}
- /* Retain count for the new entries: */
- new_nr = new_nr_entries;
-
/* Copy the new entries into the original location: */
- memcpy(entries, new_entries, new_nr*sizeof(*entries));
- *nr_entries = new_nr;
+ memcpy(entries, new_entries, new_nr_entries*sizeof(*entries));
+ table->nr_entries = new_nr_entries;
return 0;
}
-int __init e820__update_table(struct e820_table *table)
-{
- return __e820__update_table(table->entries, ARRAY_SIZE(table->entries), &table->nr_entries);
-}
-
static int __init __append_e820_table(struct boot_e820_entry *entries, u32 nr_entries)
{
struct boot_e820_entry *entry = entries;
--
2.7.4
next prev parent reply other threads:[~2017-02-01 9:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-01 9:51 [PATCH 0/5] x86: Clean up and reorganize the E820 table handling code, #updates Ingo Molnar
2017-02-01 9:51 ` [PATCH 1/5] x86/boot/e820: Fix and clean up e820_type switch() statements Ingo Molnar
2017-02-01 9:51 ` [PATCH 2/5] x86/boot/e820: Separate the E820 ABI structures from the in-kernel structures Ingo Molnar
2017-02-01 9:51 ` Ingo Molnar [this message]
2017-02-01 9:51 ` [PATCH 4/5] xen, x86/headers: Add <linux/device.h> dependency to <asm/xen/page.h> Ingo Molnar
2017-02-01 10:00 ` Juergen Gross
2017-02-01 10:08 ` Ingo Molnar
2017-02-01 9:51 ` [PATCH 5/5] x86/boot: Fix pr_debug() API braindamage Ingo Molnar
2017-02-01 11:57 ` Joe Perches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1485942677-19973-4-git-send-email-mingo@kernel.org \
--to=mingo@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=yinghai@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox