aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorFrederic Weisbecker <fweisbec@gmail.com>2012-10-05 17:07:19 -0400
committerFrederic Weisbecker <fweisbec@gmail.com>2012-10-29 16:31:31 -0400
commitb080935c8638e08134629d0a9ebdf35669bec14d (patch)
tree998a7bc80a3335e11cc3238550156edf2bd25438 /include/linux
parent11113334d1c5dd5355c86e531c29f1202a855c86 (diff)
kvm: Directly account vtime to system on guest switch
Switching to or from guest context is done on ioctl context. So by the time we call kvm_guest_enter() or kvm_guest_exit() we know we are not running the idle task. As a result, we can directly account the cputime using vtime_account_system(). There are two good reasons to do this: * We avoid some useless checks on guest switch. It optimizes a bit this fast path. * In the case of CONFIG_IRQ_TIME_ACCOUNTING, calling vtime_account() checks for irq time to account. This is pointless since we know we are not in an irq on guest switch. This is wasting cpu cycles for no good reason. vtime_account_system() OTOH is a no-op in this config option. * We can remove the irq disable/enable around kvm guest switch in s390. A further optimization may consist in introducing a vtime_account_guest() that directly calls account_guest_time(). Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Tony Luck <tony.luck@intel.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Avi Kivity <avi@redhat.com> Cc: Marcelo Tosatti <mtosatti@redhat.com> Cc: Joerg Roedel <joerg.roedel@amd.com> Cc: Alexander Graf <agraf@suse.de> Cc: Xiantao Zhang <xiantao.zhang@intel.com> Cc: Christian Borntraeger <borntraeger@de.ibm.com> Cc: Cornelia Huck <cornelia.huck@de.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Paul Gortmaker <paul.gortmaker@windriver.com>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/kvm_host.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 93bfc9f9815c..0e2212fe4784 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -737,7 +737,11 @@ static inline int kvm_deassign_device(struct kvm *kvm,
737static inline void kvm_guest_enter(void) 737static inline void kvm_guest_enter(void)
738{ 738{
739 BUG_ON(preemptible()); 739 BUG_ON(preemptible());
740 vtime_account(current); 740 /*
741 * This is running in ioctl context so we can avoid
742 * the call to vtime_account() with its unnecessary idle check.
743 */
744 vtime_account_system(current);
741 current->flags |= PF_VCPU; 745 current->flags |= PF_VCPU;
742 /* KVM does not hold any references to rcu protected data when it 746 /* KVM does not hold any references to rcu protected data when it
743 * switches CPU into a guest mode. In fact switching to a guest mode 747 * switches CPU into a guest mode. In fact switching to a guest mode
@@ -751,7 +755,11 @@ static inline void kvm_guest_enter(void)
751 755
752static inline void kvm_guest_exit(void) 756static inline void kvm_guest_exit(void)
753{ 757{
754 vtime_account(current); 758 /*
759 * This is running in ioctl context so we can avoid
760 * the call to vtime_account() with its unnecessary idle check.
761 */
762 vtime_account_system(current);
755 current->flags &= ~PF_VCPU; 763 current->flags &= ~PF_VCPU;
756} 764}
757 765