From patchwork Fri Feb 28 11:52:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 25530 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f199.google.com (mail-ob0-f199.google.com [209.85.214.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A730320543 for ; Fri, 28 Feb 2014 11:53:34 +0000 (UTC) Received: by mail-ob0-f199.google.com with SMTP id wo20sf5399595obc.10 for ; Fri, 28 Feb 2014 03:53:34 -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=guExUoPOesapTEGP1xjOmvKjTgNkaVL03GOLGRaXcjs=; b=BrxHDmHj2winDHX9UAXTkESYE+wMoEnkp9Uc6+AtdkUvgDqkiA51siP9G8B2il0IX8 4AGijs5ZQMVhOpsaeh75iiRu9W4ZrcpSLvRb1QR8s+XW+BGnXqhTJi1MyurS5L+cymRH A1rx5mTXJqTeBTro8j1HNJ0X9CTUkEU7YSPel2YjVe+6fkcFcqbI/6F04aX7BjzffN3G Sezx8EGofpbSlg1LKCPznRdgU/OhOB5kQnF8w249QyPyrNHiB2fnIEpJAQrqtrdaIdka 964nq2rxIE19z92Flnqz0GQA3oUpdIFoNrxXXO6ZY4OBLEo76FbYRf3RD8zckcpwZuRv sXPw== X-Gm-Message-State: ALoCoQkaYSiJl23Wwek3713ciBewOQuUbKyvF99D6Tz5jzrCRn286oGWlEzLyhiPx+d6YOwFNIOn X-Received: by 10.50.222.103 with SMTP id ql7mr3734239igc.1.1393588414206; Fri, 28 Feb 2014 03:53:34 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.43.246 with SMTP id e109ls1077218qga.89.gmail; Fri, 28 Feb 2014 03:53:34 -0800 (PST) X-Received: by 10.58.100.100 with SMTP id ex4mr2229864veb.2.1393588414083; Fri, 28 Feb 2014 03:53:34 -0800 (PST) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id qt5si1715382vcb.98.2014.02.28.03.53.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Feb 2014 03:53:34 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.182 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.182; Received: by mail-vc0-f182.google.com with SMTP id id10so603730vcb.13 for ; Fri, 28 Feb 2014 03:53:34 -0800 (PST) X-Received: by 10.58.200.229 with SMTP id jv5mr2125358vec.15.1393588413984; Fri, 28 Feb 2014 03:53:33 -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.130.193 with SMTP id u1csp48175vcs; Fri, 28 Feb 2014 03:53:33 -0800 (PST) X-Received: by 10.68.201.67 with SMTP id jy3mr3111150pbc.20.1393588412895; Fri, 28 Feb 2014 03:53:32 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wp1si1774074pab.194.2014.02.28.03.53.32; Fri, 28 Feb 2014 03:53:32 -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 S1752224AbaB1LxR (ORCPT + 26 others); Fri, 28 Feb 2014 06:53:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59634 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751661AbaB1LxM (ORCPT ); Fri, 28 Feb 2014 06:53:12 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s1SBrBdD027877 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 28 Feb 2014 06:53:11 -0500 Received: from hawk.usersys.redhat.com.com (dhcp-1-243.brq.redhat.com [10.34.1.243]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s1SBr6Qn029274; Fri, 28 Feb 2014 06:53:10 -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 v2] x86: kvm: introduce periodic global clock updates Date: Fri, 28 Feb 2014 12:52:55 +0100 Message-Id: <1393588375-13664-3-git-send-email-drjones@redhat.com> In-Reply-To: <1393588375-13664-1-git-send-email-drjones@redhat.com> References: <1393588375-13664-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 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.182 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 --- v2: greatly simplify things by creating per vm sync work, and not worrying about vms making simultaneous update requests. arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/x86.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 9aa09d330a4b5..85be627ef5de2 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; + struct delayed_work kvmclock_sync_work; struct kvm_xen_hvm_config xen_hvm_config; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index e656719750fdf..17c57c1ed1835 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1660,6 +1660,20 @@ static void kvm_gen_kvmclock_update(struct kvm_vcpu *v) KVMCLOCK_UPDATE_DELAY); } +#define KVMCLOCK_SYNC_PERIOD (300 * HZ) + +static void kvmclock_sync_fn(struct work_struct *work) +{ + struct delayed_work *dwork = to_delayed_work(work); + struct kvm_arch *ka = container_of(dwork, struct kvm_arch, + kvmclock_sync_work); + struct kvm *kvm = container_of(ka, struct kvm, arch); + + schedule_delayed_work(&kvm->arch.kvmclock_update_work, 0); + schedule_delayed_work(&kvm->arch.kvmclock_sync_work, + KVMCLOCK_SYNC_PERIOD); +} + static bool msr_mtrr_valid(unsigned msr) { switch (msr) { @@ -6733,6 +6747,7 @@ int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu) { int r; struct msr_data msr; + struct kvm *kvm = vcpu->kvm; r = vcpu_load(vcpu); if (r) @@ -6743,6 +6758,9 @@ int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu) kvm_write_tsc(vcpu, &msr); vcpu_put(vcpu); + schedule_delayed_work(&kvm->arch.kvmclock_sync_work, + KVMCLOCK_SYNC_PERIOD); + return r; } @@ -7036,6 +7054,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) pvclock_update_vm_gtod_copy(kvm); INIT_DELAYED_WORK(&kvm->arch.kvmclock_update_work, kvmclock_update_fn); + INIT_DELAYED_WORK(&kvm->arch.kvmclock_sync_work, kvmclock_sync_fn); return 0; } @@ -7074,6 +7093,7 @@ static void kvm_free_vcpus(struct kvm *kvm) void kvm_arch_sync_events(struct kvm *kvm) { + cancel_delayed_work_sync(&kvm->arch.kvmclock_sync_work); cancel_delayed_work_sync(&kvm->arch.kvmclock_update_work); kvm_free_all_assigned_devices(kvm); kvm_free_pit(kvm);