From patchwork Wed Mar 16 11:33:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liang Chen X-Patchwork-Id: 8598811 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EED789F44D for ; Wed, 16 Mar 2016 11:33:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0D6FD20306 for ; Wed, 16 Mar 2016 11:33:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 92495202F0 for ; Wed, 16 Mar 2016 11:33:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966575AbcCPLd2 (ORCPT ); Wed, 16 Mar 2016 07:33:28 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:36573 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751101AbcCPLd0 (ORCPT ); Wed, 16 Mar 2016 07:33:26 -0400 Received: by mail-pf0-f174.google.com with SMTP id u190so71959236pfb.3; Wed, 16 Mar 2016 04:33:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=3X2RNqeOe1kqeMG5Lj9iF+yd7t1lwWgDej5kSYJ7oNE=; b=F1kZ8Sv9d8MEMOrut8ztBIjwtdK5+uvWqH60ZCW+pQPj2jBputSHwBlHNv4joSHFkQ SpQiOL9pMxc1VZHUv4XpFuGRjGU6BXPreWIoaNbbrt2USc0PubKYiC4pd6krWvTNDav1 /OZxnAe7I/RYb/VGmWwdt8WIQlS8jjbVuOJ/aHBV3mTmrRl+OmPugmP60EcHxSyGCyuG TQWnBBOwKs33RY0GJQhv0PsrK4hOUQEwEEfM4HECn17GueB+dr9Duv6Adzw4YEMxpFUV 3SbocrlCJrsXg2yfaZBYOXhc6v38IRb2fXUofBwnzNcVcvp83dTjsD0w1VK80EoC3Flk lOmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=3X2RNqeOe1kqeMG5Lj9iF+yd7t1lwWgDej5kSYJ7oNE=; b=TR/rTocCAKWvlZUvBXwzayBy+5xI2j7MOpwneYN9trKyQBxWwL+Hv5Lk6tCYCxWszc 1RKTlhj8Fv6RFpY5Mj0yD33IAPueOkJvJ83uvWlQk7YQJt+3tGZ/qS+ebbTyp/P7XKTk TFfxbFE+Bus05KQYKO64ghP9t6vrMzxbsSVLdiROSHX1m0uQ5PFhxF49s0ilY340WM04 uXVctER/o++x8sVrIEtoCwtrEr1Y1uQw6VTgW48UUnDVbfYsia5kvEdwJmF4Uk9wCjPL J6J+yOh6GA/7/Bog75Jsjp6JVFsibu8HXLD/tOodoctDsKUh7ED3xgrO5nUa5WbZlwIM HyNQ== X-Gm-Message-State: AD7BkJIYywREOSl/iHZou9U4yS0XzuKUqXGbwYUnLY63z7XZ1YQN18VRpDFkV9+o0UTBYw== X-Received: by 10.98.67.76 with SMTP id q73mr5020130pfa.137.1458128005111; Wed, 16 Mar 2016 04:33:25 -0700 (PDT) Received: from localhost.localdomain ([23.252.122.22]) by smtp.gmail.com with ESMTPSA id u64sm4968782pfa.86.2016.03.16.04.33.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 16 Mar 2016 04:33:24 -0700 (PDT) From: Liang Chen To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Liang Chen , Gavin Guo Subject: [PATCH] KVM: x86: optimize steal time calculation Date: Wed, 16 Mar 2016 19:33:16 +0800 Message-Id: <1458127996-21799-1-git-send-email-liangchen.linux@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since accumulate_steal_time is now only called in record_steal_time, it doesn't quite make sense to put the delta calculation in a separate function. The function could be called thousands of times before guest enables the steal time MSR (though the compiler may optimize out this function call). And after it's enabled, the MSR enable bit is tested twice every time. Removing the accumulate_steal_time function also avoids the necessity of having the accum_steal field. Signed-off-by: Liang Chen Signed-off-by: Gavin Guo --- arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/x86.c | 19 +++---------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 44adbb8..3f460a7 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -547,7 +547,6 @@ struct kvm_vcpu_arch { struct { u64 msr_val; u64 last_steal; - u64 accum_steal; struct gfn_to_hva_cache stime; struct kvm_steal_time steal; } st; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index eaf6ee8..82bfefc 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2002,22 +2002,8 @@ static void kvmclock_reset(struct kvm_vcpu *vcpu) vcpu->arch.pv_time_enabled = false; } -static void accumulate_steal_time(struct kvm_vcpu *vcpu) -{ - u64 delta; - - if (!(vcpu->arch.st.msr_val & KVM_MSR_ENABLED)) - return; - - delta = current->sched_info.run_delay - vcpu->arch.st.last_steal; - vcpu->arch.st.last_steal = current->sched_info.run_delay; - vcpu->arch.st.accum_steal = delta; -} - static void record_steal_time(struct kvm_vcpu *vcpu) { - accumulate_steal_time(vcpu); - if (!(vcpu->arch.st.msr_val & KVM_MSR_ENABLED)) return; @@ -2025,9 +2011,10 @@ static void record_steal_time(struct kvm_vcpu *vcpu) &vcpu->arch.st.steal, sizeof(struct kvm_steal_time)))) return; - vcpu->arch.st.steal.steal += vcpu->arch.st.accum_steal; + vcpu->arch.st.steal.steal += current->sched_info.run_delay - + vcpu->arch.st.last_steal; + vcpu->arch.st.last_steal = current->sched_info.run_delay; vcpu->arch.st.steal.version += 2; - vcpu->arch.st.accum_steal = 0; kvm_write_guest_cached(vcpu->kvm, &vcpu->arch.st.stime, &vcpu->arch.st.steal, sizeof(struct kvm_steal_time));