linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeremy Fitzhardinge <jeremy@goop.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@elte.hu>,
	the arch/x86 maintainers <x86@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Nick Piggin <npiggin@kernel.dk>,
	Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Subject: [PATCH 0/6] Clean up ticketlock implementation
Date: Mon, 24 Jan 2011 15:41:13 -0800	[thread overview]
Message-ID: <cover.1295909908.git.jeremy.fitzhardinge@citrix.com> (raw)

From: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>

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(-)

-- 
1.7.3.4


             reply	other threads:[~2011-01-24 23:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-24 23:41 Jeremy Fitzhardinge [this message]
2011-01-24 23:41 ` [PATCH 1/6] x86/ticketlock: clean up types and accessors Jeremy Fitzhardinge
2011-01-24 23:41 ` [PATCH 2/6] x86/ticketlock: convert spin loop to C Jeremy Fitzhardinge
2011-01-24 23:41 ` [PATCH 3/6] x86/ticketlock: Use C for __ticket_spin_unlock Jeremy Fitzhardinge
2011-01-25  1:13   ` Nick Piggin
2011-01-25  1:42     ` Jeremy Fitzhardinge
2011-01-25  1:49       ` Nick Piggin
2011-01-24 23:41 ` [PATCH 4/6] x86/ticketlock: make large and small ticket versions of spin_lock the same Jeremy Fitzhardinge
2011-01-24 23:41 ` [PATCH 5/6] x86/ticketlock: make __ticket_spin_lock common Jeremy Fitzhardinge
2011-01-24 23:41 ` [PATCH 6/6] x86/ticketlock: make __ticket_spin_trylock common Jeremy Fitzhardinge
2011-01-25  1:16   ` Nick Piggin
2011-01-25  1:42     ` Jeremy Fitzhardinge
2011-01-25  1:58       ` Nick Piggin
2011-01-27 23:53         ` Jeremy Fitzhardinge
2011-01-25  1:08 ` [PATCH 0/6] Clean up ticketlock implementation Nick Piggin
2011-01-31 21:46   ` Jeremy Fitzhardinge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cover.1295909908.git.jeremy.fitzhardinge@citrix.com \
    --to=jeremy@goop.org \
    --cc=hpa@zytor.com \
    --cc=jeremy.fitzhardinge@citrix.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=npiggin@kernel.dk \
    --cc=peterz@infradead.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).