From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14003 invoked by alias); 31 Jan 2013 08:42:37 -0000 Received: (qmail 13990 invoked by uid 22791); 31 Jan 2013 08:42:36 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS,UNPARSEABLE_RELAY X-Spam-Check-By: sourceware.org Received: from imx12.toshiba.co.jp (HELO imx12.toshiba.co.jp) (61.202.160.132) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 31 Jan 2013 08:42:30 +0000 Received: from tsbmgw-mgw01.tsbmgw-mgw01.toshiba.co.jp ([133.199.232.103]) by imx12.toshiba.co.jp with ESMTP id r0V8gQHC017087 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 31 Jan 2013 17:42:27 +0900 (JST) Received: from tsbmgw-mgw01 (localhost [127.0.0.1]) by tsbmgw-mgw01.tsbmgw-mgw01.toshiba.co.jp (8.13.8/8.14.5) with ESMTP id r0V8gPY8006940 for ; Thu, 31 Jan 2013 17:42:25 +0900 Received: from localhost ([127.0.0.1]) by tsbmgw-mgw01 (JAMES SMTP Server 2.3.1) with SMTP ID 1002 for ; Thu, 31 Jan 2013 17:42:25 +0900 (JST) Received: from arc11.toshiba.co.jp ([133.199.90.127]) by tsbmgw-mgw01.tsbmgw-mgw01.toshiba.co.jp (8.13.8/8.14.5) with ESMTP id r0V8gPnQ006934 for ; Thu, 31 Jan 2013 17:42:25 +0900 Received: (from root@localhost) by arc11.toshiba.co.jp id r0V8gPFe005371 for libc-ports@sourceware.org; Thu, 31 Jan 2013 17:42:25 +0900 (JST) Received: from ovp11.toshiba.co.jp [133.199.90.148] by arc11.toshiba.co.jp with ESMTP id TAA05370; Thu, 31 Jan 2013 17:42:25 +0900 Received: from mx.toshiba.co.jp (localhost [127.0.0.1]) by ovp11.toshiba.co.jp with ESMTP id r0V8gKvj000111 for ; Thu, 31 Jan 2013 17:42:20 +0900 (JST) Received: from tgxml119.toshiba.local by toshiba.co.jp id r0V8gCBX015371; Thu, 31 Jan 2013 17:42:19 +0900 (JST) Received: from TGXML316.toshiba.local ([169.254.4.113]) by tgxml119.toshiba.local ([133.199.66.79]) with mapi id 14.02.0318.004; Thu, 31 Jan 2013 17:42:17 +0900 From: To: Subject: [PATCH] Avoid unnecessary busy loop in __lll_timedlock_wait on ARM. Date: Thu, 31 Jan 2013 08:42:00 -0000 Message-ID: msscp.transfermailtomossagent: 103 Content-Type: text/plain; charset="iso-2022-jp" Content-ID: <46DCE77003B4EF4A8DC49FAB7605B749@toshiba.local> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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: 2013-01/txt/msg00084.txt.bz2 Hi, I have found an issue in __lll_timedlock_wait on ARM. The following sequence causes unnecessary busy loop.=20 "A thread" gets the lock. (futex =3D 1) "B thread" tries to get the lock, and has not called futex syscall yet. (fu= tex =3D 2) "A thread" releases the lock (futex =3D 0) "C thread" gets the lock, and does not call futex syscall because of futex= =3D0 (futex =3D 1) "B thread" calls futex syscall, and returns with an error. Because futex syscall in Linux Kernel checks if the val is chang= ed=20 from 2, which is the 3rd arg of the syscall at futex_wait_setup(= ), but in this case futex is 1. "B thread" tries to get the lock in userspace but cannot get it=20 because futex is not 0. After all the thread keeps calling futex syscall=20 until "C thread" will release it (futex =3D 0) or timeout. Therefore I think that the value should be set 2 in every loop=20 the same as __lll_lock_wait_private, and attached a patch for this issue. --=20 UWATOKO Katsuki --- .../unix/sysv/linux/arm/nptl/lowlevellock.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/ports/sysdeps/unix/sysv/linux/arm/nptl/lowlevellock.c b/ports/= sysdeps/unix/sysv/linux/arm/nptl/lowlevellock.c index 756f39f..a495d85 100644 --- a/ports/sysdeps/unix/sysv/linux/arm/nptl/lowlevellock.c +++ b/ports/sysdeps/unix/sysv/linux/arm/nptl/lowlevellock.c @@ -65,6 +65,7 @@ __lll_timedlock_wait (int *futex, const struct timespec *= abstime, int private) do { struct timeval tv; + int oldval; =20 /* Get the current time. */ (void) __gettimeofday (&tv, NULL); @@ -82,8 +83,10 @@ __lll_timedlock_wait (int *futex, const struct timespec = *abstime, int private) if (rt.tv_sec < 0) return ETIMEDOUT; =20 + oldval =3D atomic_compare_and_exchange_val_acq (futex, 2, 1); // XYZ: Lost the lock to check whether it was private. - lll_futex_timed_wait (futex, 2, &rt, private); + if (oldval !=3D 0) + lll_futex_timed_wait (futex, 2, &rt, private); } while (atomic_compare_and_exchange_bool_acq (futex, 2, 0) !=3D 0); =20 --=20 1.7.4.1