From: "Jan Beulich" Subject: Re: [PATCHv4 3/5] xen: use ticket locks for spin locks Date: Thu, 14 May 2015 22:01:16 +0100 Message-ID: <55551B2C02000078000CF4A7@mail.emea.novell.com> References: <1431355025-20468-1-git-send-email-david.vrabel@citrix.com> <1431355025-20468-4-git-send-email-david.vrabel@citrix.com> <20150514103621.GE81528@deinos.phlegethon.org> <55550E1F02000078000CF476@mail.emea.novell.com> <20150514205501.GA32424@deinos.phlegethon.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Yt0Fr-0003Hp-RB for xen-devel@lists.xenproject.org; Thu, 14 May 2015 21:01:19 +0000 In-Reply-To: <20150514205501.GA32424@deinos.phlegethon.org> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: tim@xen.org Cc: keir@xen.org, ian.campbell@citrix.com, andrew.cooper3@citrix.com, jennifer.herbert@citrix.com, david.vrabel@citrix.com, xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org >>> Tim Deegan 05/14/15 10:55 PM >>> >At 21:05 +0100 on 14 May (1431637535), Jan Beulich wrote: >> >>> Tim Deegan 05/14/15 12:36 PM >>> >> >At 15:37 +0100 on 11 May (1431358623), David Vrabel wrote: >> >> + while ( observe_head(&lock->tickets) != sample.tail ) >> > >> >This test should be "observe_head(&lock->tickets) == sample.head", >> >i.e. wait until the thread that held the lock has released it. >> >Checking for it to reach the tail is unnecessary (other threads that >> >were queueing for the lock at the sample time don't matter) and >> >dangerous (on a contended lock head might pass sample.tail without us >> >happening to observe it being == ). >> >> The observation of there being a problem is correct, but the suggested solution >> doesn't seem to be. The new code being >> >> if ( sample.head != sample.tail ) >> { >> while ( observe_head(&lock->tickets) == sample.tail ) >> cpu_relax(); >> >> means that if head didn't change between the full sample and the head sample >> we'd end the loop right away, which can't be right. We really need to wait for >> head to reach or pass the sampled tail. > >I think you misread what I asked for. We wait until the observed head >doesn't match the sampled _head_, i.e. for whoever had the lock when >we sampled it to realease it: > >if ( sample.head != sample.tail ) >{ >while ( observe_head(&lock->tickets) == sample.head ) >cpu_relax(); Indeed. And in my simultaneously written reply to that mail I (once again) mixed up head and tail. Sorry for the noise then. Jan