WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] Re: [PATCH 00/13] [PATCH RFC] Paravirtualized ticketlocks

To: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] Re: [PATCH 00/13] [PATCH RFC] Paravirtualized ticketlocks
From: Jeremy Fitzhardinge <jeremy@xxxxxxxx>
Date: Fri, 02 Sep 2011 13:07:23 -0700
Cc: Marcelo Tosatti <mtosatti@xxxxxxxxxx>, Nick Piggin <npiggin@xxxxxxxxx>, KVM <kvm@xxxxxxxxxxxxxxx>, Peter Zijlstra <peterz@xxxxxxxxxxxxx>, the arch/x86 maintainers <x86@xxxxxxxxxx>, Linux Kernel Mailing List <linux-kernel@xxxxxxxxxxxxxxx>, Andi Kleen <andi@xxxxxxxxxxxxxx>, Avi Kivity <avi@xxxxxxxxxx>, Jeremy Fitzhardinge <jeremy.fitzhardinge@xxxxxxxxxx>, "H. Peter Anvin" <hpa@xxxxxxxxx>, Ingo Molnar <mingo@xxxxxxx>, Xen Devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Delivery-date: Fri, 02 Sep 2011 13:10:40 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <CA+55aFxpz+1bXVsg7kMeozePa=j_2-OaOuidQ4Y9Bg063=HMfg@xxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <cover.1314922370.git.jeremy.fitzhardinge@xxxxxxxxxx> <CA+55aFxpz+1bXVsg7kMeozePa=j_2-OaOuidQ4Y9Bg063=HMfg@xxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20110816 Thunderbird/6.0
On 09/02/2011 08:38 AM, Linus Torvalds wrote:
> On Thu, Sep 1, 2011 at 5:54 PM, Jeremy Fitzhardinge <jeremy@xxxxxxxx> wrote:
>> The inner part of ticket lock code becomes:
>>        inc = xadd(&lock->tickets, inc);
>>        inc.tail &= ~TICKET_SLOWPATH_FLAG;
>>
>>        for (;;) {
>>                unsigned count = SPIN_THRESHOLD;
>>
>>                do {
>>                        if (inc.head == inc.tail)
>>                                goto out;
>>                        cpu_relax();
>>                        inc.head = ACCESS_ONCE(lock->tickets.head);
>>                } while (--count);
>>                __ticket_lock_spinning(lock, inc.tail);
>>        }
> Hmm. It strikes me that I don't think you should touch the
> TICKET_SLOWPATH_FLAG in the fastpath at all.
>
> Can't you just do this:
>
>    inc = xadd(&lock->tickets, inc);
>    if (likely(inc.head == inc.tail))
>      goto out;
>
>    ### SLOWPATH ###
>    inc.tail &= ~TICKET_SLOWPATH_FLAG;
>    for (;;) {
>       .. as before ..
>
> which might alleviate the problem with the fastpath being polluted by
> all those silly slowpath things.  Hmm?
>
> (This assumes that TICKET_SLOWPATH_FLAG is never set in inc.head, so
> if it's set that equality check will fail. I didn't actually check if
> that assumption was correct)

Yes, nice idea.  That ends up making the overall code slightly longer,
but the fastpath becomes identical to the non-pv case:

        mov    $512,%ecx
        lock xadd %cx,(%rdi)
        movzbl %ch,%edx
        cmp    %cl,%dl
        je     2f

        ### SLOWPATH START
        and    $-2,%edx
        mov    $8192,%eax
        movzbl %dl,%esi
1:      cmp    %dl,%cl
        je     2f
        pause  
        dec    %eax
        mov    (%rdi),%cl
        jne    1b
        callq  __ticket_lock_spinning
        mov    $8192,%eax
        jmp    1b
        ### SLOWPATH ENDS

2:


It's especially nice that it also moves the spin counter and arg setup
into the slowpath code.

And that entire piece of slowpath code can be moved out into its own
function, so the fastpath becomes:

        mov    $512,%eax
        lock xadd %ax,(%rdi)
        movzbl %ah,%esi
        cmp    %al,%sil
        je     1f

        movzbl %sil,%esi
        callq  __ticket_lock_slow
1:

I don't know whether that fastpath code is small enough to consider
inlining everywhere?

    J

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel