From patchwork Wed Aug 3 10:56:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Torvald Riegel X-Patchwork-Id: 108114 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 2EF02B71D3 for ; Wed, 3 Aug 2011 20:57:19 +1000 (EST) Received: (qmail 1056 invoked by alias); 3 Aug 2011 10:57:17 -0000 Received: (qmail 1040 invoked by uid 22791); 3 Aug 2011 10:57:16 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS 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 10:56:56 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p73Auu9E009763 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 3 Aug 2011 06:56:56 -0400 Received: from [10.36.7.186] (vpn1-7-186.ams2.redhat.com [10.36.7.186]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p73AusGt024025; Wed, 3 Aug 2011 06:56:55 -0400 Subject: [trans-mem] New TM method: serial-irrevocable on first write From: Torvald Riegel To: GCC Patches Cc: Richard Henderson , Aldy Hernandez Date: Wed, 03 Aug 2011 12:56:53 +0200 Message-ID: <1312369013.3533.228.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 This adds a new TM method which lets transactions simply read through without any protection until the first write in the transaction, upon which the transaction switches to serial-irrevocable mode (thus isolating all other transactions from uncommitted writes). This can work well for read-mostly workloads but is too simplistic for anything else. Nevertheless, it's useful to test the performance of the upcoming changes to the serial lock implementation, and can be better than always going to serial mode (which currently is the only implemented TM method). OK for branch? commit a2eefe78d18203c40de0f4b81dc934ff575d8ee5 Author: Torvald Riegel Date: Thu Jul 28 21:21:12 2011 +0200 Add serialirr_onwrite_dispatch and use as new default method, for now. * retry.cc (GTM::gtm_transaction::decide_begin_dispatch): Use serialirr_onwrite_dispatch as new default for now. * method-serial.cc (serialirr_onwrite_dispatch): New. (GTM::dispatch_serialirr_onwrite): New. * libitm_i.h: Same. diff --git a/libitm/libitm_i.h b/libitm/libitm_i.h index 093fc0e..97f535a 100644 --- a/libitm/libitm_i.h +++ b/libitm/libitm_i.h @@ -252,6 +252,7 @@ extern void GTM_fatal (const char *fmt, ...) extern abi_dispatch *dispatch_serial(); extern abi_dispatch *dispatch_serialirr(); +extern abi_dispatch *dispatch_serialirr_onwrite(); extern gtm_cacheline_mask gtm_mask_stack(gtm_cacheline *, gtm_cacheline_mask); diff --git a/libitm/method-serial.cc b/libitm/method-serial.cc index 5912791..430f004 100644 --- a/libitm/method-serial.cc +++ b/libitm/method-serial.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2008, 2009 Free Software Foundation, Inc. +/* Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc. Contributed by Richard Henderson . This file is part of the GNU Transactional Memory Library (libitm). @@ -41,6 +41,10 @@ class serialirr_dispatch : public abi_dispatch serialirr_dispatch() : abi_dispatch(false, true, true, false) { } protected: + serialirr_dispatch(bool ro, bool wt, bool uninstrumented, + bool closed_nesting) : + abi_dispatch(ro, wt, uninstrumented, closed_nesting) { } + // Transactional loads and stores simply access memory directly. // These methods are static to avoid indirect calls, and will be used by the // virtual ABI dispatch methods or by static direct-access methods created @@ -139,10 +143,65 @@ public: serial_dispatch() : abi_dispatch(false, true, false, true) { } }; + +// Like serialirr_dispatch but does not requests serial-irrevocable mode until +// the first write in the transaction. Can be useful for read-mostly workloads +// and testing, but is likely too simple to be of general purpose. +class serialirr_onwrite_dispatch : public serialirr_dispatch +{ + public: + serialirr_onwrite_dispatch() : + serialirr_dispatch(false, true, false, false) { } + + protected: + static void pre_write() + { + gtm_transaction *tx = gtm_tx(); + if (!(tx->state & (gtm_transaction::STATE_SERIAL + | gtm_transaction::STATE_IRREVOCABLE))) + tx->serialirr_mode(); + } + + // Transactional loads access memory directly. + // Transactional stores switch to serial mode first. + template static void store(V* addr, const V value, + ls_modifier mod) + { + pre_write(); + serialirr_dispatch::store(addr, value, mod); + } + + public: + static void memtransfer_static(void *dst, const void* src, size_t size, + bool may_overlap, ls_modifier dst_mod, ls_modifier src_mod) + { + pre_write(); + serialirr_dispatch::memtransfer_static(dst, src, size, may_overlap, + dst_mod, src_mod); + } + + static void memset_static(void *dst, int c, size_t size, ls_modifier mod) + { + pre_write(); + serialirr_dispatch::memset_static(dst, c, size, mod); + } + + CREATE_DISPATCH_METHODS(virtual, ) + CREATE_DISPATCH_METHODS_MEM() + + virtual void rollback(gtm_transaction_cp *cp) + { + gtm_transaction *tx = gtm_tx(); + if (tx->state & gtm_transaction::STATE_IRREVOCABLE) + abort(); + } +}; + } // anon namespace static const serialirr_dispatch o_serialirr_dispatch; static const serial_dispatch o_serial_dispatch; +static const serialirr_onwrite_dispatch o_serialirr_onwrite_dispatch; abi_dispatch * GTM::dispatch_serialirr () @@ -156,6 +215,13 @@ GTM::dispatch_serial () return const_cast(&o_serial_dispatch); } +abi_dispatch * +GTM::dispatch_serialirr_onwrite () +{ + return + const_cast(&o_serialirr_onwrite_dispatch); +} + // Put the transaction into serial-irrevocable mode. void diff --git a/libitm/retry.cc b/libitm/retry.cc index 199201a..5b3bf90 100644 --- a/libitm/retry.cc +++ b/libitm/retry.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2008, 2009 Free Software Foundation, Inc. +/* Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc. Contributed by Richard Henderson . This file is part of the GNU Transactional Memory Library (libitm). @@ -87,6 +87,8 @@ GTM::gtm_transaction::decide_begin_dispatch (uint32_t prop) { // ??? Probably want some environment variable to choose the default // STM implementation once we have more than one implemented. + if (prop & pr_hasNoAbort) + return dispatch_serialirr_onwrite(); state = STATE_SERIAL; if (prop & pr_hasNoAbort) state |= STATE_IRREVOCABLE;