From patchwork Sat Jul 29 12:35:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Plotnikov X-Patchwork-Id: 9869923 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BD22F6038F for ; Sat, 29 Jul 2017 12:36:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A684028879 for ; Sat, 29 Jul 2017 12:36:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B81E288FA; Sat, 29 Jul 2017 12:36:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0728528879 for ; Sat, 29 Jul 2017 12:36:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753798AbdG2MgL (ORCPT ); Sat, 29 Jul 2017 08:36:11 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:5897 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753724AbdG2Mfy (ORCPT ); Sat, 29 Jul 2017 08:35:54 -0400 Received: from dptest2.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v6TCZfRu013516; Sat, 29 Jul 2017 15:35:42 +0300 (MSK) From: Denis Plotnikov To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org Cc: rkagan@virtuozzo.com, den@virtuozzo.com, svt-core@lists.sw.ru Subject: [PATCH v3 6/6] kvmclock: add the clocksource stability querying function Date: Sat, 29 Jul 2017 15:35:11 +0300 Message-Id: <1501331711-12961-7-git-send-email-dplotnikov@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1501331711-12961-1-git-send-email-dplotnikov@virtuozzo.com> References: <1501331711-12961-1-git-send-email-dplotnikov@virtuozzo.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The patch is the final part of work making kvmclock stable in L2 if it works over a stable clocksource. Signed-off-by: Denis Plotnikov --- arch/x86/kernel/kvmclock.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index 52156d9..6a4d995 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -186,10 +186,22 @@ static void kvm_clock_read_with_cycles(u64 *cycles, u64 *cycles_stamp) *cycles = __kvm_clock_read(cycles_stamp); } +static bool kvm_clock_stable(void) +{ + int cpu = get_cpu(); + struct pvclock_vcpu_time_info *vcpu_time = &hv_clock[cpu].pvti; + u8 flags = pvclock_read_flags(vcpu_time); + + put_cpu(); + + return flags & PVCLOCK_TSC_STABLE_BIT; +} + struct clocksource kvm_clock = { .name = "kvm-clock", .read = kvm_clock_get_cycles, .read_with_cycles = kvm_clock_read_with_cycles, + .is_stable = kvm_clock_stable, .rating = 400, .mask = CLOCKSOURCE_MASK(64), .flags = CLOCK_SOURCE_IS_CONTINUOUS,