From patchwork Tue Feb 6 06:41:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Liebler X-Patchwork-Id: 869685 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-90042-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="xyx/HEo4"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zbFHD3f23z9s7F for ; Tue, 6 Feb 2018 17:41:44 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:date:mime-version:content-type :message-id; q=dns; s=default; b=GM0se8epIqVstrQr7n//R1vSlgu/IR6 EIJANXoZmPsfMVRh76t6ScuKHKoV5e+Y6MeaeNoPN1mk3kIFC7qRNcBDmUQ59T67 50EkTOGdHdGFF8EW95ZdCdURjg80dwoifs4WH3uNKe5SxIHHqA3qdZvg/XLUQk0q KrAtBBRbxb4Y= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:to:from:subject:date:mime-version:content-type :message-id; s=default; bh=v2eArosjx4UZ3JjUXAkpfmNJtZ0=; b=xyx/H Eo45bIEISUpK+wWAmowttZcthEYeYAofc7jKO5dzCPQY8R06Rh8BPhCL5yJuChaO CoqE7NAxSOERQJsysGGcqdUyGHDXrrsd7ULoPx2fbyV9gZlPsi4Ie/kJmV/UVdJ2 NlxBrAuwO7rBi7Vvd2djGq5iKFdK1oEmhP8SGw= Received: (qmail 28311 invoked by alias); 6 Feb 2018 06:41:38 -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 28294 invoked by uid 89); 6 Feb 2018 06:41:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=9630 X-HELO: mx0a-001b2d01.pphosted.com To: GNU C Library From: Stefan Liebler Subject: [PATCH] Add runtime check if mutex will be elided in tst-mutex8 testcases. Date: Tue, 6 Feb 2018 07:41:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18020606-0016-0000-0000-0000051FCAAA X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18020606-0017-0000-0000-0000285C7BB5 Message-Id: <60a40476-2f26-2756-df5e-b05ddaeb5483@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-02-06_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1802060081 Hi, An elided mutex don't fail destroy. Elision was disabled for the test nptl/tst-mutex8 in nptl/Makefile. Thus we can run tests which destroy a locked mutex. As elision is only disabled for tst-mutex8, the variants tst-mutex8-static, tst-mutexpi8 and tst-mutexpi8-static are still failing if lock elision is enabled. This patch adds a runtime check, if the checked type of mutex will be elided. This check is using TUNABLE_GET_FULL to determine if elision is enabled via the tunables framework. The pthread_mutex_destroy tests are only run if we dont't assume an elided mutex. This way, we can run the whole glibc testsuite with or without enabled lock elision. Okay to commit? Bye Stefan ChangeLog: * nptl/Makefile (tst-mutex8-ENV): Delete. * nptl/tst-mutex8.c (check_type): Add runtime check if mutex will be elided. Reviewed-by: Carlos O'Donell commit eb4c91a86de283ff314c068d9d89368b229b9a33 Author: Stefan Liebler Date: Mon Feb 5 09:16:14 2018 +0000 Add runtime check if mutex will be elided in tst-mutex8 testcases. An elided mutex don't fail destroy. Elision was disabled for the test nptl/tst-mutex8 in nptl/Makefile. Thus we can run tests which destroy a locked mutex. As elision is only disabled for tst-mutex8, the variants tst-mutex8-static, tst-mutexpi8 and tst-mutexpi8-static are still failing if lock elision is enabled. This patch adds a runtime check, if the checked type of mutex will be elided. This check is using TUNABLE_GET_FULL to determine if elision is enabled via the tunables framework. The pthread_mutex_destroy tests are only run if we dont't assume an elided mutex. This way, we can run the whole glibc testsuite with or without enabled lock elision. ChangeLog: * nptl/Makefile (tst-mutex8-ENV): Delete. * nptl/tst-mutex8.c (check_type): Add runtime check if mutex will be elided. diff --git a/nptl/Makefile b/nptl/Makefile index 6fc2c8bb6a..9340f9f699 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -726,10 +726,6 @@ endif $(objpfx)tst-compat-forwarder: $(objpfx)tst-compat-forwarder-mod.so -# Disable elision for tst-mutex8 so it can verify error case for -# destroying a mutex. -tst-mutex8-ENV = GLIBC_TUNABLES=glibc.elision.enable=0 - # The tests here better do not run in parallel ifneq ($(filter %tests,$(MAKECMDGOALS)),) .NOTPARALLEL: diff --git a/nptl/tst-mutex8.c b/nptl/tst-mutex8.c index 516ef3809e..d31f342751 100644 --- a/nptl/tst-mutex8.c +++ b/nptl/tst-mutex8.c @@ -22,7 +22,8 @@ #include #include #include - +#include +#include static pthread_mutex_t *m; static pthread_barrier_t b; @@ -95,6 +96,30 @@ check_type (const char *mas, pthread_mutexattr_t *ma) { int e; + /* Check if a mutex will be elided. Lock elision can only be activated via + the tunables framework. By default, lock elision is disabled. */ + bool assume_elided_mutex = false; +#if HAVE_TUNABLES + int ma_type = PTHREAD_MUTEX_TIMED_NP; + if (ma != NULL) + { + e = pthread_mutexattr_gettype (ma, &ma_type); + if (e != 0) + { + printf ("pthread_mutexattr_gettype failed with %d (%m)\n", e); + return 1; + } + } + if (ma_type == PTHREAD_MUTEX_TIMED_NP) + { + /* This type of mutex can be elided if elision is enabled via the tunables + framework. Some tests below are failing if the mutex is elided. + Thus we only run those if we assume that the mutex won't be elided. */ + if (TUNABLE_GET_FULL (glibc, elision, enable, int32_t, NULL) == 1) + assume_elided_mutex = true; + } +#endif + e = pthread_mutex_init (m, ma); if (e != 0) { @@ -127,19 +152,23 @@ check_type (const char *mas, pthread_mutexattr_t *ma) return 1; } - /* Elided mutexes don't fail destroy, but this test is run with - elision disabled so we can test them. */ - e = pthread_mutex_destroy (m); - if (e == 0) + /* Elided mutexes don't fail destroy, thus only test this if we don't assume + elision. */ + if (assume_elided_mutex == false) { - printf ("mutex_destroy of self-locked mutex succeeded for %s\n", mas); - return 1; - } - if (e != EBUSY) - { - printf ("mutex_destroy of self-locked mutex did not return EBUSY %s\n", - mas); - return 1; + e = pthread_mutex_destroy (m); + if (e == 0) + { + printf ("mutex_destroy of self-locked mutex succeeded for %s\n", mas); + return 1; + } + if (e != EBUSY) + { + printf ("\ +mutex_destroy of self-locked mutex did not return EBUSY %s\n", + mas); + return 1; + } } if (pthread_mutex_unlock (m) != 0) @@ -155,18 +184,22 @@ check_type (const char *mas, pthread_mutexattr_t *ma) } /* Elided mutexes don't fail destroy. */ - e = pthread_mutex_destroy (m); - if (e == 0) + if (assume_elided_mutex == false) { - printf ("mutex_destroy of self-trylocked mutex succeeded for %s\n", mas); - return 1; - } - if (e != EBUSY) - { - printf ("\ + e = pthread_mutex_destroy (m); + if (e == 0) + { + printf ("mutex_destroy of self-trylocked mutex succeeded for %s\n", + mas); + return 1; + } + if (e != EBUSY) + { + printf ("\ mutex_destroy of self-trylocked mutex did not return EBUSY %s\n", - mas); - return 1; + mas); + return 1; + } } if (pthread_mutex_unlock (m) != 0) @@ -203,17 +236,21 @@ mutex_destroy of self-trylocked mutex did not return EBUSY %s\n", } /* Elided mutexes don't fail destroy. */ - e = pthread_mutex_destroy (m); - if (e == 0) - { - printf ("mutex_destroy of condvar-used mutex succeeded for %s\n", mas); - return 1; - } - if (e != EBUSY) + if (assume_elided_mutex == false) { - printf ("\ + e = pthread_mutex_destroy (m); + if (e == 0) + { + printf ("mutex_destroy of condvar-used mutex succeeded for %s\n", + mas); + return 1; + } + if (e != EBUSY) + { + printf ("\ mutex_destroy of condvar-used mutex did not return EBUSY for %s\n", mas); - return 1; + return 1; + } } done = true; @@ -274,19 +311,22 @@ mutex_destroy of condvar-used mutex did not return EBUSY for %s\n", mas); } /* Elided mutexes don't fail destroy. */ - e = pthread_mutex_destroy (m); - if (e == 0) - { - printf ("2nd mutex_destroy of condvar-used mutex succeeded for %s\n", - mas); - return 1; - } - if (e != EBUSY) + if (assume_elided_mutex == false) { - printf ("\ + e = pthread_mutex_destroy (m); + if (e == 0) + { + printf ("2nd mutex_destroy of condvar-used mutex succeeded for %s\n", + mas); + return 1; + } + if (e != EBUSY) + { + printf ("\ 2nd mutex_destroy of condvar-used mutex did not return EBUSY for %s\n", - mas); - return 1; + mas); + return 1; + } } if (pthread_cancel (th) != 0)