From patchwork Mon Jan 24 18:06:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 501411 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p0OJh2Yl026265 for ; Mon, 24 Jan 2011 19:48:06 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754076Ab1AXSIf (ORCPT ); Mon, 24 Jan 2011 13:08:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41413 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754197Ab1AXSIS (ORCPT ); Mon, 24 Jan 2011 13:08:18 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0OI81Ok014274 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 24 Jan 2011 13:08:01 -0500 Received: from virtlab1.virt.bos.redhat.com (virtlab1.virt.bos.redhat.com [10.16.72.21]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p0OI7gkG003799; Mon, 24 Jan 2011 13:07:59 -0500 From: Glauber Costa To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, aliguori@us.ibm.com, Rik van Riel , Jeremy Fitzhardinge , Peter Zijlstra , Avi Kivity Subject: [PATCH 13/16] KVM-HV: KVM Steal time calculation Date: Mon, 24 Jan 2011 13:06:34 -0500 Message-Id: <1295892397-11354-14-git-send-email-glommer@redhat.com> In-Reply-To: <1295892397-11354-1-git-send-email-glommer@redhat.com> References: <1295892397-11354-1-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 24 Jan 2011 19:48:06 +0000 (UTC) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index ffd7f8d..038679b 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -377,6 +377,9 @@ struct kvm_vcpu_arch { unsigned int hw_tsc_khz; unsigned int time_offset; struct page *time_page; + gpa_t stime; + u64 time_out; + u64 this_time_out; u64 last_host_tsc; u64 last_guest_tsc; u64 last_kernel_ns; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index f129ea1..33af936 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2123,6 +2123,9 @@ static bool need_emulate_wbinvd(struct kvm_vcpu *vcpu) void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) { + struct kvm_steal_time *st; + st = (struct kvm_steal_time *)vcpu->arch.stime; + /* Address WBINVD may be executed by guest */ if (need_emulate_wbinvd(vcpu)) { if (kvm_x86_ops->has_wbinvd_exit()) @@ -2148,6 +2151,14 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) kvm_migrate_timers(vcpu); vcpu->cpu = cpu; } + if (vcpu->arch.this_time_out) { + vcpu->arch.time_out += + (get_kernel_ns() - vcpu->arch.this_time_out); + kvm_write_guest(vcpu->kvm, (gpa_t)&st->steal, + &vcpu->arch.time_out, sizeof(st->steal)); + /* is it possible to have 2 loads in sequence? */ + vcpu->arch.this_time_out = 0; + } } void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) @@ -5333,6 +5344,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) kvm_lapic_sync_from_vapic(vcpu); + vcpu->arch.this_time_out = get_kernel_ns(); + r = kvm_x86_ops->handle_exit(vcpu); out: return r;