From: "Jan Beulich" Subject: Re: [PATCHv4 3/5] xen: use ticket locks for spin locks Date: Thu, 14 May 2015 21:51:43 +0100 Message-ID: <555518EF02000078000CF48D@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> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Yt06d-0002f1-Is for xen-devel@lists.xenproject.org; Thu, 14 May 2015 20:51:47 +0000 In-Reply-To: <55550E1F02000078000CF476@mail.emea.novell.com> 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: david.vrabel@citrix.com, tim@xen.org Cc: andrew.cooper3@citrix.com, keir@xen.org, jennifer.herbert@citrix.com, ian.campbell@citrix.com, xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org >>> "Jan Beulich" 05/14/15 10:06 PM >>> >>>> Tim Deegan 05/14/15 12:36 PM >>> >>At 15:37 +0100 on 11 May (1431358623), David Vrabel wrote: >>> void _spin_barrier(spinlock_t *lock) >>> { >>> + spinlock_tickets_t sample; >>> #ifdef LOCK_PROFILE >>> s_time_t block = NOW(); >>> - u64 loop = 0; >>> +#endif >>> >>> check_barrier(&lock->debug); >>> - do { smp_mb(); loop++;} while ( _raw_spin_is_locked(&lock->raw) ); >>> - if ((loop > 1) && lock->profile) >>> + smp_mb(); >>> + sample = observe_lock(&lock->tickets); >>> + if ( sample.head != sample.tail ) >>> { >>> - lock->profile->time_block += NOW() - block; >>> - lock->profile->block_cnt++; >>> - } >>> -#else >>> - check_barrier(&lock->debug); >>> - do { smp_mb(); } while ( _raw_spin_is_locked(&lock->raw) ); >>> + 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. Just realized that this would be too heavy again (and more difficult to do than necessary) - I think on the left side we need observe_tail() instead of observe_head(), and then the == is correct. Jan Jan _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel