From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: [patch 4/5] kvmclock: account stolen time Date: Fri, 16 Oct 2009 01:08:50 -0300 Message-ID: <20091016041415.779161960@redhat.com> References: <20091016040845.957760057@redhat.com> Cc: riel@redhat.com, Marcelo Tosatti To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:35356 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751254AbZJPEPl (ORCPT ); Fri, 16 Oct 2009 00:15:41 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9G4FF47016606 for ; Fri, 16 Oct 2009 00:15:15 -0400 Content-Disposition: inline; filename=kvm-accounts-stolen Sender: kvm-owner@vger.kernel.org List-ID: Which makes stolen time information available in procfs/vmstat. Signed-off-by: Marcelo Tosatti Index: kvm/arch/x86/kernel/kvmclock.c =================================================================== --- kvm.orig/arch/x86/kernel/kvmclock.c +++ kvm/arch/x86/kernel/kvmclock.c @@ -22,11 +22,14 @@ #include #include #include +#include #include #include +#include #define KVM_SCALE 22 +#define NS_PER_TICK (1000000000LL / HZ) static int kvmclock = 1; @@ -50,6 +53,29 @@ static DEFINE_PER_CPU_SHARED_ALIGNED(str static struct pvclock_wall_clock wall_clock; +static DEFINE_PER_CPU(u64, total_stolen); +static DEFINE_PER_CPU(u64, residual_stolen); + +void kvm_account_steal_time(void) +{ + struct kvm_vcpu_runtime_info *rinfo; + cputime_t ticks; + u64 stolen_time, stolen_delta; + + rinfo = &get_cpu_var(run_info); + stolen_time = rinfo->stolen_time; + stolen_delta = stolen_time - __get_cpu_var(total_stolen); + + __get_cpu_var(total_stolen) = stolen_time; + put_cpu_var(rinfo); + + stolen_delta += __get_cpu_var(residual_stolen); + + ticks = iter_div_u64_rem(stolen_delta, NS_PER_TICK, &stolen_delta); + __get_cpu_var(residual_stolen) = stolen_delta; + account_steal_ticks(ticks); +} + /* * The wallclock is the time of day when we booted. Since then, some time may * have elapsed since the hypervisor wrote the data. So we try to account for Index: kvm/kernel/sched.c =================================================================== --- kvm.orig/kernel/sched.c +++ kvm/kernel/sched.c @@ -74,6 +74,9 @@ #include #include +#ifdef CONFIG_KVM_CLOCK +#include +#endif #include "sched_cpupri.h" @@ -5102,6 +5105,9 @@ void account_process_tick(struct task_st one_jiffy_scaled); else account_idle_time(cputime_one_jiffy); +#ifdef CONFIG_KVM_CLOCK + kvm_account_steal_time(); +#endif } /* Index: kvm/arch/x86/include/asm/kvm_para.h =================================================================== --- kvm.orig/arch/x86/include/asm/kvm_para.h +++ kvm/arch/x86/include/asm/kvm_para.h @@ -58,6 +58,7 @@ struct kvm_vcpu_runtime_info { }; extern void kvmclock_init(void); +extern void kvm_account_steal_time(void); /* This instruction is vmcall. On non-VT architectures, it will generate a