[pypy-svn] r24195 - pypy/branch/njriley-trans/pypy/translator/c/src

njriley at codespeak.net njriley at codespeak.net
Thu Mar 9 21:14:27 CET 2006


Author: njriley
Date: Thu Mar  9 21:14:12 2006
New Revision: 24195

Modified:
   pypy/branch/njriley-trans/pypy/translator/c/src/g_include.h
   pypy/branch/njriley-trans/pypy/translator/c/src/ll_trans.h
   pypy/branch/njriley-trans/pypy/translator/c/src/mem.h
Log:
Pause transactions around memory allocation requests (high overhead
but conservative for now).  Move ll_trans.h earlier in g_include.h
because it exports RPyTrans{Pause,Unpause} - lower-level pause/unpause
that doesn't use thread-local storage.



Modified: pypy/branch/njriley-trans/pypy/translator/c/src/g_include.h
==============================================================================
--- pypy/branch/njriley-trans/pypy/translator/c/src/g_include.h	(original)
+++ pypy/branch/njriley-trans/pypy/translator/c/src/g_include.h	Thu Mar  9 21:14:12 2006
@@ -14,6 +14,7 @@
 #  include "src/standalone.h"
 #endif
 
+#include "src/ll_trans.h"
 #include "src/mem.h"
 #include "src/exception.h"
 #include "src/trace.h"
@@ -40,7 +41,6 @@
 #  include "src/ll_thread.h"
 #  include "src/ll_stackless.h"
 #  include "src/ll__socket.h"
-#  include "src/ll_trans.h"
 #  include "src/ll_tsc.h"
 #endif
 

Modified: pypy/branch/njriley-trans/pypy/translator/c/src/ll_trans.h
==============================================================================
--- pypy/branch/njriley-trans/pypy/translator/c/src/ll_trans.h	(original)
+++ pypy/branch/njriley-trans/pypy/translator/c/src/ll_trans.h	Thu Mar  9 21:14:12 2006
@@ -10,6 +10,8 @@
 void LL_trans_verbose(void);
 void LL_trans_enable(void);
 void LL_trans_disable(void);
+int RPyTransPause(void);
+void RPyTransUnpause(int pause_state);
 
 /* implementations */
 
@@ -39,6 +41,20 @@
 	;
 }
 
+int
+RPyTransPause(void)
+{
+	int pause_state;
+	XACT_PAUSE(pause_state);
+	return pause_state;
+}
+
+void
+RPyTransUnpause(int pause_state)
+{
+	XACT_UNPAUSE(pause_state);
+}
+
 /* XXX deliberately not RPyThreadTLS here => dependency problems */
 static pthread_key_t pause_state_key = 0;
 
@@ -78,8 +94,6 @@
 LL_trans_enable(void)
 {
 	int ret_val;
-	ret_val = enable_transactions();
-	assert(ret_val == 0);
 	// XXX HACK HACK HACK, 1024 is first thread id
 	if (pthread_self() == 1024) {
 		static int suspended = 0;
@@ -90,6 +104,13 @@
 		fprintf(stderr, "LL_trans_enable: suspending, pid is %d\n", pid);
 		kill(pid, SIGSTOP);
 	}
+	ret_val = enable_transactions();
+	if (ret_val != 0) {
+		printf("Load transactional memory module and press return\n");
+		while (getchar() != '\n');
+		ret_val = enable_transactions();
+		assert(ret_val == 0);
+	}
 	XACT_BEGIN;
 	XACT_PAUSE(ret_val);
 	set_auto_xact(1);
@@ -109,7 +130,8 @@
 	int ret_val;
 
 	XACT_ACTIVE(ret_val);
-	assert(ret_val == 0 || ret_val == 1);
+	if (ret_val != 0 && ret_val != 1)
+		return 0;
 
 	return ret_val;
 }

Modified: pypy/branch/njriley-trans/pypy/translator/c/src/mem.h
==============================================================================
--- pypy/branch/njriley-trans/pypy/translator/c/src/mem.h	(original)
+++ pypy/branch/njriley-trans/pypy/translator/c/src/mem.h	Thu Mar  9 21:14:12 2006
@@ -2,7 +2,6 @@
 /************************************************************/
  /***  C header subsection: operations on LowLevelTypes    ***/
 
-
 /* a reasonably safe bound on the largest allowed argument value
    that we can pass to malloc.  This is used for var-sized mallocs
    to compute the largest allowed number of items in the array. */
@@ -69,7 +68,9 @@
 /* #define BOEHM_MALLOC_1_1   GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE */
 
 #define OP_BOEHM_ZERO_MALLOC(size, r, is_atomic, is_varsize, err)   {        \
+ 	int pause_state = RPyTransPause();				     \
 	r = (void*) BOEHM_MALLOC_ ## is_atomic ## _ ## is_varsize (size);    \
+	RPyTransUnpause(pause_state);					     \
 	if (r == NULL) FAIL_EXCEPTION(err, PyExc_MemoryError, "out of memory");	\
 	if (is_atomic)  /* the non-atomic versions return cleared memory */  \
 		memset((void*) r, 0, size);                                  \
@@ -93,7 +94,9 @@
 #undef OP_ZERO_MALLOC
 
 #define OP_ZERO_MALLOC(size, r, err)  {                                 \
-    r = (void*) malloc(size);                                  \
+    int pause_state = RPyTransPause();				        \
+    r = (void*) malloc(size);                                           \
+    RPyTransUnpause(pause_state);					\
     if (r == NULL) FAIL_EXCEPTION(err, PyExc_MemoryError, "out of memory");\
     memset((void*) r, 0, size);                                         \
     COUNT_MALLOC;                                                       \



More information about the Pypy-commit mailing list