From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: KVM-Clock Date: Wed, 24 Feb 2016 09:23:59 -0300 Message-ID: <20160224122359.GB12114@amt.cnet> References: <20160224040919.GA10513@amt.cnet> <20160224113306.GA12114@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: "kvm@vger.kernel.org" To: Avi Cohen Return-path: Received: from mx1.redhat.com ([209.132.183.28]:36306 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752006AbcBXMY0 (ORCPT ); Wed, 24 Feb 2016 07:24:26 -0500 Content-Disposition: inline In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Feb 24, 2016 at 11:51:30AM +0000, Avi Cohen wrote: > >> The requirement is that the guest VM will be synced to the host clock - I'm not talking on real-time in the meaning of speed, but I need that the guest clock will measure the exact delay between packet transmission from the host to the packet received in the guest. > > >This makes no sense - if you want a "reliable clock synchronized up to X microseconds", then you have to take into account any possible delay incurred by scheduling (as scheduling determines how reliable a clock read can be) into the clock reliability calculation. > > I understand the scheduling latency , anyway my clock is totally not in sync. Actually - I see about 800ms delay in the guest clock relative to the host clock , also call clock_settime (any_time) in the host and did not see any impact on the guest host. > Also I've looked in the code in kvm_guest_time_update and I think that the clock is not updated because use_master_clock is false - how can I enable master_clock in KVM ? > > > >> My problem now is that sometimes when I receive the packet in the guest I calculate a negative delay because my clock in the guest is in delay relative to the host clock. > > >Use the guest TSC and host TSC values (rdtsc in both). > > >Then subtract from host TSC timestamps the tsc_offset value. > > >You'll get a "perfect" synchronized RDTSC clock. > > >To find out the tsc_offset value, enable kvm_write_tsc_offset tracepoint in the host (before the particular guest boots). > > Do u mean that in the host/guest I will not call clock_gettime but: > > In host : tx_time = tsc_to_ns * (rdtsc () - tsc_offset) Subtracting tsc_offset later is easier. > In guest : rx_time = tsc_to_ns * rdtsc() > Delay = rx_time - tx_time > > How to enable kvm_write_tsc_offset ? # echo kvm_write_tsc_offset > /sys/kernel/debug/tracing/set_event Then boot guest Then cat /sys/kernel/debug/tracing/trace