[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Patches for db2 on Alpha and PowerPC



Hi,

Here are two patches in "dpatch" format.

alpha-pthread-h-compile.dpatch - I needed to move the definition of
stack_pointer up to get this to compile

alpha-powerpc-db2-spinlocks.dpatch - This fixes (and activates! :) the Alpha
spinlock implementation in db2, and adds an implementation for PowerPC.
This is needed in order to make openldapd work on these architectures, since
it relies on db2's thread support.  This patch replaces the old Alpha patch
for this problem (which was never actually applied in the build process, BTW)

They seem to work, but there may be problems. db2 uses unsigned char for the
spinlock type, which strikes me as kind of a dumb idea (particularly on
big-endian RISC machines) since atomic operations are generally word-wide.
On Alpha it's okay because of little-endianness, as well as the fact that we
only mess with the LSB of the lock.

On PowerPC, it's totally wrong, but it doesn't actually matter so long as we
clear out the entire word in TSL_UNSET (and make sure to #define
MUTEX_ALIGNMENT 4)

-- 
< james>  overfiend: I am not an autobuilder, I am a human being
#! /bin/sh -e

# All lines beginning with `# DP:' are a description of the patch.
# DP: fix pt-machine.h so that linuxthreads compiles on Alpha

if [ $# -ne 2 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch) patch -d "$2" -f --no-backup-if-mismatch -p1 < $0;;
    -unpatch) patch -d "$2" -f --no-backup-if-mismatch -R -p1 < $0;;
    *)
	echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
	exit 1
esac
exit 0

diff -urN glibc-2.1.2/linuxthreads/sysdeps/alpha/pt-machine.h glibc-2.1.2.new/linuxthreads/sysdeps/alpha/pt-machine.h
--- glibc-2.1.2/linuxthreads/sysdeps/alpha/pt-machine.h	Fri Oct  9 07:22:04 1998
+++ glibc-2.1.2.new/linuxthreads/sysdeps/alpha/pt-machine.h	Tue Nov 30 18:55:55 1999
@@ -26,6 +26,12 @@
 #include <asm/pal.h>
 
 
+/* Get some notion of the current stack.  Need not be exactly the top
+   of the stack, just something somewhere in the current frame.  */
+#define CURRENT_STACK_FRAME  stack_pointer
+register char *stack_pointer __asm__("$30");
+
+
 /* Spinlock implementation; required.  */
 PT_EI long int
 testandset (int *spinlock)
@@ -58,12 +64,6 @@
 /* Begin allocating thread stacks at this address.  Default is to allocate
    them just below the initial program stack.  */
 #define THREAD_STACK_START_ADDRESS  0x40000000000
-
-
-/* Get some notion of the current stack.  Need not be exactly the top
-   of the stack, just something somewhere in the current frame.  */
-#define CURRENT_STACK_FRAME  stack_pointer
-register char *stack_pointer __asm__("$30");
 
 
 /* Return the thread descriptor for the current thread.  */
#! /bin/sh -e

# All lines beginning with `# DP:' are a description of the patch.
# DP: fix the db2 spinlocks for Alpha, and add them for PowerPC

if [ $# -ne 2 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch) patch -d "$2" -f --no-backup-if-mismatch -p1 < $0;;
    -unpatch) patch -d "$2" -f --no-backup-if-mismatch -R -p1 < $0;;
    *)
	echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
	exit 1
esac
exit 0

diff -urN --exclude=*.info glibc-2.1.2/db2/config.h glibc-2.1.2.new/db2/config.h
--- glibc-2.1.2/db2/config.h	Tue Jun  9 11:02:06 1998
+++ glibc-2.1.2.new/db2/config.h	Tue Nov 30 21:33:33 1999
@@ -66,6 +66,12 @@
 /* Define if you want to use sparc/gcc assembly spinlocks. */
 /* #undef HAVE_ASSEM_SPARC_GCC */
 
+/* Define if you want to use sparc/gcc assembly spinlocks. */
+/* #undef HAVE_ASSEM_ALPHA_GCC */
+
+/* Define if you want to use sparc/gcc assembly spinlocks. */
+/* #undef HAVE_ASSEM_POWERPC_GCC */
+
 /* Define if you want to use uts4/cc assembly spinlocks. */
 /* #undef HAVE_ASSEM_UTS4_CC */
 
diff -urN --exclude=*.info glibc-2.1.2/db2/mutex/alpha.gcc glibc-2.1.2.new/db2/mutex/alpha.gcc
--- glibc-2.1.2/db2/mutex/alpha.gcc	Wed Aug 27 15:32:54 1997
+++ glibc-2.1.2.new/db2/mutex/alpha.gcc	Tue Nov 30 23:09:14 1999
@@ -31,22 +31,23 @@
 	register tsl_t *__l = (tsl);					\
 	register tsl_t __r1, __r2;					\
 	__asm__ volatile("						\n\
-	   10: ldq_l %0,(%2)						\n\
+	   10: ldq_l %0,%3						\n\
 	       blbs  %0,30f						\n\
 	       or    %0,1,%1						\n\
-	       stq_c %1,(%2)						\n\
+	       stq_c %1,%2						\n\
 	       beq   %1,20f						\n\
 	       mb							\n\
 	       br    30f						\n\
 	   20: br    10b						\n\
 	   30: "							\
-	  : "=&r" (__r1), "=&r" (__r2)					\
-	  : "r" (__l));							\
+	  : "=&r" (__r1), "=&r" (__r2), "=m"(*__l)			\
+	  : "2" (*__l)							\
+	  : "memory");							\
 	!__r1;								\
 })
 
 #define TSL_UNSET(tsl) ({						\
 	register tsl_t *__l = (tsl);					\
-	__asm__ volatile("mb; stq $31,(%0);" : : "r" (__l));		\
+	__asm__ volatile("mb; stq $31,%0;" : "=&r" (__l) : : "memory");	\
 })
 #define	TSL_INIT(tsl)	TSL_UNSET(tsl)
diff -urN --exclude=*.info glibc-2.1.2/db2/mutex/mutex.c glibc-2.1.2.new/db2/mutex/mutex.c
--- glibc-2.1.2/db2/mutex/mutex.c	Tue Jun  9 11:04:35 1998
+++ glibc-2.1.2.new/db2/mutex/mutex.c	Tue Nov 30 21:33:33 1999
@@ -86,6 +86,14 @@
 #include "sparc.gcc"
 #endif
 
+#ifdef HAVE_ASSEM_ALPHA_GCC
+#include "alpha.gcc"
+#endif
+
+#ifdef HAVE_ASSEM_POWERPC_GCC
+#include "powerpc.gcc"
+#endif
+
 #ifdef HAVE_ASSEM_UTS4_CC
 #define TSL_INIT(x)
 #define TSL_SET(x)	(!uts_lock(x, 1))
diff -urN --exclude=*.info glibc-2.1.2/db2/mutex/powerpc.gcc glibc-2.1.2.new/db2/mutex/powerpc.gcc
--- glibc-2.1.2/db2/mutex/powerpc.gcc	Wed Dec 31 19:00:00 1969
+++ glibc-2.1.2.new/db2/mutex/powerpc.gcc	Tue Nov 30 22:54:56 1999
@@ -0,0 +1,22 @@
+/*
+ * PowerPC spinlock, adapted from the Alpha and m68k ones by dhd@debian.org
+ *
+ * For gcc/powerpc, 0 is clear, 1 is set (but *tsl will always be 0 since it's a char)
+ */
+#define TSL_SET(tsl) ({						\
+	register tsl_t *__l = (tsl);					\
+	register tsl_t __r1;						\
+	__asm__ volatile("						\n\
+	   10: lwarx  %0,0,%1						\n\
+	       cmpwi  %0,0						\n\
+	       bne+   20f						\n\
+	       stwcx. %2,0,%1						\n\
+	       bne-   10b						\n\
+	   20: "							\
+	  : "=&r" (__r1)						\
+	  : "r" (__l), "r" (-1) : "cr0", "memory");			\
+	!__r1;								\
+})
+
+#define	TSL_UNSET(tsl)	(*(tsl) = 0)
+#define	TSL_INIT(tsl)	TSL_UNSET(tsl)
diff -urN --exclude=*.info glibc-2.1.2/sysdeps/alpha/Makefile glibc-2.1.2.new/sysdeps/alpha/Makefile
--- glibc-2.1.2/sysdeps/alpha/Makefile	Sat Jun 27 05:50:41 1998
+++ glibc-2.1.2.new/sysdeps/alpha/Makefile	Tue Nov 30 22:43:29 1999
@@ -39,3 +39,5 @@
 # For now, build everything with full IEEE math support.
 # TODO: build separate libm and libm-ieee.
 sysdep-CFLAGS += -mieee
+
+CPPFLAGS += -DHAVE_SPINLOCKS=1 -DHAVE_ASSEM_ALPHA_GCC=1 -DMUTEX_ALIGNMENT=8
\ No newline at end of file
diff -urN --exclude=*.info glibc-2.1.2/sysdeps/powerpc/Makefile glibc-2.1.2.new/sysdeps/powerpc/Makefile
--- glibc-2.1.2/sysdeps/powerpc/Makefile	Tue Sep  1 10:30:52 1998
+++ glibc-2.1.2.new/sysdeps/powerpc/Makefile	Tue Nov 30 22:55:33 1999
@@ -33,3 +33,5 @@
 dl-routines += dl-machine
 rtld-routines += dl-machine dl-start
 endif
+
+CPPFLAGS += -DHAVE_SPINLOCKS=1 -DHAVE_ASSEM_POWERPC_GCC=1  -DMUTEX_ALIGNMENT=4
--- glibc-2.1.2/db2/db_int.h	Mon Aug 31 11:57:53 1998
+++ glibc-2.1.2/db2/db_int.h.fixx0red	Tue Nov 30 23:47:25 1999
@@ -165,7 +165,9 @@
  * region.  This ensures the alignment is as returned by mmap(2), which should
  * be sufficient.  All other mutex users must ensure proper alignment locally.
  */
+#ifndef MUTEX_ALIGNMENT
 #define	MUTEX_ALIGNMENT	1
+#endif
 
 /*
  * The offset of a mutex in memory.

Reply to: