[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCHv2 5/6] xen: use ticket locks for spin locks




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.

>> @@ -194,35 +174,44 @@ void _spin_unlock(spinlock_t *lock)
>>   {
>>       preempt_enable();
>>       LOCK_PROFILE_REL;
>> -    _raw_spin_unlock(&lock->raw);
>> +    lock->tickets.head++;
> 
> 
> Is it safe to do a plain increment here and a locked one?

Yes. Only the lock holder writes to head.

David

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.