From: Waiman Long <longman@redhat.com>
To: Will Deacon <will.deacon@arm.com>, Peter Zijlstra <peterz@infradead.org>
Cc: linux-arch@vger.kernel.org, linux-xtensa@linux-xtensa.org,
Davidlohr Bueso <dave@stgolabs.net>,
linux-ia64@vger.kernel.org, Tim Chen <tim.c.chen@linux.intel.com>,
Arnd Bergmann <arnd@arndb.de>,
linux-sh@vger.kernel.org, linux-hexagon@vger.kernel.org,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
linux-kernel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
linux-alpha@vger.kernel.org, sparclinux@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
linuxppc-dev@lists.ozlabs.org,
Andrew Morton <akpm@linux-foundation.org>,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v3 2/2] locking/rwsem: Optimize down_read_trylock()
Date: Thu, 14 Feb 2019 13:35:22 -0500 [thread overview]
Message-ID: <ffbd2cab-1cfd-334a-b462-2bd7986dc3b0@redhat.com> (raw)
In-Reply-To: <20190214180239.GI2475@fuggles.cambridge.arm.com>
[-- Attachment #1: Type: text/plain, Size: 3792 bytes --]
On 02/14/2019 01:02 PM, Will Deacon wrote:
> On Thu, Feb 14, 2019 at 11:33:33AM +0100, Peter Zijlstra wrote:
>> On Wed, Feb 13, 2019 at 03:32:12PM -0500, Waiman Long wrote:
>>> Modify __down_read_trylock() to optimize for an unlocked rwsem and make
>>> it generate slightly better code.
>>>
>>> Before this patch, down_read_trylock:
>>>
>>> 0x0000000000000000 <+0>: callq 0x5 <down_read_trylock+5>
>>> 0x0000000000000005 <+5>: jmp 0x18 <down_read_trylock+24>
>>> 0x0000000000000007 <+7>: lea 0x1(%rdx),%rcx
>>> 0x000000000000000b <+11>: mov %rdx,%rax
>>> 0x000000000000000e <+14>: lock cmpxchg %rcx,(%rdi)
>>> 0x0000000000000013 <+19>: cmp %rax,%rdx
>>> 0x0000000000000016 <+22>: je 0x23 <down_read_trylock+35>
>>> 0x0000000000000018 <+24>: mov (%rdi),%rdx
>>> 0x000000000000001b <+27>: test %rdx,%rdx
>>> 0x000000000000001e <+30>: jns 0x7 <down_read_trylock+7>
>>> 0x0000000000000020 <+32>: xor %eax,%eax
>>> 0x0000000000000022 <+34>: retq
>>> 0x0000000000000023 <+35>: mov %gs:0x0,%rax
>>> 0x000000000000002c <+44>: or $0x3,%rax
>>> 0x0000000000000030 <+48>: mov %rax,0x20(%rdi)
>>> 0x0000000000000034 <+52>: mov $0x1,%eax
>>> 0x0000000000000039 <+57>: retq
>>>
>>> After patch, down_read_trylock:
>>>
>>> 0x0000000000000000 <+0>: callq 0x5 <down_read_trylock+5>
>>> 0x0000000000000005 <+5>: xor %eax,%eax
>>> 0x0000000000000007 <+7>: lea 0x1(%rax),%rdx
>>> 0x000000000000000b <+11>: lock cmpxchg %rdx,(%rdi)
>>> 0x0000000000000010 <+16>: jne 0x29 <down_read_trylock+41>
>>> 0x0000000000000012 <+18>: mov %gs:0x0,%rax
>>> 0x000000000000001b <+27>: or $0x3,%rax
>>> 0x000000000000001f <+31>: mov %rax,0x20(%rdi)
>>> 0x0000000000000023 <+35>: mov $0x1,%eax
>>> 0x0000000000000028 <+40>: retq
>>> 0x0000000000000029 <+41>: test %rax,%rax
>>> 0x000000000000002c <+44>: jns 0x7 <down_read_trylock+7>
>>> 0x000000000000002e <+46>: xor %eax,%eax
>>> 0x0000000000000030 <+48>: retq
>>>
>>> By using a rwsem microbenchmark, the down_read_trylock() rate (with a
>>> load of 10 to lengthen the lock critical section) on a x86-64 system
>>> before and after the patch were:
>>>
>>> Before Patch After Patch
>>> # of Threads rlock rlock
>>> ------------ ----- -----
>>> 1 14,496 14,716
>>> 2 8,644 8,453
>>> 4 6,799 6,983
>>> 8 5,664 7,190
>>>
>>> On a ARM64 system, the performance results were:
>>>
>>> Before Patch After Patch
>>> # of Threads rlock rlock
>>> ------------ ----- -----
>>> 1 23,676 24,488
>>> 2 7,697 9,502
>>> 4 4,945 3,440
>>> 8 2,641 1,603
>> Urgh, yes LL/SC is the obvious exception that can actually do better
>> here :/
>>
>> Will, what say you?
> What machine were these numbers generated on and is it using LL/SC or LSE
> atomics for arm64? If you stick the microbenchmark somewhere, I can go play
> with a broader variety of h/w.
>
> Will
The machine is a 2-socket Cavium ThunderX2 99xx system with 64 cores and
256 threads. I was just using threads from the first socket for this
test. The microbenchmark that I used is attached. I used the command
"./run-locktest -ltryrwsem -r100 -i-10 -c10 -n<threads>" to generate the
locking rates.
The lscpu flags were:
fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics cpuid asimdrdm
Cheers,
Longman
[-- Attachment #2: locktest.tar.gz --]
[-- Type: application/gzip, Size: 9620 bytes --]
prev parent reply other threads:[~2019-02-14 18:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-13 20:32 [PATCH v3 0/2] locking/rwsem: Remove arch specific rwsem files Waiman Long
2019-02-13 20:32 ` [PATCH v3 1/2] " Waiman Long
2019-02-13 20:32 ` [PATCH v3 2/2] locking/rwsem: Optimize down_read_trylock() Waiman Long
2019-02-14 10:33 ` Peter Zijlstra
2019-02-14 14:53 ` Waiman Long
2019-02-14 17:51 ` Linus Torvalds
2019-02-14 18:09 ` Linus Torvalds
2019-02-15 18:35 ` Will Deacon
2019-02-14 18:02 ` Will Deacon
2019-02-14 18:35 ` Waiman Long [this message]
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=ffbd2cab-1cfd-334a-b462-2bd7986dc3b0@redhat.com \
--to=longman@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=bp@alien8.de \
--cc=dave@stgolabs.net \
--cc=hpa@zytor.com \
--cc=linux-alpha@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-hexagon@vger.kernel.org \
--cc=linux-ia64@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=linux-xtensa@linux-xtensa.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=sparclinux@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=tim.c.chen@linux.intel.com \
--cc=torvalds@linux-foundation.org \
--cc=will.deacon@arm.com \
--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).