From: Keir Fraser Subject: Re: [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:48:40 +0000 Message-ID: References: <22C8C9FD-3B4A-45C2-A901-15A25648482A@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <22C8C9FD-3B4A-45C2-A901-15A25648482A@gmail.com> 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 , Jan Beulich Cc: xen-devel@lists.xensource.com, Haibo Chen List-Id: xen-devel@lists.xenproject.org On 16/11/2010 14:51, "Song Xiang" wrote: > + /* > + * if acquired the PMTState lock then update the time > + * else other vcpu is updating it ,it should be up to date. > + */ > + tmp = atomic_read(&s-> ownership); > + if (spin_trylock(&s->lock)) { > + pmt_update_time(s); > + *val = s->pm.tmr_val; > + spin_unlock(&s->lock); > + atomic_inc(&s-> ownership); > + } > + else { > + while (tmp == atomic_read(&s-> ownership)); You've kind of implemented a spin_barrier(). What you implemented could be better and equivalently done as something like: if (spin_trylock(&s->lock)) { ... } else { spin_barrier(&s->lock); } No need for your new field at all! It initially seems weird that this performs much better than the original code, but I guess it might: if all VCPUs are piling in here at the same time, rather than having to execute one by one, we'll have one go first and then the others will all execute simultaneously read-only in convoy... Anyway, please modify your patch as I suggest above, and then also confirm what speedups you get with the revised patch. I want to know what the wins are before applying optimisation hacks. I don't particularly have an issue with them as long as they work! :-) -- Keir