From mboxrd@z Thu Jan 1 00:00:00 1970 From: Boris Ostrovsky Subject: Re: [PATCHv2 5/6] xen: use ticket locks for spin locks Date: Fri, 10 Apr 2015 13:58:38 -0400 Message-ID: <55280F4E.50707@oracle.com> References: <1428675597-28465-1-git-send-email-david.vrabel@citrix.com> <1428675597-28465-6-git-send-email-david.vrabel@citrix.com> <5527FDF6.3030706@oracle.com> <5528086D.7090407@cantab.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YgdGO-0006lb-R5 for xen-devel@lists.xenproject.org; Fri, 10 Apr 2015 18:02:44 +0000 In-Reply-To: <5528086D.7090407@cantab.net> 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 , David Vrabel , xen-devel@lists.xenproject.org Cc: Keir Fraser , Tim Deegan , Ian Campbell , Jan Beulich , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org On 04/10/2015 01:29 PM, David Vrabel wrote: > > On 10/04/2015 17:44, Boris Ostrovsky wrote: >> On 04/10/2015 10:19 AM, David Vrabel wrote: >> >>> @@ -138,14 +138,17 @@ void spin_debug_disable(void) >>> >>> void _spin_lock(spinlock_t *lock) >>> { >>> + spinlock_tickets_t tickets = { .tail = 1, }; >>> LOCK_PROFILE_VAR; >>> >>> check_lock(&lock->debug); >>> - while ( unlikely(!_raw_spin_trylock(&lock->raw)) ) >>> + tickets.head_tail = xadd(&lock->tickets, tickets.head_tail); >>> + if ( tickets.tail != read_atomic(&lock->tickets.head) ) >>> { >>> LOCK_PROFILE_BLOCK; >>> - while ( likely(_raw_spin_is_locked(&lock->raw)) ) >>> + do { >>> cpu_relax(); >>> + } while ( tickets.tail != read_atomic(&lock->tickets.head) ); >>> } >> >> Why do you use both 'if' and 'while"? I.e. why not just >> >> while ( tickets.tail != read_atomic(&lock->tickets.head) ) >> { >> LOCK_PROFILE_BLOCK; >> cpu_relax(); >> } > We need to only call LOCK_PROFILE_BLOCK once when we start blocking. LOCK_PROFILE_BLOCK is a "one-shot" assignment. Once 'block' is set to NOW() it doesn't change anymore. So it will be updated only on the first iteration of the loop. -boris