[pypy-commit] pypy stm: Tweaks.
arigo
noreply at buildbot.pypy.org
Thu Nov 3 11:23:51 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r48688:65eb6e47e3b4
Date: 2011-11-03 11:23 +0100
http://bitbucket.org/pypy/pypy/changeset/65eb6e47e3b4/
Log: Tweaks.
diff --git a/pypy/translator/stm/funcgen.py b/pypy/translator/stm/funcgen.py
--- a/pypy/translator/stm/funcgen.py
+++ b/pypy/translator/stm/funcgen.py
@@ -111,6 +111,7 @@
def op_stm(funcgen, op):
- assert funcgen.db.translator.stm_transformation_applied
+ if not getattr(funcgen.db.translator, 'stm_transformation_applied', None):
+ raise AssertionError("STM transformation not applied. You need '--stm'")
func = globals()[op.opname]
return func(funcgen, op)
diff --git a/pypy/translator/stm/src_stm/et.c b/pypy/translator/stm/src_stm/et.c
--- a/pypy/translator/stm/src_stm/et.c
+++ b/pypy/translator/stm/src_stm/et.c
@@ -22,7 +22,8 @@
#include "src_stm/et.h"
#include "src_stm/atomic_ops.h"
-#ifdef RPY_STM_ASSERT
+#ifdef PYPY_STANDALONE /* obscure: cannot include debug_print.h if compiled */
+# define RPY_STM_DEBUG_PRINT /* via ll2ctypes; only include it in normal builds */
# include "src/debug_print.h"
#endif
@@ -346,18 +347,22 @@
/* mutex: only to avoid busy-looping too much in tx_spinloop() below */
static pthread_mutex_t mutex_inevitable = PTHREAD_MUTEX_INITIALIZER;
# ifdef RPY_STM_ASSERT
+unsigned long locked_by = 0;
void mutex_lock(void)
{
unsigned long pself = (unsigned long)pthread_self();
if (PYPY_HAVE_DEBUG_PRINTS) fprintf(PYPY_DEBUG_FILE,
"%lx: mutex inev locking...\n", pself);
+ assert(locked_by != pself);
pthread_mutex_lock(&mutex_inevitable);
+ locked_by = pself;
if (PYPY_HAVE_DEBUG_PRINTS) fprintf(PYPY_DEBUG_FILE,
"%lx: mutex inev locked\n", pself);
}
void mutex_unlock(void)
{
unsigned long pself = (unsigned long)pthread_self();
+ locked_by = 0;
pthread_mutex_unlock(&mutex_inevitable);
if (PYPY_HAVE_DEBUG_PRINTS) fprintf(PYPY_DEBUG_FILE,
"%lx: mutex inev unlocked\n", pself);
@@ -577,9 +582,6 @@
void stm_descriptor_init(void)
{
-#ifdef RPY_STM_ASSERT
- PYPY_DEBUG_START("stm-init");
-#endif
if (thread_descriptor != NULL)
thread_descriptor->init_counter++;
else
@@ -587,6 +589,10 @@
struct tx_descriptor *d = malloc(sizeof(struct tx_descriptor));
memset(d, 0, sizeof(struct tx_descriptor));
+#ifdef RPY_STM_DEBUG_PRINT
+ PYPY_DEBUG_START("stm-init");
+#endif
+
/* initialize 'my_lock_word' to be a unique negative number */
d->my_lock_word = (owner_version_t)d;
if (!IS_LOCKED(d->my_lock_word))
@@ -596,10 +602,13 @@
d->init_counter = 1;
thread_descriptor = d;
+
+#ifdef RPY_STM_DEBUG_PRINT
+ if (PYPY_HAVE_DEBUG_PRINTS) fprintf(PYPY_DEBUG_FILE, "thread %lx starting\n",
+ d->my_lock_word);
+ PYPY_DEBUG_STOP("stm-init");
+#endif
}
-#ifdef RPY_STM_ASSERT
- PYPY_DEBUG_STOP("stm-init");
-#endif
}
void stm_descriptor_done(void)
@@ -611,7 +620,7 @@
thread_descriptor = NULL;
-#ifdef RPY_STM_ASSERT
+#ifdef RPY_STM_DEBUG_PRINT
PYPY_DEBUG_START("stm-done");
if (PYPY_HAVE_DEBUG_PRINTS) {
int num_aborts = 0, num_spinloops = 0;
@@ -816,6 +825,10 @@
struct tx_descriptor *d = thread_descriptor;
unsigned long curtime;
+#ifdef RPY_STM_ASSERT
+ assert(!d->transaction_active);
+#endif
+
retry:
mutex_lock(); /* possibly waiting here */
diff --git a/pypy/translator/stm/test/targetdemo.py b/pypy/translator/stm/test/targetdemo.py
--- a/pypy/translator/stm/test/targetdemo.py
+++ b/pypy/translator/stm/test/targetdemo.py
@@ -4,7 +4,7 @@
NUM_THREADS = 4
-LENGTH = 1000
+LENGTH = 10000
class Node:
diff --git a/pypy/translator/stm/transform.py b/pypy/translator/stm/transform.py
--- a/pypy/translator/stm/transform.py
+++ b/pypy/translator/stm/transform.py
@@ -40,7 +40,7 @@
self.add_stm_declare_variable(graph)
if self.seen_gc_stack_bottom:
self.add_descriptor_init_stuff(graph)
- self.add_descriptor_init_stuff(entrypointgraph)
+ self.add_descriptor_init_stuff(entrypointgraph, main=True)
self.translator.stm_transformation_applied = True
def transform_block(self, block):
@@ -71,9 +71,13 @@
for block in graph.iterblocks():
self.transform_block(block)
- def add_descriptor_init_stuff(self, graph):
- f_init = _rffi_stm.descriptor_init_and_being_inevitable_transaction
- f_done = _rffi_stm.commit_transaction_and_descriptor_done
+ def add_descriptor_init_stuff(self, graph, main=False):
+ if main:
+ f_init = _rffi_stm.descriptor_init_and_being_inevitable_transaction
+ f_done = _rffi_stm.commit_transaction_and_descriptor_done
+ else:
+ f_init = _rffi_stm.descriptor_init
+ f_done = _rffi_stm.descriptor_done
c_init = Constant(f_init, lltype.typeOf(f_init))
c_done = Constant(f_done, lltype.typeOf(f_done))
#
@@ -108,7 +112,7 @@
if STRUCT._immutable_field(op.args[1].value):
op1 = op
elif STRUCT._gckind == 'raw':
- turn_inevitable(newoperations, "getfield_raw")
+ turn_inevitable(newoperations, "getfield-raw")
op1 = op
else:
op1 = SpaceOperation('stm_getfield', op.args, op.result)
@@ -119,7 +123,7 @@
if STRUCT._immutable_field(op.args[1].value):
op1 = op
elif STRUCT._gckind == 'raw':
- turn_inevitable(newoperations, "setfield_raw")
+ turn_inevitable(newoperations, "setfield-raw")
op1 = op
else:
op1 = SpaceOperation('stm_setfield', op.args, op.result)
More information about the pypy-commit
mailing list