From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18361 invoked by alias); 14 Jun 2012 04:36:14 -0000 Received: (qmail 17863 invoked by uid 22791); 14 Jun 2012 04:36:12 -0000 X-SWARE-Spam-Status: No, hits=-3.8 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,TW_EQ X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 14 Jun 2012 04:35:58 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1Sf1mn-0000NA-TU from Maxim_Kuvyrkov@mentor.com ; Wed, 13 Jun 2012 21:35:57 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 13 Jun 2012 21:35:22 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.1.289.1; Thu, 14 Jun 2012 05:35:55 +0100 From: Maxim Kuvyrkov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: [PATCH 2/3, MIPS] Rewrite MIPS' pthread_spin_[try]lock using __atomic_* builtins. Date: Thu, 14 Jun 2012 04:36:00 -0000 Message-ID: <2109EAD5-BBE8-4C8C-8D61-0AF33290F240@codesourcery.com> CC: Richard Sandiford , To: "Joseph S. Myers" MIME-Version: 1.0 (Apple Message framework v1278) Mailing-List: contact libc-ports-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: libc-ports-owner@sourceware.org X-SW-Source: 2012-06/txt/msg00029.txt.bz2 This is a follow-up patch to convert assembly implementations of MIPS' pthr= ead_spin_[try]lock routines using __atomic_* builtins. Using the builtins = the compiler can generate optimal code for a particular MIPS processor for = which GLIBC is being built. OK to apply once 2.16 branches? Thank you, -- Maxim Kuvyrkov CodeSourcery / Mentor Graphics 2012-06-13 Tom de Vries Maxim Kuvyrkov * sysdeps/mips/nptl/pthread_spin_[try]lock.S: Remove. * sysdeps/mips/nptl/pthread_spin_[try]lock.c: New files. --- sysdeps/mips/nptl/pthread_spin_lock.S | 36 ------------------------- sysdeps/mips/nptl/pthread_spin_lock.c | 43 ++++++++++++++++++++++++++= ++++ sysdeps/mips/nptl/pthread_spin_trylock.S | 40 --------------------------- sysdeps/mips/nptl/pthread_spin_trylock.c | 26 ++++++++++++++++++ 4 files changed, 69 insertions(+), 76 deletions(-) delete mode 100644 sysdeps/mips/nptl/pthread_spin_lock.S create mode 100644 sysdeps/mips/nptl/pthread_spin_lock.c delete mode 100644 sysdeps/mips/nptl/pthread_spin_trylock.S create mode 100644 sysdeps/mips/nptl/pthread_spin_trylock.c diff --git a/sysdeps/mips/nptl/pthread_spin_lock.S b/sysdeps/mips/nptl/pthr= ead_spin_lock.S deleted file mode 100644 index a8504f1..0000000 --- a/sysdeps/mips/nptl/pthread_spin_lock.S +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 2005 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 -#include -#include - -ENTRY (pthread_spin_lock) - .set push -#if _MIPS_SIM =3D=3D _ABIO32 - .set mips2 -#endif -1: ll a2, 0(a0) - li a1, 1 - bnez a2, 1b - sc a1, 0(a0) - beqz a1, 1b - MIPS_SYNC - .set pop - li v0, 0 - ret -PSEUDO_END (pthread_spin_lock) diff --git a/sysdeps/mips/nptl/pthread_spin_lock.c b/sysdeps/mips/nptl/pthr= ead_spin_lock.c new file mode 100644 index 0000000..42dcb8d --- /dev/null +++ b/sysdeps/mips/nptl/pthread_spin_lock.c @@ -0,0 +1,43 @@ +/* Copyright (C) 2012 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; see the file COPYING.LIB. If + not, see . */ + +#include +#include "pthreadP.h" + +int +pthread_spin_lock (pthread_spinlock_t *lock) +{ + + /* atomic_exchange takes less instructions than atomic_compare_and_excha= nge + for MIPS, in particular when the MIPS ISA supports an atomic exchange + instruction. On the other hand, atomic_exchange potentially generate= s more + bus traffic in case the value already present is written back. + We assume that the first try mostly will be successful, so we use + atomic_exchange. For the other tries, we use + atomic_compare_and_exchange. */ + if (atomic_exchange_acq (lock, 1) =3D=3D 0) + return 0; + + do + { + while (*lock !=3D 0) + ; + } + while (atomic_compare_and_exchange_val_acq (lock, 1, 0) !=3D 0); + + return 0; +} diff --git a/sysdeps/mips/nptl/pthread_spin_trylock.S b/sysdeps/mips/nptl/p= thread_spin_trylock.S deleted file mode 100644 index 95b55c3..0000000 --- a/sysdeps/mips/nptl/pthread_spin_trylock.S +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (C) 2005 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 -#include -#define _ERRNO_H 1 -#include -#include - -ENTRY (pthread_spin_trylock) - .set push -#if _MIPS_SIM =3D=3D _ABIO32 - .set mips2 -#endif - ll a2, 0(a0) - li a1, 1 - bnez a2, 1f - sc a1, 0(a0) - beqz a1, 1f - MIPS_SYNC - .set pop - li v0, 0 - ret -1: li v0, EBUSY - ret -PSEUDO_END (pthread_spin_trylock) diff --git a/sysdeps/mips/nptl/pthread_spin_trylock.c b/sysdeps/mips/nptl/p= thread_spin_trylock.c new file mode 100644 index 0000000..ed75813 --- /dev/null +++ b/sysdeps/mips/nptl/pthread_spin_trylock.c @@ -0,0 +1,26 @@ +/* Copyright (C) 2012 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; see the file COPYING.LIB. If + not, see . */ + +#include +#include +#include "pthreadP.h" + +int +pthread_spin_trylock (pthread_spinlock_t *lock) +{ + return atomic_compare_and_exchange_val_acq (lock, 1, 0) ? EBUSY : 0; +} --=20 1.7.4.1