From patchwork Fri Oct 16 04:08:50 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 54142 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n9G4MUTV022089 for ; Fri, 16 Oct 2009 04:22:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751396AbZJPEPo (ORCPT ); Fri, 16 Oct 2009 00:15:44 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751354AbZJPEPn (ORCPT ); Fri, 16 Oct 2009 00:15:43 -0400 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 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9G4FEkt010481; Fri, 16 Oct 2009 00:15:14 -0400 Received: from amt.cnet (vpn-10-29.str.redhat.com [10.32.10.29]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n9G4FCji012770; Fri, 16 Oct 2009 00:15:13 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 400AE674346; Fri, 16 Oct 2009 01:15:01 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id n9G4ExM0032164; Fri, 16 Oct 2009 01:14:59 -0300 Message-Id: <20091016041415.779161960@redhat.com> User-Agent: quilt/0.47-1 Date: Fri, 16 Oct 2009 01:08:50 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org Cc: riel@redhat.com, Marcelo Tosatti Subject: [patch 4/5] kvmclock: account stolen time References: <20091016040845.957760057@redhat.com> Content-Disposition: inline; filename=kvm-accounts-stolen X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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