From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS, USER_AGENT_MUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F899C43381 for ; Thu, 14 Feb 2019 18:02:55 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5C9942080A for ; Thu, 14 Feb 2019 18:02:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="h7sDSZvJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C9942080A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ODjKEwaKLAAsKFITqpMsH1FbYc9DUJtLjtfbwzjOZ+o=; b=h7sDSZvJE1bExS ddWEzZU/qYxryAUVVuQ8erqxHdc6I7m6bEwEVIjfyfpSH5hLq5icke9n4RXWg81YSOoWv6ZeDf0VM eWRAXxHX0JfOu9Zy8gOn1Fbv8dtcPu5m+oIDyrYiFm4WhAslwVHlow6Z75rTRPhVe07l2N8crfCFU 2pxuPYv6Oaga5BIjZh8I7RWXlsqQ5RNikYFTtfu4q4pNq5UJv7G3TNh+86ExeRpdgBNtD622639f1 83m/oF6KaZxjdbsCyNFgd2jxi8rAUs4bcLbMvh53BsAk3p3Rv4USHXkTlyH8U0BGm1ZVad6vvpHwi B9nMewt4gG64wFTEGObA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1guLLV-00044t-6b; Thu, 14 Feb 2019 18:02:49 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1guLLR-00044V-Mm for linux-arm-kernel@lists.infradead.org; Thu, 14 Feb 2019 18:02:47 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 65562EBD; Thu, 14 Feb 2019 10:02:45 -0800 (PST) Received: from fuggles.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D806D3F589; Thu, 14 Feb 2019 10:02:41 -0800 (PST) Date: Thu, 14 Feb 2019 18:02:39 +0000 From: Will Deacon To: Peter Zijlstra Subject: Re: [PATCH v3 2/2] locking/rwsem: Optimize down_read_trylock() Message-ID: <20190214180239.GI2475@fuggles.cambridge.arm.com> References: <1550089932-6888-1-git-send-email-longman@redhat.com> <1550089932-6888-3-git-send-email-longman@redhat.com> <20190214103333.GH32494@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190214103333.GH32494@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.11.1+86 (6f28e57d73f2) () X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190214_100245_776642_C3A5F799 X-CRM114-Status: GOOD ( 15.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, linux-xtensa@linux-xtensa.org, Davidlohr Bueso , linux-ia64@vger.kernel.org, Tim Chen , Arnd Bergmann , linux-sh@vger.kernel.org, linux-hexagon@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Linus Torvalds , Ingo Molnar , Borislav Petkov , linux-alpha@vger.kernel.org, sparclinux@vger.kernel.org, Waiman Long , Thomas Gleixner , linuxppc-dev@lists.ozlabs.org, Andrew Morton , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 > > 0x0000000000000005 <+5>: jmp 0x18 > > 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 > > 0x0000000000000018 <+24>: mov (%rdi),%rdx > > 0x000000000000001b <+27>: test %rdx,%rdx > > 0x000000000000001e <+30>: jns 0x7 > > 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 > > 0x0000000000000005 <+5>: xor %eax,%eax > > 0x0000000000000007 <+7>: lea 0x1(%rax),%rdx > > 0x000000000000000b <+11>: lock cmpxchg %rdx,(%rdi) > > 0x0000000000000010 <+16>: jne 0x29 > > 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 > > 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel