From: Stefano Stabellini Subject: Re: Could you please answer some questions regarding Solaris PVHVM pvclock support. Date: Thu, 27 Feb 2014 13:03:48 +0000 Message-ID: References: <52D6566C.5050302@oracle.com> <530DD57A.8010709@oracle.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="1342847746-846335373-1393506228=:31489" Return-path: In-Reply-To: <530DD57A.8010709@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Qin Li Cc: Roger Pau Monne , xen-devel@lists.xensource.com, Stefano Stabellini List-Id: xen-devel@lists.xenproject.org --1342847746-846335373-1393506228=:31489 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: QUOTED-PRINTABLE On Wed, 26 Feb 2014, Qin Li wrote: >=20 > =E4=BA=8E 2014/1/16 20:17, Stefano Stabellini =E5=86=99=E9=81=93: >=20 > . For a PV-on-HVM guest OS, the "shared_info->vcpu_info->vcpu_time_info" > > is already visiable. Does guest OS still need any action to ask > > hypervisor to update this piece of memory periodically? >=20 > I don't think you need to ask the hypervisor to update vcpu_time_info > periodically, what gave you that idea? >=20 > Hi Stefano, >=20 > Now, I see it's the hypervisor that will update vcpu_time_info, but anoth= er thing confuse me: > HVM guest has time drift issue because TSC on different vCPU could be out= -of-sync, especially after domain suspend/resume. > But how pvclock actually fix this issue? Let's see how FreeBSD port calcu= late the system time: >=20 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > static uint64_t > get_nsec_offset(struct vcpu_time_info *tinfo) > { >=20 > =C2=A0=C2=A0=C2=A0 return (scale_delta(rdtsc() - tinfo->tsc_timestamp, > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 tinfo->tsc_to_system_mul, tinfo->ts= c_shift)); > } >=20 > /** > =C2=A0* \brief Get the current time, in nanoseconds, since the hypervisor= booted. > =C2=A0* > =C2=A0* \note This function returns the current CPU's idea of this value,= unless > =C2=A0*=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 it happens to be less than an= other CPU's previously determined value. > =C2=A0*/ > static uint64_t > xen_fetch_vcpu_time(void) > { > =C2=A0=C2=A0=C2=A0 struct vcpu_time_info dst; > =C2=A0=C2=A0=C2=A0 struct vcpu_time_info *src; > =C2=A0=C2=A0=C2=A0 uint32_t pre_version; > =C2=A0=C2=A0=C2=A0 uint64_t now; > =C2=A0=C2=A0=C2=A0 volatile uint64_t last; > =C2=A0=C2=A0=C2=A0 struct vcpu_info *vcpu =3D DPCPU_GET(vcpu_info); >=20 > =C2=A0=C2=A0=C2=A0 src =3D &vcpu->time; >=20 > =C2=A0=C2=A0=C2=A0 critical_enter(); > =C2=A0=C2=A0=C2=A0 do { > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 pre_version =3D xen_fetch_vcpu_tinf= o(&dst, src); > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 barrier(); > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 now =3D dst.system_time + get_nsec_= offset(&dst); > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 barrier(); > =C2=A0=C2=A0=C2=A0 } while (pre_version !=3D src->version); >=20 > =C2=A0=C2=A0=C2=A0 /* > =C2=A0=C2=A0=C2=A0 =C2=A0* Enforce a monotonically increasing clock time = across all > =C2=A0=C2=A0=C2=A0 =C2=A0* VCPUs.=C2=A0 If our time is too old, use the l= ast time and return. > =C2=A0=C2=A0=C2=A0 =C2=A0* Otherwise, try to update the last time. > =C2=A0=C2=A0=C2=A0 =C2=A0*/ > =C2=A0=C2=A0=C2=A0 do { > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 last =3D last_time; > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 if (last > now) { > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 now =3D last; > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 break; > =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 } > =C2=A0=C2=A0=C2=A0 } while (!atomic_cmpset_64(&last_time, last, now)); >=20 > =C2=A0=C2=A0=C2=A0 critical_exit(); >=20 > =C2=A0=C2=A0=C2=A0 return (now); > } > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >=20 > I guest linux guest will do the same thing, rdtsc() fetch current timesta= mp from current running vCPU, TSC out-of-sync issue is still there. > It seems to me pvclock finally fix the time drift issue just because the = workaround enforced as above, right? First you should know that TSC is not always guaranteed to be synchronized across multiple processors, especially on older systems. On "TSC-safe" systems, Xen would export a consistent TSC to guests, by setting the vtsc offset and scale appropriately. --1342847746-846335373-1393506228=:31489 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --1342847746-846335373-1393506228=:31489--