* Re: [trans-mem] __sync_add_and_fetch_8 on ia32
[not found] ` <4B968550.6070001@redhat.com>
@ 2010-07-07 15:51 ` Aldy Hernandez
2010-07-07 17:11 ` Richard Henderson
0 siblings, 1 reply; 2+ messages in thread
From: Aldy Hernandez @ 2010-07-07 15:51 UTC (permalink / raw)
To: Richard Henderson; +Cc: Paolo Carlini, gcc, pearly.zhao, gcc-patches
> > ... a slightly more sophisticated variant of b) would be using
> > uint64_t for 64-bit targets and uint32_t for 32-bit targets, should
> > make everybody happy.
>
> There's a correctness issue in the library interface -- there's no
> clean way to handle that value overflowing. Rather than make the
> library interface way more complex, it seemed far easier to simply
> use a 64-bit value, which we simply assume won't overflow.
>
> I'd be fine with -m586 (which is how things will get built on e.g.
> Fedora), but that isn't going to help other 32-bit targets that miss
> that operation. We'll need a configure test and a mutex if needed.
Sorry to have dropped the ball on this for so long, but 32-bit problems
weren't too high on my priority list :-).
I have added configury magic to check for 64-bit sync builtins. If
there are no 64-bit builtins, we implement the global thread id with
POSIX threads.
Alas, this surfaced some seemingly unrelated runtime problems in 32-bit
land, which I'll tackle next.
At least we can now build and run (some) tests. Yay!
Tested on x86-64 with: RUNTESTFLAGS="--target_board=unix'{-m32,-m64}'"
OK for branch?
* configure.ac: Call LIBITM_CHECK_64BIT_SYNC_BUILTINS.
* beginend.cc (begin_transaction): If 64-bit sync builtins are not
available, use pthread mutexes.
* acinclude.m4 (LIBITM_CHECK_64BIT_SYNC_BUILTINS): New.
* config.h.in: Regenerate.
* configure: Regenerate.
Index: configure.ac
===================================================================
--- configure.ac (revision 161318)
+++ configure.ac (working copy)
@@ -216,6 +216,7 @@ CFLAGS="$save_CFLAGS $XCFLAGS"
# Check for __sync_val_compare_and_swap, but only after the target has
# had a chance to set XCFLAGS.
LIBITM_CHECK_SYNC_BUILTINS
+LIBITM_CHECK_64BIT_SYNC_BUILTINS
# Cleanup and exit.
CFLAGS="$save_CFLAGS"
Index: beginend.cc
===================================================================
--- beginend.cc (revision 161318)
+++ beginend.cc (working copy)
@@ -84,6 +84,10 @@ GTM::gtm_transaction::operator delete(vo
thr->free_tx[idx] = tx;
}
+#ifndef HAVE_64BIT_SYNC_BUILTINS
+static pthread_mutex_t global_tid_lock = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
uint32_t
GTM::gtm_transaction::begin_transaction (uint32_t prop, const gtm_jmpbuf *jb)
{
@@ -99,7 +103,13 @@ GTM::gtm_transaction::begin_transaction
tx->prev = gtm_tx();
if (tx->prev)
tx->nesting = tx->prev->nesting + 1;
+#ifdef HAVE_64BIT_SYNC_BUILTINS
tx->id = __sync_add_and_fetch (&global_tid, 1);
+#else
+ pthread_mutex_lock (&global_tid_lock);
+ tx->id = ++global_tid;
+ pthread_mutex_unlock (&global_tid_lock);
+#endif
tx->jb = *jb;
set_gtm_tx (tx);
Index: acinclude.m4
===================================================================
--- acinclude.m4 (revision 161318)
+++ acinclude.m4 (working copy)
@@ -12,6 +12,20 @@ AC_DEFUN([LIBITM_CHECK_SYNC_BUILTINS], [
[Define to 1 if the target supports __sync_*_compare_and_swap])
fi])
+dnl Check whether the target supports 64-bit __sync_*_compare_and_swap.
+AC_DEFUN([LIBITM_CHECK_64BIT_SYNC_BUILTINS], [
+ AC_CACHE_CHECK([whether the target supports 64-bit __sync_*_compare_and_swap],
+ libitm_cv_have_64bit_sync_builtins, [
+ AC_TRY_LINK([#include <stdint.h>],
+ [uint64_t foo, bar;
+ bar = __sync_val_compare_and_swap(&foo, 0, 1);],
+ libitm_cv_have_64bit_sync_builtins=yes,
+ libitm_cv_have_64bit_sync_builtins=no)])
+ if test $libitm_cv_have_64bit_sync_builtins = yes; then
+ AC_DEFINE(HAVE_64BIT_SYNC_BUILTINS, 1,
+ [Define to 1 if the target supports 64-bit __sync_*_compare_and_swap])
+ fi])
+
dnl Check whether the target supports hidden visibility.
AC_DEFUN([LIBITM_CHECK_ATTRIBUTE_VISIBILITY], [
AC_CACHE_CHECK([whether the target supports hidden visibility],
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [trans-mem] __sync_add_and_fetch_8 on ia32
2010-07-07 15:51 ` [trans-mem] __sync_add_and_fetch_8 on ia32 Aldy Hernandez
@ 2010-07-07 17:11 ` Richard Henderson
0 siblings, 0 replies; 2+ messages in thread
From: Richard Henderson @ 2010-07-07 17:11 UTC (permalink / raw)
To: Aldy Hernandez; +Cc: Paolo Carlini, gcc, pearly.zhao, gcc-patches
On 07/07/2010 08:51 AM, Aldy Hernandez wrote:
> * configure.ac: Call LIBITM_CHECK_64BIT_SYNC_BUILTINS.
> * beginend.cc (begin_transaction): If 64-bit sync builtins are not
> available, use pthread mutexes.
> * acinclude.m4 (LIBITM_CHECK_64BIT_SYNC_BUILTINS): New.
> * config.h.in: Regenerate.
> * configure: Regenerate.
Ok.
r~
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-07-07 17:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20100219113812.GB3097@redhat.com>
[not found] ` <4B7E7F06.20809@oracle.com>
[not found] ` <4B7E81A9.9010306@oracle.com>
[not found] ` <4B968550.6070001@redhat.com>
2010-07-07 15:51 ` [trans-mem] __sync_add_and_fetch_8 on ia32 Aldy Hernandez
2010-07-07 17:11 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).