[m-rev.] for review: enable parallel marking on linux

Peter Wang wangp at students.cs.mu.oz.au
Wed Aug 2 11:46:43 AEST 2006


This didn't use to show any benefit before when I just reused the x86
atomic ops on saturn, but now it makes a big difference.  Also, if it's
planned to upgrade to gc7.0alphaN soon, that'd be fine as well.

I'm going to see about enabling thread-local allocation and parallel
marking on Solaris, too, now that there is a fancy new machine :)


Estimated hours taken: 1
Branches: main

Mmake.common.in:
configure.in:
	Enable the parallel marking code in the Boehm GC in parallel grades
	by adding -DPARALLEL_MARK to the compiler flags, on Linux.

boehm_gc/include/private/gc_locks.h:
	Backport implementations of GC_test_and_set, GC_compare_and_exchange,
	and GC_memory_barrier for x86-64 from libatomic_ops-1.2.

boehm_gc/include/private/gcconfig.h:
	Fix a typo that prevented gcc prefetch builtins from being used on
	x86-64.

Index: Mmake.common.in
===================================================================
RCS file: /home/mercury1/repository/mercury/Mmake.common.in,v
retrieving revision 1.88
diff -u -r1.88 Mmake.common.in
--- Mmake.common.in	21 Apr 2006 01:04:46 -0000	1.88
+++ Mmake.common.in	1 Aug 2006 08:00:24 -0000
@@ -148,7 +148,8 @@
 
 # Additional options to pass to the C compiler when building Boehm-GC for
 # threads.
-BOEHM_CFLAGS_FOR_THREADS = @ENABLE_BOEHM_THREAD_LOCAL_ALLOC@
+BOEHM_CFLAGS_FOR_THREADS = @ENABLE_BOEHM_THREAD_LOCAL_ALLOC@ \
+	@ENABLE_BOEHM_PARALLEL_MARK@
 
 # Do we want to deal with intermodule information when building the library?
 # By default yes, since this way we note immediately when intermodule
Index: configure.in
===================================================================
RCS file: /home/mercury1/repository/mercury/configure.in,v
retrieving revision 1.457
diff -u -r1.457 configure.in
--- configure.in	25 Jul 2006 14:03:56 -0000	1.457
+++ configure.in	1 Aug 2006 08:10:52 -0000
@@ -2495,6 +2495,7 @@
 			-D_THREAD_SAFE -D_REENTRANT -DGC_REDIRECT_TO_LOCAL"
 		THREAD_LIBS="-lpthread -ldl"
 		ENABLE_BOEHM_THREAD_LOCAL_ALLOC="-DTHREAD_LOCAL_ALLOC"
+		ENABLE_BOEHM_PARALLEL_MARK="-DPARALLEL_MARK"
 		;;
 
 	*cygwin*)
@@ -2570,6 +2571,7 @@
 AC_SUBST(LDFLAGS_FOR_THREADS)
 AC_SUBST(LD_LIBFLAGS_FOR_THREADS)
 AC_SUBST(ENABLE_BOEHM_THREAD_LOCAL_ALLOC)
+AC_SUBST(ENABLE_BOEHM_PARALLEL_MARK)
 
 #-----------------------------------------------------------------------------#
 
Index: boehm_gc/include/private/gc_locks.h
===================================================================
RCS file: /home/mercury1/repository/mercury/boehm_gc/include/private/gc_locks.h,v
retrieving revision 1.5
diff -u -r1.5 gc_locks.h
--- boehm_gc/include/private/gc_locks.h	5 Sep 2005 06:49:06 -0000	1.5
+++ boehm_gc/include/private/gc_locks.h	1 Aug 2006 09:51:11 -0000
@@ -99,6 +99,17 @@
        }
 #      define GC_TEST_AND_SET_DEFINED
 #    endif
+#    if defined(X86_64)
+       inline static int GC_test_and_set(volatile unsigned int *addr) {
+	  char oldval;
+	  /* Note: the "xchg" instruction does not need a "lock" prefix */
+	  __asm__ __volatile__("xchgb %0, %1"
+		: "=q"(oldval), "=m"(*addr)
+		: "0"(0xff), "m"(*addr) : "memory");
+	  return oldval;
+       }
+#      define GC_TEST_AND_SET_DEFINED
+#    endif /* X86_64 */
 #    if defined(IA64)
 #      if defined(__INTEL_COMPILER)
 #        include <ia64intrin.h>
@@ -437,6 +448,26 @@
        }
 #     endif /* I386 */
 
+#     if defined(X86_64)
+#      if !defined(GENERIC_COMPARE_AND_SWAP)
+         /* Returns TRUE if the comparison succeeded. */
+         inline static GC_bool GC_compare_and_exchange(volatile GC_word *addr,
+		  				       GC_word old,
+						       GC_word new_val) 
+         {
+	   char result;
+	   __asm__ __volatile__("lock; cmpxchgq %3, %0; setz %1"
+		: "=m"(*addr), "=q"(result)
+		: "m"(*addr), "r" (new_val), "a"(old) : "memory");
+	   return (GC_bool) result;
+         }
+#      endif /* !GENERIC_COMPARE_AND_SWAP */
+       inline static void GC_memory_barrier()
+       {
+         __asm__ __volatile__("" : : : "memory");
+       }
+#     endif /* X86_64 */
+
 #     if defined(POWERPC)
 #      if !defined(GENERIC_COMPARE_AND_SWAP)
 #       if CPP_WORDSZ == 64
Index: boehm_gc/include/private/gcconfig.h
===================================================================
RCS file: /home/mercury1/repository/mercury/boehm_gc/include/private/gcconfig.h,v
retrieving revision 1.10
diff -u -r1.10 gcconfig.h
--- boehm_gc/include/private/gcconfig.h	5 Sep 2005 06:49:07 -0000	1.10
+++ boehm_gc/include/private/gcconfig.h	1 Aug 2006 08:07:08 -0000
@@ -1931,7 +1931,7 @@
 	     extern int etext[];
 #            define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
 #       endif
-#       if defined(__GNUC__) && __GNUC >= 3
+#       if defined(__GNUC__) && __GNUC__ >= 3
 #	    define PREFETCH(x) __builtin_prefetch((x), 0, 0)
 #	    define PREFETCH_FOR_WRITE(x) __builtin_prefetch((x), 1)
 #	endif
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list