Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752952AbdHBO6L (ORCPT ); Wed, 2 Aug 2017 10:58:11 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:29068 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752581AbdHBO6K (ORCPT ); Wed, 2 Aug 2017 10:58:10 -0400 From: Denis Plotnikov To: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org, john.stultz@linaro.org, tglx@linutronix.de Cc: mingo@redhat.com, hpa@zytor.com, linux-kernel@vger.kernel.org, x86@kernel.org, rkagan@virtuozzo.com, den@virtuozzo.com Subject: [PATCH v4 10/10] kvmclock: implement the extended reading function Date: Wed, 2 Aug 2017 17:38:10 +0300 Message-Id: <1501684690-211093-11-git-send-email-dplotnikov@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1501684690-211093-1-git-send-email-dplotnikov@virtuozzo.com> References: <1501684690-211093-1-git-send-email-dplotnikov@virtuozzo.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1811 Lines: 65 This allows L2 guests to use masterclock, namely provide KVM with ability to use masterclock while running over kvmclock closksource in the cases when it's possible. This is the final part of the work of teaching KVM to use masterclock when over kvmclock clocksource. Signed-off-by: Denis Plotnikov --- arch/x86/kernel/kvmclock.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index f692579..8c1008f 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -82,7 +82,7 @@ static int kvm_set_wallclock(const struct timespec *now) return -1; } -static u64 kvm_clock_read(void) +static inline u64 __kvm_clock_read(u64 *cycles, u8 *flags) { struct pvclock_vcpu_time_info *src; u64 ret; @@ -91,10 +91,14 @@ static u64 kvm_clock_read(void) preempt_disable_notrace(); cpu = smp_processor_id(); src = &hv_clock[cpu].pvti; - ret = pvclock_clocksource_read(src, NULL, NULL); + ret = pvclock_clocksource_read(src, cycles, flags); preempt_enable_notrace(); return ret; } +static u64 kvm_clock_read(void) +{ + return __kvm_clock_read(NULL, NULL); +} static u64 kvm_clock_get_cycles(struct clocksource *cs) { @@ -177,9 +181,20 @@ bool kvm_check_and_clear_guest_paused(void) return ret; } +static bool kvm_clock_read_with_stamp(struct clocksource *cs, + u64 *cycles, u64 *cycles_stamp) +{ + u8 flags; + + *cycles = __kvm_clock_read(cycles_stamp, &flags); + + return (bool) flags & PVCLOCK_TSC_STABLE_BIT; +} + struct clocksource kvm_clock = { .name = "kvm-clock", .read = kvm_clock_get_cycles, + .read_with_stamp = kvm_clock_read_with_stamp, .rating = 400, .mask = CLOCKSOURCE_MASK(64), .flags = CLOCK_SOURCE_IS_CONTINUOUS, -- 2.7.4