From: "tip-bot for venkatesh.pallipadi@intel.com" <venkatesh.pallipadi@intel.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@redhat.com,
venkatesh.pallipadi@intel.com, suresh.b.siddha@intel.com,
tglx@linutronix.de
Subject: [tip:x86/pat] x86, pat: Preparatory changes in pat.c for bigger rbtree change
Date: Fri, 19 Feb 2010 00:22:05 GMT [thread overview]
Message-ID: <tip-be5a0c126ad1dea2128dc5aef12c87083518d1ab@git.kernel.org> (raw)
In-Reply-To: <20100210195909.792781000@intel.com>
Commit-ID: be5a0c126ad1dea2128dc5aef12c87083518d1ab
Gitweb: http://git.kernel.org/tip/be5a0c126ad1dea2128dc5aef12c87083518d1ab
Author: venkatesh.pallipadi@intel.com <venkatesh.pallipadi@intel.com>
AuthorDate: Wed, 10 Feb 2010 11:57:06 -0800
Committer: H. Peter Anvin <hpa@zytor.com>
CommitDate: Thu, 18 Feb 2010 15:41:21 -0800
x86, pat: Preparatory changes in pat.c for bigger rbtree change
Minor changes in pat.c to cleanup code and make it smoother to introduce
bigger rbtree only change in the following patch. The changes are cleaup
only and should not have any functional impact.
Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
LKML-Reference: <20100210195909.792781000@intel.com>
Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
arch/x86/mm/pat.c | 170 +++++++++++++++++++++++---------------------
arch/x86/mm/pat_internal.h | 28 +++++++
2 files changed, 116 insertions(+), 82 deletions(-)
diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
index ae9648e..628e507 100644
--- a/arch/x86/mm/pat.c
+++ b/arch/x86/mm/pat.c
@@ -30,6 +30,8 @@
#include <asm/pat.h>
#include <asm/io.h>
+#include "pat_internal.h"
+
#ifdef CONFIG_X86_PAT
int __read_mostly pat_enabled = 1;
@@ -53,19 +55,15 @@ static inline void pat_disable(const char *reason)
#endif
-static int debug_enable;
+int pat_debug_enable;
static int __init pat_debug_setup(char *str)
{
- debug_enable = 1;
+ pat_debug_enable = 1;
return 0;
}
__setup("debugpat", pat_debug_setup);
-#define dprintk(fmt, arg...) \
- do { if (debug_enable) printk(KERN_INFO fmt, ##arg); } while (0)
-
-
static u64 __read_mostly boot_pat_state;
enum {
@@ -132,17 +130,6 @@ void pat_init(void)
#undef PAT
-static char *cattr_name(unsigned long flags)
-{
- switch (flags & _PAGE_CACHE_MASK) {
- case _PAGE_CACHE_UC: return "uncached";
- case _PAGE_CACHE_UC_MINUS: return "uncached-minus";
- case _PAGE_CACHE_WB: return "write-back";
- case _PAGE_CACHE_WC: return "write-combining";
- default: return "broken";
- }
-}
-
/*
* The global memtype list keeps track of memory type for specific
* physical memory areas. Conflicting memory types in different
@@ -159,14 +146,6 @@ static char *cattr_name(unsigned long flags)
* memtype_lock protects both the linear list and rbtree.
*/
-struct memtype {
- u64 start;
- u64 end;
- unsigned long type;
- struct list_head nd;
- struct rb_node rb;
-};
-
static struct rb_root memtype_rbroot = RB_ROOT;
static LIST_HEAD(memtype_list);
static DEFINE_SPINLOCK(memtype_lock); /* protects memtype list */
@@ -349,6 +328,64 @@ static int free_ram_pages_type(u64 start, u64 end)
return 0;
}
+static int memtype_check_insert(struct memtype *new, unsigned long *new_type)
+{
+ struct memtype *entry;
+ u64 start, end;
+ unsigned long actual_type;
+ struct list_head *where;
+ int err = 0;
+
+ start = new->start;
+ end = new->end;
+ actual_type = new->type;
+
+ /* Search for existing mapping that overlaps the current range */
+ where = NULL;
+ list_for_each_entry(entry, &memtype_list, nd) {
+ if (end <= entry->start) {
+ where = entry->nd.prev;
+ break;
+ } else if (start <= entry->start) { /* end > entry->start */
+ err = chk_conflict(new, entry, new_type);
+ if (!err) {
+ dprintk("Overlap at 0x%Lx-0x%Lx\n",
+ entry->start, entry->end);
+ where = entry->nd.prev;
+ }
+ break;
+ } else if (start < entry->end) { /* start > entry->start */
+ err = chk_conflict(new, entry, new_type);
+ if (!err) {
+ dprintk("Overlap at 0x%Lx-0x%Lx\n",
+ entry->start, entry->end);
+
+ /*
+ * Move to right position in the linked
+ * list to add this new entry
+ */
+ list_for_each_entry_continue(entry,
+ &memtype_list, nd) {
+ if (start <= entry->start) {
+ where = entry->nd.prev;
+ break;
+ }
+ }
+ }
+ break;
+ }
+ }
+ if (!err) {
+ if (where)
+ list_add(&new->nd, where);
+ else
+ list_add_tail(&new->nd, &memtype_list);
+
+ memtype_rb_insert(&memtype_rbroot, new);
+ }
+ return err;
+}
+
/*
* req_type typically has one of the:
* - _PAGE_CACHE_WB
@@ -364,9 +401,8 @@ static int free_ram_pages_type(u64 start, u64 end)
int reserve_memtype(u64 start, u64 end, unsigned long req_type,
unsigned long *new_type)
{
- struct memtype *new, *entry;
+ struct memtype *new;
unsigned long actual_type;
- struct list_head *where;
int is_range_ram;
int err = 0;
@@ -423,42 +459,7 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type,
spin_lock(&memtype_lock);
- /* Search for existing mapping that overlaps the current range */
- where = NULL;
- list_for_each_entry(entry, &memtype_list, nd) {
- if (end <= entry->start) {
- where = entry->nd.prev;
- break;
- } else if (start <= entry->start) { /* end > entry->start */
- err = chk_conflict(new, entry, new_type);
- if (!err) {
- dprintk("Overlap at 0x%Lx-0x%Lx\n",
- entry->start, entry->end);
- where = entry->nd.prev;
- }
- break;
- } else if (start < entry->end) { /* start > entry->start */
- err = chk_conflict(new, entry, new_type);
- if (!err) {
- dprintk("Overlap at 0x%Lx-0x%Lx\n",
- entry->start, entry->end);
-
- /*
- * Move to right position in the linked
- * list to add this new entry
- */
- list_for_each_entry_continue(entry,
- &memtype_list, nd) {
- if (start <= entry->start) {
- where = entry->nd.prev;
- break;
- }
- }
- }
- break;
- }
- }
-
+ err = memtype_check_insert(new, new_type);
if (err) {
printk(KERN_INFO "reserve_memtype failed 0x%Lx-0x%Lx, "
"track %s, req %s\n",
@@ -469,13 +470,6 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type,
return err;
}
- if (where)
- list_add(&new->nd, where);
- else
- list_add_tail(&new->nd, &memtype_list);
-
- memtype_rb_insert(&memtype_rbroot, new);
-
spin_unlock(&memtype_lock);
dprintk("reserve_memtype added 0x%Lx-0x%Lx, track %s, req %s, ret %s\n",
@@ -937,28 +931,40 @@ EXPORT_SYMBOL_GPL(pgprot_writecombine);
#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_X86_PAT)
/* get Nth element of the linked list */
-static struct memtype *memtype_get_idx(loff_t pos)
+static int copy_memtype_nth_element(struct memtype *out, loff_t pos)
{
- struct memtype *list_node, *print_entry;
+ struct memtype *list_node;
int i = 1;
- print_entry = kmalloc(sizeof(struct memtype), GFP_KERNEL);
- if (!print_entry)
- return NULL;
-
- spin_lock(&memtype_lock);
list_for_each_entry(list_node, &memtype_list, nd) {
if (pos == i) {
- *print_entry = *list_node;
- spin_unlock(&memtype_lock);
- return print_entry;
+ *out = *list_node;
+ return 0;
}
++i;
}
+ return 1;
+}
+
+static struct memtype *memtype_get_idx(loff_t pos)
+{
+ struct memtype *print_entry;
+ int ret;
+
+ print_entry = kzalloc(sizeof(struct memtype), GFP_KERNEL);
+ if (!print_entry)
+ return NULL;
+
+ spin_lock(&memtype_lock);
+ ret = copy_memtype_nth_element(print_entry, pos);
spin_unlock(&memtype_lock);
- kfree(print_entry);
- return NULL;
+ if (!ret) {
+ return print_entry;
+ } else {
+ kfree(print_entry);
+ return NULL;
+ }
}
static void *memtype_seq_start(struct seq_file *seq, loff_t *pos)
diff --git a/arch/x86/mm/pat_internal.h b/arch/x86/mm/pat_internal.h
new file mode 100644
index 0000000..6c98780
--- /dev/null
+++ b/arch/x86/mm/pat_internal.h
@@ -0,0 +1,28 @@
+#ifndef __PAT_INTERNAL_H_
+#define __PAT_INTERNAL_H_
+
+extern int pat_debug_enable;
+
+#define dprintk(fmt, arg...) \
+ do { if (pat_debug_enable) printk(KERN_INFO fmt, ##arg); } while (0)
+
+struct memtype {
+ u64 start;
+ u64 end;
+ unsigned long type;
+ struct list_head nd;
+ struct rb_node rb;
+};
+
+static inline char *cattr_name(unsigned long flags)
+{
+ switch (flags & _PAGE_CACHE_MASK) {
+ case _PAGE_CACHE_UC: return "uncached";
+ case _PAGE_CACHE_UC_MINUS: return "uncached-minus";
+ case _PAGE_CACHE_WB: return "write-back";
+ case _PAGE_CACHE_WC: return "write-combining";
+ default: return "broken";
+ }
+}
+
+#endif /* __PAT_INTERNAL_H_ */
next prev parent reply other threads:[~2010-02-19 0:24 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-10 19:57 [patch 0/3] x86: Use interval tree to keep track of PAT reserve/free venkatesh.pallipadi
2010-02-10 19:57 ` [patch 1/3] rbtree: Add support for augmented rbtrees venkatesh.pallipadi
2010-02-10 23:23 ` [patch 1/3] rbtree: Add support for augmented rbtrees (ver 2) Pallipadi, Venkatesh
2010-02-19 0:21 ` [tip:x86/pat] rbtree: Add support for augmented rbtrees tip-bot for Pallipadi, Venkatesh
2010-05-27 15:29 ` Peter Zijlstra
2010-05-29 12:29 ` [RFC][PATCH] rbtree: undo augmented damage Peter Zijlstra
2010-05-29 13:31 ` [PATCH] rbtree: undo augmented damage -v2 Peter Zijlstra
2010-06-01 17:00 ` Venkatesh Pallipadi
2010-06-01 17:19 ` Peter Zijlstra
2010-06-01 17:34 ` Peter Zijlstra
2010-06-01 17:34 ` Venkatesh Pallipadi
2010-06-01 17:42 ` Peter Zijlstra
2010-06-01 18:09 ` Venkatesh Pallipadi
2010-06-01 18:42 ` Peter Zijlstra
2010-06-01 20:31 ` Venkatesh Pallipadi
2010-06-02 21:11 ` Suresh Siddha
2010-06-03 1:15 ` Venkatesh Pallipadi
2010-06-03 7:13 ` Peter Zijlstra
2010-06-03 7:48 ` Peter Zijlstra
2010-06-03 16:04 ` Suresh Siddha
2010-06-09 10:12 ` [tip:x86/pat] rbtree: Undo augmented trees performance damage tip-bot for Peter Zijlstra
2010-07-05 12:48 ` [tip:x86/urgent] rbtree: Undo augmented trees performance damage and regression tip-bot for Peter Zijlstra
2010-02-10 19:57 ` [patch 2/3] x86: Preparatory changes in pat.c for bigger rbtree change venkatesh.pallipadi
2010-02-19 0:22 ` tip-bot for venkatesh.pallipadi@intel.com [this message]
2010-02-10 19:57 ` [patch 3/3] x86: Migrate to rbtree only backend for pat memtype management venkatesh.pallipadi
2010-02-10 23:26 ` [patch 3/3] x86: Migrate to rbtree only backend for pat memtype management (ver 2) Pallipadi, Venkatesh
2010-02-19 0:22 ` [tip:x86/pat] x86, pat: Migrate to rbtree only backend for pat memtype management tip-bot for Pallipadi, Venkatesh
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=tip-be5a0c126ad1dea2128dc5aef12c87083518d1ab@git.kernel.org \
--to=venkatesh.pallipadi@intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=suresh.b.siddha@intel.com \
--cc=tglx@linutronix.de \
/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;
as well as URLs for NNTP newsgroup(s).