From patchwork Tue Dec 15 04:08:40 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zachary Amsden X-Patchwork-Id: 67474 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nBF4QSLm016846 for ; Tue, 15 Dec 2009 04:26:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759220AbZLOEKM (ORCPT ); Mon, 14 Dec 2009 23:10:12 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1759249AbZLOEJ7 (ORCPT ); Mon, 14 Dec 2009 23:09:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:30702 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932387AbZLOEHW (ORCPT ); Mon, 14 Dec 2009 23:07:22 -0500 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 nBF47Lfw024174 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 14 Dec 2009 23:07:21 -0500 Received: from localhost.localdomain (vpn-9-100.rdu.redhat.com [10.11.9.100]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBF46m97031119; Mon, 14 Dec 2009 23:07:19 -0500 From: Zachary Amsden To: kvm@vger.kernel.org Cc: Zachary Amsden , Avi Kivity , Marcelo Tosatti , Joerg Roedel , linux-kernel@vger.kernel.org, Dor Laor Subject: [PATCH RFC: kvm tsc virtualization 13/20] Combine observed TSC deviation into moving average Date: Mon, 14 Dec 2009 18:08:40 -1000 Message-Id: <1260850127-9766-14-git-send-email-zamsden@redhat.com> In-Reply-To: <1260850127-9766-13-git-send-email-zamsden@redhat.com> References: <1260850127-9766-1-git-send-email-zamsden@redhat.com> <1260850127-9766-2-git-send-email-zamsden@redhat.com> <1260850127-9766-3-git-send-email-zamsden@redhat.com> <1260850127-9766-4-git-send-email-zamsden@redhat.com> <1260850127-9766-5-git-send-email-zamsden@redhat.com> <1260850127-9766-6-git-send-email-zamsden@redhat.com> <1260850127-9766-7-git-send-email-zamsden@redhat.com> <1260850127-9766-8-git-send-email-zamsden@redhat.com> <1260850127-9766-9-git-send-email-zamsden@redhat.com> <1260850127-9766-10-git-send-email-zamsden@redhat.com> <1260850127-9766-11-git-send-email-zamsden@redhat.com> <1260850127-9766-12-git-send-email-zamsden@redhat.com> <1260850127-9766-13-git-send-email-zamsden@redhat.com> Organization: Frobozz Magic Timekeeping Company 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 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c66dede..8bd362b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -914,6 +914,7 @@ static void sync_tsc_helper(int measure_cpu, s64 *delta, atomic_t *ready) /* * Average and trim the samples of any outliers; we use > 2 x sigma */ +static u64 tsc_deviation; static s64 average_samples(s64 *samples, unsigned num_samples) { unsigned i, j; @@ -936,6 +937,11 @@ static s64 average_samples(s64 *samples, unsigned num_samples) stddev = stddev / (num_samples - 1); stddev = int_sqrt(stddev); + /* Accumulate deviation measurement into a moving average */ + tsc_deviation = tsc_deviation ? + ((tsc_deviation << 4) - tsc_deviation + stddev) >> 4 : + stddev; + /* Throw out anything outside 2x stddev */ stddev <<= 1; average = 0, j = 0; @@ -950,10 +956,12 @@ static s64 average_samples(s64 *samples, unsigned num_samples) } if (j > 0) average = average / j; - else + else { printk(KERN_ERR "kvm: TSC samples failed to converge!\n"); - pr_debug("%s: mean = %lld, stddev = %llu, average = %lld\n", - __func__, mean, stddev, average); + average = mean; + } + pr_debug("%s: mean=%lld, stddev=%llu, average=%lld hdev=%llu\n", + __func__, mean, stddev, average, tsc_deviation); return average; }