Author: Remi Meier <remi.me...@inf.ethz.ch> Branch: stmgc-c8-gcc Changeset: r78702:5af34e2240be Date: 2015-07-29 11:42 +0200 http://bitbucket.org/pypy/pypy/changeset/5af34e2240be/
Log: import stmgc diff --git a/rpython/translator/stm/src_stm/revision b/rpython/translator/stm/src_stm/revision --- a/rpython/translator/stm/src_stm/revision +++ b/rpython/translator/stm/src_stm/revision @@ -1,1 +1,1 @@ -088f807586c2 +36aff8ee0d87 diff --git a/rpython/translator/stm/src_stm/stm/core.c b/rpython/translator/stm/src_stm/stm/core.c --- a/rpython/translator/stm/src_stm/stm/core.c +++ b/rpython/translator/stm/src_stm/stm/core.c @@ -615,7 +615,8 @@ new = _create_commit_log_entry(); if (STM_PSEGMENT->transaction_state == TS_INEVITABLE) { - assert(_stm_detached_inevitable_from_thread == 0); /* running it */ + assert(_stm_detached_inevitable_from_thread == 0 /* running it */ + || _stm_detached_inevitable_from_thread == -1); /* committing external */ old = STM_PSEGMENT->last_commit_log_entry; new->rev_num = old->rev_num + 1; @@ -1336,6 +1337,14 @@ push_large_overflow_objects_to_other_segments(); /* push before validate. otherwise they are reachable too early */ + + /* before releasing _stm_detached_inevitable_from_thread, perform + the commit. Otherwise, the same thread whose (inev) transaction we try + to commit here may start a new one in another segment *but* w/o + the committed data from its previous inev transaction. */ + bool was_inev = STM_PSEGMENT->transaction_state == TS_INEVITABLE; + _validate_and_add_to_commit_log(); + if (external) { /* from this point on, unlink the original 'stm_thread_local_t *' from its segment. Better do it as soon as possible, because @@ -1347,8 +1356,6 @@ _stm_detached_inevitable_from_thread = 0; } - bool was_inev = STM_PSEGMENT->transaction_state == TS_INEVITABLE; - _validate_and_add_to_commit_log(); if (!was_inev) { assert(!external); diff --git a/rpython/translator/stm/src_stm/stm/detach.c b/rpython/translator/stm/src_stm/stm/detach.c --- a/rpython/translator/stm/src_stm/stm/detach.c +++ b/rpython/translator/stm/src_stm/stm/detach.c @@ -122,6 +122,9 @@ dprintf(("reattach_transaction: commit detached from seg %d\n", remote_seg_num)); + assert(tl != old_tl); + + // XXX: not sure if the next line is a good idea tl->last_associated_segment_num = remote_seg_num; ensure_gs_register(remote_seg_num); commit_external_inevitable_transaction(); @@ -135,6 +138,7 @@ { dprintf(("> stm_force_transaction_break()\n")); assert(STM_SEGMENT->running_thread == tl); + assert(!stm_is_atomic(tl)); _stm_commit_transaction(); _stm_start_transaction(tl); } @@ -180,14 +184,9 @@ dprintf(("commit_fetched_detached_transaction from seg %d\n", segnum)); assert(segnum > 0); - if (segnum != mysegnum) { - set_gs_register(get_segment_base(segnum)); - } + ensure_gs_register(segnum); commit_external_inevitable_transaction(); - - if (segnum != mysegnum) { - set_gs_register(get_segment_base(mysegnum)); - } + ensure_gs_register(mysegnum); } static void commit_detached_transaction_if_from(stm_thread_local_t *tl) diff --git a/rpython/translator/stm/src_stm/stm/forksupport.c b/rpython/translator/stm/src_stm/stm/forksupport.c --- a/rpython/translator/stm/src_stm/stm/forksupport.c +++ b/rpython/translator/stm/src_stm/stm/forksupport.c @@ -87,7 +87,7 @@ assert(tl->last_associated_segment_num == i); assert(in_transaction(tl)); assert(pr->transaction_state != TS_INEVITABLE); - set_gs_register(get_segment_base(i)); + ensure_gs_register(i); assert(STM_SEGMENT->segment_num == i); s_mutex_lock(); @@ -155,7 +155,7 @@ int segnum = fork_this_tl->last_associated_segment_num; assert(1 <= segnum && segnum < NB_SEGMENTS); *_get_cpth(fork_this_tl) = pthread_self(); - set_gs_register(get_segment_base(segnum)); + ensure_gs_register(segnum); assert(STM_SEGMENT->segment_num == segnum); if (!fork_was_in_transaction) { diff --git a/rpython/translator/stm/src_stm/stm/nursery.c b/rpython/translator/stm/src_stm/stm/nursery.c --- a/rpython/translator/stm/src_stm/stm/nursery.c +++ b/rpython/translator/stm/src_stm/stm/nursery.c @@ -723,7 +723,7 @@ /* including the sharing seg0 */ for (i = 0; i < NB_SEGMENTS; i++) { - set_gs_register(get_segment_base(i)); + ensure_gs_register(i); bool ok = _stm_validate(); assert(get_priv_segment(i)->last_commit_log_entry->next == NULL @@ -769,7 +769,7 @@ } } - set_gs_register(get_segment_base(original_num)); + ensure_gs_register(original_num); } diff --git a/rpython/translator/stm/src_stm/stm/sync.c b/rpython/translator/stm/src_stm/stm/sync.c --- a/rpython/translator/stm/src_stm/stm/sync.c +++ b/rpython/translator/stm/src_stm/stm/sync.c @@ -66,7 +66,6 @@ static void ensure_gs_register(long segnum) { - /* XXX use this instead of set_gs_register() in many places */ if (STM_SEGMENT->segment_num != segnum) { set_gs_register(get_segment_base(segnum)); assert(STM_SEGMENT->segment_num == segnum); @@ -211,16 +210,12 @@ assert(_has_mutex()); assert(_is_tl_registered(tl)); - int num = tl->last_associated_segment_num - 1; // 0..NB_SEG-1 + int num = tl->last_associated_segment_num - 1; // 0..NB_SEG-2 OPT_ASSERT(num >= 0); if (sync_ctl.in_use1[num+1] == 0) { /* fast-path: we can get the same segment number than the one - we had before. The value stored in GS is still valid. */ -#ifdef STM_TESTS - /* that can be optimized away, except during tests, because - they use only one thread */ - set_gs_register(get_segment_base(num+1)); -#endif + we had before. The value stored in GS may still be valid. */ + ensure_gs_register(num+1); dprintf(("acquired same segment: %d\n", num+1)); goto got_num; } @@ -234,7 +229,7 @@ int old_num = tl->last_associated_segment_num; dprintf(("acquired different segment: %d->%d\n", old_num, num+1)); tl->last_associated_segment_num = num+1; - set_gs_register(get_segment_base(num+1)); + ensure_gs_register(num+1); dprintf((" %d->%d\n", old_num, num+1)); (void)old_num; goto got_num; @@ -313,14 +308,14 @@ void _stm_test_switch(stm_thread_local_t *tl) { assert(_stm_in_transaction(tl)); - set_gs_register(get_segment_base(tl->last_associated_segment_num)); + ensure_gs_register(tl->last_associated_segment_num); assert(STM_SEGMENT->running_thread == tl); exec_local_finalizers(); } void _stm_test_switch_segment(int segnum) { - set_gs_register(get_segment_base(segnum+1)); + ensure_gs_register(segnum+1); } #if STM_TESTS diff --git a/rpython/translator/stm/src_stm/stmgcintf.c b/rpython/translator/stm/src_stm/stmgcintf.c --- a/rpython/translator/stm/src_stm/stmgcintf.c +++ b/rpython/translator/stm/src_stm/stmgcintf.c @@ -3,7 +3,7 @@ of PyPy's #defines and #includes prepended. */ __thread -struct stm_thread_local_s stm_thread_local __attribute__((aligned(64))); +struct stm_thread_local_s stm_thread_local __attribute__((aligned(64))) = {0}; extern Signed pypy_stmcb_size_rounded_up(void*); _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit