From: Liang Li <liang.z.li@intel.com>
To: xen-devel@lists.xen.org
Cc: george.dunlap@eu.citrix.com, andrew.cooper3@citrix.com,
Liang Li <liang.z.li@intel.com>,
jbeulich@suse.com
Subject: [RFC PATCH] p2m-pt: avoid get the pte falgs repeatedly.
Date: Thu, 17 Nov 2016 16:24:18 +0800 [thread overview]
Message-ID: <1479371058-4837-1-git-send-email-liang.z.li@intel.com> (raw)
There are a lot of code try to get the pte flags repeatedly, why
not save the result and reuse it in the following code? It can help
to save some CPU cycles and make the code cleaner, no?
I am not sure if this is the right direction, just change one place.
Signed-off-by: Liang Li <liang.z.li@intel.com>
---
xen/arch/x86/mm/p2m-pt.c | 35 +++++++++++++++++++++--------------
1 file changed, 21 insertions(+), 14 deletions(-)
diff --git a/xen/arch/x86/mm/p2m-pt.c b/xen/arch/x86/mm/p2m-pt.c
index 3b025d5..bbaa54f 100644
--- a/xen/arch/x86/mm/p2m-pt.c
+++ b/xen/arch/x86/mm/p2m-pt.c
@@ -64,7 +64,7 @@
#define clear_recalc(level, ent) level##e_add_flags(ent, RECALC_FLAGS)
#define _needs_recalc(flags) (!((flags) & _PAGE_USER))
#define needs_recalc(level, ent) _needs_recalc(level##e_get_flags(ent))
-#define valid_recalc(level, ent) (!(level##e_get_flags(ent) & _PAGE_ACCESSED))
+#define valid_recalc(flags) (!(flags & _PAGE_ACCESSED))
static const unsigned long pgt[] = {
PGT_l1_page_table,
@@ -367,7 +367,7 @@ static int do_recalc(struct p2m_domain *p2m, unsigned long gfn)
{
void *table;
unsigned long gfn_remainder = gfn;
- unsigned int level = 4;
+ unsigned int level = 4, pte_flags;
l1_pgentry_t *pent;
int err = 0;
@@ -378,15 +378,20 @@ static int do_recalc(struct p2m_domain *p2m, unsigned long gfn)
pent = p2m_find_entry(table, &remainder, gfn,
level * PAGETABLE_ORDER, 1 << PAGETABLE_ORDER);
- if ( !pent || !(l1e_get_flags(*pent) & _PAGE_PRESENT) )
+ if ( !pent )
+ goto out;
+ else
+ pte_flags = l1e_get_flags(*pent);
+
+ if ( !(pte_flags & _PAGE_PRESENT) )
goto out;
- if ( l1e_get_flags(*pent) & _PAGE_PSE )
+ if ( pte_flags & _PAGE_PSE )
{
unsigned long mask = ~0UL << (level * PAGETABLE_ORDER);
- if ( !needs_recalc(l1, *pent) ||
- !p2m_is_changeable(p2m_flags_to_type(l1e_get_flags(*pent))) ||
+ if ( !_needs_recalc(pte_flags) ||
+ !p2m_is_changeable(p2m_flags_to_type(pte_flags)) ||
p2m_is_logdirty_range(p2m, gfn & mask, gfn | ~mask) >= 0 )
break;
}
@@ -397,21 +402,21 @@ static int do_recalc(struct p2m_domain *p2m, unsigned long gfn)
if ( err )
goto out;
- if ( needs_recalc(l1, *pent) )
+ if ( _needs_recalc(pte_flags) )
{
l1_pgentry_t e = *pent, *ptab = table;
unsigned int i;
- if ( !valid_recalc(l1, e) )
+ if ( !valid_recalc(pte_flags) )
P2M_DEBUG("bogus recalc state at d%d:%lx:%u\n",
p2m->domain->domain_id, gfn, level);
remainder = gfn_remainder;
for ( i = 0; i < (1 << PAGETABLE_ORDER); ++i )
{
l1_pgentry_t ent = ptab[i];
+ int flags = l1e_get_flags(ent);
- if ( (l1e_get_flags(ent) & _PAGE_PRESENT) &&
- !needs_recalc(l1, ent) )
+ if ( (flags & _PAGE_PRESENT) && !_needs_recalc(flags) )
{
set_recalc(l1, ent);
p2m->write_p2m_entry(p2m, gfn - remainder, &ptab[i],
@@ -428,15 +433,17 @@ static int do_recalc(struct p2m_domain *p2m, unsigned long gfn)
pent = p2m_find_entry(table, &gfn_remainder, gfn,
level * PAGETABLE_ORDER, 1 << PAGETABLE_ORDER);
- if ( pent && (l1e_get_flags(*pent) & _PAGE_PRESENT) &&
- needs_recalc(l1, *pent) )
+ if (!pent)
+ goto out;
+ pte_flags = l1e_get_flags(*pent);
+ if ( (pte_flags & _PAGE_PRESENT) && _needs_recalc(pte_flags) )
{
l1_pgentry_t e = *pent;
- if ( !valid_recalc(l1, e) )
+ if ( !valid_recalc(pte_flags) )
P2M_DEBUG("bogus recalc leaf at d%d:%lx:%u\n",
p2m->domain->domain_id, gfn, level);
- if ( p2m_is_changeable(p2m_flags_to_type(l1e_get_flags(e))) )
+ if ( p2m_is_changeable(p2m_flags_to_type(pte_flags)) )
{
unsigned long mask = ~0UL << (level * PAGETABLE_ORDER);
p2m_type_t p2mt = p2m_is_logdirty_range(p2m, gfn & mask, gfn | ~mask)
--
1.9.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next reply other threads:[~2016-11-17 8:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-17 8:24 Liang Li [this message]
2016-11-17 11:29 ` [RFC PATCH] p2m-pt: avoid get the pte falgs repeatedly Jan Beulich
2016-11-17 13:42 ` Li, Liang Z
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=1479371058-4837-1-git-send-email-liang.z.li@intel.com \
--to=liang.z.li@intel.com \
--cc=andrew.cooper3@citrix.com \
--cc=george.dunlap@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=xen-devel@lists.xen.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;
as well as URLs for NNTP newsgroup(s).