From patchwork Tue Dec 13 08:54:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Liebler X-Patchwork-Id: 18421 Received: (qmail 440 invoked by alias); 13 Dec 2016 08:55:11 -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 130706 invoked by uid 89); 13 Dec 2016 08:55:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=acquired, jumps X-HELO: mx0a-001b2d01.pphosted.com To: libc-alpha@sourceware.org From: Stefan Liebler Subject: [PATCH] Add __glibc_unlikely hint in lll_trylock, lll_cond_trylock. Date: Tue, 13 Dec 2016 09:54:42 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16121308-0020-0000-0000-00000246BA2A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16121308-0021-0000-0000-00001EA83CFE Message-Id: <4adc080f-9975-4ee0-003e-675f3c9f1203@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-12-13_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1612130155 Hi, the macros lll_trylock, lll_cond_trylock are extended by a __glibc_unlikely hint. Now the trylock macros are based on the same assumption about a free/busy lock as lll_lock. With the hint gcc emits code in e.g. pthread_mutex_trylock which does not use jumps if the lock is free. Without the hint it had to jump away if the lock is free. Tested on s390x, ppc. Okay to commit? Bye Stefan ChangeLog: * sysdeps/nptl/lowlevellock.h (lll_trylock, lll_cond_trylock): Add __glibc_unlikely hint. commit 2e11862aaf6d563518780a470b97b59a6e0b2717 Author: Stefan Liebler Date: Tue Dec 13 09:14:09 2016 +0100 Add __glibc_unlikely hint in lll_trylock, lll_cond_trylock. The macros lll_trylock, lll_cond_trylock are extended by an __glibc_unlikely hint. Now the trylock macros are based on the same assumption about a free/busy lock as lll_lock. With the hint gcc emits code in e.g. pthread_mutex_trylock which does not use jumps if the lock is free. Without the hint it had to jump away if the lock is free. Tested on s390x, ppc. ChangeLog: * sysdeps/nptl/lowlevellock.h (lll_trylock, lll_cond_trylock): Add __glibc_unlikely hint. diff --git a/sysdeps/nptl/lowlevellock.h b/sysdeps/nptl/lowlevellock.h index 3890145..b77043b 100644 --- a/sysdeps/nptl/lowlevellock.h +++ b/sysdeps/nptl/lowlevellock.h @@ -64,13 +64,13 @@ 0. Otherwise leave lock unchanged and return non-zero to indicate that the lock was not acquired. */ #define lll_trylock(lock) \ - atomic_compare_and_exchange_bool_acq (&(lock), 1, 0) + __glibc_unlikely (atomic_compare_and_exchange_bool_acq (&(lock), 1, 0)) /* If LOCK is 0 (not acquired), set to 2 (acquired, possibly with waiters) and return 0. Otherwise leave lock unchanged and return non-zero to indicate that the lock was not acquired. */ #define lll_cond_trylock(lock) \ - atomic_compare_and_exchange_bool_acq (&(lock), 2, 0) + __glibc_unlikely (atomic_compare_and_exchange_bool_acq (&(lock), 2, 0)) extern void __lll_lock_wait_private (int *futex) attribute_hidden; extern void __lll_lock_wait (int *futex, int private) attribute_hidden;