Re: Reorganization of spinlock defines - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: Reorganization of spinlock defines
Date
Msg-id 200309121609.h8CG9LK08156@candle.pha.pa.us
Whole thread Raw
In response to Reorganization of spinlock defines  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-patches
Bruce Momjian wrote:
> Prompted by confusion over Itanium/Opterion, I have written a patch to
> improve the way we define spinlocks for platforms and cpu's.  It
> basically decouples the OS from the CPU spinlock code.  In almost all
> cases, the spinlock code cares only about the compiler and CPU, not the
> OS.
>
> The patch:
>
>     o defines HAS_TEST_AND_SET inside each spinlock routine, not in
>       platform-specific files
>     o moves slock_t defines into the spinlock routines
>     o remove NEED_{CPU}_TAS_ASM define because it is no longer needed
>     o reports a compile error if spinlocks are not defined
>     o adds a configure option --without-spinlocks to allow
>       non-spinlock compiles

OK, this applied patch implements the last two items.  The earlier items
will have to wait for 7.5.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: configure
===================================================================
RCS file: /cvsroot/pgsql-server/configure,v
retrieving revision 1.295
diff -c -c -r1.295 configure
*** configure    7 Sep 2003 16:49:41 -0000    1.295
--- configure    12 Sep 2003 16:05:13 -0000
***************
*** 869,874 ****
--- 869,875 ----
    --with-rendezvous       build with Rendezvous support
    --with-openssl[=DIR]    build with OpenSSL support [/usr/local/ssl]
    --without-readline      do not use Readline
+   --without-spinlocks     do not use Spinlocks
    --without-zlib          do not use Zlib
    --with-gnu-ld           assume the C compiler uses GNU ld default=no

***************
*** 3494,3499 ****
--- 3495,3530 ----


  #
+ # Spinlocks
+ #
+
+
+
+ # Check whether --with-spinlocks or --without-spinlocks was given.
+ if test "${with_spinlocks+set}" = set; then
+   withval="$with_spinlocks"
+
+   case $withval in
+     yes)
+       :
+       ;;
+     no)
+       :
+       ;;
+     *)
+       { { echo "$as_me:$LINENO: error: no argument expected for --with-spinlocks option" >&5
+ echo "$as_me: error: no argument expected for --with-spinlocks option" >&2;}
+    { (exit 1); exit 1; }; }
+       ;;
+   esac
+
+ else
+   with_spinlocks=yes
+
+ fi;
+
+
+ #
  # Zlib
  #

***************
*** 3523,3529 ****
  fi;


-
  #
  # Elf
  #
--- 3554,3559 ----
***************
*** 6060,6065 ****
--- 6090,6108 ----
     { (exit 1); exit 1; }; }
  fi

+ fi
+
+ if test "$with_spinlocks" = yes; then
+
+ cat >>confdefs.h <<\_ACEOF
+ #define HAVE_SPINLOCKS 1
+ _ACEOF
+
+ else
+   { echo "$as_me:$LINENO: WARNING:
+ *** Not using spinlocks will cause poor performance." >&5
+ echo "$as_me: WARNING:
+ *** Not using spinlocks will cause poor performance." >&2;}
  fi

  if test "$with_krb4" = yes ; then
Index: configure.in
===================================================================
RCS file: /cvsroot/pgsql-server/configure.in,v
retrieving revision 1.286
diff -c -c -r1.286 configure.in
*** configure.in    7 Sep 2003 16:38:05 -0000    1.286
--- configure.in    12 Sep 2003 16:05:15 -0000
***************
*** 522,533 ****
                [  --without-readline      do not use Readline])

  #
  # Zlib
  #
  PGAC_ARG_BOOL(with, zlib, yes,
                [  --without-zlib          do not use Zlib])

-
  #
  # Elf
  #
--- 522,538 ----
                [  --without-readline      do not use Readline])

  #
+ # Spinlocks
+ #
+ PGAC_ARG_BOOL(with, spinlocks, yes,
+               [  --without-spinlocks     do not use Spinlocks])
+
+ #
  # Zlib
  #
  PGAC_ARG_BOOL(with, zlib, yes,
                [  --without-zlib          do not use Zlib])

  #
  # Elf
  #
***************
*** 676,681 ****
--- 681,693 ----
  If you have zlib already installed, see config.log for details on the
  failure.  It is possible the compiler isn't looking in the proper directory.
  Use --without-zlib to disable zlib support.])])
+ fi
+
+ if test "$with_spinlocks" = yes; then
+   AC_DEFINE(HAVE_SPINLOCKS, 1, [Define to 1 if you have spinlocks.])
+ else
+   AC_MSG_WARN([
+ *** Not using spinlocks will cause poor performance.])
  fi

  if test "$with_krb4" = yes ; then
Index: doc/src/sgml/installation.sgml
===================================================================
RCS file: /cvsroot/pgsql-server/doc/src/sgml/installation.sgml,v
retrieving revision 1.141
diff -c -c -r1.141 installation.sgml
*** doc/src/sgml/installation.sgml    11 Sep 2003 21:42:20 -0000    1.141
--- doc/src/sgml/installation.sgml    12 Sep 2003 16:05:17 -0000
***************
*** 900,905 ****
--- 900,917 ----
        </varlistentry>

        <varlistentry>
+        <term><option>--without-spinlocks</option></term>
+        <listitem>
+         <para>
+          Allows source builds to succeed without CPU spinlock support.
+          Lack of spinlock support will produce poor performance.
+          This option is to be used only by platforms without
+          spinlock support.
+         </para>
+        </listitem>
+       </varlistentry>
+
+       <varlistentry>
         <term><option>--enable-thread-safety</option></term>
         <listitem>
          <para>
Index: src/include/pg_config.h.in
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/pg_config.h.in,v
retrieving revision 1.62
diff -c -c -r1.62 pg_config.h.in
*** src/include/pg_config.h.in    7 Sep 2003 03:43:56 -0000    1.62
--- src/include/pg_config.h.in    12 Sep 2003 16:05:19 -0000
***************
*** 357,362 ****
--- 357,365 ----
  /* Define to 1 if you have the `snprintf' function. */
  #undef HAVE_SNPRINTF

+ /* Define to 1 if you have spinlocks. */
+ #undef HAVE_SPINLOCKS
+
  /* Define to 1 if you have the `srandom' function. */
  #undef HAVE_SRANDOM

Index: src/include/storage/s_lock.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/storage/s_lock.h,v
retrieving revision 1.112
diff -c -c -r1.112 s_lock.h
*** src/include/storage/s_lock.h    4 Aug 2003 02:40:15 -0000    1.112
--- src/include/storage/s_lock.h    12 Sep 2003 16:05:20 -0000
***************
*** 537,543 ****



! #else                            /* !HAS_TEST_AND_SET */

  /*
   * Fake spinlock implementation using semaphores --- slow and prone
--- 537,547 ----



! #else     /* HAS_TEST_AND_SET */
!
! #ifdef HAVE_SPINLOCKS
! #error This platform does not support native spinlocks.  To continue the compile, rerun configure using
--without-spinlocks. However, performance will be poor.  Please report this to pgsql-bugs@postgresql.org. 
! #endif

  /*
   * Fake spinlock implementation using semaphores --- slow and prone

pgsql-patches by date:

Previous
From: Manfred Koizar
Date:
Subject: Re: Regression test for stats collector
Next
From: Bruce Momjian
Date:
Subject: Re: WIN32_CONSOLE usage