From mboxrd@z Thu Jan 1 00:00:00 1970 From: Radim =?utf-8?B?S3LEjW3DocWZ?= Subject: Re: kvm-clock again Date: Wed, 6 Apr 2016 16:17:56 +0200 Message-ID: <20160406141755.GH21537@potion.brq.redhat.com> References: <20160405202524.GB29308@potion.brq.redhat.com> 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]:53432 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753018AbcDFOSF (ORCPT ); Wed, 6 Apr 2016 10:18:05 -0400 Content-Disposition: inline In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: 2016-04-06 13:51+0000, Avi Cohen: >> 2016-04-05 15:07+0000, Avi Cohen: >> > What do you think about this simple solution: >> > Currently the KVM updates the system-time in the structure >> > pvclock_vcpu_time_info in the guest memory with the MONOTONIC time >> struct pvclock_vcpu_time_info { >> > u32 version; >> > u32 pad0; >> > u64 tsc_timestamp; >> > u64 system_time; >> > u32 tsc_to_system_mul; >> > s8 tsc_shift; >> > u8 flags; >> > u8 pad[2]; >> > } __attribute__((__packed__)); >> > >> > This is the default kvm-clcok. >> > I think to add another clock source named - kvm-clock-realtime, and to update >> system_time with host's REAL_TIME clock. >> > What is your opinion ? >> >> Would you be ok with a wall_time entry in pvclock_vcpu_time_info that would >> tell the host real time at system_time? >> struct pvclock_wall_clock should say the host real time when system_time was >> 0, so it's the same. wallclock = CLOCK_REALTIME, most likely. >> >> Creating a new clock would allow us to get rid of many other problems, but your >> goal might be achievable with existing interfaces. >> > > Yes - it will be ok to update the pvclock_wall_clock with the host CLOCK_REALTIME. > But I think I also need the guest's TSC at that time of update, > struct pvclock_wall_clock { > 37 u32 version; > 38 u32 sec; > 39 u32 nsec; > New field tsc_timestamp; > New field tsc_to_system_mul; > 40 } __attribute__((__packed__)); > > Now the guest - when need to read the current time - can do something like this : > Current_time = sec * sec_to_nano + nsec + (rdtdc () - tsc_timestamp) * tsc_to_system_mul No need. pvclock_wall_clock.{sec,nsec} is synchronized with system_time and system_time is synchronized with TSC. To get the current real time, you just add times from pvclock_vcpu_time_info, pvclock_wall_clock and TSC, like kvm_get_wallclock() does.