[pypy-commit] pypy stmgc-c8-gil-like: Yay, the first ztranslation test passes
arigo
noreply at buildbot.pypy.org
Fri Jun 12 19:00:35 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c8-gil-like
Changeset: r78049:1fd7822491a3
Date: 2015-06-12 19:00 +0200
http://bitbucket.org/pypy/pypy/changeset/1fd7822491a3/
Log: Yay, the first ztranslation test passes
diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py
--- a/rpython/rlib/rstm.py
+++ b/rpython/rlib/rstm.py
@@ -43,10 +43,10 @@
adr_pypy__rewind_jmp_copy_stack_slice = (
CFlexSymbolic('((long)&pypy__rewind_jmp_copy_stack_slice)'))
-adr_pypy_stm_commit_if_not_atomic = (
- CFlexSymbolic('((long)&pypy_stm_commit_if_not_atomic)'))
-adr_pypy_stm_start_if_not_atomic = (
- CFlexSymbolic('((long)&pypy_stm_start_if_not_atomic)'))
+#adr_pypy_stm_commit_if_not_atomic = (
+# CFlexSymbolic('((long)&pypy_stm_commit_if_not_atomic)'))
+#adr_pypy_stm_start_if_not_atomic = (
+# CFlexSymbolic('((long)&pypy_stm_start_if_not_atomic)'))
def rewind_jmp_frame():
@@ -123,16 +123,14 @@
@dont_look_inside
def before_external_call():
if we_are_translated():
- # this tries to commit, or becomes inevitable if atomic
- llop.stm_commit_if_not_atomic(lltype.Void)
+ llop.stm_leave_transactional_zone(lltype.Void)
before_external_call._dont_reach_me_in_del_ = True
before_external_call._transaction_break_ = True
@dont_look_inside
def after_external_call():
if we_are_translated():
- # starts a new transaction if we are not atomic already
- llop.stm_start_if_not_atomic(lltype.Void)
+ llop.stm_enter_transactional_zone(lltype.Void)
after_external_call._dont_reach_me_in_del_ = True
after_external_call._transaction_break_ = True
diff --git a/rpython/rtyper/llinterp.py b/rpython/rtyper/llinterp.py
--- a/rpython/rtyper/llinterp.py
+++ b/rpython/rtyper/llinterp.py
@@ -969,8 +969,8 @@
op_stm_push_root = _stm_not_implemented
op_stm_pop_root_into = _stm_not_implemented
op_stm_get_root_stack_top = _stm_not_implemented
- op_stm_start_if_not_atomic = _stm_not_implemented
- op_stm_commit_if_not_atomic = _stm_not_implemented
+ op_stm_enter_transactional_zone = _stm_not_implemented
+ op_stm_leave_transactional_zone = _stm_not_implemented
op_stm_enter_callback_call = _stm_not_implemented
op_stm_leave_callback_call = _stm_not_implemented
op_stm_get_atomic = _stm_not_implemented
diff --git a/rpython/rtyper/lltypesystem/lloperation.py b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -434,8 +434,8 @@
'stm_become_inevitable': LLOp(canmallocgc=True),
'stm_push_root': LLOp(),
'stm_pop_root_into': LLOp(),
- 'stm_commit_if_not_atomic': LLOp(canmallocgc=True),
- 'stm_start_if_not_atomic': LLOp(canmallocgc=True),
+ 'stm_enter_transactional_zone': LLOp(canmallocgc=True),
+ 'stm_leave_transactional_zone': LLOp(canmallocgc=True),
'stm_abort_and_retry': LLOp(canmallocgc=True),
'stm_enter_callback_call': LLOp(canmallocgc=True),
'stm_leave_callback_call': LLOp(),
diff --git a/rpython/translator/stm/breakfinder.py b/rpython/translator/stm/breakfinder.py
--- a/rpython/translator/stm/breakfinder.py
+++ b/rpython/translator/stm/breakfinder.py
@@ -3,8 +3,8 @@
TRANSACTION_BREAK = set([
- 'stm_commit_if_not_atomic',
- 'stm_start_if_not_atomic',
+ 'stm_enter_transactional_zone',
+ 'stm_leave_transactional_zone',
#'jit_assembler_call',
'stm_enter_callback_call',
'stm_leave_callback_call',
diff --git a/rpython/translator/stm/funcgen.py b/rpython/translator/stm/funcgen.py
--- a/rpython/translator/stm/funcgen.py
+++ b/rpython/translator/stm/funcgen.py
@@ -44,7 +44,7 @@
def stm_hint_commit_soon(funcgen, op):
- return 'stmcb_commit_soon();'
+ return '/* stmcb_commit_soon(); XXX */'
def stm_register_thread_local(funcgen, op):
return 'pypy_stm_register_thread_local();'
@@ -166,7 +166,7 @@
except AttributeError:
pass
string_literal = c_string_constant(info)
- return 'pypy_stm_become_inevitable(%s);' % (string_literal,)
+ return 'stm_become_inevitable(&stm_thread_local, %s);' % (string_literal,)
def stm_stop_all_other_threads(funcgen, op):
return 'stm_stop_all_other_threads();'
@@ -184,11 +184,11 @@
return '/* %s = */ STM_POP_ROOT_RET(stm_thread_local);' % (arg0,)
return 'STM_POP_ROOT(stm_thread_local, %s);' % (arg0,)
-def stm_commit_if_not_atomic(funcgen, op):
- return 'pypy_stm_commit_if_not_atomic();'
+def stm_enter_transactional_zone(funcgen, op):
+ return 'stm_enter_transactional_zone(&stm_thread_local);'
-def stm_start_if_not_atomic(funcgen, op):
- return 'pypy_stm_start_if_not_atomic();'
+def stm_leave_transactional_zone(funcgen, op):
+ return 'stm_leave_transactional_zone(&stm_thread_local);'
def stm_enter_callback_call(funcgen, op):
arg0 = funcgen.expr(op.args[0])
@@ -202,24 +202,23 @@
def stm_should_break_transaction(funcgen, op):
result = funcgen.expr(op.result)
- return '%s = pypy_stm_should_break_transaction();' % (result,)
+ return '%s = stm_should_break_transaction();' % (result,)
def stm_set_transaction_length(funcgen, op):
arg0 = funcgen.expr(op.args[0])
- return 'pypy_stm_set_transaction_length(%s);' % (arg0,)
+ return 'stm_fill_mark_nursery_bytes = %s;' % (arg0,)
def stm_transaction_break(funcgen, op):
- return 'pypy_stm_transaction_break();'
+ return 'stm_force_transaction_break(&stm_thread_local);'
def stm_increment_atomic(funcgen, op):
- return 'pypy_stm_increment_atomic();'
+ XXX
def stm_decrement_atomic(funcgen, op):
- return 'pypy_stm_decrement_atomic();'
+ XXX
def stm_get_atomic(funcgen, op):
- result = funcgen.expr(op.result)
- return '%s = pypy_stm_get_atomic();' % (result,)
+ XXX
def stm_is_inevitable(funcgen, op):
result = funcgen.expr(op.result)
diff --git a/rpython/translator/stm/src_stm/extracode.h b/rpython/translator/stm/src_stm/extracode.h
--- a/rpython/translator/stm/src_stm/extracode.h
+++ b/rpython/translator/stm/src_stm/extracode.h
@@ -47,6 +47,7 @@
void pypy_stm_unregister_thread_local(void)
{
stm_unregister_thread_local(&stm_thread_local);
+ stm_thread_local.shadowstack_base = NULL;
}
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 @@
-bf0dfe206de5
+5af967809206
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
@@ -1154,7 +1154,7 @@
#endif
STM_PSEGMENT->shadowstack_at_start_of_transaction = tl->shadowstack;
STM_PSEGMENT->threadlocal_at_start_of_transaction = tl->thread_local_obj;
-
+ STM_PSEGMENT->total_throw_away_nursery = 0;
assert(list_is_empty(STM_PSEGMENT->modified_old_objects));
assert(list_is_empty(STM_PSEGMENT->large_overflow_objects));
@@ -1195,15 +1195,26 @@
stm_validate();
}
+#ifdef STM_NO_AUTOMATIC_SETJMP
+static int did_abort = 0;
+#endif
+
long _stm_start_transaction(stm_thread_local_t *tl)
{
s_mutex_lock();
#ifdef STM_NO_AUTOMATIC_SETJMP
- long repeat_count = 0; /* test/support.py */
+ long repeat_count = did_abort; /* test/support.py */
+ did_abort = 0;
#else
long repeat_count = stm_rewind_jmp_setjmp(tl);
#endif
_do_start_transaction(tl);
+
+ if (repeat_count == 0) { /* else, 'nursery_mark' was already set
+ in abort_data_structures_from_segment_num() */
+ STM_SEGMENT->nursery_mark = ((stm_char *)_stm_nursery_start +
+ stm_fill_mark_nursery_bytes);
+ }
return repeat_count;
}
@@ -1427,7 +1438,7 @@
abort_finalizers(pseg);
- long bytes_in_nursery = throw_away_nursery(pseg);
+ throw_away_nursery(pseg);
/* clear CARD_MARKED on objs (don't care about CARD_MARKED_OLD) */
LIST_FOREACH_R(pseg->old_objects_with_cards_set, object_t * /*item*/,
@@ -1461,7 +1472,26 @@
assert(tl->shadowstack == pseg->shadowstack_at_start_of_transaction);
#endif
tl->thread_local_obj = pseg->threadlocal_at_start_of_transaction;
- tl->last_abort__bytes_in_nursery = bytes_in_nursery;
+
+
+ /* Set the next nursery_mark: first compute the value that
+ nursery_mark must have had at the start of the aborted transaction */
+ stm_char *old_mark =pseg->pub.nursery_mark + pseg->total_throw_away_nursery;
+
+ /* This means that the limit, in term of bytes, was: */
+ uintptr_t old_limit = old_mark - (stm_char *)_stm_nursery_start;
+
+ /* If 'total_throw_away_nursery' is smaller than old_limit, use that */
+ if (pseg->total_throw_away_nursery < old_limit)
+ old_limit = pseg->total_throw_away_nursery;
+
+ /* Now set the new limit to 90% of the old limit */
+ pseg->pub.nursery_mark = ((stm_char *)_stm_nursery_start +
+ (uintptr_t)(old_limit * 0.9));
+
+#ifdef STM_NO_AUTOMATIC_SETJMP
+ did_abort = 1;
+#endif
list_clear(pseg->objects_pointing_to_nursery);
list_clear(pseg->old_objects_with_cards_set);
diff --git a/rpython/translator/stm/src_stm/stm/core.h b/rpython/translator/stm/src_stm/stm/core.h
--- a/rpython/translator/stm/src_stm/stm/core.h
+++ b/rpython/translator/stm/src_stm/stm/core.h
@@ -152,6 +152,9 @@
stm_char *sq_fragments[SYNC_QUEUE_SIZE];
int sq_fragsizes[SYNC_QUEUE_SIZE];
int sq_len;
+
+ /* For nursery_mark */
+ uintptr_t total_throw_away_nursery;
};
enum /* safe_point */ {
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
@@ -11,8 +11,13 @@
static uintptr_t _stm_nursery_start;
+#define DEFAULT_FILL_MARK_NURSERY_BYTES (NURSERY_SIZE / 4)
+
+uintptr_t stm_fill_mark_nursery_bytes = DEFAULT_FILL_MARK_NURSERY_BYTES;
+
/************************************************************/
+
static void setup_nursery(void)
{
assert(_STM_FAST_ALLOC <= NURSERY_SIZE);
@@ -449,7 +454,7 @@
}
-static size_t throw_away_nursery(struct stm_priv_segment_info_s *pseg)
+static void throw_away_nursery(struct stm_priv_segment_info_s *pseg)
{
#pragma push_macro("STM_PSEGMENT")
#pragma push_macro("STM_SEGMENT")
@@ -482,7 +487,9 @@
#endif
#endif
+ pseg->total_throw_away_nursery += nursery_used;
pseg->pub.nursery_current = (stm_char *)_stm_nursery_start;
+ pseg->pub.nursery_mark -= nursery_used;
/* free any object left from 'young_outside_nursery' */
if (!tree_is_cleared(pseg->young_outside_nursery)) {
@@ -507,8 +514,6 @@
}
tree_clear(pseg->nursery_objects_shadows);
-
- return nursery_used;
#pragma pop_macro("STM_SEGMENT")
#pragma pop_macro("STM_PSEGMENT")
}
diff --git a/rpython/translator/stm/src_stm/stm/nursery.h b/rpython/translator/stm/src_stm/stm/nursery.h
--- a/rpython/translator/stm/src_stm/stm/nursery.h
+++ b/rpython/translator/stm/src_stm/stm/nursery.h
@@ -12,7 +12,7 @@
static void minor_collection(bool commit, bool external);
static void check_nursery_at_transaction_start(void);
-static size_t throw_away_nursery(struct stm_priv_segment_info_s *pseg);
+static void throw_away_nursery(struct stm_priv_segment_info_s *pseg);
static void major_do_validation_and_minor_collections(void);
static void assert_memset_zero(void *s, size_t n);
diff --git a/rpython/translator/stm/src_stm/stmgc.h b/rpython/translator/stm/src_stm/stmgc.h
--- a/rpython/translator/stm/src_stm/stmgc.h
+++ b/rpython/translator/stm/src_stm/stmgc.h
@@ -44,6 +44,7 @@
int segment_num;
char *segment_base;
stm_char *nursery_current;
+ stm_char *nursery_mark;
uintptr_t nursery_end;
struct stm_thread_local_s *running_thread;
};
@@ -67,9 +68,6 @@
the following raw region of memory is cleared. */
char *mem_clear_on_abort;
size_t mem_bytes_to_clear_on_abort;
- /* after an abort, some details about the abort are stored there.
- (this field is not modified on a successful commit) */
- long last_abort__bytes_in_nursery;
/* the next fields are handled internally by the library */
int last_associated_segment_num; /* always a valid seg num */
int thread_local_counter;
@@ -459,7 +457,8 @@
stm_enter_transactional_zone(); however, it is supposed to be
called in CPU-heavy threads that had a transaction run for a while,
and so it *always* forces a commit and starts the next transaction.
- The new transaction is never inevitable. */
+ The new transaction is never inevitable. See also
+ stm_should_break_transaction(). */
void stm_force_transaction_break(stm_thread_local_t *tl);
/* Abort the currently running transaction. This function never
@@ -490,6 +489,23 @@
void stm_collect(long level);
+/* A way to detect that we've run for a while and should call
+ stm_force_transaction_break() */
+static inline int stm_should_break_transaction(void)
+{
+ return ((intptr_t)STM_SEGMENT->nursery_current >=
+ (intptr_t)STM_SEGMENT->nursery_mark);
+}
+extern uintptr_t stm_fill_mark_nursery_bytes;
+/* ^^^ at the start of a transaction, 'nursery_mark' is initialized to
+ 'stm_fill_mark_nursery_bytes' inside the nursery. This value can
+ be larger than the nursery; every minor collection shifts the
+ current 'nursery_mark' down by one nursery-size. After an abort
+ and restart, 'nursery_mark' is set to ~90% of the value it reached
+ in the last attempt.
+*/
+
+
/* Prepare an immortal "prebuilt" object managed by the GC. Takes a
pointer to an 'object_t', which should not actually be a GC-managed
structure but a real static structure. Returns the equivalent
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
@@ -2,13 +2,8 @@
/* This is not meant to be compiled stand-alone, but with all
of PyPy's #defines and #includes prepended. */
-__thread struct stm_thread_local_s stm_thread_local __attribute__((aligned(64)));
-
-/* 0 = not initialized; 1 = normal mode; 2 or more = atomic mode */
-__thread long pypy_stm_ready_atomic;
-__thread uintptr_t pypy_stm_nursery_low_fill_mark;
-__thread uintptr_t pypy_stm_nursery_low_fill_mark_saved;
-
+__thread
+struct stm_thread_local_s stm_thread_local __attribute__((aligned(64)));
extern Signed pypy_stmcb_size_rounded_up(void*);
@@ -43,19 +38,6 @@
pypy_stmcb_trace_cards(obj, (void(*)(void*))visit, start, stop);
}
-inline void stmcb_commit_soon()
-{
- if (pypy_stm_nursery_low_fill_mark == (uintptr_t)-1) {
- /* atomic */
- if (((long)pypy_stm_nursery_low_fill_mark_saved) > 0) {
- pypy_stm_nursery_low_fill_mark_saved = 0;
- }
- } else if (((long)pypy_stm_nursery_low_fill_mark) > 0) {
- /* if not set to unlimited by pypy_stm_setup() (s.b.) */
- pypy_stm_nursery_low_fill_mark = 0;
- }
-}
-
/************************************************************/
/* "include" the stmgc.c file here */
@@ -64,33 +46,22 @@
/************************************************************/
-#define LOW_FILL_MARK (NURSERY_SIZE / 2)
-
-static long pypy_transaction_length;
-
-
-void pypy_stm_set_transaction_length(double fraction)
-{
- /* the value '1.0' means 'use the default'. Other values are
- interpreted proportionally, up to some maximum. */
- long low_fill_mark = (long)(LOW_FILL_MARK * fraction);
- if (low_fill_mark > (long)(NURSERY_SIZE * 3 / 4))
- low_fill_mark = NURSERY_SIZE * 3 / 4;
- pypy_transaction_length = low_fill_mark;
-}
-
void pypy_stm_setup(void)
{
stm_setup();
pypy_stm_setup_prebuilt();
pypy_stm_register_thread_local();
- pypy_stm_ready_atomic = 1;
- /* set transaction length to unlimited until the first thread
- starts. pypy_stm_set_transaction_length will then be called
+ /* set transaction length to a very large limit until the first
+ thread starts. stm_set_transaction_length() will then be called
again by pypy. */
- pypy_stm_set_transaction_length(-10000.0);
- pypy_stm_start_inevitable_if_not_atomic();
+ stm_fill_mark_nursery_bytes = 1024 * NURSERY_SIZE;
+
+ rewind_jmp_buf rjbuf;
+ stm_rewind_jmp_enterframe(&stm_thread_local, &rjbuf);
+ stm_enter_transactional_zone(&stm_thread_local);
+ stm_become_inevitable(&stm_thread_local, "start-up");
+ stm_rewind_jmp_leaveframe(&stm_thread_local, &rjbuf);
}
void pypy_stm_teardown(void)
@@ -101,128 +72,48 @@
long pypy_stm_enter_callback_call(void *rjbuf)
{
- if (pypy_stm_ready_atomic == 0) {
+ if (stm_thread_local.shadowstack_base == NULL) {
/* first time we see this thread */
- assert(pypy_transaction_length >= 0);
int e = errno;
pypy_stm_register_thread_local();
stm_rewind_jmp_enterprepframe(&stm_thread_local,
(rewind_jmp_buf *)rjbuf);
errno = e;
- pypy_stm_ready_atomic = 1;
- pypy_stm_start_if_not_atomic();
+ stm_enter_transactional_zone(&stm_thread_local);
return 1;
}
else {
/* callback from C code, itself called from Python code */
stm_rewind_jmp_enterprepframe(&stm_thread_local,
(rewind_jmp_buf *)rjbuf);
- pypy_stm_start_if_not_atomic();
+ stm_enter_transactional_zone(&stm_thread_local);
return 0;
}
}
void pypy_stm_leave_callback_call(void *rjbuf, long token)
{
- int e = errno;
+ stm_leave_transactional_zone(&stm_thread_local);
+ stm_rewind_jmp_leaveframe(&stm_thread_local, (rewind_jmp_buf *)rjbuf);
+
if (token == 1) {
/* if we're returning into foreign C code that was not itself
called from Python code, then we're ignoring the atomic
status and committing anyway. */
- pypy_stm_ready_atomic = 1;
- stm_commit_transaction();
- pypy_stm_ready_atomic = 0;
- stm_rewind_jmp_leaveframe(&stm_thread_local, (rewind_jmp_buf *)rjbuf);
+ int e = errno;
pypy_stm_unregister_thread_local();
- }
- else {
- pypy_stm_commit_if_not_atomic();
- stm_rewind_jmp_leaveframe(&stm_thread_local, (rewind_jmp_buf *)rjbuf);
- }
- errno = e;
-}
-
-void _pypy_stm_initialize_nursery_low_fill_mark(long v_counter)
-{
- /* If v_counter==0, initialize 'pypy_stm_nursery_low_fill_mark'
- from the configured length limit. If v_counter>0, we did an
- abort, and we now configure 'pypy_stm_nursery_low_fill_mark'
- to a value slightly smaller than the value at last abort.
- */
- long counter, limit;
-#ifdef HTM_INFO_AVAILABLE
- if (_htm_info.use_gil)
- counter = 0; /* maybe we want the default size here... */
- else
- counter = _htm_info.retry_counter;
- limit = pypy_transaction_length >> counter;
-#else
- counter = v_counter;
-
- if (counter == 0) {
- limit = pypy_transaction_length;
- }
- else {
- limit = stm_thread_local.last_abort__bytes_in_nursery;
- limit -= (limit >> 4);
- }
-#endif
-
- pypy_stm_nursery_low_fill_mark = _stm_nursery_start + limit;
-}
-
-void _pypy_stm_start_transaction(void)
-{
- pypy_stm_nursery_low_fill_mark = 1; /* will be set to a correct value below */
- long counter = stm_start_transaction(&stm_thread_local);
-
- _pypy_stm_initialize_nursery_low_fill_mark(counter);
-
- pypy_stm_ready_atomic = 1; /* reset after abort */
-}
-
-void _pypy_stm_start_transaction_save_errno_wait_inev(void)
-{
- int e = errno;
- stm_wait_for_current_inevitable_transaction();
- _pypy_stm_start_transaction();
- errno = e;
-}
-
-void pypy_stm_transaction_break(void)
-{
- assert(pypy_stm_nursery_low_fill_mark != (uintptr_t) -1);
- stm_commit_transaction();
- _pypy_stm_start_transaction();
-}
-
-void _pypy_stm_inev_state(void)
-{
- /* Reduce the limit so that inevitable transactions are generally
- shorter. We depend a bit on stmcb_commit_soon() in order for
- other transactions to signal us in case we block them. */
- long t;
- if (pypy_stm_ready_atomic == 1) {
- t = (long)pypy_stm_nursery_low_fill_mark;
- t = _stm_nursery_start + ((t - (long)_stm_nursery_start) >> 2);
- pypy_stm_nursery_low_fill_mark = t;
- }
- else {
- assert(pypy_stm_nursery_low_fill_mark == (uintptr_t) -1);
- t = (long)pypy_stm_nursery_low_fill_mark_saved;
- t = _stm_nursery_start + ((t - (long)_stm_nursery_start) >> 2);
- pypy_stm_nursery_low_fill_mark_saved = t;
+ errno = e;
}
}
-void _pypy_stm_become_inevitable(const char *msg)
+/*void _pypy_stm_become_inevitable(const char *msg)
{
_pypy_stm_inev_state();
if (msg == NULL) {
msg = "return from JITted function";
}
_stm_become_inevitable(msg);
-}
+}*/
long _pypy_stm_count(void)
{
diff --git a/rpython/translator/stm/src_stm/stmgcintf.h b/rpython/translator/stm/src_stm/stmgcintf.h
--- a/rpython/translator/stm/src_stm/stmgcintf.h
+++ b/rpython/translator/stm/src_stm/stmgcintf.h
@@ -2,21 +2,10 @@
#define _RPY_STMGCINTF_H
-/* meant to be #included after src_stm/stmgc.h */
-
#include <errno.h>
#include "stmgc.h"
-#include "stm/atomic.h" /* for spin_loop(), write_fence(), spinlock_xxx() */
extern __thread struct stm_thread_local_s stm_thread_local;
-extern __thread long pypy_stm_ready_atomic;
-extern __thread uintptr_t pypy_stm_nursery_low_fill_mark;
-extern __thread uintptr_t pypy_stm_nursery_low_fill_mark_saved;
-/* Invariant: if we're running a transaction:
- - if it is atomic, pypy_stm_nursery_low_fill_mark == (uintptr_t) -1
- - otherwise, if it is inevitable, pypy_stm_nursery_low_fill_mark == 0
- - otherwise, it's a fraction of the nursery size strictly between 0 and 1
-*/
void pypy_stm_setup(void);
void pypy_stm_teardown(void);
@@ -26,13 +15,6 @@
void pypy_stm_memclearinit(object_t *obj, size_t offset, size_t size);
-void _pypy_stm_initialize_nursery_low_fill_mark(long v_counter);
-void _pypy_stm_inev_state(void);
-void _pypy_stm_start_transaction(void);
-void _pypy_stm_start_transaction_save_errno_wait_inev(void);
-
-void _pypy_stm_become_inevitable(const char *);
-
char *_pypy_stm_test_expand_marker(void);
void pypy_stm_setup_expand_marker(long co_filename_ofs,
long co_name_ofs,
@@ -41,88 +23,11 @@
long _pypy_stm_count(void);
-
-
-/* C8: not implemented properly yet: */
-extern void stmcb_commit_soon(void);
-/* C8: not implemented properly yet ^^^^^^^^^^^^^^^^^^ */
-
-
-static inline void pypy_stm_become_inevitable(const char *msg)
-{
- assert(STM_SEGMENT->running_thread == &stm_thread_local);
- if (!stm_is_inevitable()) {
- _pypy_stm_become_inevitable(msg);
- }
-}
-static inline void pypy_stm_commit_if_not_atomic(void) {
- int e = errno;
- if (pypy_stm_ready_atomic == 1) {
- stm_commit_transaction();
- }
- else {
- pypy_stm_become_inevitable("commit_if_not_atomic in atomic");
- }
- errno = e;
-}
-static inline void pypy_stm_start_if_not_atomic(void) {
- if (pypy_stm_ready_atomic == 1)
- _pypy_stm_start_transaction_save_errno_wait_inev();
-}
-static inline void pypy_stm_start_inevitable_if_not_atomic(void) {
- if (pypy_stm_ready_atomic == 1) {
- int e = errno;
- stm_start_inevitable_transaction(&stm_thread_local);
- _pypy_stm_initialize_nursery_low_fill_mark(0);
- _pypy_stm_inev_state();
- errno = e;
- }
-}
-static inline void pypy_stm_increment_atomic(void) {
- switch (++pypy_stm_ready_atomic) {
- case 2:
- assert(pypy_stm_nursery_low_fill_mark != (uintptr_t) -1);
- pypy_stm_nursery_low_fill_mark_saved = pypy_stm_nursery_low_fill_mark;
- pypy_stm_nursery_low_fill_mark = (uintptr_t) -1;
- break;
- default:
- break;
- }
-}
-static inline void pypy_stm_decrement_atomic(void) {
- switch (--pypy_stm_ready_atomic) {
- case 1:
- pypy_stm_nursery_low_fill_mark = pypy_stm_nursery_low_fill_mark_saved;
- assert(pypy_stm_nursery_low_fill_mark != (uintptr_t) -1);
- break;
- case 0:
- pypy_stm_ready_atomic = 1;
- break;
- default:
- break;
- }
-}
-static inline long pypy_stm_get_atomic(void) {
- return pypy_stm_ready_atomic - 1;
-}
long pypy_stm_enter_callback_call(void *);
void pypy_stm_leave_callback_call(void *, long);
void pypy_stm_set_transaction_length(double);
void pypy_stm_transaction_break(void);
-static inline int pypy_stm_should_break_transaction(void)
-{
- /* we should break the current transaction if we have used more than
- some initial portion of the nursery, or if we are running inevitable
- (in which case pypy_stm_nursery_low_fill_mark is set to 0).
- If the transaction is atomic, pypy_stm_nursery_low_fill_mark is
- instead set to (uintptr_t) -1, and the following check is never true.
- */
- uintptr_t current = (uintptr_t)STM_SEGMENT->nursery_current;
- return current > pypy_stm_nursery_low_fill_mark;
- /* NB. this logic is hard-coded in jit/backend/x86/assembler.py too */
-}
-
static void pypy__rewind_jmp_copy_stack_slice(void)
{
_rewind_jmp_copy_stack_slice(&stm_thread_local.rjthread);
diff --git a/rpython/translator/stm/test/test_readbarrier.py b/rpython/translator/stm/test/test_readbarrier.py
--- a/rpython/translator/stm/test/test_readbarrier.py
+++ b/rpython/translator/stm/test/test_readbarrier.py
@@ -230,9 +230,9 @@
def f1(f):
x.a = f
t = x.a # no read barrier
- llop.stm_commit_if_not_atomic(lltype.Void)
+ llop.stm_leave_transactional_zone(lltype.Void)
t += x.a
- llop.stm_start_if_not_atomic(lltype.Void)
+ llop.stm_enter_transactional_zone(lltype.Void)
t += x.a
llop.stm_transaction_break(lltype.Void)
t += x.a
diff --git a/rpython/translator/stm/test/transform_support.py b/rpython/translator/stm/test/transform_support.py
--- a/rpython/translator/stm/test/transform_support.py
+++ b/rpython/translator/stm/test/transform_support.py
@@ -123,10 +123,10 @@
def op_stm_transaction_break(self):
self.transaction_break()
- def op_stm_commit_if_not_atomic(self):
+ def op_stm_leave_transactional_zone(self):
self.transaction_break()
- def op_stm_start_if_not_atomic(self):
+ def op_stm_enter_transactional_zone(self):
self.transaction_break()
def op_stm_enter_callback_call(self):
More information about the pypy-commit
mailing list