From patchwork Wed Feb 26 18:15:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 25385 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F1C7520636 for ; Wed, 26 Feb 2014 18:16:08 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id wo20sf4239381obc.4 for ; Wed, 26 Feb 2014 10:16:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=jMWsiAd2W1pAUObbDndamBr9HAdswLZ8UMvEE92lhXk=; b=Tw37KKm/hSfgQr8AGHKNdNlV9kIixxomaaIXY+/kye/Q7Mzs5ndbqYz+eWjxgWNhMx SmDzRlu4C0sG1qKlURYO9s7IJgkTvmCvXodSefw3ytUIJ9u8h4oNdJ4chp59BcwpZSKd VrFK9aQWa4qR9TbG9ofJP66dVMFmSWC2TP684CGohe+9m9RioCM3tGW4WoAGZdS4DOR1 31vCQYfN/YyS9hlNO9doMp7TMewnsrnQMdbcBWw8RZOzsxp09p/7k9rwK3IhTGsz1SlZ S4w8JAhfIs+IbWo6NNSAYLkRnG24zQQbqL9SHhQWOLqxJrTPogJYzr1DqfWNrJXdJFnh ScdQ== X-Gm-Message-State: ALoCoQkC28UeH3EwRRF6sFqrTmes/r7nWxelOxeoSEk3v4Z4oyBd51fMH9KkfcOIEeliyYvggVwJ X-Received: by 10.182.24.134 with SMTP id u6mr1969818obf.24.1393438568242; Wed, 26 Feb 2014 10:16:08 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.43.246 with SMTP id e109ls358325qga.89.gmail; Wed, 26 Feb 2014 10:16:08 -0800 (PST) X-Received: by 10.58.18.133 with SMTP id w5mr18256ved.77.1393438565208; Wed, 26 Feb 2014 10:16:05 -0800 (PST) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id ry8si205022vdc.32.2014.02.26.10.16.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 26 Feb 2014 10:16:05 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.181 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id lg15so1295803vcb.26 for ; Wed, 26 Feb 2014 10:16:05 -0800 (PST) X-Received: by 10.220.162.196 with SMTP id w4mr26525vcx.58.1393438565095; Wed, 26 Feb 2014 10:16:05 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp45267vcz; Wed, 26 Feb 2014 10:16:04 -0800 (PST) X-Received: by 10.66.122.101 with SMTP id lr5mr10291236pab.130.1393438563393; Wed, 26 Feb 2014 10:16:03 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ey10si1781772pab.285.2014.02.26.10.16.02; Wed, 26 Feb 2014 10:16:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753165AbaBZSPY (ORCPT + 26 others); Wed, 26 Feb 2014 13:15:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:5413 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751698AbaBZSPW (ORCPT ); Wed, 26 Feb 2014 13:15:22 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1QIFLBV024102 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 26 Feb 2014 13:15:22 -0500 Received: from hawk.usersys.redhat.com.com (dhcp-1-243.brq.redhat.com [10.34.1.243]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s1QIFGDO017815; Wed, 26 Feb 2014 13:15:19 -0500 From: Andrew Jones To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: mtosatti@redhat.com, pbonzini@redhat.com Subject: [PATCH 2/2] x86: kvm: introduce periodic global clock updates Date: Wed, 26 Feb 2014 19:15:12 +0100 Message-Id: <1393438512-21273-3-git-send-email-drjones@redhat.com> In-Reply-To: <1393438512-21273-1-git-send-email-drjones@redhat.com> References: <1393438512-21273-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: drjones@redhat.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.181 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , commit 0061d53daf26f introduced a mechanism to execute a global clock update for a vm. We can apply this periodically in order to propagate host NTP corrections. Also, if all vcpus of a vm are pinned, then without an additional trigger, no guest NTP corrections can propagate either, as the current trigger is only vcpu cpu migration. Signed-off-by: Andrew Jones --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/x86.c | 65 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 9aa09d330a4b5..77c69aa4756f9 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -599,6 +599,7 @@ struct kvm_arch { u64 master_kernel_ns; cycle_t master_cycle_now; struct delayed_work kvmclock_update_work; + bool clocks_synced; struct kvm_xen_hvm_config xen_hvm_config; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index a2d30de597b7d..5cba20b446aac 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1620,6 +1620,60 @@ static int kvm_guest_time_update(struct kvm_vcpu *v) return 0; } +static void kvm_schedule_kvmclock_update(struct kvm *kvm, bool now); +static void clock_sync_fn(struct work_struct *work); +static DECLARE_DELAYED_WORK(clock_sync_work, clock_sync_fn); + +#define CLOCK_SYNC_PERIOD_SECS 300 +#define CLOCK_SYNC_BUMP_SECS 30 +#define CLOCK_SYNC_STEP_MSECS 100 + +#define __steps(s) (((s) * MSEC_PER_SEC) / CLOCK_SYNC_STEP_MSECS) + +static void clock_sync_fn(struct work_struct *work) +{ + static unsigned reset_step = __steps(CLOCK_SYNC_PERIOD_SECS); + static unsigned step = 0; + struct kvm *kvm; + bool sync = false; + + spin_lock(&kvm_lock); + + if (step == 0) + list_for_each_entry(kvm, &vm_list, vm_list) + kvm->arch.clocks_synced = false; + + list_for_each_entry(kvm, &vm_list, vm_list) { + if (!kvm->arch.clocks_synced) { + kvm_get_kvm(kvm); + sync = true; + break; + } + } + + spin_unlock(&kvm_lock); + + if (sync) { + kvm_schedule_kvmclock_update(kvm, true); + kvm_put_kvm(kvm); + + if (++step == reset_step) { + reset_step += __steps(CLOCK_SYNC_BUMP_SECS); + pr_warn("kvmclock: reducing VM clock sync frequency " + "to every %ld seconds.\n", (reset_step + * CLOCK_SYNC_STEP_MSECS)/MSEC_PER_SEC); + } + + schedule_delayed_work(&clock_sync_work, + msecs_to_jiffies(CLOCK_SYNC_STEP_MSECS)); + } else { + unsigned s = reset_step - step; + step = 0; + schedule_delayed_work(&clock_sync_work, + msecs_to_jiffies(s * CLOCK_SYNC_STEP_MSECS)); + } +} + /* * kvmclock updates which are isolated to a given vcpu, such as * vcpu->cpu migration, should not allow system_timestamp from @@ -1652,11 +1706,12 @@ static void kvmclock_update_fn(struct work_struct *work) kvm_put_kvm(kvm); } -static void kvm_schedule_kvmclock_update(struct kvm *kvm) +static void kvm_schedule_kvmclock_update(struct kvm *kvm, bool now) { kvm_get_kvm(kvm); + kvm->arch.clocks_synced = true; schedule_delayed_work(&kvm->arch.kvmclock_update_work, - KVMCLOCK_UPDATE_DELAY); + now ? 0 : KVMCLOCK_UPDATE_DELAY); } static void kvm_gen_kvmclock_update(struct kvm_vcpu *v) @@ -1664,7 +1719,7 @@ static void kvm_gen_kvmclock_update(struct kvm_vcpu *v) struct kvm *kvm = v->kvm; set_bit(KVM_REQ_CLOCK_UPDATE, &v->requests); - kvm_schedule_kvmclock_update(kvm); + kvm_schedule_kvmclock_update(kvm, false); } static bool msr_mtrr_valid(unsigned msr) @@ -5584,6 +5639,8 @@ int kvm_arch_init(void *opaque) pvclock_gtod_register_notifier(&pvclock_gtod_notifier); #endif + schedule_delayed_work(&clock_sync_work, CLOCK_SYNC_PERIOD_SECS * HZ); + return 0; out_free_percpu: @@ -5594,6 +5651,8 @@ out: void kvm_arch_exit(void) { + cancel_delayed_work_sync(&clock_sync_work); + perf_unregister_guest_info_callbacks(&kvm_guest_cbs); if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC))