[PATCH] Use the same exported ABI for --disable-linux-futex and --enable-linux-futex libgomp
Jakub Jelinek
jakub@redhat.com
Mon Jun 19 16:33:00 GMT 2006
On Wed, Jun 07, 2006 at 04:29:22AM -0400, Jakub Jelinek wrote:
> On Tue, Jun 06, 2006 at 07:48:01AM -0700, Richard Henderson wrote:
> > On Mon, Jun 05, 2006 at 03:51:53PM -0400, Jakub Jelinek wrote:
> > > The reason why I'd like to default to --enable-linux-futex as much as
> > > possible is because the two are ABI incompatible ...
> >
> > Eh? How, specifically? I thought all the differences were
> > hidden within the library itself.
>
> With --enable-linux-futex, the size/alignment of omp_lock_t/omp_nest_lock_t
> and omp_lock_kind/omp_nest_lock_kind are different from
> --disable-linux-futex.
> With config/linux, omp_lock_t is 4 bytes, omp_nest_lock_t is 8 bytes
> (and similarly Fortran kinds), with config/posix, omp_lock_t is 40 bytes
> on 64-bit arches, 24 bytes on 32-bit arches and both Fortran kinds are
> sizeof (void *).
The following patch changes the libgomp ABI (omp_lock_t, omp_nest_lock_t,
omp_lock_kind, omp_nest_lock_kind and all functions using those), so that
--disable-linux-futex vs. --enable-linux-futex is an implementation detail,
not part of the exported ABI.
In --enable-linux-futex builds that means extra 4 bytes allocated per
omp_lock_t, in --disable-linux-futex (which is already slow) adds a
dereference and some overhead on lock initialization and destruction.
Ok for trunk?
2006-06-19 Jakub Jelinek <jakub@redhat.com>
* configure.ac (libtool_VERSION): Bump to 2:0:0.
* configure: Rebuilt.
* configure.tgt: Use linux/nofutex in config_path on linux if not
enable_linux_futex.
* config/linux/omp-lock.h (omp_lock_t, omp_nest_lock_t): Align to
8 bytes.
* config/linux/nofutex/omp-lock.h: New file.
* config/linux/nofutex/lock.c: New file.
--- libgomp/configure.tgt.jj 2006-06-07 13:28:28.000000000 +0200
+++ libgomp/configure.tgt 2006-06-19 15:23:15.000000000 +0200
@@ -21,6 +21,26 @@ fi
# Since we require POSIX threads, assume a POSIX system by default.
config_path="posix"
+case "${target}" in
+
+ *-*-linux*)
+ config_path="linux/nofutex posix"
+ ;;
+
+ *-*-hpux11*)
+ # HPUX v11.x requires -lrt to resolve sem_init in libgomp.la
+ XLDFLAGS="${XLDFLAGS} -lrt"
+ ;;
+
+ *-*-mingw32*)
+ config_path="mingw32 posix"
+ ;;
+
+ *)
+ ;;
+
+esac
+
# Check for futex enabled all at once.
if test $enable_linux_futex = yes; then
case "${target}" in
@@ -82,20 +102,3 @@ if test $enable_linux_futex = yes; then
;;
esac
fi
-
-# Other system configury
-case "${target}" in
-
- *-*-hpux11*)
- # HPUX v11.x requires -lrt to resolve sem_init in libgomp.la
- XLDFLAGS="${XLDFLAGS} -lrt"
- ;;
-
- *-*-mingw32*)
- config_path="mingw32 posix"
- ;;
-
- *)
- ;;
-
-esac
--- libgomp/config/linux/omp-lock.h.jj 2006-01-27 08:31:15.000000000 +0100
+++ libgomp/config/linux/omp-lock.h 2006-06-19 15:47:35.000000000 +0200
@@ -4,7 +4,12 @@
When using the Linux futex primitive, non-recursive locks require
only one int. Recursive locks require we identify the owning thread
- and so require two ints. */
+ and so require two ints.
-typedef int omp_lock_t;
-typedef struct { int owner, count; } omp_nest_lock_t;
+ As libgomp ABI shouldn't change on Linux depending if futex
+ primitive is available or not, make the types big enough to contain
+ a pointer for nofutex implementation. */
+
+typedef int omp_lock_t __attribute__((aligned (8)));
+typedef struct { int owner, count; } omp_nest_lock_t
+ __attribute__((aligned (8)));
--- libgomp/config/linux/nofutex/omp-lock.h.jj 2006-06-19 15:44:37.000000000 +0200
+++ libgomp/config/linux/nofutex/omp-lock.h 2006-06-19 15:52:01.000000000 +0200
@@ -0,0 +1,13 @@
+/* This header is used during the build process to find the size and
+ alignment of the public OpenMP locks, so that we can export data
+ structures without polluting the namespace.
+
+ As libgomp ABI shouldn't change on Linux depending if futex
+ primitive is available or not, make the types big enough to contain
+ a pointer for nofutex implementation. */
+
+#include <pthread.h>
+
+typedef pthread_mutex_t *omp_lock_t __attribute__((aligned (8)));
+typedef struct { pthread_mutex_t lock; int count; } *omp_nest_lock_t
+ __attribute__((aligned (8)));
--- libgomp/config/linux/nofutex/lock.c.jj 2006-06-19 15:46:39.000000000 +0200
+++ libgomp/config/linux/nofutex/lock.c 2006-06-19 17:24:57.000000000 +0200
@@ -0,0 +1,128 @@
+/* Copyright (C) 2006 Free Software Foundation, Inc.
+ Contributed by Jakub Jelinek <jakub@redhat.com>.
+
+ This file is part of the GNU OpenMP Library (libgomp).
+
+ Libgomp is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
+ more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with libgomp; see the file COPYING.LIB. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ MA 02110-1301, USA. */
+
+/* As a special exception, if you link this library with other files, some
+ of which are compiled with GCC, to produce an executable, this library
+ does not by itself cause the resulting executable to be covered by the
+ GNU General Public License. This exception does not however invalidate
+ any other reasons why the executable file might be covered by the GNU
+ General Public License. */
+
+/* This is the Linux non-futex implementation of the public OpenMP
+ locking primitives.
+
+ Because OpenMP uses different entry points for normal and recursive
+ locks, and pthreads uses only one entry point, a system may be able
+ to do better and streamline the locking as well as reduce the size
+ of the types exported. */
+
+/* We need Unix98 extensions to get recursive locks. */
+#define _XOPEN_SOURCE 500
+
+#include <stdlib.h>
+#include "libgomp.h"
+
+
+void
+omp_init_lock (omp_lock_t *lock)
+{
+ *lock = malloc (sizeof (pthread_mutex_t));
+ pthread_mutex_init (*lock, NULL);
+}
+
+void
+omp_destroy_lock (omp_lock_t *lock)
+{
+ pthread_mutex_destroy (*lock);
+ free (*lock);
+ *lock = NULL;
+}
+
+void
+omp_set_lock (omp_lock_t *lock)
+{
+ pthread_mutex_lock (*lock);
+}
+
+void
+omp_unset_lock (omp_lock_t *lock)
+{
+ pthread_mutex_unlock (*lock);
+}
+
+int
+omp_test_lock (omp_lock_t *lock)
+{
+ return pthread_mutex_trylock (*lock) == 0;
+}
+
+void
+omp_init_nest_lock (omp_nest_lock_t *lock)
+{
+ pthread_mutexattr_t attr;
+
+ *lock = malloc (sizeof (**lock));
+ pthread_mutexattr_init (&attr);
+ pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
+ pthread_mutex_init (&(*lock)->lock, &attr);
+ (*lock)->count = 0;
+ pthread_mutexattr_destroy (&attr);
+}
+
+void
+omp_destroy_nest_lock (omp_nest_lock_t *lock)
+{
+ pthread_mutex_destroy (&(*lock)->lock);
+ free (*lock);
+ *lock = NULL;
+}
+
+void
+omp_set_nest_lock (omp_nest_lock_t *lock)
+{
+ pthread_mutex_lock (&(*lock)->lock);
+ (*lock)->count++;
+}
+
+void
+omp_unset_nest_lock (omp_nest_lock_t *lock)
+{
+ (*lock)->count--;
+ pthread_mutex_unlock (&(*lock)->lock);
+}
+
+int
+omp_test_nest_lock (omp_nest_lock_t *lock)
+{
+ if (pthread_mutex_trylock (&(*lock)->lock) == 0)
+ return ++(*lock)->count;
+ return 0;
+}
+
+ialias (omp_init_lock)
+ialias (omp_init_nest_lock)
+ialias (omp_destroy_lock)
+ialias (omp_destroy_nest_lock)
+ialias (omp_set_lock)
+ialias (omp_set_nest_lock)
+ialias (omp_unset_lock)
+ialias (omp_unset_nest_lock)
+ialias (omp_test_lock)
+ialias (omp_test_nest_lock)
--- libgomp/configure.ac.jj 2006-06-19 15:26:19.000000000 +0200
+++ libgomp/configure.ac 2006-06-19 16:17:35.000000000 +0200
@@ -132,7 +132,7 @@ AC_PROG_FC(gfortran)
FCFLAGS="$FCFLAGS -Wall"
# For libtool versioning info, format is CURRENT:REVISION:AGE
-libtool_VERSION=1:0:0
+libtool_VERSION=2:0:0
AC_SUBST(libtool_VERSION)
# Check header files.
--- libgomp/configure.jj 2006-06-19 15:12:00.000000000 +0200
+++ libgomp/configure 2006-06-19 16:17:39.000000000 +0200
@@ -4784,7 +4784,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
FCFLAGS="$FCFLAGS -Wall"
# For libtool versioning info, format is CURRENT:REVISION:AGE
-libtool_VERSION=1:0:0
+libtool_VERSION=2:0:0
# Check header files.
Jakub
More information about the Gcc-patches
mailing list