Skip to content

Clean up ticketlock implementation

Jeremy Fitzhardinge lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest6 patches 9 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6x86/ticketlock: clean up types and accessorsarch/x86/include/asm/spinlock.h arch/x86/include/asm/spinlock_types.h+28 -160 replies
2/6x86/ticketlock: convert spin loop to Carch/x86/include/asm/spinlock.h+30 -300 replies
3/6x86/ticketlock: Use C for __ticket_spin_unlockarch/x86/include/asm/spinlock.h+17 -153 replies
4/6x86/ticketlock: make large and small ticket versions of spin_lock the samearch/x86/include/asm/spinlock.h+8 -150 replies
5/6x86/ticketlock: make __ticket_spin_lock commonarch/x86/include/asm/spinlock.h+20 -220 replies
6/6x86/ticketlock: make __ticket_spin_trylock commonarch/x86/include/asm/spinlock.h arch/x86/include/asm/spinlock_types.h+14 -414 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/6] Clean up ticketlock implementation

From: Jeremy Fitzhardinge <[email protected]>

Hi all,

This series cleans up the x86 ticketlock implementation by converting a large proportion of it to C. This eliminates the need for having separate implementations for "large" (NR_CPUS >= 256) and "small" (NR_CPUS < 256) ticket locks.

This also lays the groundwork for future changes to the ticketlock implementation.

Of course, the big question when converting from assembler to C is what the compiler will do to the code. In general, the results are very similar.

For example, the original hand-coded small-ticket ticket_lock is:
movl $256, %eax
lock xadd %ax,(%rdi)
1: cmp %ah,%al

      je     2f
      pause  
      mov    (%rdi),%al
      jmp    1b

2:

The C version, compiled by gcc 4.5.1 is:

        movl   $256, %eax
        lock; xaddw %ax, (%rdi)
        movzbl  %ah, %edx

.L3: cmpb %dl, %al
je .L2
rep; nop
movb (%rdi), %al # lock_1(D)->D.5949.tickets.head, inc$head
jmp .L3 #
.L2:

So very similar, except the compiler misses directly comparing %ah to %al.

With big tickets, which is what distros are typically compiled with, the results are:

hand-coded:

        movl    $65536, %eax    #, inc
        lock; xaddl %eax, (%rdi)        # inc, lock_2(D)->slock
	movzwl %ax, %edx        # inc, tmp
        shrl $16, %eax  # inc

1: cmpl %eax, %edx # inc, tmp
je 2f
rep ; nop
movzwl (%rdi), %edx # lock_2(D)->slock, tmp
jmp 1b
2:

Compiled C:

        movl    $65536, %eax    #, tickets
        lock; xaddl %eax, (%rdi)        # tickets, lock_1(D)->D.5952.tickets
        movl    %eax, %edx      # tickets,
        shrl    $16, %edx       #,

.L3: cmpw %dx, %ax # tickets$tail, inc$head
je .L2 #,
rep; nop
movw (%rdi), %ax # lock_1(D)->D.5952.tickets.head, inc$head
jmp .L3 #
.L2:

In this case the code is pretty much identical except for slight variations in where the 32-bit values are truncated to 16.

So overall, I think this change will have negligable performance impact.

Thanks,
J

Jeremy Fitzhardinge (6):
x86/ticketlock: clean up types and accessors x86/ticketlock: convert spin loop to C
x86/ticketlock: Use C for __ticket_spin_unlock x86/ticketlock: make large and small ticket versions of spin_lock the
same
x86/ticketlock: make __ticket_spin_lock common x86/ticketlock: make __ticket_spin_trylock common

 arch/x86/include/asm/spinlock.h       |  146 ++++++++++++---------------------
 arch/x86/include/asm/spinlock_types.h |   22 +++++-
 2 files changed, 73 insertions(+), 95 deletions(-)
Signature · 1 line
1.7.3.4