From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16501 invoked by alias); 7 Feb 2013 23:33:40 -0000 Received: (qmail 16483 invoked by uid 22791); 7 Feb 2013 23:33:40 -0000 X-SWARE-Spam-Status: No, hits=-4.8 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL 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, 07 Feb 2013 23:33:34 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1U3ayD-0001zx-M0 from joseph_myers@mentor.com ; Thu, 07 Feb 2013 15:33:33 -0800 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Thu, 7 Feb 2013 15:33:33 -0800 Received: from digraph.polyomino.org.uk (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, 7 Feb 2013 23:33:31 +0000 Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.76) (envelope-from ) id 1U3ayA-0005uC-AG; Thu, 07 Feb 2013 23:33:30 +0000 Date: Thu, 07 Feb 2013 23:33:00 -0000 From: "Joseph S. Myers" To: CC: , Carlos O'Donell Subject: Re: [PATCH] Avoid unnecessary busy loop in __lll_timedlock_wait on ARM. In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" 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-02/txt/msg00008.txt.bz2 On Thu, 31 Jan 2013, katsuki.uwatoko@toshiba.co.jp wrote: > Hi, > > I have found an issue in __lll_timedlock_wait on ARM. I think the busy loop should have a bug filed in Bugzilla, as a user-visible bug - could you file that bug? > The following sequence causes unnecessary busy loop. > > "A thread" gets the lock. (futex = 1) > "B thread" tries to get the lock, and has not called futex syscall yet. (futex = 2) > "A thread" releases the lock (futex = 0) > "C thread" gets the lock, and does not call futex syscall because of futex=0 (futex = 1) > "B thread" calls futex syscall, and returns with an error. > Because futex syscall in Linux Kernel checks if the val is changed > 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 > because futex is not 0. > After all the thread keeps calling futex syscall > until "C thread" will release it (futex = 0) or timeout. > > Therefore I think that the value should be set 2 in every loop > the same as __lll_lock_wait_private, and attached a patch for this issue. Carlos, any comments on this patch ? It makes the ARM version of __lll_timedlock_wait closer to the HPPA version, but I don't know if many of the differences between different architecture versions of this code are really deliberate.... Would you agree that the generic Linux version (nptl/sysdeps/unix/sysv/linux/lowlevellock.c) doesn't need such a change because the loop is using atomic_exchange_acq rather than atomic_compare_and_exchange_bool_acq, so is already setting the futex to 2 in every loop iteration? -- Joseph S. Myers joseph@codesourcery.com