[pypy-commit] pypy stm-thread: fix fix fix
arigo
noreply at buildbot.pypy.org
Sat May 5 17:21:54 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: stm-thread
Changeset: r54899:2f769f82169c
Date: 2012-05-04 21:40 +0200
http://bitbucket.org/pypy/pypy/changeset/2f769f82169c/
Log: fix fix fix
diff --git a/pypy/rlib/rstm.py b/pypy/rlib/rstm.py
--- a/pypy/rlib/rstm.py
+++ b/pypy/rlib/rstm.py
@@ -2,12 +2,12 @@
def before_external_call():
- stmgcintf.StmOperations.before_external_call()
+ stmgcintf.StmOperations.commit_transaction()
before_external_call._gctransformer_hint_cannot_collect_ = True
before_external_call._dont_reach_me_in_del_ = True
def after_external_call():
- stmgcintf.StmOperations.after_external_call()
+ stmgcintf.StmOperations.begin_inevitable_transaction()
after_external_call._gctransformer_hint_cannot_collect_ = True
after_external_call._dont_reach_me_in_del_ = True
diff --git a/pypy/rpython/memory/gc/stmtls.py b/pypy/rpython/memory/gc/stmtls.py
--- a/pypy/rpython/memory/gc/stmtls.py
+++ b/pypy/rpython/memory/gc/stmtls.py
@@ -337,8 +337,6 @@
# detect_flag_combination is GCFLAG_WAS_COPIED|GCFLAG_VISITED.
# This case is to force pointers to the LOCAL copy to be
# replaced with pointers to the GLOBAL copy.
- ll_assert(not self.in_main_thread,
- "unexpected flag combination in the main thread")
return 2
if can_be_in_nursery and self.is_in_nursery(obj):
diff --git a/pypy/rpython/memory/gctransform/stmframework.py b/pypy/rpython/memory/gctransform/stmframework.py
--- a/pypy/rpython/memory/gctransform/stmframework.py
+++ b/pypy/rpython/memory/gctransform/stmframework.py
@@ -12,45 +12,34 @@
class StmFrameworkGCTransformer(FrameworkGCTransformer):
def _declare_functions(self, GCClass, getfn, s_gc, *args):
+ gc = self.gcdata.gc
#
- def thread_starting(gc):
+ def gc_thread_start():
self.root_walker.allocate_shadow_stack()
gc.setup_thread()
#
- def thread_stopping(gc):
+ def gc_thread_die():
gc.teardown_thread()
self.root_walker.free_shadow_stack()
#
- def start_transaction(gc):
- self.root_walker.start_transaction()
- gc.start_transaction()
+ #def start_transaction(gc):
+ # self.root_walker.start_transaction()
+ # gc.start_transaction()
#
super(StmFrameworkGCTransformer, self)._declare_functions(
GCClass, getfn, s_gc, *args)
- self.thread_starting_ptr = getfn(
- thread_starting,
- [s_gc], annmodel.s_None)
- self.thread_stopping_ptr = getfn(
- thread_stopping,
- [s_gc], annmodel.s_None)
+ self.thread_start_ptr = getfn(
+ gc_thread_start,
+ [], annmodel.s_None)
+ self.thread_die_ptr = getfn(
+ gc_thread_die,
+ [], annmodel.s_None)
self.stm_writebarrier_ptr = getfn(
- self.gcdata.gc.stm_writebarrier,
+ gc.stm_writebarrier,
[annmodel.SomeAddress()], annmodel.SomeAddress())
self.stm_normalize_global_ptr = getfn(
- self.gcdata.gc.stm_normalize_global,
+ gc.stm_normalize_global,
[annmodel.SomeAddress()], annmodel.SomeAddress())
- self.stm_enter_transactional_mode_ptr = getfn(
- self.gcdata.gc.enter_transactional_mode.im_func,
- [s_gc], annmodel.s_None)
- self.stm_leave_transactional_mode_ptr = getfn(
- self.gcdata.gc.leave_transactional_mode.im_func,
- [s_gc], annmodel.s_None)
- self.stm_start_ptr = getfn(
- start_transaction,
- [s_gc], annmodel.s_None)
- self.stm_stop_ptr = getfn(
- self.gcdata.gc.stop_transaction.im_func,
- [s_gc], annmodel.s_None)
def build_root_walker(self):
return StmShadowStackRootWalker(self)
@@ -159,6 +148,11 @@
if rsd is not None:
self.root_stack_depth = rsd
+ def need_thread_support(self, gctransformer, getfn):
+ # we always have thread support, and it is handled
+ # in _declare_functions() already
+ pass
+
def setup_root_walker(self):
self.allocate_shadow_stack()
self.gcdata.main_thread_stack_base = self.stackgcdata.root_stack_base
diff --git a/pypy/translator/stm/src_stm/core.c b/pypy/translator/stm/src_stm/core.c
--- a/pypy/translator/stm/src_stm/core.c
+++ b/pypy/translator/stm/src_stm/core.c
@@ -404,10 +404,6 @@
owner_version_t ovt; \
\
assert(sizeof(TYPE) == SIZE); \
- /* XXX try to remove this check from the main path: */ \
- /* d is NULL when running in the main thread */ \
- if (d == NULL) \
- return *(TYPE *)(((char *)addr) + offset); \
\
if ((GETTID(o) & GCFLAG_WAS_COPIED) != 0) \
{ \
@@ -439,8 +435,6 @@
volatile orec_t *o = get_orec(src);
owner_version_t ovt;
- assert(d != NULL);
-
/* don't copy the header */
src = ((char *)src) + sizeof(orec_t);
dst = ((char *)dst) + sizeof(orec_t);
@@ -449,14 +443,10 @@
STM_DO_READ(memcpy(dst, src, size));
}
-static void descriptor_init(long in_main_thread)
+static void descriptor_init(void)
{
assert(thread_descriptor == NULL);
- if (in_main_thread)
- {
- /* the main thread doesn't have a thread_descriptor at all */
- }
- else
+ if (1)
{
struct tx_descriptor *d = malloc(sizeof(struct tx_descriptor));
memset(d, 0, sizeof(struct tx_descriptor));
@@ -485,8 +475,7 @@
static void descriptor_done(void)
{
struct tx_descriptor *d = thread_descriptor;
- if (d == NULL)
- return;
+ assert(d != NULL);
thread_descriptor = NULL;
@@ -527,13 +516,32 @@
static void begin_transaction(jmp_buf* buf)
{
struct tx_descriptor *d = thread_descriptor;
- /* you need to call descriptor_init() before calling this */
- assert(d != NULL);
d->setjmp_buf = buf;
d->start_time = (/*d->last_known_global_timestamp*/ global_timestamp) & ~1;
}
-static void commit_transaction(void)
+void stm_begin_inevitable_transaction(void)
+{
+ /* Equivalent to begin_transaction(); stm_try_inevitable();
+ except more efficient */
+ struct tx_descriptor *d = thread_descriptor;
+ d->setjmp_buf = NULL;
+
+ while (1)
+ {
+ mutex_lock();
+ unsigned long curtime = get_global_timestamp(d) & ~1;
+ if (change_global_timestamp(d, curtime, curtime + 1))
+ {
+ d->start_time = curtime;
+ break;
+ }
+ mutex_unlock();
+ tx_spinloop(6);
+ }
+}
+
+void stm_commit_transaction(void)
{
struct tx_descriptor *d = thread_descriptor;
assert(d != NULL);
@@ -604,8 +612,6 @@
by another thread. We set the lowest bit in global_timestamp
to 1. */
struct tx_descriptor *d = thread_descriptor;
- if (d == NULL)
- return; /* I am running in the main thread */
if (is_inevitable(d))
return; /* I am already inevitable */
@@ -632,13 +638,14 @@
in try_inevitable() very soon)? unclear. For now
let's try to spinloop, after the waiting done by
acquiring the mutex */
- mutex_unlock();
- tx_spinloop(6);
- continue;
}
- if (change_global_timestamp(d, curtime, curtime + 1))
- break;
+ else
+ {
+ if (change_global_timestamp(d, curtime, curtime + 1))
+ break;
+ }
mutex_unlock();
+ tx_spinloop(6);
}
d->setjmp_buf = NULL; /* inevitable from now on */
#ifdef RPY_STM_DEBUG_PRINT
@@ -656,16 +663,14 @@
long stm_thread_id(void)
{
struct tx_descriptor *d = thread_descriptor;
- if (d == NULL)
- return 0; /* no thread_descriptor: it's the main thread */
return d->my_lock_word;
}
static __thread void *rpython_tls_object;
-void stm_set_tls(void *newtls, long in_main_thread)
+void stm_set_tls(void *newtls)
{
- descriptor_init(in_main_thread);
+ descriptor_init();
rpython_tls_object = newtls;
}
@@ -709,12 +714,6 @@
} REDOLOG_LOOP_END;
}
-long stm_in_transaction(void)
-{
- struct tx_descriptor *d = thread_descriptor;
- return d != NULL;
-}
-
#undef GETVERSION
#undef GETVERSIONREF
#undef SETVERSION
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
@@ -54,6 +54,5 @@
#include "src_stm/lists.c"
#include "src_stm/core.c"
-#include "src_stm/rpyintf.c"
/************************************************************/
diff --git a/pypy/translator/stm/src_stm/et.h b/pypy/translator/stm/src_stm/et.h
--- a/pypy/translator/stm/src_stm/et.h
+++ b/pypy/translator/stm/src_stm/et.h
@@ -12,10 +12,7 @@
/* see comments in ../stmgcintf.py */
-long stm_in_transaction(void);
-void stm_run_all_transactions(void*, long);
-
-void stm_set_tls(void *, long);
+void stm_set_tls(void *);
void *stm_get_tls(void);
void stm_del_tls(void);
long stm_thread_id(void);
@@ -24,6 +21,9 @@
void stm_tldict_add(void *, void *);
void stm_tldict_enum(void);
+void stm_begin_inevitable_transaction(void);
+void stm_commit_transaction(void);
+
/* these functions are declared by generated C code from pypy.rlib.rstm
and from the GC (see llop.nop(...)) */
extern void pypy_g__stm_thread_starting(void);
diff --git a/pypy/translator/stm/stmgcintf.py b/pypy/translator/stm/stmgcintf.py
--- a/pypy/translator/stm/stmgcintf.py
+++ b/pypy/translator/stm/stmgcintf.py
@@ -47,17 +47,17 @@
# C part of the implementation of the pypy.rlib.rstm module
in_transaction = smexternal('stm_in_transaction', [], lltype.Signed)
- before_external_call = smexternal('stm_before_external_call',
- [], lltype.Void)
- after_external_call = smexternal('stm_after_external_call',
- [], lltype.Void)
+ is_inevitable = smexternal('stm_is_inevitable', [], lltype.Signed)
+ begin_inevitable_transaction = smexternal(
+ 'stm_begin_inevitable_transaction', [], lltype.Void)
+ commit_transaction = smexternal(
+ 'stm_commit_transaction', [], lltype.Void)
do_yield_thread = smexternal('stm_do_yield_thread',
[], lltype.Void)
# for the GC: store and read a thread-local-storage field, as well
# as initialize and shut down the internal thread_descriptor
- set_tls = smexternal('stm_set_tls', [llmemory.Address, lltype.Signed],
- lltype.Void)
+ set_tls = smexternal('stm_set_tls', [llmemory.Address], lltype.Void)
get_tls = smexternal('stm_get_tls', [], llmemory.Address)
del_tls = smexternal('stm_del_tls', [], lltype.Void)
diff --git a/pypy/translator/stm/test/targetdemo2.py b/pypy/translator/stm/test/targetdemo2.py
--- a/pypy/translator/stm/test/targetdemo2.py
+++ b/pypy/translator/stm/test/targetdemo2.py
@@ -63,15 +63,12 @@
def run(self):
try:
- self.really_run()
+ for value in range(glob.LENGTH):
+ add_at_end_of_chained_list(glob.anchor, value, self.index)
+ #rstm.do_yield_thread()
finally:
self.finished_lock.release()
- def really_run(self):
- for value in range(glob.LENGTH):
- add_at_end_of_chained_list(glob.anchor, value, self.index)
- rstm.do_yield_thread()
-
# ____________________________________________________________
# bah, we are really missing an RPython interface to threads
More information about the pypy-commit
mailing list