From: "Jan Beulich" Subject: [SPAM] Re: A patch to xen/arch/x86/hvm/pmtimer.c for both Xen 4.0.0 and Xen 4.0.1 to improve HVM scalability Date: Tue, 16 Nov 2010 07:50:11 +0000 Message-ID: <4CE245C30200007800022701@vpn.id2.novell.com> References: <1208B612-80C6-4009-ACEB-1D4E99D0FA7E@gmail.com> <4CE0FD5102000078000222D9@vpn.id2.novell.com> <22C8C9FD-3B4A-45C2-A901-15A25648482A@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <22C8C9FD-3B4A-45C2-A901-15A25648482A@gmail.com> 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: Song Xiang Cc: xen-devel@lists.xensource.com, Haibo Chen List-Id: xen-devel@lists.xenproject.org >>> On 16.11.10 at 15:51, Song Xiang wrote: > We updated our patch as follows: >=20 > Index: arch/x86/hvm/pmtimer.c > =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=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 > --- arch/x86/hvm/pmtimer.c > +++ arch/x86/hvm/pmtimer.c > @@ -206,13 +206,23 @@ >=20 > if ( dir =3D=3D IOREQ_READ ) > { > - spin_lock(&s->lock); > - pmt_update_time(s); > - *val =3D s->pm.tmr_val; > - spin_unlock(&s->lock); > + uint32_t tmp; > + /* > + * if acquired the PMTState lock then update the time > + * else other vcpu is updating it ,it should be up to date. > + */ > + tmp =3D atomic_read(&s-> ownership); > + if (spin_trylock(&s->lock)) { > + pmt_update_time(s); > + *val =3D s->pm.tmr_val; > + spin_unlock(&s->lock); > + atomic_inc(&s-> ownership); > + } > + else { > + while (tmp =3D=3D atomic_read(&s-> ownership)); > + > + *val =3D s->pm.tmr_val; > + } > return X86EMUL_OKAY; > } >=20 > Index: include/asm-x86/hvm/vpt.h > =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=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 > --- include/asm-x86/hvm/vpt.h > +++ include/asm-x86/hvm/vpt.h > @@ -120,6 +120,7 @@ > uint64_t scale; /* Multiplier to get from tsc to =20 > timer ticks */ > struct timer timer; /* To make sure we send SCIs */ > spinlock_t lock; > + atomic_t ownership; > } PMTState; >=20 > struct pl_time { /* platform time */ >=20 >=20 > The key idea is, to keep the returned time fresh, any VCPU that fails = =20 > to acquire the PMTState lock will wait until the PMTState lock holder = =20 > updates the global virtual time, and then returns the freshest time. > > We add a field in PMTState, named ownership. The PMTState->ownership =20 > can only be updated by the PMTState lock holder.It is updated after =20 > the PMTState lock holder has updated the global virtual time and =20 > released the MTState lock. Other VCPUs that fail to acquire the =20 > PMTState lock will check whether the MTState->ownership is updated in = =20 > a while loop. When the PMTState->ownership is changed, the global =20 > virtual time must be the freshest, and can be returned to the guest OS. >=20 > The time returned to the guest in this patch is fresher than the =20 > previous one we have proposed. That's not better: Depending on timing, the reader may well loop until the *next* acquirer releases the lock (and increments "ownership"). Jan