From patchwork Wed Jun 29 15:29:44 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 929342 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5TFW1tK003923 for ; Wed, 29 Jun 2011 15:47:03 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756853Ab1F2PiC (ORCPT ); Wed, 29 Jun 2011 11:38:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34358 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756048Ab1F2PiA (ORCPT ); Wed, 29 Jun 2011 11:38:00 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5TFbmNp030595 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 29 Jun 2011 11:37:49 -0400 Received: from virtlab1.virt.bos.redhat.com (virtlab1.virt.bos.redhat.com [10.16.72.21]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p5TFbhGi019065; Wed, 29 Jun 2011 11:37:47 -0400 From: Glauber Costa To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Rik van Riel , Jeremy Fitzhardinge , Peter Zijlstra , Avi Kivity , Anthony Liguori , Eric B Munson , Marcelo Tosatti Subject: [PATCH v3 5/9] KVM-HV: use schedstats to calculate steal time Date: Wed, 29 Jun 2011 11:29:44 -0400 Message-Id: <1309361388-30163-6-git-send-email-glommer@redhat.com> In-Reply-To: <1309361388-30163-1-git-send-email-glommer@redhat.com> References: <1309361388-30163-1-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 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]); Wed, 29 Jun 2011 15:47:03 +0000 (UTC) SCHEDSTATS provide a precise source of information about time tasks spent on a runqueue, but not running (among other things). It is specially useful for the steal time implementation, because it doesn't record halt time at all. To avoid a hard dependency on schedstats, since it is possible one won't want to record statistics about all processes running, the previous method of time measurement on put/load vcpu is kept for !SCHEDSTATS. Signed-off-by: Glauber Costa CC: Rik van Riel CC: Jeremy Fitzhardinge CC: Peter Zijlstra CC: Avi Kivity CC: Anthony Liguori CC: Eric B Munson CC: Marcelo Tosatti Tested-by: Eric B Munson --- arch/x86/kvm/x86.c | 22 ++++++++++++++++++---- 1 files changed, 18 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index df9d274..7e87159 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1502,7 +1502,13 @@ static void record_steal_time(struct kvm_vcpu *vcpu) &vcpu->arch.st.steal, sizeof(struct kvm_steal_time)))) return; - delta = (get_kernel_ns() - vcpu->arch.st.this_time_out); +#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) + if (likely(sched_info_on())) { + delta = current->sched_info.run_delay - vcpu->arch.st.this_time_out; + vcpu->arch.st.this_time_out = current->sched_info.run_delay; + } else +#endif + delta = (get_kernel_ns() - vcpu->arch.st.this_time_out); vcpu->arch.st.steal.steal += delta; vcpu->arch.st.steal.version += 2; @@ -1607,9 +1613,14 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data) data & KVM_STEAL_VALID_BITS)) return 1; - vcpu->arch.st.this_time_out = get_kernel_ns(); - record_steal_time(vcpu); +#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) + if (likely(sched_info_on())) + vcpu->arch.st.this_time_out = current->sched_info.run_delay; + else +#endif + vcpu->arch.st.this_time_out = get_kernel_ns(); + record_steal_time(vcpu); break; case MSR_IA32_MCG_CTL: @@ -2220,7 +2231,10 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) kvm_x86_ops->vcpu_put(vcpu); kvm_put_guest_fpu(vcpu); kvm_get_msr(vcpu, MSR_IA32_TSC, &vcpu->arch.last_guest_tsc); - vcpu->arch.st.this_time_out = get_kernel_ns(); +#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT) + if (unlikely(!sched_info_on())) +#endif + vcpu->arch.st.this_time_out = get_kernel_ns(); } static int is_efer_nx(void)