From patchwork Wed Aug 3 11:51:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Torvald Riegel X-Patchwork-Id: 108129 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id D805EB71D5 for ; Wed, 3 Aug 2011 21:52:18 +1000 (EST) Received: (qmail 18534 invoked by alias); 3 Aug 2011 11:52:15 -0000 Received: (qmail 18522 invoked by uid 22791); 3 Aug 2011 11:52:14 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_TX X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 03 Aug 2011 11:51:55 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p73BpsPE019997 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 3 Aug 2011 07:51:54 -0400 Received: from [10.36.7.186] (vpn1-7-186.ams2.redhat.com [10.36.7.186]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p73BprkP017387; Wed, 3 Aug 2011 07:51:53 -0400 Subject: [trans-mem] Test that nested txns started from pure/unsafe code work correctly From: Torvald Riegel To: GCC Patches Cc: Aldy Hernandez , Richard Henderson Date: Wed, 03 Aug 2011 13:51:52 +0200 Message-ID: <1312372312.3533.262.camel@triegel.csb> Mime-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Tests that new transactions can be started from both transaction_pure and transaction_unsafe code. This also checks proper handling of reentrant nesting in the serial_lock implementation (reentrant in the sense that we go from transactional to nontransactional to transactional code). This test currently does not compile due to a GCC bug (no bug report yet). OK for branch? commit c1eafd7cfbdb71dadb3ac5f797fb2a596026f1be Author: Torvald Riegel Date: Mon Aug 1 15:43:05 2011 +0200 Test that nested txns started from pure/unsafe code work correctly. * testsuite/libitm.c/reentrant.c: New file. diff --git a/libitm/testsuite/libitm.c/reentrant.c b/libitm/testsuite/libitm.c/reentrant.c new file mode 100644 index 0000000..aeb9a0e --- /dev/null +++ b/libitm/testsuite/libitm.c/reentrant.c @@ -0,0 +1,64 @@ +/* Tests that new transactions can be started from both transaction_pure and + transaction_unsafe code. This also requires proper handling of reentrant + nesting in the serial_lock implementation. */ + +#include +#include +#include + +int x = 0; + +int __attribute__((transaction_pure)) pure(int i) +{ + __transaction { + x++; + } + if (_ITM_inTransaction() == outsideTransaction) + abort(); + return i+1; +} + +int __attribute__((transaction_unsafe)) unsafe(int i) +{ + if (_ITM_inTransaction() != inIrrevocableTransaction) + abort(); + __transaction { + x++; + } + if (_ITM_inTransaction() != inIrrevocableTransaction) + abort(); + return i+1; +} + +static void *thread (void *dummy __attribute__((unused))) +{ + __transaction { + pure(1); + } + __transaction[[relaxed]] { + unsafe(1); + } + return 0; +} + +int main() +{ + pthread_t pt; + int r = 0; + + __transaction { + r += pure(1) + x; + } + __transaction[[relaxed]] { + r += unsafe(1) + x; + } + if (r != 7) + abort(); + + // Spawn a new thread to check that the serial lock is not held. + pthread_create(&pt, NULL, thread, NULL); + pthread_join(pt, NULL); + if (x != 4) + abort(); + return 0; +}