From patchwork Mon Oct 28 13:39:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xuelei Zhang X-Patchwork-Id: 35397 Received: (qmail 81220 invoked by alias); 28 Oct 2019 13:39:45 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 81211 invoked by uid 89); 28 Oct 2019 13:39:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_MANYTO, KAM_SHORT autolearn=ham version=3.3.1 spammy= X-HELO: huawei.com From: Xuelei Zhang To: , , , , , Subject: [PATCH] aarch64: Optimized implementation of pthread_spin_trylock Date: Mon, 28 Oct 2019 21:39:30 +0800 Message-ID: <20191028133930.24004-1-zhangxuelei4@huawei.com> MIME-Version: 1.0 Judge the value of ldaxr before stxr, to reduce the memmory store operation in the case spin_lock is already used by other threads. --- sysdeps/aarch64/nptl/pthread_spin_trylock.S | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 sysdeps/aarch64/nptl/pthread_spin_trylock.S diff --git a/sysdeps/aarch64/nptl/pthread_spin_trylock.S b/sysdeps/aarch64/nptl/pthread_spin_trylock.S new file mode 100644 index 00000000000..408861dd9f7 --- /dev/null +++ b/sysdeps/aarch64/nptl/pthread_spin_trylock.S @@ -0,0 +1,46 @@ +/* pthread_spin_trylock -- trylock a spin lock. Generic version. + Copyright (C) 2012-2019 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#include + +/* Assumptions: + * + * ARMv8-a, AArch64 + */ + +ENTRY (pthread_spin_trylock) + DELOUSE (0) + mov w1, #0x1 + +L(spin): + ldaxr w2, [x0] + cbnz w2, L(fail) + stxr w3, w1, [x0] + cbnz w3, L(spin) + mov w0, #0 + ret + nop + +L(fail): + mov w0, #16 + ret + +END (pthread_spin_trylock) +libc_hidden_builtin_def (pthread_spin_trylock) +weak_alias (pthread_spin_trylock, index) +