From: "Jan Beulich" Subject: RE: RE: rdtsc: correctness vs performance on Xen (and KVM?) Date: Wed, 02 Sep 2009 08:16:30 +0100 Message-ID: <4A9E37EE0200007800012E8B@vpn.id2.novell.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Keir Fraser , Dan Magenheimer Cc: Jeremy Fitzhardinge , "Xen-Devel (E-mail)" , Alan Cox List-Id: xen-devel@lists.xenproject.org >>> Dan Magenheimer 02.09.09 00:08 >>> >> > Just like what is being used to allow apps to get the CPU=20 >> number on native >> > kernels (or the vCPU one on Xen-ified ones): Have a GDT=20 >> entry the limit of >> > which is the number you want, and have the app use the lsl=20 >> instruction to >> > get at it. >>=20 >> Yes, that's true. Xen could provide such a segment descriptor=20 >> in its private >> area of the GDT. The issue then would be that, in a compound pvclock >> operation spanning multiple machine instructions, the pCPU=20 >> number revealed >> by the LSL instruction can be stale by the time it is used=20 >> later in the >> compound operation. > >The algorithm could check the pCPU number before and after >reading the pvclock data and doing the rdtsc, and if they >don't match, start again. (Doesn't the pvclock algorithm >already do that with some versioning number in the pvclock >data itself to ensure that the rest of the data didn't >change while it was being read?) No, that won't do - the underlying pCPU may change multiple times during that process. >I'm clueless about GDTs and the LSL instrution so would >need some help prototyping this. As said in another reply, such a descriptor already exists (PER_CPU_GDT_ENTRY). But as also already said, I doubt you really need this.