From: Anthony Liguori <aliguori@us.ibm.com>
To: Andi Kleen <ak@suse.de>
Cc: kvm-devel <kvm-devel@lists.sourceforge.net>,
Ingo Molnar <mingo@elte.hu>,
virtualization@lists.linux-foundation.org
Subject: Re: [PATCH 3/3] Eliminate read_cr3 on TLB flush
Date: Wed, 30 May 2007 10:32:23 -0500 [thread overview]
Message-ID: <465D9907.40406@us.ibm.com> (raw)
In-Reply-To: <200705301701.23386.ak@suse.de>
[-- Attachment #1: Type: text/plain, Size: 576 bytes --]
Andi Kleen wrote:
> On Wednesday 30 May 2007 16:53:41 Anthony Liguori wrote:
>
>> Subject: [PATCH][PARAVIRT] Eliminate unnecessary CR3 read in TLB flush
>>
>> This patch eliminates the CR3 read (which would cause a VM exit) in the TLB
>> flush path. The patch is based on Ingo Molnar's paravirt series.
>>
>>
>
> This change could be just done generically for the native architecture, couldn't
> it?
>
Sure. It adds a few more cycles onto native though (two memory reads,
and some math). How does the following look?
Regards,
Anthony Liguori
> -Andi
>
[-- Attachment #2: no-read-cr3-on-tlbflush.diff --]
[-- Type: text/x-patch, Size: 2122 bytes --]
Subject: [PATCH] Avoid reading CR3 on TLB flush
From: Anthony Liguori <aliguori@us.ibm.com>
In a virtualized environment, there is significant overhead in reading and
writing control registers. Since we already have the value of CR3 in
current->active_mm->pgd, we can avoid taking the exit on CR3 read when
doing a TLB flush.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Index: kvm/include/asm-i386/tlbflush.h
===================================================================
--- kvm.orig/include/asm-i386/tlbflush.h 2007-05-30 10:22:48.000000000 -0500
+++ kvm/include/asm-i386/tlbflush.h 2007-05-30 10:22:54.000000000 -0500
@@ -14,13 +14,12 @@
#define __native_flush_tlb() \
do { \
- unsigned int tmpreg; \
+ unsigned int cr3 = __pa(current->active_mm->pgd); \
\
__asm__ __volatile__( \
- "movl %%cr3, %0; \n" \
"movl %0, %%cr3; # flush TLB \n" \
- : "=r" (tmpreg) \
- :: "memory"); \
+ :: "r" (cr3) \
+ : "memory"); \
} while (0)
/*
@@ -29,18 +28,18 @@
*/
#define __native_flush_tlb_global() \
do { \
- unsigned int tmpreg, cr4, cr4_orig; \
+ unsigned int cr3 = __pa(current->active_mm->pgd); \
+ unsigned int cr4, cr4_orig; \
\
__asm__ __volatile__( \
- "movl %%cr4, %2; # turn off PGE \n" \
- "movl %2, %1; \n" \
- "andl %3, %1; \n" \
- "movl %1, %%cr4; \n" \
- "movl %%cr3, %0; \n" \
- "movl %0, %%cr3; # flush TLB \n" \
- "movl %2, %%cr4; # turn PGE back on \n" \
- : "=&r" (tmpreg), "=&r" (cr4), "=&r" (cr4_orig) \
- : "i" (~X86_CR4_PGE) \
+ "movl %%cr4, %1; # turn off PGE \n" \
+ "movl %1, %0; \n" \
+ "andl %2, %0; \n" \
+ "movl %0, %%cr4; \n" \
+ "movl %3, %%cr3; # flush TLB \n" \
+ "movl %1, %%cr4; # turn PGE back on \n" \
+ : "=&r" (cr4), "=&r" (cr4_orig) \
+ : "i" (~X86_CR4_PGE), "r" (cr3) \
: "memory"); \
} while (0)
[-- Attachment #3: Type: text/plain, Size: 184 bytes --]
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/virtualization
next prev parent reply other threads:[~2007-05-30 15:32 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-30 14:49 [PATCH 0/3] KVM paravirt_ops implementation Anthony Liguori
2007-05-30 14:52 ` [PATCH 1/3] KVM paravirt_ops infrastructure Anthony Liguori
2007-05-30 16:42 ` [kvm-devel] " Nakajima, Jun
[not found] ` <97D612E30E1F88419025B06CB4CF1BE10259AAD7-1a9uaKK1+wJcIJlls4ac1rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-05-30 18:11 ` Anthony Liguori
[not found] ` <465DBE3A.6030908-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-05-30 19:04 ` Nakajima, Jun
[not found] ` <97D612E30E1F88419025B06CB4CF1BE10259AD83-1a9uaKK1+wJcIJlls4ac1rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-05-31 17:31 ` Anthony Liguori
[not found] ` <465F0688.1050702-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-05-31 18:47 ` Nakajima, Jun
2007-05-31 1:02 ` Rusty Russell
2007-05-31 1:15 ` [kvm-devel] " Anthony Liguori
[not found] ` <1180573347.30202.135.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2007-05-31 7:48 ` Avi Kivity
2007-05-31 9:58 ` Andi Kleen
[not found] ` <200705311158.28632.ak-l3A5Bk7waGM@public.gmane.org>
2007-05-31 10:11 ` Ingo Molnar
[not found] ` <20070531101116.GA10872-X9Un+BFzKDI@public.gmane.org>
2007-05-31 10:40 ` Andi Kleen
[not found] ` <200705311240.19794.ak-l3A5Bk7waGM@public.gmane.org>
2007-05-31 11:12 ` Rusty Russell
2007-05-31 17:28 ` [kvm-devel] " Anthony Liguori
2007-05-31 17:29 ` Anthony Liguori
2007-05-30 14:53 ` [PATCH 2/3][PARAVIRT] Make IO delay a NOP Anthony Liguori
[not found] ` <465D8F03.7000201-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-05-30 14:53 ` [PATCH 3/3] Eliminate read_cr3 on TLB flush Anthony Liguori
[not found] ` <465D8FF5.6040804-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2007-05-30 15:01 ` Andi Kleen
2007-05-30 15:32 ` Anthony Liguori [this message]
2007-05-30 15:38 ` Jeremy Fitzhardinge
2007-05-30 17:11 ` [kvm-devel] " Nakajima, Jun
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=465D9907.40406@us.ibm.com \
--to=aliguori@us.ibm.com \
--cc=ak@suse.de \
--cc=kvm-devel@lists.sourceforge.net \
--cc=mingo@elte.hu \
--cc=virtualization@lists.linux-foundation.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).