diff options
author | Torvald Riegel <triegel@redhat.com> | 2012-11-09 17:04:40 +0000 |
---|---|---|
committer | Torvald Riegel <torvald@gcc.gnu.org> | 2012-11-09 17:04:40 +0000 |
commit | 64fbcc74a336dd37eed05336788188ad9374f6e1 (patch) | |
tree | 9fd7bd08f877808bd7bb4eb601fd7482c9c85d6f /libitm/config | |
parent | 2a28e76a78ec4f3bb1219c4ba5795f86dccb43cd (diff) | |
download | gcc-64fbcc74a336dd37eed05336788188ad9374f6e1.zip gcc-64fbcc74a336dd37eed05336788188ad9374f6e1.tar.gz gcc-64fbcc74a336dd37eed05336788188ad9374f6e1.tar.bz2 |
Add HTM fastpath and use Intel RTM for it on x86.
* beginend.cc (htm_fastpath): New.
(gtm_thread::begin_transaction, _ITM_commitTransaction,
_ITM_commitTransactionEH): Add HTM fastpath handling.
* config/linux/rwlock.h (gtm_rwlock.is_write_locked): New.
* config/posix/rwlock.h (gtm_rwlock.is_write_locked): New.
* config/x86/target.h (htm_available, htm_init, htm_begin_success,
htm_begin, htm_commit, htm_abort, htm_abort_should_retry): New.
* configure.tgt: Add -mrtm to XCFLAGS.
* method-serial.cc (htm_mg, o_htm_mg, htm_dispatch, dispatch_htm): New.
(gtm_thread::serialirr_mode): Add HTM fastpath handling.
* libitm_i.h (htm_fastpath, dispatch_htm): Declare.
* retry.cc (parse_default_method): Add HTM method parsing.
(gtm_thread::number_of_threads_changed): Use HTM by default if
available.
From-SVN: r193369
Diffstat (limited to 'libitm/config')
-rw-r--r-- | libitm/config/linux/rwlock.h | 10 | ||||
-rw-r--r-- | libitm/config/posix/rwlock.h | 10 | ||||
-rw-r--r-- | libitm/config/x86/target.h | 81 |
3 files changed, 84 insertions, 17 deletions
diff --git a/libitm/config/linux/rwlock.h b/libitm/config/linux/rwlock.h index 987e580..f13d287 100644 --- a/libitm/config/linux/rwlock.h +++ b/libitm/config/linux/rwlock.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Free Software Foundation, Inc. +/* Copyright (C) 2011, 2012 Free Software Foundation, Inc. Contributed by Torvald Riegel <triegel@redhat.com>. This file is part of the GNU Transactional Memory Library (libitm). @@ -59,6 +59,14 @@ class gtm_rwlock bool write_upgrade (gtm_thread *tx); void write_upgrade_finish (gtm_thread *tx); + // Returns true iff there is a concurrent active or waiting writer. + // This is primarily useful for simple HyTM approaches, and the value being + // checked is loaded with memory_order_relaxed. + bool is_write_locked() + { + return writers.load (memory_order_relaxed) != 0; + } + protected: bool write_lock_generic (gtm_thread *tx); }; diff --git a/libitm/config/posix/rwlock.h b/libitm/config/posix/rwlock.h index a1a6042..79f1429 100644 --- a/libitm/config/posix/rwlock.h +++ b/libitm/config/posix/rwlock.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2009, 2011 Free Software Foundation, Inc. +/* Copyright (C) 2009, 2011, 2012 Free Software Foundation, Inc. Contributed by Richard Henderson <rth@redhat.com>. This file is part of the GNU Transactional Memory Library (libitm). @@ -74,6 +74,14 @@ class gtm_rwlock bool write_upgrade (gtm_thread *tx); void write_upgrade_finish (gtm_thread *tx); + // Returns true iff there is a concurrent active or waiting writer. + // This is primarily useful for simple HyTM approaches, and the value being + // checked is loaded with memory_order_relaxed. + bool is_write_locked() + { + return summary.load (memory_order_relaxed) & (a_writer | w_writer); + } + protected: bool write_lock_generic (gtm_thread *tx); }; diff --git a/libitm/config/x86/target.h b/libitm/config/x86/target.h index 74f4f92..ef95960 100644 --- a/libitm/config/x86/target.h +++ b/libitm/config/x86/target.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc. +/* Copyright (C) 2008, 2009, 2011, 2012 Free Software Foundation, Inc. Contributed by Richard Henderson <rth@redhat.com>. This file is part of the GNU Transactional Memory Library (libitm). @@ -22,6 +22,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see <http://www.gnu.org/licenses/>. */ +// We'll be using some of the cpu builtins, and their associated types. +#include <x86intrin.h> +#include <cpuid.h> + namespace GTM HIDDEN { /* ??? This doesn't work for Win64. */ @@ -62,19 +66,66 @@ cpu_relax (void) __builtin_ia32_pause (); } -} // namespace GTM +// Use Intel RTM if supported by the assembler. +// See gtm_thread::begin_transaction for how these functions are used. +#ifdef HAVE_AS_RTM +#define USE_HTM_FASTPATH -// We'll be using some of the cpu builtins, and their associated types. -#ifndef __cplusplus -/* ??? It's broken for C++. */ -#include <x86intrin.h> -#else -# ifdef __SSE2__ -# include <emmintrin.h> -# elif defined(__SSE__) -# include <xmmintrin.h> -# endif -# ifdef __AVX__ -# include <immintrin.h> -# endif +static inline bool +htm_available () +{ + const unsigned cpuid_rtm = bit_RTM; + if (__get_cpuid_max (0, NULL) >= 7) + { + unsigned a, b, c, d; + __cpuid_count (7, 0, a, b, c, d); + if (b & cpuid_rtm) + return true; + } + return false; +} + +static inline uint32_t +htm_init () +{ + // Maximum number of times we try to execute a transaction as a HW + // transaction. + // ??? Why 2? Any offline or runtime tuning necessary? + return htm_available () ? 2 : 0; +} + +static inline uint32_t +htm_begin () +{ + return _xbegin(); +} + +static inline bool +htm_begin_success (uint32_t begin_ret) +{ + return begin_ret == _XBEGIN_STARTED; +} + +static inline void +htm_commit () +{ + _xend(); +} + +static inline void +htm_abort () +{ + // ??? According to a yet unpublished ABI rule, 0xff is reserved and + // supposed to signal a busy lock. Source: andi.kleen@intel.com + _xabort(0xff); +} + +static inline bool +htm_abort_should_retry (uint32_t begin_ret) +{ + return begin_ret & _XABORT_RETRY; +} #endif + + +} // namespace GTM |