From mboxrd@z Thu Jan 1 00:00:00 1970 From: Radim =?utf-8?B?S3LEjW3DocWZ?= Subject: Re: kvm-clock again Date: Tue, 5 Apr 2016 22:25:24 +0200 Message-ID: <20160405202524.GB29308@potion.brq.redhat.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: "kvm@vger.kernel.org" To: Avi Cohen Return-path: Received: from mx1.redhat.com ([209.132.183.28]:40346 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933662AbcDEUZ2 (ORCPT ); Tue, 5 Apr 2016 16:25:28 -0400 Content-Disposition: inline In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: 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=20 > 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__)); >=20 > This is the default kvm-clcok. > I think to add another clock source named - kvm-clock-realtime, and t= o 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_tim= e was 0, so it's the same. wallclock =3D 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. > I want to enter the KVM =C2=A0code and try to make a REAL_TIME and ac= curate synchronization between the host and=C2=A0 guest =C2=A0clocks . > Currently I don=E2=80=99t see that KVM =C2=A0updates the guest=E2=80=99= s clock when I manually set the host=E2=80=99s clock. I don=E2=80=99t s= ee any impact on the guest=E2=80=99s clock Also after booting the guest= I see a=C2=A0 diff-time of ~1ms between the 2 clocks.=20 > Questions: > - What can you tell about the feasibility of this task ? Doable. > - Can you give me a reference/guides=C2=A0 for this task=E2=80=99s =C2= =A0design ? where to start ? potential problems ? pvclock ? when to upd= ate , when reentering the VM ? etc.. Start by using kvm_get_wallclock to pass the host CLOCK_REALTIME into the guest and turn wallclock into guest CLOCK_REALTIME. A reasonable solution would be to create a thread that periodically synchronizes CLOCK_REALTIME with wallclock. The wallclock thread would behave like PTP/NTP, so it should be easy to do. (A notification from the host that the wallclock has changed would be better, but needs new interface.) I think that using wallclock directly as CLOCK_REALTIME would cause mor= e complications: - many guest interfaces expect that they can touch CLOCK_REALTIME, but that shouldn't be allowed - changes in wallclock should trigger guest notifiers as if the change was done by the guest - wallclock is updated only when the guest writes to the MSR, which would be wasteful for frequent reads and not possible in userspace We'll have enough experience to decide on followup if no solution using the existing framework is acceptable.