From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: Monotonic clock with KVM pv-clock Date: Tue, 21 Jan 2014 13:27:58 -0200 Message-ID: <20140121152758.GA13319@amt.cnet> References: <20140120095656.GA1282@fermat.math.technion.ac.il> <20140120133317.GA7509@amt.cnet> <20140121132443.GA19460@fermat.math.technion.ac.il> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org To: "Nadav Har'El" Return-path: Received: from mx1.redhat.com ([209.132.183.28]:20330 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754438AbaAUQde (ORCPT ); Tue, 21 Jan 2014 11:33:34 -0500 Content-Disposition: inline In-Reply-To: <20140121132443.GA19460@fermat.math.technion.ac.il> Sender: kvm-owner@vger.kernel.org List-ID: On Tue, Jan 21, 2014 at 03:24:43PM +0200, Nadav Har'El wrote: > On Mon, Jan 20, 2014, Marcelo Tosatti wrote about "Re: Monotonic clock with KVM pv-clock": > > On Mon, Jan 20, 2014 at 11:56:56AM +0200, Nadav Har'El wrote: > > > Hi, > > > > > > I'm trying to figure out how a guest OS can get a monotonic clock using > > > KVM's paravirtual clock. > > > > > > At first, I thought that the clock I get using KVM_SYSTEM_TIME is a > > > monotonic clock, based on the host's monotonic clock. > > > > It is. However, it is used in conjunction with TSC delta, part > > of the structure which is written at KVM_SYSTEM_TIME GPA. See > > pvclock_clocksource_read at arch/x86/kernel/pvclock.c. > > Sure, I'm using the whole protocol for KVM_SYSTEM_TIME. I just wondered > if it has a meaningful definition (namely, of being a monotonic clock) when > being used not in conjunction with the KVM_WALL_CLOCK protocol. If flags field contains PVCLOCK_TSC_STABLE_BIT, yes, otherwise, no. Should use a global accumulator with cmpxchg if PVCLOCK_TSC_STABLE_BIT is clear. > > > 2. What happens when the wall-clock time is set on the host? I was > > > hoping that only KVM_WALL_CLOCK changes and KVM_SYSTEM_TIME doesn't, > > > but am no longer sure this is actually the case. > > > > Yes, it is the case. The host clock which backs system_timestamp field > > of pvclock structure is > > > > CLOCK_MONOTONIC > > Clock that cannot be set and represents monotonic time > > since some unspecified starting point. This clock is not affected by > > discontinuous jumps in the system time (e.g., if the system > > administrator manually changes the clock), but is affected by the > > incremental adjustments per???formed by adjtime(3) and NTP. > > Excellent. > > > > > > If KVM_SYSTEM_TIME is not a correct way to get a monotonic paravirtual clock > > > from KVM, is there a correct way? > > > > Inside a Linux guest? Can use sched_clock(). > > > > If not a Linux guest, either implement kvmclock-like driver > > (kvm-unit-test contains one). > > This is actually an OSv guest (http://osv.io/). > > Until now we were using kvmclock by adding up the wallclock and > systemtime protocol, and this resulted with a good wall-time clock > (CLOCK_REALTIME), but I really wanted to also have a monotonic clock > (CLOCK_MONOTONIC) for the guest. > > I took a look and how a Linux guest uses the KVM pv clock, and thought > that the "system time" part of the kvm clock protocol will be a good > monotonic clock, but wasn't sure I was understanding this right. > > Thanks for the clarifications! > > Nadav. > > -- > Nadav Har'El | Tuesday, Jan 21 2014, 20 Shevat 5774 > nyh@math.technion.ac.il |----------------------------------------- > Phone +972-523-790466, ICQ 13349191 |"The average person thinks he isn't." - > http://nadav.harel.org.il |Father Larry Lorenzoni