[pypy-commit] stmgc c8-efficient-serial-execution-master: Merge TCP style optimization
Author: Tobias Weber Branch: c8-efficient-serial-execution-master Changeset: r2152:d56fd821ed46 Date: 2017-08-21 12:10 +0200 http://bitbucket.org/pypy/stmgc/changeset/d56fd821ed46/ Log:Merge TCP style optimization diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1117,11 +1117,9 @@ _do_start_transaction(tl); STM_PSEGMENT->commit_if_not_atomic = false; -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); -} +STM_SEGMENT->nursery_mark = ((stm_char *)_stm_nursery_start + +stm_get_transaction_length(tl)); + return repeat_count; } @@ -1304,6 +1302,8 @@ s_mutex_unlock(); +stm_transaction_length_handle_validation(thread_local_for_logging, false); + /* between transactions, call finalizers. this will execute a transaction itself */ if (tl != NULL) @@ -1468,22 +1468,6 @@ if (pseg->active_queues) queues_deactivate_all(pseg, /*at_commit=*/false); - -/* 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 @@ -1518,6 +1502,8 @@ tl->self_or_0_if_atomic = (intptr_t)tl; /* clear the 'atomic' flag */ STM_PSEGMENT->atomic_nesting_levels = 0; +stm_transaction_length_handle_validation(tl, true); + if (tl->mem_clear_on_abort) memset(tl->mem_clear_on_abort, 0, tl->mem_bytes_to_clear_on_abort); if (tl->mem_reset_on_abort) { diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -4,6 +4,8 @@ #endif #include "finalizer.h" +#include +#include // @@ -13,14 +15,79 @@ static uintptr_t _stm_nursery_start; +#define DEFAULT_FILL_MARK_NURSERY_BYTES (NURSERY_SIZE / 4) -#define DEFAULT_FILL_MARK_NURSERY_BYTES (NURSERY_SIZE / 4) +// corresponds to ~4 GB +#define LARGE_FILL_MARK_NURSERY_BYTES 0x1L -uintptr_t stm_fill_mark_nursery_bytes = DEFAULT_FILL_MARK_NURSERY_BYTES; +// corresponds to ~4 MB nursery fill +#define STM_DEFAULT_RELATIVE_TRANSACTION_LENGTH (0.001) +// corresponds to ~400 KB nursery fill +#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.0001) + +#define BACKOFF_COUNT (20) +#define BACKOFF_MULTIPLIER (BACKOFF_COUNT / -log10(STM_MIN_RELATIVE_TRANSACTION_LENGTH)) + +static inline void set_backoff(stm_thread_local_t *tl, double rel_trx_len) { +/* the shorter the trx, the more backoff: +think a*x + b = backoff, x := -log(rel-trx-len), +backoff is + b at default trx length, +linear decrease to b at max trx length */ +const int b = 5; +int new_backoff = (int)((BACKOFF_MULTIPLIER * -log10(rel_trx_len)) + b); +tl->transaction_length_backoff = new_backoff; +// printf("thread %d, backoff %d\n", tl->thread_local_counter, tl->transaction_length_backoff); +tl->linear_transaction_length_increment = rel_trx_len / new_backoff; +} + +static inline double get_new_transaction_length(stm_thread_local_t *tl, bool aborts) { +const int multiplier = 2; +double previous = tl->relative_transaction_length; +double new; +if (aborts) { +new = previous / multiplier; +if (new < STM_MIN_RELATIVE_TRANSACTION_LENGTH) { +new = STM_MIN_RELATIVE_TRANSACTION_LENGTH; +} +set_backoff(tl, new); +} else if (tl->transaction_length_backoff == 0) { +// backoff counter is zero, exponential increase up to 1 +new = previous * multiplier; +if (new > 1) { +new = 1; +} +if (tl->linear_transaction_length_increment != 0) { +// thread had to abort before: slow start +set_backoff(tl, new); +} +} else { // not abort and backoff != 0 +// in backoff, linear increase up to 1 +new = previous + tl->linear_transaction_length_increment; +if (new > 1) { +new = 1; +} +tl->transaction_length_backoff -= 1; +} +return new; +} + +static inline void stm_transaction_length_han
[pypy-commit] stmgc c8-efficient-serial-execution-master: Fix trx length update depends on instrumentation for thread local reference and remove logging of trx length
Author: Tobias Weber Branch: c8-efficient-serial-execution-master Changeset: r2153:cadbddf81079 Date: 2017-08-21 12:40 +0200 http://bitbucket.org/pypy/stmgc/changeset/cadbddf81079/ Log:Fix trx length update depends on instrumentation for thread local reference and remove logging of trx length diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1255,6 +1255,8 @@ bool was_inev = STM_PSEGMENT->transaction_state == TS_INEVITABLE; _validate_and_add_to_commit_log(); + +stm_thread_local_t *tl_for_trx_len = STM_SEGMENT->running_thread; if (external) { /* from this point on, unlink the original 'stm_thread_local_t *' from its segment. Better do it as soon as possible, because @@ -1302,7 +1304,7 @@ s_mutex_unlock(); -stm_transaction_length_handle_validation(thread_local_for_logging, false); +stm_transaction_length_handle_validation(tl_for_trx_len, false); /* between transactions, call finalizers. this will execute a transaction itself */ diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -77,8 +77,6 @@ static inline uintptr_t stm_get_transaction_length(stm_thread_local_t *tl) { double relative_additional_length = tl->relative_transaction_length; -publish_custom_value_event( -relative_additional_length, STM_SINGLE_THREAD_MODE_ADAPTIVE); uintptr_t result = (uintptr_t)(LARGE_FILL_MARK_NURSERY_BYTES * relative_additional_length); // printf("%020" PRIxPTR "\n", result); ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-efficient-serial-execution-master: Merge timing events enum so that all branches share the same interface with print_stm_log.py
Author: Tobias Weber Branch: c8-efficient-serial-execution-master Changeset: r2151:4a71ee20626e Date: 2017-08-05 14:17 +0200 http://bitbucket.org/pypy/stmgc/changeset/4a71ee20626e/ Log:Merge timing events enum so that all branches share the same interface with print_stm_log.py diff --git a/c8/stmgc.h b/c8/stmgc.h --- a/c8/stmgc.h +++ b/c8/stmgc.h @@ -201,7 +201,7 @@ /* PUBLIC API */ /* Number of segments (i.e. how many transactions can be executed in - parallel, in maximum). If you try to start transactions in more + parallel, at maximum). If you try to start transactions in more threads than the number of segments, it will block, waiting for the next segment to become free. */ @@ -574,21 +574,49 @@ STM_GC_MAJOR_START, STM_GC_MAJOR_DONE, +/* execution duration profiling events */ +STM_WARMUP_COMPLETE, + +STM_DURATION_START_TRX, +STM_DURATION_WRITE_GC_ONLY, +STM_DURATION_WRITE_SLOWPATH, +STM_DURATION_VALIDATION, +STM_DURATION_CREATE_CLE, +STM_DURATION_COMMIT_EXCEPT_GC, +STM_DURATION_MINOR_GC, +STM_DURATION_MAJOR_GC_LOG_ONLY, +STM_DURATION_MAJOR_GC_FULL, + +STM_SINGLE_THREAD_MODE_ON, +STM_SINGLE_THREAD_MODE_OFF, +STM_SINGLE_THREAD_MODE_ADAPTIVE, + _STM_EVENT_N }; -#define STM_EVENT_NAMES \ -"transaction start",\ -"transaction commit", \ -"transaction abort",\ -"contention write read",\ -"wait free segment",\ -"wait other inevitable",\ -"wait done",\ -"gc minor start", \ -"gc minor done",\ -"gc major start", \ -"gc major done" +#define STM_EVENT_NAMES \ +"transaction start",\ +"transaction commit", \ +"transaction abort",\ +"contention write read",\ +"wait free segment",\ +"wait other inevitable",\ +"wait done",\ +"gc minor start", \ +"gc minor done",\ +"gc major start", \ +"gc major done",\ +/* names of duration events */ \ +"marks completion of benchmark warm up phase" \ +"duration of transaction start",\ +"duration of gc due to write", \ +"duration of write slowpath", \ +"duration of validation", \ +"duration of commit log entry creation",\ +"duration of commit except gc", \ +"duration of minor gc", \ +"duration of major gc doing log clean up only", \ +"duration of full major gc" /* The markers pushed in the shadowstack are an odd number followed by a regular object pointer. */ ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-binary-trx-length-per-thread: Fix missing type definitions for custom payload
Author: Tobias Weber Branch: c8-binary-trx-length-per-thread Changeset: r2150:3394aed50b06 Date: 2017-07-14 20:27 +0200 http://bitbucket.org/pypy/stmgc/changeset/3394aed50b06/ Log:Fix missing type definitions for custom payload diff --git a/c8/stm/timing.h b/c8/stm/timing.h --- a/c8/stm/timing.h +++ b/c8/stm/timing.h @@ -1,5 +1,9 @@ #include +#define define_payload_types() \ +stm_timing_event_payload_data_t stm_duration_data; \ +stm_timing_event_payload_t stm_duration_payload; + #define continue_timer() clock_gettime(CLOCK_MONOTONIC_RAW, &start); /* Use raw monotonic time, i.e., solely based on local hardware (no NTP @@ -8,8 +12,7 @@ #define start_timer() struct timespec start, stop; \ struct timespec duration = { .tv_sec = 0, .tv_nsec = 0 };\ uint32_t nanosec_diff, sec_diff; \ - stm_timing_event_payload_data_t stm_duration_data; \ - stm_timing_event_payload_t stm_duration_payload; \ + define_payload_types() \ continue_timer() /* Must use start_timer before using this macro. */ @@ -59,5 +62,6 @@ #define publish_custom_value_event(double_value, event) \ set_payload((double_value)) \ +define_payload_types() \ stm_duration_payload(payload_value);\ publish_event(STM_SEGMENT->running_thread, (event)) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-binary-trx-length-per-thread: Update trx length on commit and abort only
Author: Tobias Weber Branch: c8-binary-trx-length-per-thread Changeset: r2148:114803b15227 Date: 2017-07-10 16:55 +0200 http://bitbucket.org/pypy/stmgc/changeset/114803b15227/ Log:Update trx length on commit and abort only diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -347,7 +347,6 @@ } if (thread_local_for_logging != NULL) { -stm_transaction_length_handle_validation(thread_local_for_logging, needs_abort); stop_timer_and_publish_for_thread( thread_local_for_logging, STM_DURATION_VALIDATION); } @@ -1380,6 +1379,8 @@ s_mutex_unlock(); +stm_transaction_length_handle_validation(thread_local_for_logging, false); + stop_timer_and_publish_for_thread( thread_local_for_logging, STM_DURATION_COMMIT_EXCEPT_GC); @@ -1551,6 +1552,8 @@ did_abort = 1; #endif +stm_transaction_length_handle_validation(pseg->pub.running_thread, true); + list_clear(pseg->objects_pointing_to_nursery); list_clear(pseg->old_objects_with_cards_set); LIST_FOREACH_R(pseg->large_overflow_objects, uintptr_t /*item*/, ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-binary-trx-length-per-thread: Update transaction lengths with learnings from TCP style
Author: Tobias Weber Branch: c8-binary-trx-length-per-thread Changeset: r2147:cac4878ee56a Date: 2017-08-04 11:48 +0200 http://bitbucket.org/pypy/stmgc/changeset/cac4878ee56a/ Log:Update transaction lengths with learnings from TCP style diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -16,13 +16,17 @@ static uintptr_t _stm_nursery_start; #define DEFAULT_FILL_MARK_NURSERY_BYTES (NURSERY_SIZE / 4) -#define LARGE_FILL_MARK_NURSERY_BYTES 0x10L + +// corresponds to ~4 GB +#define LARGE_FILL_MARK_NURSERY_BYTES 0x1L +// corresponds to ~400 KB nursery fill +#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.0001) static double get_new_transaction_length(stm_thread_local_t *tl, bool aborts) { double new = tl->relative_transaction_length; if (aborts) { -tl->transaction_length_backoff = 3; -new = 100.0 / LARGE_FILL_MARK_NURSERY_BYTES; +new = STM_MIN_RELATIVE_TRANSACTION_LENGTH; +tl->transaction_length_backoff = 20; } else if (tl->transaction_length_backoff == 0) { new = 1; } else { // not abort and backoff != 0 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-binary-trx-length-per-thread: Move transaction length update on abort
Author: Tobias Weber Branch: c8-binary-trx-length-per-thread Changeset: r2149:aa5b73c18b88 Date: 2017-07-14 12:49 +0200 http://bitbucket.org/pypy/stmgc/changeset/aa5b73c18b88/ Log:Move transaction length update on abort diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1552,8 +1552,6 @@ did_abort = 1; #endif -stm_transaction_length_handle_validation(pseg->pub.running_thread, true); - list_clear(pseg->objects_pointing_to_nursery); list_clear(pseg->old_objects_with_cards_set); LIST_FOREACH_R(pseg->large_overflow_objects, uintptr_t /*item*/, @@ -1584,6 +1582,8 @@ tl->self_or_0_if_atomic = (intptr_t)tl; /* clear the 'atomic' flag */ STM_PSEGMENT->atomic_nesting_levels = 0; +stm_transaction_length_handle_validation(tl, true); + if (tl->mem_clear_on_abort) memset(tl->mem_clear_on_abort, 0, tl->mem_bytes_to_clear_on_abort); if (tl->mem_reset_on_abort) { ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-binary-trx-length-per-thread: Merge instrumentation updates
Author: Tobias Weber Branch: c8-binary-trx-length-per-thread Changeset: r2146:bcf327fad4ce Date: 2017-08-04 11:42 +0200 http://bitbucket.org/pypy/stmgc/changeset/bcf327fad4ce/ Log:Merge instrumentation updates diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -469,8 +469,8 @@ #endif if (STM_PSEGMENT->last_commit_log_entry->next == INEV_RUNNING) { -pause_timer(); -wait_for_inevitable(); // TODO may abort!! timing event lost +stop_timer_and_publish(STM_DURATION_VALIDATION); +wait_for_inevitable(); continue_timer(); goto retry_from_start; /* redo _stm_validate() now */ } @@ -560,14 +560,13 @@ OPT_ASSERT(yes); release_modification_lock_wr(STM_SEGMENT->segment_num); + +stop_timer_and_publish(STM_DURATION_VALIDATION); } else { -pause_timer(); +stop_timer_and_publish(STM_DURATION_VALIDATION); _validate_and_attach(new); -continue_timer(); } - -stop_timer_and_publish(STM_DURATION_VALIDATION); } /* # STM # */ @@ -1328,7 +1327,9 @@ if there is an inevitable tx running) */ bool was_inev = STM_PSEGMENT->transaction_state == TS_INEVITABLE; -pause_timer(); +// publish here because the validation may abort +stop_timer_and_publish_for_thread( +thread_local_for_logging, STM_DURATION_COMMIT_EXCEPT_GC); _validate_and_add_to_commit_log(); continue_timer(); @@ -1653,9 +1654,9 @@ signal_commit_to_inevitable_transaction(); s_mutex_lock(); -if (any_soon_finished_or_inevitable_thread_segment() && -!safe_point_requested() && -num_waits <= NB_SEGMENTS) { +if (any_soon_finished_or_inevitable_thread_segment() +&& !safe_point_requested() +&& num_waits <= NB_SEGMENTS) { /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -759,16 +759,21 @@ static void major_do_validation_and_minor_collections(void) { +start_timer(); + int original_num = STM_SEGMENT->segment_num; long i; assert(_has_mutex()); /* including the sharing seg0 */ -for (i = 0; i < NB_SEGMENTS; i++) { +for (i = 0; i < NB_SEGMENTS; i++) { // TODO why is this strictly smaller than? ensure_gs_register(i); +pause_timer(); bool ok = _stm_validate(); +continue_timer(); + assert(get_priv_segment(i)->last_commit_log_entry->next == NULL || get_priv_segment(i)->last_commit_log_entry->next == INEV_RUNNING); if (!ok) { @@ -803,7 +808,9 @@ Collecting might fail due to invalid state. */ if (!must_abort()) { +pause_timer(); _do_minor_collection(/*commit=*/ false); +continue_timer(); assert(MINOR_NOTHING_TO_DO(STM_PSEGMENT)); } else { @@ -813,6 +820,8 @@ } ensure_gs_register(original_num); + +stop_timer_and_publish(STM_DURATION_MAJOR_GC_FULL); } diff --git a/c8/stm/timing.h b/c8/stm/timing.h --- a/c8/stm/timing.h +++ b/c8/stm/timing.h @@ -8,6 +8,8 @@ #define start_timer() struct timespec start, stop; \ struct timespec duration = { .tv_sec = 0, .tv_nsec = 0 };\ uint32_t nanosec_diff, sec_diff; \ + stm_timing_event_payload_data_t stm_duration_data; \ + stm_timing_event_payload_t stm_duration_payload; \ continue_timer() /* Must use start_timer before using this macro. */ @@ -27,11 +29,12 @@ #define pause_timer() clock_gettime(CLOCK_MONOTONIC_RAW, &stop);\ get_duration() +#define reset_timer() duration.tv_sec = 0; duration.tv_nsec = 0; + #define stm_duration_payload(duration_data) \ -stm_timing_event_payload_data_t stm_duration_data = \ -{ .duration = &(duration_data) }; \ -stm_timing_event_payload_t stm_duration_payload = \ -{ STM_EVENT_PAYLOAD_DURATION, stm_duration_data }; +stm_duration_data.duration = &(duration_data); \ +stm_duration_payload.type = STM_EVENT_PAYLOAD_DURATION; \ +stm_duration_payload.data = stm_duration_data; #define publish_event(thread_local, event) \ (timing_enabled() ? \ @@ -42,7 +45,8 @@ pause_timer() \ stm_duration_payload(dur
[pypy-commit] stmgc c8-binary-trx-length-per-thread: Merge commit signalling
Author: Tobias Weber Branch: c8-binary-trx-length-per-thread Changeset: r2145:6cc14f08abf7 Date: 2017-08-04 11:35 +0200 http://bitbucket.org/pypy/stmgc/changeset/6cc14f08abf7/ Log:Merge commit signalling diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -380,6 +380,14 @@ static void readd_wb_executed_flags(void); static void check_all_write_barrier_flags(char *segbase, struct list_s *list); +static void signal_commit_to_inevitable_transaction(void) { +struct stm_priv_segment_info_s* inevitable_segement = get_inevitable_thread_segment(); +if (inevitable_segement != 0) { +// the inevitable thread is still running: set its "please commit" flag (is ignored by the inevitable thread if it is atomic) +inevitable_segement->commit_if_not_atomic = true; +} +} + static void wait_for_inevitable(void) { intptr_t detached = 0; @@ -396,6 +404,8 @@ try to detach an inevitable transaction regularly */ detached = fetch_detached_transaction(); if (detached == 0) { +// the inevitable trx was not detached or it was detached but is atomic +signal_commit_to_inevitable_transaction(); EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) goto wait_some_more; @@ -1169,6 +1179,7 @@ _do_start_transaction(tl); continue_timer(); +STM_PSEGMENT->commit_if_not_atomic = false; STM_SEGMENT->nursery_mark = ((stm_char *)_stm_nursery_start + stm_get_transaction_length(tl)); @@ -1623,7 +1634,7 @@ void _stm_become_inevitable(const char *msg) { -int num_waits = 0; +int num_waits = 1; timing_become_inevitable(); @@ -1634,50 +1645,48 @@ if (msg != MSG_INEV_DONT_SLEEP) { dprintf(("become_inevitable: %s\n", msg)); -if (any_soon_finished_or_inevitable_thread_segment() && -num_waits <= NB_SEGMENTS) { +if (any_soon_finished_or_inevitable_thread_segment()) { #if STM_TESTS /* for tests: another transaction */ stm_abort_transaction();/* is already inevitable, abort */ #endif -bool timed_out = false; +signal_commit_to_inevitable_transaction(); s_mutex_lock(); if (any_soon_finished_or_inevitable_thread_segment() && -!safe_point_requested()) { +!safe_point_requested() && +num_waits <= NB_SEGMENTS) { /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); -if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, - 0.54321)) -timed_out = true; +if (cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) { +num_waits++; +} } s_mutex_unlock(); - -if (timed_out) { -/* try to detach another inevitable transaction, but - only after waiting a bit. This is necessary to avoid - deadlocks in some situations, which are hopefully - not too common. We don't want two threads constantly - detaching each other. */ -intptr_t detached = fetch_detached_transaction(); -if (detached != 0) { -EMIT_WAIT_DONE(); -commit_fetched_detached_transaction(detached); -} -} -else { -num_waits++; +/* XXX try to detach another inevitable transaction, but + only after waiting a bit. This is necessary to avoid + deadlocks in some situations, which are hopefully + not too common. We don't want two threads constantly + detaching each other. */ +intptr_t detached = fetch_detached_transaction(); +if (detached != 0) { + EMIT_WAIT_DONE(); + commit_fetched_detached_transaction(detached); + EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); } goto retry_from_start; } -EMIT_WAIT_DONE(); -if (!_validate_and_turn_inevitable()) -goto retry_from_start; +else { +EMIT_WAIT_DONE(); +if (!_validate_and_turn_inevitable()) { +EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); +goto retry_from_start; +} +} } -else { -if (!_validate_and_turn_inevitable()) -return; +else if (!_validate_and_turn_inevitable()) { +return; } /* There may be a concurrent commit of a detached Tx going on. @@ -1689,6 +1698,7 @@ stm_spin_loop(); a
[pypy-commit] stmgc c8-tcp-style-trx-length: Backed out changeset cdbb6dade13a
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2143:7ffcfbd0993a Date: 2017-08-03 12:13 +0200 http://bitbucket.org/pypy/stmgc/changeset/7ffcfbd0993a/ Log:Backed out changeset cdbb6dade13a diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -20,8 +20,8 @@ // corresponds to ~4 GB #define LARGE_FILL_MARK_NURSERY_BYTES 0x1L -// corresponds to ~40 KB nursery fill -#define STM_DEFAULT_RELATIVE_TRANSACTION_LENGTH (0.1) +// corresponds to ~4 MB nursery fill +#define STM_DEFAULT_RELATIVE_TRANSACTION_LENGTH (0.001) // corresponds to ~4 KB nursery fill #define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.01) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Change default transaction length to ~40 KB
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2142:cdbb6dade13a Date: 2017-08-02 17:10 +0200 http://bitbucket.org/pypy/stmgc/changeset/cdbb6dade13a/ Log:Change default transaction length to ~40 KB diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -20,8 +20,8 @@ // corresponds to ~4 GB #define LARGE_FILL_MARK_NURSERY_BYTES 0x1L -// corresponds to ~4 MB nursery fill -#define STM_DEFAULT_RELATIVE_TRANSACTION_LENGTH (0.001) +// corresponds to ~40 KB nursery fill +#define STM_DEFAULT_RELATIVE_TRANSACTION_LENGTH (0.1) // corresponds to ~4 KB nursery fill #define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.01) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Increase min trx len to ~400KB
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2144:2d68598c75fd Date: 2017-08-03 12:14 +0200 http://bitbucket.org/pypy/stmgc/changeset/2d68598c75fd/ Log:Increase min trx len to ~400KB diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -22,8 +22,8 @@ // corresponds to ~4 MB nursery fill #define STM_DEFAULT_RELATIVE_TRANSACTION_LENGTH (0.001) -// corresponds to ~4 KB nursery fill -#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.01) +// corresponds to ~400 KB nursery fill +#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.0001) #define BACKOFF_COUNT (20) #define BACKOFF_MULTIPLIER (BACKOFF_COUNT / -log10(STM_MIN_RELATIVE_TRANSACTION_LENGTH)) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Disable slow start
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2135:d9897d451fff Date: 2017-07-23 13:36 +0200 http://bitbucket.org/pypy/stmgc/changeset/d9897d451fff/ Log:Disable slow start diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -55,10 +55,10 @@ if (new > 1) { new = 1; } -if (tl->linear_transaction_length_increment != 0) { -// thread had to abort before: slow start -set_backoff(tl, new); -} +// if (tl->linear_transaction_length_increment != 0) { +// // thread had to abort before: slow start +// set_backoff(tl, new); +// } } else { // not abort and backoff != 0 // in backoff, linear increase up to 1 new = previous + tl->linear_transaction_length_increment; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Distinguish min and default trx length to allow shrinking to single instruction level
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2132:c6265dd2c77c Date: 2017-07-21 11:29 +0200 http://bitbucket.org/pypy/stmgc/changeset/c6265dd2c77c/ Log:Distinguish min and default trx length to allow shrinking to single instruction level diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -22,12 +22,18 @@ // #define LARGE_FILL_MARK_NURSERY_BYTES 0x1000L // corresponds to ~4 KB nursery fill -#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.01) +#define STM_DEFAULT_REL_TRANSACTION_LENGTH (0.01) +// commit after ~4 B or likely after every instruction +#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.1) + #define BACKOFF_COUNT (10) -#define BACKOFF_MULTIPLIER (BACKOFF_COUNT / -log10(STM_MIN_RELATIVE_TRANSACTION_LENGTH)) +#define BACKOFF_MULTIPLIER (BACKOFF_COUNT / -log10(STM_DEFAULT_REL_TRANSACTION_LENGTH)) static inline void set_backoff(stm_thread_local_t *tl, double rel_trx_len) { -// the shorter the trx, the more backoff: 100 at min trx length, proportional decrease to 5 at max trx length (think a/x + b = backoff) +/* the shorter the trx, the more backoff: +think a*x + b = backoff, x := -log(rel-trx-len), +backoff is + b at default trx length, +linear decrease to b at max trx length */ tl->transaction_length_backoff = (int)((BACKOFF_MULTIPLIER * -log10(rel_trx_len)) + 5); // printf("thread %d, backoff %d\n", tl->thread_local_counter, tl->transaction_length_backoff); diff --git a/c8/stm/setup.c b/c8/stm/setup.c --- a/c8/stm/setup.c +++ b/c8/stm/setup.c @@ -247,7 +247,7 @@ tl->thread_local_counter = ++thread_local_counters; /* init adaptive transaction length mode */ -tl->relative_transaction_length = STM_MIN_RELATIVE_TRANSACTION_LENGTH; +tl->relative_transaction_length = STM_DEFAULT_REL_TRANSACTION_LENGTH; tl->transaction_length_backoff = 0; tl->linear_transaction_length_increment = 0; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Initialize trx len roughly to old default of 1MB and hard cap on lower limit of 4KB
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2140:3bc9bfa7d481 Date: 2017-07-24 16:24 +0200 http://bitbucket.org/pypy/stmgc/changeset/3bc9bfa7d481/ Log:Initialize trx len roughly to old default of 1MB and hard cap on lower limit of 4KB diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -17,12 +17,14 @@ #define DEFAULT_FILL_MARK_NURSERY_BYTES (NURSERY_SIZE / 4) -// #define LARGE_FILL_MARK_NURSERY_BYTES DEFAULT_FILL_MARK_NURSERY_BYTES +// corresponds to ~4 GB #define LARGE_FILL_MARK_NURSERY_BYTES 0x1L -// #define LARGE_FILL_MARK_NURSERY_BYTES 0x1000L +// corresponds to ~4 MB nursery fill +#define STM_DEFAULT_RELATIVE_TRANSACTION_LENGTH (0.001) // corresponds to ~4 KB nursery fill #define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.01) + #define BACKOFF_COUNT (20) #define BACKOFF_MULTIPLIER (BACKOFF_COUNT / -log10(STM_MIN_RELATIVE_TRANSACTION_LENGTH)) @@ -45,8 +47,7 @@ if (aborts) { new = previous / multiplier; if (new < STM_MIN_RELATIVE_TRANSACTION_LENGTH) { -// reached min trx length, only decrease slowly -new = 0.9 * previous; +new = STM_MIN_RELATIVE_TRANSACTION_LENGTH; } set_backoff(tl, new); } else if (tl->transaction_length_backoff == 0) { diff --git a/c8/stm/setup.c b/c8/stm/setup.c --- a/c8/stm/setup.c +++ b/c8/stm/setup.c @@ -247,7 +247,7 @@ tl->thread_local_counter = ++thread_local_counters; /* init adaptive transaction length mode */ -tl->relative_transaction_length = STM_MIN_RELATIVE_TRANSACTION_LENGTH; +tl->relative_transaction_length = STM_DEFAULT_RELATIVE_TRANSACTION_LENGTH; tl->transaction_length_backoff = 0; tl->linear_transaction_length_increment = 0; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Backed out changeset dbea548c4c6e
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2136:5563999ed658 Date: 2017-07-23 13:37 +0200 http://bitbucket.org/pypy/stmgc/changeset/5563999ed658/ Log:Backed out changeset dbea548c4c6e diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -347,9 +347,6 @@ } if (thread_local_for_logging != NULL) { -if (needs_abort) { -stm_transaction_length_handle_validation(thread_local_for_logging, true); -} stop_timer_and_publish_for_thread( thread_local_for_logging, STM_DURATION_VALIDATION); } @@ -1585,6 +1582,8 @@ tl->self_or_0_if_atomic = (intptr_t)tl; /* clear the 'atomic' flag */ STM_PSEGMENT->atomic_nesting_levels = 0; +stm_transaction_length_handle_validation(tl, true); + if (tl->mem_clear_on_abort) memset(tl->mem_clear_on_abort, 0, tl->mem_bytes_to_clear_on_abort); if (tl->mem_reset_on_abort) { ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Backed out changeset feed32340eb2
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2138:48e819b53680 Date: 2017-07-24 10:42 +0200 http://bitbucket.org/pypy/stmgc/changeset/48e819b53680/ Log:Backed out changeset feed32340eb2 diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -32,7 +32,7 @@ backoff is + b at default trx length, linear decrease to b at max trx length */ const int b = 5; -tl->transaction_length_backoff += +tl->transaction_length_backoff = (int)((BACKOFF_MULTIPLIER * -log10(rel_trx_len)) + b); // printf("thread %d, backoff %d\n", tl->thread_local_counter, tl->transaction_length_backoff); tl->linear_transaction_length_increment = rel_trx_len / (BACKOFF_COUNT + b); ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Set backoff to best working value so far and re-enable slow start
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2139:6a3c6e601284 Date: 2017-07-24 11:10 +0200 http://bitbucket.org/pypy/stmgc/changeset/6a3c6e601284/ Log:Set backoff to best working value so far and re-enable slow start diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -23,7 +23,7 @@ // corresponds to ~4 KB nursery fill #define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.01) -#define BACKOFF_COUNT (5) +#define BACKOFF_COUNT (20) #define BACKOFF_MULTIPLIER (BACKOFF_COUNT / -log10(STM_MIN_RELATIVE_TRANSACTION_LENGTH)) static inline void set_backoff(stm_thread_local_t *tl, double rel_trx_len) { @@ -32,10 +32,10 @@ backoff is + b at default trx length, linear decrease to b at max trx length */ const int b = 5; -tl->transaction_length_backoff = -(int)((BACKOFF_MULTIPLIER * -log10(rel_trx_len)) + b); +int new_backoff = (int)((BACKOFF_MULTIPLIER * -log10(rel_trx_len)) + b); +tl->transaction_length_backoff = new_backoff; // printf("thread %d, backoff %d\n", tl->thread_local_counter, tl->transaction_length_backoff); -tl->linear_transaction_length_increment = rel_trx_len / (BACKOFF_COUNT + b); +tl->linear_transaction_length_increment = rel_trx_len / new_backoff; } static inline double get_new_transaction_length(stm_thread_local_t *tl, bool aborts) { @@ -55,10 +55,10 @@ if (new > 1) { new = 1; } -// if (tl->linear_transaction_length_increment != 0) { -// // thread had to abort before: slow start -// set_backoff(tl, new); -// } +if (tl->linear_transaction_length_increment != 0) { +// thread had to abort before: slow start +set_backoff(tl, new); +} } else { // not abort and backoff != 0 // in backoff, linear increase up to 1 new = previous + tl->linear_transaction_length_increment; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Grow backoff cumulatively on repeated aborts
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2137:feed32340eb2 Date: 2017-07-23 17:29 +0200 http://bitbucket.org/pypy/stmgc/changeset/feed32340eb2/ Log:Grow backoff cumulatively on repeated aborts diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -32,7 +32,7 @@ backoff is + b at default trx length, linear decrease to b at max trx length */ const int b = 5; -tl->transaction_length_backoff = +tl->transaction_length_backoff += (int)((BACKOFF_MULTIPLIER * -log10(rel_trx_len)) + b); // printf("thread %d, backoff %d\n", tl->thread_local_counter, tl->transaction_length_backoff); tl->linear_transaction_length_increment = rel_trx_len / (BACKOFF_COUNT + b); ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Backed out changeset c6265dd2c77c
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2133:08a8d7fd1866 Date: 2017-07-21 14:19 +0200 http://bitbucket.org/pypy/stmgc/changeset/08a8d7fd1866/ Log:Backed out changeset c6265dd2c77c diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -22,18 +22,12 @@ // #define LARGE_FILL_MARK_NURSERY_BYTES 0x1000L // corresponds to ~4 KB nursery fill -#define STM_DEFAULT_REL_TRANSACTION_LENGTH (0.01) -// commit after ~4 B or likely after every instruction -#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.1) - +#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.01) #define BACKOFF_COUNT (10) -#define BACKOFF_MULTIPLIER (BACKOFF_COUNT / -log10(STM_DEFAULT_REL_TRANSACTION_LENGTH)) +#define BACKOFF_MULTIPLIER (BACKOFF_COUNT / -log10(STM_MIN_RELATIVE_TRANSACTION_LENGTH)) static inline void set_backoff(stm_thread_local_t *tl, double rel_trx_len) { -/* the shorter the trx, the more backoff: -think a*x + b = backoff, x := -log(rel-trx-len), -backoff is + b at default trx length, -linear decrease to b at max trx length */ +// the shorter the trx, the more backoff: 100 at min trx length, proportional decrease to 5 at max trx length (think a/x + b = backoff) tl->transaction_length_backoff = (int)((BACKOFF_MULTIPLIER * -log10(rel_trx_len)) + 5); // printf("thread %d, backoff %d\n", tl->thread_local_counter, tl->transaction_length_backoff); diff --git a/c8/stm/setup.c b/c8/stm/setup.c --- a/c8/stm/setup.c +++ b/c8/stm/setup.c @@ -247,7 +247,7 @@ tl->thread_local_counter = ++thread_local_counters; /* init adaptive transaction length mode */ -tl->relative_transaction_length = STM_DEFAULT_REL_TRANSACTION_LENGTH; +tl->relative_transaction_length = STM_MIN_RELATIVE_TRANSACTION_LENGTH; tl->transaction_length_backoff = 0; tl->linear_transaction_length_increment = 0; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Merge warm up complete event
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2141:2828bbba12a4 Date: 2017-07-29 11:25 +0200 http://bitbucket.org/pypy/stmgc/changeset/2828bbba12a4/ Log:Merge warm up complete event diff --git a/c8/stmgc.h b/c8/stmgc.h --- a/c8/stmgc.h +++ b/c8/stmgc.h @@ -583,6 +583,8 @@ STM_GC_MAJOR_DONE, /* execution duration profiling events */ +STM_WARMUP_COMPLETE, + STM_DURATION_START_TRX, STM_DURATION_WRITE_GC_ONLY, STM_DURATION_WRITE_SLOWPATH, @@ -613,6 +615,7 @@ "gc major start", \ "gc major done",\ /* names of duration events */ \ +"marks completion of benchmark warm up phase" \ "duration of transaction start",\ "duration of gc due to write", \ "duration of write slowpath", \ ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Decrease trx len just ten percent at a time below min
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2134:70e630a22710 Date: 2017-07-21 14:42 +0200 http://bitbucket.org/pypy/stmgc/changeset/70e630a22710/ Log:Decrease trx len just ten percent at a time below min diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -23,15 +23,19 @@ // corresponds to ~4 KB nursery fill #define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.01) -#define BACKOFF_COUNT (10) +#define BACKOFF_COUNT (5) #define BACKOFF_MULTIPLIER (BACKOFF_COUNT / -log10(STM_MIN_RELATIVE_TRANSACTION_LENGTH)) static inline void set_backoff(stm_thread_local_t *tl, double rel_trx_len) { -// the shorter the trx, the more backoff: 100 at min trx length, proportional decrease to 5 at max trx length (think a/x + b = backoff) +/* the shorter the trx, the more backoff: +think a*x + b = backoff, x := -log(rel-trx-len), +backoff is + b at default trx length, +linear decrease to b at max trx length */ +const int b = 5; tl->transaction_length_backoff = -(int)((BACKOFF_MULTIPLIER * -log10(rel_trx_len)) + 5); +(int)((BACKOFF_MULTIPLIER * -log10(rel_trx_len)) + b); // printf("thread %d, backoff %d\n", tl->thread_local_counter, tl->transaction_length_backoff); -tl->linear_transaction_length_increment = rel_trx_len / BACKOFF_COUNT; +tl->linear_transaction_length_increment = rel_trx_len / (BACKOFF_COUNT + b); } static inline double get_new_transaction_length(stm_thread_local_t *tl, bool aborts) { @@ -41,7 +45,8 @@ if (aborts) { new = previous / multiplier; if (new < STM_MIN_RELATIVE_TRANSACTION_LENGTH) { -new = STM_MIN_RELATIVE_TRANSACTION_LENGTH; +// reached min trx length, only decrease slowly +new = 0.9 * previous; } set_backoff(tl, new); } else if (tl->transaction_length_backoff == 0) { ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Increase min trx length and fix capping trx length
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2131:d86628e2626c Date: 2017-07-20 20:15 +0200 http://bitbucket.org/pypy/stmgc/changeset/d86628e2626c/ Log:Increase min trx length and fix capping trx length diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -21,9 +21,9 @@ #define LARGE_FILL_MARK_NURSERY_BYTES 0x1L // #define LARGE_FILL_MARK_NURSERY_BYTES 0x1000L -// corresponds to ~430 bytes nursery fill -#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.001) -#define BACKOFF_COUNT (20) +// corresponds to ~4 KB nursery fill +#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.01) +#define BACKOFF_COUNT (10) #define BACKOFF_MULTIPLIER (BACKOFF_COUNT / -log10(STM_MIN_RELATIVE_TRANSACTION_LENGTH)) static inline void set_backoff(stm_thread_local_t *tl, double rel_trx_len) { @@ -37,18 +37,18 @@ static inline double get_new_transaction_length(stm_thread_local_t *tl, bool aborts) { const int multiplier = 2; double previous = tl->relative_transaction_length; -double new = previous; +double new; if (aborts) { -if (previous > STM_MIN_RELATIVE_TRANSACTION_LENGTH) { -new = previous / multiplier; -} else { +new = previous / multiplier; +if (new < STM_MIN_RELATIVE_TRANSACTION_LENGTH) { new = STM_MIN_RELATIVE_TRANSACTION_LENGTH; } set_backoff(tl, new); } else if (tl->transaction_length_backoff == 0) { // backoff counter is zero, exponential increase up to 1 -if (previous < 1) { -new = previous * multiplier; +new = previous * multiplier; +if (new > 1) { +new = 1; } if (tl->linear_transaction_length_increment != 0) { // thread had to abort before: slow start @@ -56,8 +56,9 @@ } } else { // not abort and backoff != 0 // in backoff, linear increase up to 1 -if (previous < 1) { -new = previous + tl->linear_transaction_length_increment; +new = previous + tl->linear_transaction_length_increment; +if (new > 1) { +new = 1; } tl->transaction_length_backoff -= 1; } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Set exponential base to two, i.e., double trx length on commit
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2130:dba308a7d960 Date: 2017-07-17 16:53 +0200 http://bitbucket.org/pypy/stmgc/changeset/dba308a7d960/ Log:Set exponential base to two, i.e., double trx length on commit diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -18,23 +18,24 @@ #define DEFAULT_FILL_MARK_NURSERY_BYTES (NURSERY_SIZE / 4) // #define LARGE_FILL_MARK_NURSERY_BYTES DEFAULT_FILL_MARK_NURSERY_BYTES -#define LARGE_FILL_MARK_NURSERY_BYTES 0x1000L +#define LARGE_FILL_MARK_NURSERY_BYTES 0x1L // #define LARGE_FILL_MARK_NURSERY_BYTES 0x1000L -// corresponds to ~270 bytes nursery fill -#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.01) -#define BACKOFF_MULTIPLIER (20 / -log10(STM_MIN_RELATIVE_TRANSACTION_LENGTH)) +// corresponds to ~430 bytes nursery fill +#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.001) +#define BACKOFF_COUNT (20) +#define BACKOFF_MULTIPLIER (BACKOFF_COUNT / -log10(STM_MIN_RELATIVE_TRANSACTION_LENGTH)) static inline void set_backoff(stm_thread_local_t *tl, double rel_trx_len) { // the shorter the trx, the more backoff: 100 at min trx length, proportional decrease to 5 at max trx length (think a/x + b = backoff) tl->transaction_length_backoff = (int)((BACKOFF_MULTIPLIER * -log10(rel_trx_len)) + 5); // printf("thread %d, backoff %d\n", tl->thread_local_counter, tl->transaction_length_backoff); -tl->linear_transaction_length_increment = rel_trx_len; +tl->linear_transaction_length_increment = rel_trx_len / BACKOFF_COUNT; } static inline double get_new_transaction_length(stm_thread_local_t *tl, bool aborts) { -const int multiplier = 100; +const int multiplier = 2; double previous = tl->relative_transaction_length; double new = previous; if (aborts) { ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-overheads-instrumentation: Add warmup complete event
Author: Tobias Weber Branch: c8-overheads-instrumentation Changeset: r2129:1432eab6963e Date: 2017-07-29 11:24 +0200 http://bitbucket.org/pypy/stmgc/changeset/1432eab6963e/ Log:Add warmup complete event diff --git a/c8/stmgc.h b/c8/stmgc.h --- a/c8/stmgc.h +++ b/c8/stmgc.h @@ -575,6 +575,8 @@ STM_GC_MAJOR_DONE, /* execution duration profiling events */ +STM_WARMUP_COMPLETE, + STM_DURATION_START_TRX, STM_DURATION_WRITE_GC_ONLY, STM_DURATION_WRITE_SLOWPATH, @@ -605,6 +607,7 @@ "gc major start", \ "gc major done",\ /* names of duration events */ \ +"marks completion of benchmark warm up phase" \ "duration of transaction start",\ "duration of gc due to write", \ "duration of write slowpath", \ ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Merge latest instrumentation fixes
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2128:de8f34537c9b Date: 2017-07-14 17:50 +0200 http://bitbucket.org/pypy/stmgc/changeset/de8f34537c9b/ Log:Merge latest instrumentation fixes diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -468,8 +468,8 @@ #endif if (STM_PSEGMENT->last_commit_log_entry->next == INEV_RUNNING) { -pause_timer(); -wait_for_inevitable(); // TODO may abort!! timing event lost +stop_timer_and_publish(STM_DURATION_VALIDATION); +wait_for_inevitable(); continue_timer(); goto retry_from_start; /* redo _stm_validate() now */ } @@ -559,14 +559,13 @@ OPT_ASSERT(yes); release_modification_lock_wr(STM_SEGMENT->segment_num); + +stop_timer_and_publish(STM_DURATION_VALIDATION); } else { -pause_timer(); +stop_timer_and_publish(STM_DURATION_VALIDATION); _validate_and_attach(new); -continue_timer(); } - -stop_timer_and_publish(STM_DURATION_VALIDATION); } /* # STM # */ @@ -1327,7 +1326,9 @@ if there is an inevitable tx running) */ bool was_inev = STM_PSEGMENT->transaction_state == TS_INEVITABLE; -pause_timer(); +// publish here because the validation may abort +stop_timer_and_publish_for_thread( +thread_local_for_logging, STM_DURATION_COMMIT_EXCEPT_GC); _validate_and_add_to_commit_log(); continue_timer(); @@ -1656,9 +1657,9 @@ signal_commit_to_inevitable_transaction(); s_mutex_lock(); -if (any_soon_finished_or_inevitable_thread_segment() && -!safe_point_requested() && -num_waits <= NB_SEGMENTS) { +if (any_soon_finished_or_inevitable_thread_segment() +&& !safe_point_requested() +&& num_waits <= NB_SEGMENTS) { /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -774,16 +774,21 @@ static void major_do_validation_and_minor_collections(void) { +start_timer(); + int original_num = STM_SEGMENT->segment_num; long i; assert(_has_mutex()); /* including the sharing seg0 */ -for (i = 0; i < NB_SEGMENTS; i++) { +for (i = 0; i < NB_SEGMENTS; i++) { // TODO why is this strictly smaller than? ensure_gs_register(i); +pause_timer(); bool ok = _stm_validate(); +continue_timer(); + assert(get_priv_segment(i)->last_commit_log_entry->next == NULL || get_priv_segment(i)->last_commit_log_entry->next == INEV_RUNNING); if (!ok) { @@ -818,7 +823,9 @@ Collecting might fail due to invalid state. */ if (!must_abort()) { +pause_timer(); _do_minor_collection(/*commit=*/ false); +continue_timer(); assert(MINOR_NOTHING_TO_DO(STM_PSEGMENT)); } else { @@ -828,6 +835,8 @@ } ensure_gs_register(original_num); + +stop_timer_and_publish(STM_DURATION_MAJOR_GC_FULL); } diff --git a/c8/stm/timing.h b/c8/stm/timing.h --- a/c8/stm/timing.h +++ b/c8/stm/timing.h @@ -27,6 +27,8 @@ #define pause_timer() clock_gettime(CLOCK_MONOTONIC_RAW, &stop);\ get_duration() +#define reset_timer() duration.tv_sec = 0; duration.tv_nsec = 0; + #define stm_duration_payload(duration_data) \ stm_timing_event_payload_data_t stm_duration_data = \ { .duration = &(duration_data) }; \ @@ -42,7 +44,8 @@ pause_timer() \ stm_duration_payload(duration) \ assert((thread_local) != NULL); \ -publish_event((thread_local), (event)) +publish_event((thread_local), (event)) \ +reset_timer() #define stop_timer_and_publish(event) \ stop_timer_and_publish_for_thread(STM_SEGMENT->running_thread, (event)) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Merge fix for syntax error
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2126:ff769635407d Date: 2017-07-13 22:37 +0200 http://bitbucket.org/pypy/stmgc/changeset/ff769635407d/ Log:Merge fix for syntax error diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -542,7 +542,7 @@ pseg->pub.nursery_current = (stm_char *)_stm_nursery_start; pseg->pub.nursery_mark -= nursery_used; -assert((pseg->transaction_state == TS_INEVITABLE) || !pseg->commit_if_not_atomic) +assert((pseg->transaction_state == TS_INEVITABLE) || !pseg->commit_if_not_atomic); if (pseg->commit_if_not_atomic && pseg->transaction_state == TS_INEVITABLE && pseg->pub.running_thread->self_or_0_if_atomic != 0) { ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Update trx length on commit and abort only
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2124:2f4291869a47 Date: 2017-07-10 16:55 +0200 http://bitbucket.org/pypy/stmgc/changeset/2f4291869a47/ Log:Update trx length on commit and abort only diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -347,7 +347,6 @@ } if (thread_local_for_logging != NULL) { -stm_transaction_length_handle_validation(thread_local_for_logging, needs_abort); stop_timer_and_publish_for_thread( thread_local_for_logging, STM_DURATION_VALIDATION); } @@ -1378,6 +1377,8 @@ s_mutex_unlock(); +stm_transaction_length_handle_validation(thread_local_for_logging, false); + stop_timer_and_publish_for_thread( thread_local_for_logging, STM_DURATION_COMMIT_EXCEPT_GC); @@ -1549,6 +1550,8 @@ did_abort = 1; #endif +stm_transaction_length_handle_validation(pseg->pub.running_thread, true); + list_clear(pseg->objects_pointing_to_nursery); list_clear(pseg->old_objects_with_cards_set); LIST_FOREACH_R(pseg->large_overflow_objects, uintptr_t /*item*/, ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Move transaction length update on abort
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2127:77cbbb3d1a97 Date: 2017-07-14 12:49 +0200 http://bitbucket.org/pypy/stmgc/changeset/77cbbb3d1a97/ Log:Move transaction length update on abort diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1551,8 +1551,6 @@ did_abort = 1; #endif -stm_transaction_length_handle_validation(pseg->pub.running_thread, true); - list_clear(pseg->objects_pointing_to_nursery); list_clear(pseg->old_objects_with_cards_set); LIST_FOREACH_R(pseg->large_overflow_objects, uintptr_t /*item*/, @@ -1583,6 +1581,8 @@ tl->self_or_0_if_atomic = (intptr_t)tl; /* clear the 'atomic' flag */ STM_PSEGMENT->atomic_nesting_levels = 0; +stm_transaction_length_handle_validation(tl, true); + if (tl->mem_clear_on_abort) memset(tl->mem_clear_on_abort, 0, tl->mem_bytes_to_clear_on_abort); if (tl->mem_reset_on_abort) { ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Improve backoff computation
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2121:de7da0f0b0ad Date: 2017-07-16 00:30 +0200 http://bitbucket.org/pypy/stmgc/changeset/de7da0f0b0ad/ Log:Improve backoff computation diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -23,12 +23,12 @@ // corresponds to ~700 bytes nursery fill #define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.0001) -#define BACKOFF_MULTIPLIER (0.05 / STM_MIN_RELATIVE_TRANSACTION_LENGTH) +#define BACKOFF_MULTIPLIER (20 / -log10(STM_MIN_RELATIVE_TRANSACTION_LENGTH)) static inline void set_backoff(stm_thread_local_t *tl, double rel_trx_len) { // the shorter the trx, the more backoff: 100 at min trx length, proportional decrease to 5 at max trx length (think a/x + b = backoff) tl->transaction_length_backoff = -(int)(1 / (BACKOFF_MULTIPLIER * rel_trx_len) + 5); +(int)((BACKOFF_MULTIPLIER * -log10(rel_trx_len)) + 5); // printf("thread %d, backoff %d\n", tl->thread_local_counter, tl->transaction_length_backoff); tl->linear_transaction_length_increment = rel_trx_len; } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Merge commit signalling fix
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2125:c1b97c862a98 Date: 2017-07-13 21:43 +0200 http://bitbucket.org/pypy/stmgc/changeset/c1b97c862a98/ Log:Merge commit signalling fix diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1178,6 +1178,7 @@ _do_start_transaction(tl); continue_timer(); +STM_PSEGMENT->commit_if_not_atomic = false; STM_SEGMENT->nursery_mark = ((stm_char *)_stm_nursery_start + stm_get_transaction_length(tl)); diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -542,8 +542,9 @@ pseg->pub.nursery_current = (stm_char *)_stm_nursery_start; pseg->pub.nursery_mark -= nursery_used; +assert((pseg->transaction_state == TS_INEVITABLE) || !pseg->commit_if_not_atomic) if (pseg->commit_if_not_atomic -// && pseg->transaction_state == TS_INEVITABLE // TODO why does this break the mechanism? +&& pseg->transaction_state == TS_INEVITABLE && pseg->pub.running_thread->self_or_0_if_atomic != 0) { // transaction is inevitable, not atomic, and commit has been signalled by waiting thread: commit immediately pseg->pub.nursery_mark = 0; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Merge fix for stop timer macro
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2117:93461fbaabd1 Date: 2017-07-14 19:01 +0200 http://bitbucket.org/pypy/stmgc/changeset/93461fbaabd1/ Log:Merge fix for stop timer macro diff --git a/c8/stm/timing.h b/c8/stm/timing.h --- a/c8/stm/timing.h +++ b/c8/stm/timing.h @@ -8,6 +8,8 @@ #define start_timer() struct timespec start, stop; \ struct timespec duration = { .tv_sec = 0, .tv_nsec = 0 };\ uint32_t nanosec_diff, sec_diff; \ + stm_timing_event_payload_data_t stm_duration_data; \ + stm_timing_event_payload_t stm_duration_payload; \ continue_timer() /* Must use start_timer before using this macro. */ @@ -30,10 +32,9 @@ #define reset_timer() duration.tv_sec = 0; duration.tv_nsec = 0; #define stm_duration_payload(duration_data) \ -stm_timing_event_payload_data_t stm_duration_data = \ -{ .duration = &(duration_data) }; \ -stm_timing_event_payload_t stm_duration_payload = \ -{ STM_EVENT_PAYLOAD_DURATION, stm_duration_data }; +stm_duration_data.duration = &(duration_data); \ +stm_duration_payload.type = STM_EVENT_PAYLOAD_DURATION; \ +stm_duration_payload.data = stm_duration_data; #define publish_event(thread_local, event) \ (timing_enabled() ? \ ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Optimize min/max trx length
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2123:d62e76b278bd Date: 2017-07-16 19:47 +0200 http://bitbucket.org/pypy/stmgc/changeset/d62e76b278bd/ Log:Optimize min/max trx length diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -18,11 +18,11 @@ #define DEFAULT_FILL_MARK_NURSERY_BYTES (NURSERY_SIZE / 4) // #define LARGE_FILL_MARK_NURSERY_BYTES DEFAULT_FILL_MARK_NURSERY_BYTES -#define LARGE_FILL_MARK_NURSERY_BYTES 0x10L +#define LARGE_FILL_MARK_NURSERY_BYTES 0x1000L // #define LARGE_FILL_MARK_NURSERY_BYTES 0x1000L -// corresponds to ~700 bytes nursery fill -#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.0001) +// corresponds to ~270 bytes nursery fill +#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.01) #define BACKOFF_MULTIPLIER (20 / -log10(STM_MIN_RELATIVE_TRANSACTION_LENGTH)) static inline void set_backoff(stm_thread_local_t *tl, double rel_trx_len) { ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Fix and refactor backoff mechanism
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2120:adf35813ae8d Date: 2017-07-15 18:13 +0200 http://bitbucket.org/pypy/stmgc/changeset/adf35813ae8d/ Log:Fix and refactor backoff mechanism diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -23,8 +23,17 @@ // corresponds to ~700 bytes nursery fill #define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.0001) +#define BACKOFF_MULTIPLIER (0.05 / STM_MIN_RELATIVE_TRANSACTION_LENGTH) -static double get_new_transaction_length(stm_thread_local_t *tl, bool aborts) { +static inline void set_backoff(stm_thread_local_t *tl, double rel_trx_len) { +// the shorter the trx, the more backoff: 100 at min trx length, proportional decrease to 5 at max trx length (think a/x + b = backoff) +tl->transaction_length_backoff = +(int)(1 / (BACKOFF_MULTIPLIER * rel_trx_len) + 5); +// printf("thread %d, backoff %d\n", tl->thread_local_counter, tl->transaction_length_backoff); +tl->linear_transaction_length_increment = rel_trx_len; +} + +static inline double get_new_transaction_length(stm_thread_local_t *tl, bool aborts) { const int multiplier = 100; double previous = tl->relative_transaction_length; double new = previous; @@ -34,10 +43,7 @@ } else { new = STM_MIN_RELATIVE_TRANSACTION_LENGTH; } -// the shorter the trx, the more backoff: 1000 at min trx length, proportional decrease to 1 at max trx length (think a/x + b = backoff) -tl->transaction_length_backoff = (int)(1 / (1 * new) + 5); -// printf("thread %d, backoff %d\n", tl->thread_local_counter, tl->transaction_length_backoff); -tl->linear_transaction_length_increment = new; +set_backoff(tl, new); } else if (tl->transaction_length_backoff == 0) { // backoff counter is zero, exponential increase up to 1 if (previous < 1) { @@ -53,11 +59,11 @@ return new; } -static void stm_transaction_length_handle_validation(stm_thread_local_t *tl, bool aborts) { +static inline void stm_transaction_length_handle_validation(stm_thread_local_t *tl, bool aborts) { tl->relative_transaction_length = get_new_transaction_length(tl, aborts); } -static uintptr_t stm_get_transaction_length(stm_thread_local_t *tl) { +static inline uintptr_t stm_get_transaction_length(stm_thread_local_t *tl) { double relative_additional_length = tl->relative_transaction_length; publish_custom_value_event( relative_additional_length, STM_SINGLE_THREAD_MODE_ADAPTIVE); diff --git a/c8/stm/nursery.h b/c8/stm/nursery.h --- a/c8/stm/nursery.h +++ b/c8/stm/nursery.h @@ -59,7 +59,7 @@ static uint32_t stm_max_conflicts; static uint32_t stm_global_conflicts; -static void stm_transaction_length_handle_validation(stm_thread_local_t *tl, bool aborts); -static uintptr_t stm_get_transaction_length(stm_thread_local_t *tl); +static inline void stm_transaction_length_handle_validation(stm_thread_local_t *tl, bool aborts); +static inline uintptr_t stm_get_transaction_length(stm_thread_local_t *tl); #endif ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Introduce slow start mechanism
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2122:f6be3fc14929 Date: 2017-07-16 13:38 +0200 http://bitbucket.org/pypy/stmgc/changeset/f6be3fc14929/ Log:Introduce slow start mechanism diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -49,6 +49,10 @@ if (previous < 1) { new = previous * multiplier; } +if (tl->linear_transaction_length_increment != 0) { +// thread had to abort before: slow start +set_backoff(tl, new); +} } else { // not abort and backoff != 0 // in backoff, linear increase up to 1 if (previous < 1) { ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Fix missing type definitions for custom payload
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2118:e912698faa40 Date: 2017-07-14 20:27 +0200 http://bitbucket.org/pypy/stmgc/changeset/e912698faa40/ Log:Fix missing type definitions for custom payload diff --git a/c8/stm/timing.h b/c8/stm/timing.h --- a/c8/stm/timing.h +++ b/c8/stm/timing.h @@ -1,5 +1,9 @@ #include +#define define_payload_types() \ +stm_timing_event_payload_data_t stm_duration_data; \ +stm_timing_event_payload_t stm_duration_payload; + #define continue_timer() clock_gettime(CLOCK_MONOTONIC_RAW, &start); /* Use raw monotonic time, i.e., solely based on local hardware (no NTP @@ -8,8 +12,7 @@ #define start_timer() struct timespec start, stop; \ struct timespec duration = { .tv_sec = 0, .tv_nsec = 0 };\ uint32_t nanosec_diff, sec_diff; \ - stm_timing_event_payload_data_t stm_duration_data; \ - stm_timing_event_payload_t stm_duration_payload; \ + define_payload_types() \ continue_timer() /* Must use start_timer before using this macro. */ @@ -59,5 +62,6 @@ #define publish_custom_value_event(double_value, event) \ set_payload((double_value)) \ +define_payload_types() \ stm_duration_payload(payload_value);\ publish_event(STM_SEGMENT->running_thread, (event)) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Move transaction length update on abort
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2114:7b939c8fa0b0 Date: 2017-07-14 12:49 +0200 http://bitbucket.org/pypy/stmgc/changeset/7b939c8fa0b0/ Log:Move transaction length update on abort diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1551,8 +1551,6 @@ did_abort = 1; #endif -stm_transaction_length_handle_validation(pseg->pub.running_thread, true); - list_clear(pseg->objects_pointing_to_nursery); list_clear(pseg->old_objects_with_cards_set); LIST_FOREACH_R(pseg->large_overflow_objects, uintptr_t /*item*/, @@ -1583,6 +1581,8 @@ tl->self_or_0_if_atomic = (intptr_t)tl; /* clear the 'atomic' flag */ STM_PSEGMENT->atomic_nesting_levels = 0; +stm_transaction_length_handle_validation(tl, true); + if (tl->mem_clear_on_abort) memset(tl->mem_clear_on_abort, 0, tl->mem_bytes_to_clear_on_abort); if (tl->mem_reset_on_abort) { ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-overheads-instrumentation: Merge latest changes from master
Author: Tobias Weber Branch: c8-overheads-instrumentation Changeset: r2110:683f252182e3 Date: 2017-07-14 17:41 +0200 http://bitbucket.org/pypy/stmgc/changeset/683f252182e3/ Log:Merge latest changes from master diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -379,6 +379,14 @@ static void readd_wb_executed_flags(void); static void check_all_write_barrier_flags(char *segbase, struct list_s *list); +static void signal_commit_to_inevitable_transaction(void) { +struct stm_priv_segment_info_s* inevitable_segement = get_inevitable_thread_segment(); +if (inevitable_segement != 0) { +// the inevitable thread is still running: set its "please commit" flag (is ignored by the inevitable thread if it is atomic) +inevitable_segement->commit_if_not_atomic = true; +} +} + static void wait_for_inevitable(void) { intptr_t detached = 0; @@ -395,6 +403,8 @@ try to detach an inevitable transaction regularly */ detached = fetch_detached_transaction(); if (detached == 0) { +// the inevitable trx was not detached or it was detached but is atomic +signal_commit_to_inevitable_transaction(); EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) goto wait_some_more; @@ -1168,6 +1178,7 @@ _do_start_transaction(tl); continue_timer(); +STM_PSEGMENT->commit_if_not_atomic = false; 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 + @@ -1641,7 +1652,7 @@ void _stm_become_inevitable(const char *msg) { -int num_waits = 0; +int num_waits = 1; timing_become_inevitable(); @@ -1652,50 +1663,48 @@ if (msg != MSG_INEV_DONT_SLEEP) { dprintf(("become_inevitable: %s\n", msg)); -if (any_soon_finished_or_inevitable_thread_segment() && -num_waits <= NB_SEGMENTS) { +if (any_soon_finished_or_inevitable_thread_segment()) { #if STM_TESTS /* for tests: another transaction */ stm_abort_transaction();/* is already inevitable, abort */ #endif -bool timed_out = false; +signal_commit_to_inevitable_transaction(); s_mutex_lock(); if (any_soon_finished_or_inevitable_thread_segment() && -!safe_point_requested()) { +!safe_point_requested() && +num_waits <= NB_SEGMENTS) { /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); -if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, - 0.54321)) -timed_out = true; +if (cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) { +num_waits++; +} } s_mutex_unlock(); - -if (timed_out) { -/* try to detach another inevitable transaction, but - only after waiting a bit. This is necessary to avoid - deadlocks in some situations, which are hopefully - not too common. We don't want two threads constantly - detaching each other. */ -intptr_t detached = fetch_detached_transaction(); -if (detached != 0) { -EMIT_WAIT_DONE(); -commit_fetched_detached_transaction(detached); -} -} -else { -num_waits++; +/* XXX try to detach another inevitable transaction, but + only after waiting a bit. This is necessary to avoid + deadlocks in some situations, which are hopefully + not too common. We don't want two threads constantly + detaching each other. */ +intptr_t detached = fetch_detached_transaction(); +if (detached != 0) { + EMIT_WAIT_DONE(); + commit_fetched_detached_transaction(detached); + EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); } goto retry_from_start; } -EMIT_WAIT_DONE(); -if (!_validate_and_turn_inevitable()) -goto retry_from_start; +else { +EMIT_WAIT_DONE(); +if (!_validate_and_turn_inevitable()) { +EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); +goto retry_from_start; +} +} } -else { -if (!_validate_and_turn_inevitable()) -return; +else if (!_validate_and_turn_inevitable()) { +return; } /* There may be a concurrent co
[pypy-commit] stmgc c8-tcp-style-trx-length: Move transaction length update for aborts to validation
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2119:dbea548c4c6e Date: 2017-07-15 18:12 +0200 http://bitbucket.org/pypy/stmgc/changeset/dbea548c4c6e/ Log:Move transaction length update for aborts to validation diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -347,6 +347,9 @@ } if (thread_local_for_logging != NULL) { +if (needs_abort) { +stm_transaction_length_handle_validation(thread_local_for_logging, true); +} stop_timer_and_publish_for_thread( thread_local_for_logging, STM_DURATION_VALIDATION); } @@ -1582,8 +1585,6 @@ tl->self_or_0_if_atomic = (intptr_t)tl; /* clear the 'atomic' flag */ STM_PSEGMENT->atomic_nesting_levels = 0; -stm_transaction_length_handle_validation(tl, true); - if (tl->mem_clear_on_abort) memset(tl->mem_clear_on_abort, 0, tl->mem_bytes_to_clear_on_abort); if (tl->mem_reset_on_abort) { ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Merge fix of commit signalling fix
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2113:003bd8a738d7 Date: 2017-07-14 17:57 +0200 http://bitbucket.org/pypy/stmgc/changeset/003bd8a738d7/ Log:Merge fix of commit signalling fix diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1178,6 +1178,7 @@ _do_start_transaction(tl); continue_timer(); +STM_PSEGMENT->commit_if_not_atomic = false; STM_SEGMENT->nursery_mark = ((stm_char *)_stm_nursery_start + stm_get_transaction_length(tl)); diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -549,8 +549,9 @@ pseg->pub.nursery_current = (stm_char *)_stm_nursery_start; pseg->pub.nursery_mark -= nursery_used; +assert((pseg->transaction_state == TS_INEVITABLE) || !pseg->commit_if_not_atomic); if (pseg->commit_if_not_atomic -// && pseg->transaction_state == TS_INEVITABLE // TODO why does this break the mechanism? +&& pseg->transaction_state == TS_INEVITABLE && pseg->pub.running_thread->self_or_0_if_atomic != 0) { // transaction is inevitable, not atomic, and commit has been signalled by waiting thread: commit immediately pseg->pub.nursery_mark = 0; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-overheads-instrumentation: Fix redefinition of payload data when using stop timer macro more than once in a function
Author: Tobias Weber Branch: c8-overheads-instrumentation Changeset: r2116:59e0bec0fd9b Date: 2017-07-14 19:00 +0200 http://bitbucket.org/pypy/stmgc/changeset/59e0bec0fd9b/ Log:Fix redefinition of payload data when using stop timer macro more than once in a function diff --git a/c8/stm/timing.h b/c8/stm/timing.h --- a/c8/stm/timing.h +++ b/c8/stm/timing.h @@ -8,6 +8,8 @@ #define start_timer() struct timespec start, stop; \ struct timespec duration = { .tv_sec = 0, .tv_nsec = 0 };\ uint32_t nanosec_diff, sec_diff; \ + stm_timing_event_payload_data_t stm_duration_data; \ + stm_timing_event_payload_t stm_duration_payload; \ continue_timer() /* Must use start_timer before using this macro. */ @@ -30,10 +32,9 @@ #define reset_timer() duration.tv_sec = 0; duration.tv_nsec = 0; #define stm_duration_payload(duration_data) \ -stm_timing_event_payload_data_t stm_duration_data = \ -{ .duration = &(duration_data) }; \ -stm_timing_event_payload_t stm_duration_payload = \ -{ STM_EVENT_PAYLOAD_DURATION, stm_duration_data }; +stm_duration_data.duration = &(duration_data); \ +stm_duration_payload.type = STM_EVENT_PAYLOAD_DURATION; \ +stm_duration_payload.data = stm_duration_data; #define publish_event(thread_local, event) \ (timing_enabled() ? \ ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-efficient-serial-execution-master: Fix commit signal was not reset on transaction start
Author: Tobias Weber Branch: c8-efficient-serial-execution-master Changeset: r2108:b5c1dadb9699 Date: 2017-07-13 21:40 +0200 http://bitbucket.org/pypy/stmgc/changeset/b5c1dadb9699/ Log:Fix commit signal was not reset on transaction start diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1116,6 +1116,7 @@ } _do_start_transaction(tl); +STM_PSEGMENT->commit_if_not_atomic = false; 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 + diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -500,8 +500,9 @@ pseg->pub.nursery_current = (stm_char *)_stm_nursery_start; pseg->pub.nursery_mark -= nursery_used; +assert((pseg->transaction_state == TS_INEVITABLE) || !pseg->commit_if_not_atomic) if (pseg->commit_if_not_atomic -// && pseg->transaction_state == TS_INEVITABLE // TODO why does this break the mechanism? +&& pseg->transaction_state == TS_INEVITABLE && pseg->pub.running_thread->self_or_0_if_atomic != 0) { // transaction is inevitable, not atomic, and commit has been signalled by waiting thread: commit immediately pseg->pub.nursery_mark = 0; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Merge latest instrumentation fixes
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2115:47ae8bbc2b7e Date: 2017-07-14 18:01 +0200 http://bitbucket.org/pypy/stmgc/changeset/47ae8bbc2b7e/ Log:Merge latest instrumentation fixes diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -468,8 +468,8 @@ #endif if (STM_PSEGMENT->last_commit_log_entry->next == INEV_RUNNING) { -pause_timer(); -wait_for_inevitable(); // TODO may abort!! timing event lost +stop_timer_and_publish(STM_DURATION_VALIDATION); +wait_for_inevitable(); continue_timer(); goto retry_from_start; /* redo _stm_validate() now */ } @@ -559,14 +559,13 @@ OPT_ASSERT(yes); release_modification_lock_wr(STM_SEGMENT->segment_num); + +stop_timer_and_publish(STM_DURATION_VALIDATION); } else { -pause_timer(); +stop_timer_and_publish(STM_DURATION_VALIDATION); _validate_and_attach(new); -continue_timer(); } - -stop_timer_and_publish(STM_DURATION_VALIDATION); } /* # STM # */ @@ -1327,7 +1326,9 @@ if there is an inevitable tx running) */ bool was_inev = STM_PSEGMENT->transaction_state == TS_INEVITABLE; -pause_timer(); +// publish here because the validation may abort +stop_timer_and_publish_for_thread( +thread_local_for_logging, STM_DURATION_COMMIT_EXCEPT_GC); _validate_and_add_to_commit_log(); continue_timer(); @@ -1656,9 +1657,9 @@ signal_commit_to_inevitable_transaction(); s_mutex_lock(); -if (any_soon_finished_or_inevitable_thread_segment() && -!safe_point_requested() && -num_waits <= NB_SEGMENTS) { +if (any_soon_finished_or_inevitable_thread_segment() +&& !safe_point_requested() +&& num_waits <= NB_SEGMENTS) { /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -781,16 +781,21 @@ static void major_do_validation_and_minor_collections(void) { +start_timer(); + int original_num = STM_SEGMENT->segment_num; long i; assert(_has_mutex()); /* including the sharing seg0 */ -for (i = 0; i < NB_SEGMENTS; i++) { +for (i = 0; i < NB_SEGMENTS; i++) { // TODO why is this strictly smaller than? ensure_gs_register(i); +pause_timer(); bool ok = _stm_validate(); +continue_timer(); + assert(get_priv_segment(i)->last_commit_log_entry->next == NULL || get_priv_segment(i)->last_commit_log_entry->next == INEV_RUNNING); if (!ok) { @@ -825,7 +830,9 @@ Collecting might fail due to invalid state. */ if (!must_abort()) { +pause_timer(); _do_minor_collection(/*commit=*/ false); +continue_timer(); assert(MINOR_NOTHING_TO_DO(STM_PSEGMENT)); } else { @@ -835,6 +842,8 @@ } ensure_gs_register(original_num); + +stop_timer_and_publish(STM_DURATION_MAJOR_GC_FULL); } diff --git a/c8/stm/timing.h b/c8/stm/timing.h --- a/c8/stm/timing.h +++ b/c8/stm/timing.h @@ -27,6 +27,8 @@ #define pause_timer() clock_gettime(CLOCK_MONOTONIC_RAW, &stop);\ get_duration() +#define reset_timer() duration.tv_sec = 0; duration.tv_nsec = 0; + #define stm_duration_payload(duration_data) \ stm_timing_event_payload_data_t stm_duration_data = \ { .duration = &(duration_data) }; \ @@ -42,7 +44,8 @@ pause_timer() \ stm_duration_payload(duration) \ assert((thread_local) != NULL); \ -publish_event((thread_local), (event)) +publish_event((thread_local), (event)) \ +reset_timer() #define stop_timer_and_publish(event) \ stop_timer_and_publish_for_thread(STM_SEGMENT->running_thread, (event)) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Update from efficient serial execution master with starvation fix
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2107:3868dfdf70fd Date: 2017-07-12 19:55 +0200 http://bitbucket.org/pypy/stmgc/changeset/3868dfdf70fd/ Log:Update from efficient serial execution master with starvation fix diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1636,7 +1636,7 @@ void _stm_become_inevitable(const char *msg) { -int num_waits = 0; +int num_waits = 1; timing_become_inevitable(); @@ -1647,42 +1647,42 @@ if (msg != MSG_INEV_DONT_SLEEP) { dprintf(("become_inevitable: %s\n", msg)); -if (any_soon_finished_or_inevitable_thread_segment() && -num_waits <= NB_SEGMENTS) { +if (any_soon_finished_or_inevitable_thread_segment()) { #if STM_TESTS /* for tests: another transaction */ stm_abort_transaction();/* is already inevitable, abort */ #endif +signal_commit_to_inevitable_transaction(); + s_mutex_lock(); if (any_soon_finished_or_inevitable_thread_segment() && -!safe_point_requested()) { - -signal_commit_to_inevitable_transaction(); +!safe_point_requested() && +num_waits <= NB_SEGMENTS) { /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); -if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) { -s_mutex_unlock(); -/* try to detach another inevitable transaction, but - only after waiting a bit. This is necessary to avoid - deadlocks in some situations, which are hopefully - not too common. We don't want two threads constantly - detaching each other. */ -intptr_t detached = fetch_detached_transaction(); -if (detached != 0) { - EMIT_WAIT_DONE(); - commit_fetched_detached_transaction(detached); -} -goto retry_from_start; +if (cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) { +num_waits++; } -num_waits++; } s_mutex_unlock(); +/* XXX try to detach another inevitable transaction, but + only after waiting a bit. This is necessary to avoid + deadlocks in some situations, which are hopefully + not too common. We don't want two threads constantly + detaching each other. */ +intptr_t detached = fetch_detached_transaction(); +if (detached != 0) { + EMIT_WAIT_DONE(); + commit_fetched_detached_transaction(detached); + EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); +} goto retry_from_start; } else { EMIT_WAIT_DONE(); if (!_validate_and_turn_inevitable()) { +EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); goto retry_from_start; } } diff --git a/c8/stm/detach.c b/c8/stm/detach.c --- a/c8/stm/detach.c +++ b/c8/stm/detach.c @@ -229,14 +229,18 @@ return STM_PSEGMENT->atomic_nesting_levels; } +// max intptr_t value is 7FFF on 64-bit => larger than 2 * huge value #define HUGE_INTPTR_VALUE 0x3000L void stm_enable_atomic(stm_thread_local_t *tl) { if (!stm_is_atomic(tl)) { +// do for outermost atomic block only tl->self_or_0_if_atomic = 0; /* increment 'nursery_mark' by HUGE_INTPTR_VALUE, so that - stm_should_break_transaction() returns always false */ + stm_should_break_transaction() returns always false. + preserves the previous nursery_mark, unless it is < 0 + or >= huge value */ intptr_t mark = (intptr_t)STM_SEGMENT->nursery_mark; if (mark < 0) mark = 0; @@ -256,6 +260,7 @@ STM_PSEGMENT->atomic_nesting_levels--; if (STM_PSEGMENT->atomic_nesting_levels == 0) { +// revert changes by stm_enable_atomic only if we left the outermost atomic block tl->self_or_0_if_atomic = (intptr_t)tl; /* decrement 'nursery_mark' by HUGE_INTPTR_VALUE, to cancel what was done in stm_enable_atomic() */ ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-overheads-instrumentation: Fix some timings that could be lost when aborting by publishing and resetting timer eagerly
Author: Tobias Weber Branch: c8-overheads-instrumentation Changeset: r2111:364f9fb71d3e Date: 2017-07-14 17:43 +0200 http://bitbucket.org/pypy/stmgc/changeset/364f9fb71d3e/ Log:Fix some timings that could be lost when aborting by publishing and resetting timer eagerly diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -468,8 +468,8 @@ #endif if (STM_PSEGMENT->last_commit_log_entry->next == INEV_RUNNING) { -pause_timer(); -wait_for_inevitable(); // TODO may abort!! timing event lost +stop_timer_and_publish(STM_DURATION_VALIDATION); +wait_for_inevitable(); continue_timer(); goto retry_from_start; /* redo _stm_validate() now */ } @@ -559,14 +559,13 @@ OPT_ASSERT(yes); release_modification_lock_wr(STM_SEGMENT->segment_num); + +stop_timer_and_publish(STM_DURATION_VALIDATION); } else { -pause_timer(); +stop_timer_and_publish(STM_DURATION_VALIDATION); _validate_and_attach(new); -continue_timer(); } - -stop_timer_and_publish(STM_DURATION_VALIDATION); } /* # STM # */ @@ -1330,7 +1329,9 @@ if there is an inevitable tx running) */ bool was_inev = STM_PSEGMENT->transaction_state == TS_INEVITABLE; -pause_timer(); +// publish here because the validation may abort +stop_timer_and_publish_for_thread( +thread_local_for_logging, STM_DURATION_COMMIT_EXCEPT_GC); _validate_and_add_to_commit_log(); continue_timer(); @@ -1671,9 +1672,9 @@ signal_commit_to_inevitable_transaction(); s_mutex_lock(); -if (any_soon_finished_or_inevitable_thread_segment() && -!safe_point_requested() && -num_waits <= NB_SEGMENTS) { +if (any_soon_finished_or_inevitable_thread_segment() +&& !safe_point_requested() +&& num_waits <= NB_SEGMENTS) { /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); diff --git a/c8/stm/timing.h b/c8/stm/timing.h --- a/c8/stm/timing.h +++ b/c8/stm/timing.h @@ -27,6 +27,8 @@ #define pause_timer() clock_gettime(CLOCK_MONOTONIC_RAW, &stop);\ get_duration() +#define reset_timer() duration.tv_sec = 0; duration.tv_nsec = 0; + #define stm_duration_payload(duration_data) \ stm_timing_event_payload_data_t stm_duration_data = \ { .duration = &(duration_data) }; \ @@ -42,7 +44,8 @@ pause_timer() \ stm_duration_payload(duration) \ assert((thread_local) != NULL); \ -publish_event((thread_local), (event)) +publish_event((thread_local), (event)) \ +reset_timer() #define stop_timer_and_publish(event) \ stop_timer_and_publish_for_thread(STM_SEGMENT->running_thread, (event)) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-efficient-serial-execution-master: Fix syntax error
Author: Tobias Weber Branch: c8-efficient-serial-execution-master Changeset: r2109:88e69ad8 Date: 2017-07-13 22:37 +0200 http://bitbucket.org/pypy/stmgc/changeset/88e69ad8/ Log:Fix syntax error diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -500,7 +500,7 @@ pseg->pub.nursery_current = (stm_char *)_stm_nursery_start; pseg->pub.nursery_mark -= nursery_used; -assert((pseg->transaction_state == TS_INEVITABLE) || !pseg->commit_if_not_atomic) +assert((pseg->transaction_state == TS_INEVITABLE) || !pseg->commit_if_not_atomic); if (pseg->commit_if_not_atomic && pseg->transaction_state == TS_INEVITABLE && pseg->pub.running_thread->self_or_0_if_atomic != 0) { ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-overheads-instrumentation: Instrument more of the major GC
Author: Tobias Weber Branch: c8-overheads-instrumentation Changeset: r2112:00fa92be3c0f Date: 2017-07-14 17:44 +0200 http://bitbucket.org/pypy/stmgc/changeset/00fa92be3c0f/ Log:Instrument more of the major GC diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -732,16 +732,21 @@ static void major_do_validation_and_minor_collections(void) { +start_timer(); + int original_num = STM_SEGMENT->segment_num; long i; assert(_has_mutex()); /* including the sharing seg0 */ -for (i = 0; i < NB_SEGMENTS; i++) { +for (i = 0; i < NB_SEGMENTS; i++) { // TODO why is this strictly smaller than? ensure_gs_register(i); +pause_timer(); bool ok = _stm_validate(); +continue_timer(); + assert(get_priv_segment(i)->last_commit_log_entry->next == NULL || get_priv_segment(i)->last_commit_log_entry->next == INEV_RUNNING); if (!ok) { @@ -776,7 +781,9 @@ Collecting might fail due to invalid state. */ if (!must_abort()) { +pause_timer(); _do_minor_collection(/*commit=*/ false); +continue_timer(); assert(MINOR_NOTHING_TO_DO(STM_PSEGMENT)); } else { @@ -786,6 +793,8 @@ } ensure_gs_register(original_num); + +stop_timer_and_publish(STM_DURATION_MAJOR_GC_FULL); } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Merge instrumentation updates
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2103:5d396c49837a Date: 2017-07-11 17:04 +0200 http://bitbucket.org/pypy/stmgc/changeset/5d396c49837a/ Log:Merge instrumentation updates diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -358,9 +358,6 @@ static struct stm_commit_log_entry_s *_create_commit_log_entry(void) { /* puts all modified_old_objects in a new commit log entry */ - -start_timer(); - // we don't need the privatization lock, as we are only // reading from modified_old_objs and nobody but us can change it struct list_s *list = STM_PSEGMENT->modified_old_objects; @@ -374,8 +371,6 @@ result->written_count = count; memcpy(result->written, list->items, count * sizeof(struct stm_undo_s)); -stop_timer_and_publish(STM_DURATION_CREATE_CLE); - return result; } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-overheads-instrumentation: Remove timing that was nested with the expanded validation timing
Author: Tobias Weber Branch: c8-overheads-instrumentation Changeset: r2101:8efefe78725b Date: 2017-07-11 17:02 +0200 http://bitbucket.org/pypy/stmgc/changeset/8efefe78725b/ Log:Remove timing that was nested with the expanded validation timing diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -358,9 +358,6 @@ static struct stm_commit_log_entry_s *_create_commit_log_entry(void) { /* puts all modified_old_objects in a new commit log entry */ - -start_timer(); - // we don't need the privatization lock, as we are only // reading from modified_old_objs and nobody but us can change it struct list_s *list = STM_PSEGMENT->modified_old_objects; @@ -374,8 +371,6 @@ result->written_count = count; memcpy(result->written, list->items, count * sizeof(struct stm_undo_s)); -stop_timer_and_publish(STM_DURATION_CREATE_CLE); - return result; } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-efficient-serial-execution-master: Merge fix for starvation when becoming inevitable
Author: Tobias Weber Branch: c8-efficient-serial-execution-master Changeset: r2099:1d6ca16fa0aa Date: 2017-07-11 13:12 +0200 http://bitbucket.org/pypy/stmgc/changeset/1d6ca16fa0aa/ Log:Merge fix for starvation when becoming inevitable diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1571,7 +1571,7 @@ void _stm_become_inevitable(const char *msg) { -int num_waits = 0; +int num_waits = 1; timing_become_inevitable(); @@ -1582,42 +1582,42 @@ if (msg != MSG_INEV_DONT_SLEEP) { dprintf(("become_inevitable: %s\n", msg)); -if (any_soon_finished_or_inevitable_thread_segment() && -num_waits <= NB_SEGMENTS) { +if (any_soon_finished_or_inevitable_thread_segment()) { #if STM_TESTS /* for tests: another transaction */ stm_abort_transaction();/* is already inevitable, abort */ #endif +signal_commit_to_inevitable_transaction(); + s_mutex_lock(); if (any_soon_finished_or_inevitable_thread_segment() && -!safe_point_requested()) { - -signal_commit_to_inevitable_transaction(); +!safe_point_requested() && +num_waits <= NB_SEGMENTS) { /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); -if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) { -s_mutex_unlock(); -/* try to detach another inevitable transaction, but - only after waiting a bit. This is necessary to avoid - deadlocks in some situations, which are hopefully - not too common. We don't want two threads constantly - detaching each other. */ -intptr_t detached = fetch_detached_transaction(); -if (detached != 0) { - EMIT_WAIT_DONE(); - commit_fetched_detached_transaction(detached); -} -goto retry_from_start; +if (cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) { +num_waits++; } -num_waits++; } s_mutex_unlock(); +/* XXX try to detach another inevitable transaction, but + only after waiting a bit. This is necessary to avoid + deadlocks in some situations, which are hopefully + not too common. We don't want two threads constantly + detaching each other. */ +intptr_t detached = fetch_detached_transaction(); +if (detached != 0) { + EMIT_WAIT_DONE(); + commit_fetched_detached_transaction(detached); + EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); +} goto retry_from_start; } else { EMIT_WAIT_DONE(); if (!_validate_and_turn_inevitable()) { +EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); goto retry_from_start; } } diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -501,7 +501,7 @@ pseg->pub.nursery_mark -= nursery_used; if (pseg->commit_if_not_atomic -// && pseg->transaction_state == TS_INEVITABLE // TODO why does this break the mechanism? +// && pseg->transaction_state == TS_INEVITABLE // TODO why does this break the mechanism? && pseg->pub.running_thread->self_or_0_if_atomic != 0) { // transaction is inevitable, not atomic, and commit has been signalled by waiting thread: commit immediately pseg->pub.nursery_mark = 0; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-prolonged-backoff:
Author: Tobias Weber Branch: c8-adaptive-trx-length-prolonged-backoff Changeset: r2105:925c3ad90c24 Date: 2017-07-11 17:05 +0200 http://bitbucket.org/pypy/stmgc/changeset/925c3ad90c24/ Log: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length:
Author: Tobias Weber Branch: c8-adaptive-trx-length Changeset: r2106:7230091fb9c5 Date: 2017-07-11 17:05 +0200 http://bitbucket.org/pypy/stmgc/changeset/7230091fb9c5/ Log: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Merge starvation fix
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2100:66f838f8595b Date: 2017-07-11 13:15 +0200 http://bitbucket.org/pypy/stmgc/changeset/66f838f8595b/ Log:Merge starvation fix diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1638,7 +1638,7 @@ void _stm_become_inevitable(const char *msg) { -int num_waits = 0; +int num_waits = 1; timing_become_inevitable(); @@ -1649,42 +1649,42 @@ if (msg != MSG_INEV_DONT_SLEEP) { dprintf(("become_inevitable: %s\n", msg)); -if (any_soon_finished_or_inevitable_thread_segment() && -num_waits <= NB_SEGMENTS) { +if (any_soon_finished_or_inevitable_thread_segment()) { #if STM_TESTS /* for tests: another transaction */ stm_abort_transaction();/* is already inevitable, abort */ #endif +signal_commit_to_inevitable_transaction(); + s_mutex_lock(); if (any_soon_finished_or_inevitable_thread_segment() && -!safe_point_requested()) { - -signal_commit_to_inevitable_transaction(); +!safe_point_requested() && +num_waits <= NB_SEGMENTS) { /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); -if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) { -s_mutex_unlock(); -/* try to detach another inevitable transaction, but - only after waiting a bit. This is necessary to avoid - deadlocks in some situations, which are hopefully - not too common. We don't want two threads constantly - detaching each other. */ -intptr_t detached = fetch_detached_transaction(); -if (detached != 0) { - EMIT_WAIT_DONE(); - commit_fetched_detached_transaction(detached); -} -goto retry_from_start; +if (cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) { +num_waits++; } -num_waits++; } s_mutex_unlock(); +/* XXX try to detach another inevitable transaction, but + only after waiting a bit. This is necessary to avoid + deadlocks in some situations, which are hopefully + not too common. We don't want two threads constantly + detaching each other. */ +intptr_t detached = fetch_detached_transaction(); +if (detached != 0) { + EMIT_WAIT_DONE(); + commit_fetched_detached_transaction(detached); + EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); +} goto retry_from_start; } else { EMIT_WAIT_DONE(); if (!_validate_and_turn_inevitable()) { +EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); goto retry_from_start; } } diff --git a/c8/stm/detach.c b/c8/stm/detach.c --- a/c8/stm/detach.c +++ b/c8/stm/detach.c @@ -229,14 +229,18 @@ return STM_PSEGMENT->atomic_nesting_levels; } +// max intptr_t value is 7FFF on 64-bit => larger than 2 * huge value #define HUGE_INTPTR_VALUE 0x3000L void stm_enable_atomic(stm_thread_local_t *tl) { if (!stm_is_atomic(tl)) { +// do for outermost atomic block only tl->self_or_0_if_atomic = 0; /* increment 'nursery_mark' by HUGE_INTPTR_VALUE, so that - stm_should_break_transaction() returns always false */ + stm_should_break_transaction() returns always false. + preserves the previous nursery_mark, unless it is < 0 + or >= huge value */ intptr_t mark = (intptr_t)STM_SEGMENT->nursery_mark; if (mark < 0) mark = 0; @@ -256,6 +260,7 @@ STM_PSEGMENT->atomic_nesting_levels--; if (STM_PSEGMENT->atomic_nesting_levels == 0) { +// revert changes by stm_enable_atomic only if we left the outermost atomic block tl->self_or_0_if_atomic = (intptr_t)tl; /* decrement 'nursery_mark' by HUGE_INTPTR_VALUE, to cancel what was done in stm_enable_atomic() */ diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -543,7 +543,7 @@ pseg->pub.nursery_mark -= nursery_used; if (pseg->commit_if_not_atomic -// && pseg->transaction_state == TS_INEVITABLE // TODO why does this break the mechanism? +// && pseg->transaction_state == TS_INEVITABLE // TODO why does this break the mechanism? && pseg->pub.running_thread->self_or_0_if_atomic != 0) { // transaction is inevitable, not a
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Merge instrumentation updates
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2102:4f80bfd40482 Date: 2017-07-11 17:03 +0200 http://bitbucket.org/pypy/stmgc/changeset/4f80bfd40482/ Log:Merge instrumentation updates diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -359,9 +359,6 @@ static struct stm_commit_log_entry_s *_create_commit_log_entry(void) { /* puts all modified_old_objects in a new commit log entry */ - -start_timer(); - // we don't need the privatization lock, as we are only // reading from modified_old_objs and nobody but us can change it struct list_s *list = STM_PSEGMENT->modified_old_objects; @@ -375,8 +372,6 @@ result->written_count = count; memcpy(result->written, list->items, count * sizeof(struct stm_undo_s)); -stop_timer_and_publish(STM_DURATION_CREATE_CLE); - return result; } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-binary-trx-length-per-thread: Merge instrumentation updates
Author: Tobias Weber Branch: c8-binary-trx-length-per-thread Changeset: r2104:c86068cb4b91 Date: 2017-07-11 17:05 +0200 http://bitbucket.org/pypy/stmgc/changeset/c86068cb4b91/ Log:Merge instrumentation updates diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -359,9 +359,6 @@ static struct stm_commit_log_entry_s *_create_commit_log_entry(void) { /* puts all modified_old_objects in a new commit log entry */ - -start_timer(); - // we don't need the privatization lock, as we are only // reading from modified_old_objs and nobody but us can change it struct list_s *list = STM_PSEGMENT->modified_old_objects; @@ -375,8 +372,6 @@ result->written_count = count; memcpy(result->written, list->items, count * sizeof(struct stm_undo_s)); -stop_timer_and_publish(STM_DURATION_CREATE_CLE); - return result; } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-efficient-serial-execution-master: Merge signal commit to inevitable transactions
Author: Tobias Weber Branch: c8-efficient-serial-execution-master Changeset: r2096:3990ee687ca5 Date: 2017-07-10 17:05 +0200 http://bitbucket.org/pypy/stmgc/changeset/3990ee687ca5/ Log:Merge signal commit to inevitable transactions diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -366,6 +366,14 @@ static void readd_wb_executed_flags(void); static void check_all_write_barrier_flags(char *segbase, struct list_s *list); +static void signal_commit_to_inevitable_transaction(void) { +struct stm_priv_segment_info_s* inevitable_segement = get_inevitable_thread_segment(); +if (inevitable_segement != 0) { +// the inevitable thread is still running: set its "please commit" flag (is ignored by the inevitable thread if it is atomic) +inevitable_segement->commit_if_not_atomic = true; +} +} + static void wait_for_inevitable(void) { intptr_t detached = 0; @@ -382,6 +390,8 @@ try to detach an inevitable transaction regularly */ detached = fetch_detached_transaction(); if (detached == 0) { +// the inevitable trx was not detached or it was detached but is atomic +signal_commit_to_inevitable_transaction(); EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) goto wait_some_more; @@ -1578,44 +1588,42 @@ stm_abort_transaction();/* is already inevitable, abort */ #endif -bool timed_out = false; - s_mutex_lock(); if (any_soon_finished_or_inevitable_thread_segment() && !safe_point_requested()) { +signal_commit_to_inevitable_transaction(); + /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); -if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, - 0.54321)) -timed_out = true; +if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) { +s_mutex_unlock(); +/* try to detach another inevitable transaction, but + only after waiting a bit. This is necessary to avoid + deadlocks in some situations, which are hopefully + not too common. We don't want two threads constantly + detaching each other. */ +intptr_t detached = fetch_detached_transaction(); +if (detached != 0) { + EMIT_WAIT_DONE(); + commit_fetched_detached_transaction(detached); +} +goto retry_from_start; +} +num_waits++; } s_mutex_unlock(); - -if (timed_out) { -/* try to detach another inevitable transaction, but - only after waiting a bit. This is necessary to avoid - deadlocks in some situations, which are hopefully - not too common. We don't want two threads constantly - detaching each other. */ -intptr_t detached = fetch_detached_transaction(); -if (detached != 0) { -EMIT_WAIT_DONE(); -commit_fetched_detached_transaction(detached); -} -} -else { -num_waits++; -} goto retry_from_start; } -EMIT_WAIT_DONE(); -if (!_validate_and_turn_inevitable()) -goto retry_from_start; +else { +EMIT_WAIT_DONE(); +if (!_validate_and_turn_inevitable()) { +goto retry_from_start; +} +} } -else { -if (!_validate_and_turn_inevitable()) -return; +else if (!_validate_and_turn_inevitable()) { +return; } /* There may be a concurrent commit of a detached Tx going on. @@ -1627,6 +1635,7 @@ stm_spin_loop(); assert(_stm_detached_inevitable_from_thread == 0); +STM_PSEGMENT->commit_if_not_atomic = false; soon_finished_or_inevitable_thread_segment(); STM_PSEGMENT->transaction_state = TS_INEVITABLE; diff --git a/c8/stm/core.h b/c8/stm/core.h --- a/c8/stm/core.h +++ b/c8/stm/core.h @@ -168,6 +168,9 @@ /* For stm_enable_atomic() */ uintptr_t atomic_nesting_levels; + +// TODO signal flag that is checked in throw_away_nursery() for making immediate commit +bool commit_if_not_atomic; }; enum /* safe_point */ { diff --git a/c8/stm/detach.c b/c8/stm/detach.c --- a/c8/stm/detach.c +++ b/c8/stm/detach.c @@ -215,6 +215,7 @@ } } +// TODO write tests, verify is working, verify no overflows with adaptive mode uintptr_t stm_is_atomic(stm
[pypy-commit] stmgc c8-efficient-serial-execution-master: Add some commentary to enable/disable atomic
Author: Tobias Weber Branch: c8-efficient-serial-execution-master Changeset: r2098:6da61052f101 Date: 2017-07-10 17:15 +0200 http://bitbucket.org/pypy/stmgc/changeset/6da61052f101/ Log:Add some commentary to enable/disable atomic diff --git a/c8/stm/detach.c b/c8/stm/detach.c --- a/c8/stm/detach.c +++ b/c8/stm/detach.c @@ -229,14 +229,18 @@ return STM_PSEGMENT->atomic_nesting_levels; } +// max intptr_t value is 7FFF on 64-bit => larger than 2 * huge value #define HUGE_INTPTR_VALUE 0x3000L void stm_enable_atomic(stm_thread_local_t *tl) { if (!stm_is_atomic(tl)) { +// do for outermost atomic block only tl->self_or_0_if_atomic = 0; /* increment 'nursery_mark' by HUGE_INTPTR_VALUE, so that - stm_should_break_transaction() returns always false */ + stm_should_break_transaction() returns always false. + preserves the previous nursery_mark, unless it is < 0 + or >= huge value */ intptr_t mark = (intptr_t)STM_SEGMENT->nursery_mark; if (mark < 0) mark = 0; @@ -256,6 +260,7 @@ STM_PSEGMENT->atomic_nesting_levels--; if (STM_PSEGMENT->atomic_nesting_levels == 0) { +// revert changes by stm_enable_atomic only if we left the outermost atomic block tl->self_or_0_if_atomic = (intptr_t)tl; /* decrement 'nursery_mark' by HUGE_INTPTR_VALUE, to cancel what was done in stm_enable_atomic() */ ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-fix-starvation: Fetch detached trx more often during wait to become inevitable
Author: Tobias Weber Branch: c8-fix-starvation Changeset: r2097:c9b8371e72df Date: 2017-07-10 17:11 +0200 http://bitbucket.org/pypy/stmgc/changeset/c9b8371e72df/ Log:Fetch detached trx more often during wait to become inevitable diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1571,7 +1571,7 @@ void _stm_become_inevitable(const char *msg) { -int num_waits = 0; +int num_waits = 1; timing_become_inevitable(); @@ -1582,42 +1582,42 @@ if (msg != MSG_INEV_DONT_SLEEP) { dprintf(("become_inevitable: %s\n", msg)); -if (any_soon_finished_or_inevitable_thread_segment() && -num_waits <= NB_SEGMENTS) { +if (any_soon_finished_or_inevitable_thread_segment()) { #if STM_TESTS /* for tests: another transaction */ stm_abort_transaction();/* is already inevitable, abort */ #endif +signal_commit_to_inevitable_transaction(); + s_mutex_lock(); if (any_soon_finished_or_inevitable_thread_segment() && -!safe_point_requested()) { - -signal_commit_to_inevitable_transaction(); +!safe_point_requested() && +num_waits <= NB_SEGMENTS) { /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); -if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) { -s_mutex_unlock(); -/* try to detach another inevitable transaction, but - only after waiting a bit. This is necessary to avoid - deadlocks in some situations, which are hopefully - not too common. We don't want two threads constantly - detaching each other. */ -intptr_t detached = fetch_detached_transaction(); -if (detached != 0) { - EMIT_WAIT_DONE(); - commit_fetched_detached_transaction(detached); -} -goto retry_from_start; +if (cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) { +num_waits++; } -num_waits++; } s_mutex_unlock(); +/* XXX try to detach another inevitable transaction, but + only after waiting a bit. This is necessary to avoid + deadlocks in some situations, which are hopefully + not too common. We don't want two threads constantly + detaching each other. */ +intptr_t detached = fetch_detached_transaction(); +if (detached != 0) { + EMIT_WAIT_DONE(); + commit_fetched_detached_transaction(detached); + EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); +} goto retry_from_start; } else { EMIT_WAIT_DONE(); if (!_validate_and_turn_inevitable()) { +EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); goto retry_from_start; } } diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -501,7 +501,7 @@ pseg->pub.nursery_mark -= nursery_used; if (pseg->commit_if_not_atomic -// && pseg->transaction_state == TS_INEVITABLE // TODO why does this break the mechanism? +// && pseg->transaction_state == TS_INEVITABLE // TODO why does this break the mechanism? && pseg->pub.running_thread->self_or_0_if_atomic != 0) { // transaction is inevitable, not atomic, and commit has been signalled by waiting thread: commit immediately pseg->pub.nursery_mark = 0; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Increase minimum trx length
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2093:273315d7d544 Date: 2017-07-10 16:54 +0200 http://bitbucket.org/pypy/stmgc/changeset/273315d7d544/ Log:Increase minimum trx length diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -21,8 +21,8 @@ #define LARGE_FILL_MARK_NURSERY_BYTES 0x10L // #define LARGE_FILL_MARK_NURSERY_BYTES 0x1000L -// corresponds to ~7 bytes nursery fill -#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.01) +// corresponds to ~700 bytes nursery fill +#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.0001) static double get_new_transaction_length(stm_thread_local_t *tl, bool aborts) { const int multiplier = 100; @@ -550,7 +550,7 @@ pseg->pub.nursery_mark -= nursery_used; if (pseg->commit_if_not_atomic -// && pseg->transaction_state == TS_INEVITABLE // TODO why does this break the mechanism? +// && pseg->transaction_state == TS_INEVITABLE // TODO why does this break the mechanism? && pseg->pub.running_thread->self_or_0_if_atomic != 0) { // transaction is inevitable, not atomic, and commit has been signalled by waiting thread: commit immediately pseg->pub.nursery_mark = 0; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-efficient-serial-execution:
Author: Tobias Weber Branch: c8-efficient-serial-execution Changeset: r2095:b61ffbe4c4a1 Date: 2017-07-10 16:56 +0200 http://bitbucket.org/pypy/stmgc/changeset/b61ffbe4c4a1/ Log: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Update trx length on commit and abort only
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2094:1de39189c503 Date: 2017-07-10 16:55 +0200 http://bitbucket.org/pypy/stmgc/changeset/1de39189c503/ Log:Update trx length on commit and abort only diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -347,7 +347,6 @@ } if (thread_local_for_logging != NULL) { -stm_transaction_length_handle_validation(thread_local_for_logging, needs_abort); stop_timer_and_publish_for_thread( thread_local_for_logging, STM_DURATION_VALIDATION); } @@ -1383,6 +1382,8 @@ s_mutex_unlock(); +stm_transaction_length_handle_validation(thread_local_for_logging, false); + stop_timer_and_publish_for_thread( thread_local_for_logging, STM_DURATION_COMMIT_EXCEPT_GC); @@ -1554,6 +1555,8 @@ did_abort = 1; #endif +stm_transaction_length_handle_validation(pseg->pub.running_thread, true); + list_clear(pseg->objects_pointing_to_nursery); list_clear(pseg->old_objects_with_cards_set); LIST_FOREACH_R(pseg->large_overflow_objects, uintptr_t /*item*/, ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-fix-commit-signalling: Revert aggressive wait
Author: Tobias Weber Branch: c8-fix-commit-signalling Changeset: r2087:1ea4b3c11042 Date: 2017-07-04 17:24 +0200 http://bitbucket.org/pypy/stmgc/changeset/1ea4b3c11042/ Log:Revert aggressive wait diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1571,7 +1571,7 @@ void _stm_become_inevitable(const char *msg) { -int num_waits = NB_SEGMENTS; //0; +int num_waits = 0; timing_become_inevitable(); ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Merge revert aggressive wait and fix check for inevitable breaks commit signalling
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2088:43693de1f6ff Date: 2017-07-04 17:27 +0200 http://bitbucket.org/pypy/stmgc/changeset/43693de1f6ff/ Log:Merge revert aggressive wait and fix check for inevitable breaks commit signalling diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1638,7 +1638,7 @@ void _stm_become_inevitable(const char *msg) { -int num_waits = NB_SEGMENTS; //0; // TODO try disable +int num_waits = 0; timing_become_inevitable(); @@ -1681,7 +1681,8 @@ } s_mutex_unlock(); goto retry_from_start; -} else { +} +else { EMIT_WAIT_DONE(); if (!_validate_and_turn_inevitable()) { goto retry_from_start; diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -550,7 +550,7 @@ pseg->pub.nursery_mark -= nursery_used; if (pseg->commit_if_not_atomic -&& pseg->transaction_state == TS_INEVITABLE +// && pseg->transaction_state == TS_INEVITABLE // TODO why does this break the mechanism? && pseg->pub.running_thread->self_or_0_if_atomic != 0) { // transaction is inevitable, not atomic, and commit has been signalled by waiting thread: commit immediately pseg->pub.nursery_mark = 0; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Merge fix for inevitable transaction commit signalling
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2089:136efd31d83f Date: 2017-06-30 21:53 +0200 http://bitbucket.org/pypy/stmgc/changeset/136efd31d83f/ Log:Merge fix for inevitable transaction commit signalling diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -385,6 +385,14 @@ static void readd_wb_executed_flags(void); static void check_all_write_barrier_flags(char *segbase, struct list_s *list); +static void signal_commit_to_inevitable_transaction(void) { +struct stm_priv_segment_info_s* inevitable_segement = get_inevitable_thread_segment(); +if (inevitable_segement != 0) { +// the inevitable thread is still running: set its "please commit" flag (is ignored by the inevitable thread if it is atomic) +inevitable_segement->commit_if_not_atomic = true; +} +} + static void wait_for_inevitable(void) { intptr_t detached = 0; @@ -401,6 +409,8 @@ try to detach an inevitable transaction regularly */ detached = fetch_detached_transaction(); if (detached == 0) { +// the inevitable trx was not detached or it was detached but is atomic +signal_commit_to_inevitable_transaction(); EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) goto wait_some_more; @@ -1694,6 +1704,7 @@ stm_spin_loop(); assert(_stm_detached_inevitable_from_thread == 0); +STM_PSEGMENT->commit_if_not_atomic = false; soon_finished_or_inevitable_thread_segment(); STM_PSEGMENT->transaction_state = TS_INEVITABLE; diff --git a/c8/stm/core.h b/c8/stm/core.h --- a/c8/stm/core.h +++ b/c8/stm/core.h @@ -169,6 +169,9 @@ /* For stm_enable_atomic() */ uintptr_t atomic_nesting_levels; + +// TODO signal flag that is checked in throw_away_nursery() for making immediate commit +bool commit_if_not_atomic; }; enum /* safe_point */ { diff --git a/c8/stm/detach.c b/c8/stm/detach.c --- a/c8/stm/detach.c +++ b/c8/stm/detach.c @@ -215,6 +215,7 @@ } } +// TODO write tests, verify is working, verify no overflows with adaptive mode uintptr_t stm_is_atomic(stm_thread_local_t *tl) { assert(STM_SEGMENT->running_thread == tl); diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -542,6 +542,11 @@ pseg->pub.nursery_current = (stm_char *)_stm_nursery_start; pseg->pub.nursery_mark -= nursery_used; +if (pseg->commit_if_not_atomic && pseg->pub.running_thread->self_or_0_if_atomic != 0) { +// not atomic and commit signalled by waiting thread: commit immediately +pseg->pub.nursery_mark = 0; +} + /* free any object left from 'young_outside_nursery' */ if (!tree_is_cleared(pseg->young_outside_nursery)) { wlog_t *item; diff --git a/c8/stm/sync.c b/c8/stm/sync.c --- a/c8/stm/sync.c +++ b/c8/stm/sync.c @@ -302,6 +302,19 @@ return false; } +static struct stm_priv_segment_info_s* get_inevitable_thread_segment(void) +{ +struct stm_priv_segment_info_s* segment; +int num; +for (num = 1; num < NB_SEGMENTS; num++) { +segment = get_priv_segment(num); +if (segment->transaction_state == TS_INEVITABLE) { +return segment; +} +} +return 0; +} + __attribute__((unused)) static bool _seems_to_be_running_transaction(void) { diff --git a/c8/stm/sync.h b/c8/stm/sync.h --- a/c8/stm/sync.h +++ b/c8/stm/sync.h @@ -30,6 +30,7 @@ static void release_thread_segment(stm_thread_local_t *tl); static void soon_finished_or_inevitable_thread_segment(void); static bool any_soon_finished_or_inevitable_thread_segment(void); +static struct stm_priv_segment_info_s* get_inevitable_thread_segment(void); enum sync_type_e { STOP_OTHERS_UNTIL_MUTEX_UNLOCK, ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Merge revert aggressive wait
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2092:0c811825c149 Date: 2017-07-04 17:25 +0200 http://bitbucket.org/pypy/stmgc/changeset/0c811825c149/ Log:Merge revert aggressive wait diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1638,7 +1638,7 @@ void _stm_become_inevitable(const char *msg) { -int num_waits = NB_SEGMENTS; //0; +int num_waits = 0; timing_become_inevitable(); ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Merge add signal to commit inevitable trx when becoming inevitable
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2090:cf2b97b05bc6 Date: 2017-06-30 23:25 +0200 http://bitbucket.org/pypy/stmgc/changeset/cf2b97b05bc6/ Log:Merge add signal to commit inevitable trx when becoming inevitable diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1661,6 +1661,8 @@ if (any_soon_finished_or_inevitable_thread_segment() && !safe_point_requested()) { +signal_commit_to_inevitable_transaction(); + /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Merge aggressive wait when becoming inevitable
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2091:d36657eedf72 Date: 2017-07-04 16:01 +0200 http://bitbucket.org/pypy/stmgc/changeset/d36657eedf72/ Log:Merge aggressive wait when becoming inevitable diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1638,7 +1638,7 @@ void _stm_become_inevitable(const char *msg) { -int num_waits = 0; +int num_waits = NB_SEGMENTS; //0; timing_become_inevitable(); @@ -1655,8 +1655,6 @@ stm_abort_transaction();/* is already inevitable, abort */ #endif -bool timed_out = false; - s_mutex_lock(); if (any_soon_finished_or_inevitable_thread_segment() && !safe_point_requested()) { @@ -1665,36 +1663,34 @@ /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); -if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, - 0.54321)) -timed_out = true; +if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) { +s_mutex_unlock(); +/* try to detach another inevitable transaction, but + only after waiting a bit. This is necessary to avoid + deadlocks in some situations, which are hopefully + not too common. We don't want two threads constantly + detaching each other. */ +intptr_t detached = fetch_detached_transaction(); +if (detached != 0) { + EMIT_WAIT_DONE(); + commit_fetched_detached_transaction(detached); +} +goto retry_from_start; +} +num_waits++; } s_mutex_unlock(); - -if (timed_out) { -/* try to detach another inevitable transaction, but - only after waiting a bit. This is necessary to avoid - deadlocks in some situations, which are hopefully - not too common. We don't want two threads constantly - detaching each other. */ -intptr_t detached = fetch_detached_transaction(); -if (detached != 0) { -EMIT_WAIT_DONE(); -commit_fetched_detached_transaction(detached); -} -} -else { -num_waits++; -} goto retry_from_start; } -EMIT_WAIT_DONE(); -if (!_validate_and_turn_inevitable()) -goto retry_from_start; +else { +EMIT_WAIT_DONE(); +if (!_validate_and_turn_inevitable()) { +goto retry_from_start; +} +} } -else { -if (!_validate_and_turn_inevitable()) -return; +else if (!_validate_and_turn_inevitable()) { +return; } /* There may be a concurrent commit of a detached Tx going on. diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -542,8 +542,10 @@ pseg->pub.nursery_current = (stm_char *)_stm_nursery_start; pseg->pub.nursery_mark -= nursery_used; -if (pseg->commit_if_not_atomic && pseg->pub.running_thread->self_or_0_if_atomic != 0) { -// not atomic and commit signalled by waiting thread: commit immediately +if (pseg->commit_if_not_atomic +// && pseg->transaction_state == TS_INEVITABLE // TODO why does this break the mechanism? +&& pseg->pub.running_thread->self_or_0_if_atomic != 0) { +// transaction is inevitable, not atomic, and commit has been signalled by waiting thread: commit immediately pseg->pub.nursery_mark = 0; } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-fix-commit-signalling: Evaluate signal to commit only if running inevitable, and refactor wait implementation of become inevitable method
Author: Tobias Weber Branch: c8-fix-commit-signalling Changeset: r2084:f27950321d3c Date: 2017-07-04 12:47 +0200 http://bitbucket.org/pypy/stmgc/changeset/f27950321d3c/ Log:Evaluate signal to commit only if running inevitable, and refactor wait implementation of become inevitable method diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1571,7 +1571,7 @@ void _stm_become_inevitable(const char *msg) { -int num_waits = 0; +int num_waits = NB_SEGMENTS; //0; // TODO try disable timing_become_inevitable(); @@ -1588,8 +1588,6 @@ stm_abort_transaction();/* is already inevitable, abort */ #endif -bool timed_out = false; - s_mutex_lock(); if (any_soon_finished_or_inevitable_thread_segment() && !safe_point_requested()) { @@ -1598,36 +1596,33 @@ /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); -if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, - 0.54321)) -timed_out = true; +if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) { +s_mutex_unlock(); +/* try to detach another inevitable transaction, but + only after waiting a bit. This is necessary to avoid + deadlocks in some situations, which are hopefully + not too common. We don't want two threads constantly + detaching each other. */ +intptr_t detached = fetch_detached_transaction(); +if (detached != 0) { + EMIT_WAIT_DONE(); + commit_fetched_detached_transaction(detached); +} +goto retry_from_start; +} +num_waits++; } s_mutex_unlock(); - -if (timed_out) { -/* try to detach another inevitable transaction, but - only after waiting a bit. This is necessary to avoid - deadlocks in some situations, which are hopefully - not too common. We don't want two threads constantly - detaching each other. */ -intptr_t detached = fetch_detached_transaction(); -if (detached != 0) { -EMIT_WAIT_DONE(); -commit_fetched_detached_transaction(detached); -} +goto retry_from_start; +} else { +EMIT_WAIT_DONE(); +if (!_validate_and_turn_inevitable()) { +goto retry_from_start; } -else { -num_waits++; -} -goto retry_from_start; } -EMIT_WAIT_DONE(); -if (!_validate_and_turn_inevitable()) -goto retry_from_start; } -else { -if (!_validate_and_turn_inevitable()) -return; +else if (!_validate_and_turn_inevitable()) { +return; } /* There may be a concurrent commit of a detached Tx going on. diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -500,8 +500,10 @@ pseg->pub.nursery_current = (stm_char *)_stm_nursery_start; pseg->pub.nursery_mark -= nursery_used; -if (pseg->commit_if_not_atomic && pseg->pub.running_thread->self_or_0_if_atomic != 0) { -// not atomic and commit signalled by waiting thread: commit immediately +if (pseg->commit_if_not_atomic +&& pseg->transaction_state == TS_INEVITABLE +&& pseg->pub.running_thread->self_or_0_if_atomic != 0) { +// transaction is inevitable, not atomic, and commit has been signalled by waiting thread: commit immediately pseg->pub.nursery_mark = 0; } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-fix-commit-signalling: Add signalling also to become inevitable
Author: Tobias Weber Branch: c8-fix-commit-signalling Changeset: r2081:51b2dcee8206 Date: 2017-06-30 23:17 +0200 http://bitbucket.org/pypy/stmgc/changeset/51b2dcee8206/ Log:Add signalling also to become inevitable diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1594,6 +1594,8 @@ if (any_soon_finished_or_inevitable_thread_segment() && !safe_point_requested()) { +signal_commit_to_inevitable_transaction(); + /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Merge fix for commit signalling to inevitable transactions
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2082:39f4ab9d3e31 Date: 2017-07-01 19:15 +0200 http://bitbucket.org/pypy/stmgc/changeset/39f4ab9d3e31/ Log:Merge fix for commit signalling to inevitable transactions diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -385,6 +385,14 @@ static void readd_wb_executed_flags(void); static void check_all_write_barrier_flags(char *segbase, struct list_s *list); +static void signal_commit_to_inevitable_transaction(void) { +struct stm_priv_segment_info_s* inevitable_segement = get_inevitable_thread_segment(); +if (inevitable_segement != 0) { +// the inevitable thread is still running: set its "please commit" flag (is ignored by the inevitable thread if it is atomic) +inevitable_segement->commit_if_not_atomic = true; +} +} + static void wait_for_inevitable(void) { intptr_t detached = 0; @@ -401,6 +409,8 @@ try to detach an inevitable transaction regularly */ detached = fetch_detached_transaction(); if (detached == 0) { +// the inevitable trx was not detached or it was detached but is atomic +signal_commit_to_inevitable_transaction(); EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) goto wait_some_more; @@ -1651,6 +1661,8 @@ if (any_soon_finished_or_inevitable_thread_segment() && !safe_point_requested()) { +signal_commit_to_inevitable_transaction(); + /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, @@ -1694,6 +1706,7 @@ stm_spin_loop(); assert(_stm_detached_inevitable_from_thread == 0); +STM_PSEGMENT->commit_if_not_atomic = false; soon_finished_or_inevitable_thread_segment(); STM_PSEGMENT->transaction_state = TS_INEVITABLE; diff --git a/c8/stm/core.h b/c8/stm/core.h --- a/c8/stm/core.h +++ b/c8/stm/core.h @@ -169,6 +169,9 @@ /* For stm_enable_atomic() */ uintptr_t atomic_nesting_levels; + +// TODO signal flag that is checked in throw_away_nursery() for making immediate commit +bool commit_if_not_atomic; }; enum /* safe_point */ { diff --git a/c8/stm/detach.c b/c8/stm/detach.c --- a/c8/stm/detach.c +++ b/c8/stm/detach.c @@ -215,6 +215,7 @@ } } +// TODO write tests, verify is working, verify no overflows with adaptive mode uintptr_t stm_is_atomic(stm_thread_local_t *tl) { assert(STM_SEGMENT->running_thread == tl); diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -548,6 +548,11 @@ pseg->pub.nursery_current = (stm_char *)_stm_nursery_start; pseg->pub.nursery_mark -= nursery_used; +if (pseg->commit_if_not_atomic && pseg->pub.running_thread->self_or_0_if_atomic != 0) { +// not atomic and commit signalled by waiting thread: commit immediately +pseg->pub.nursery_mark = 0; +} + /* free any object left from 'young_outside_nursery' */ if (!tree_is_cleared(pseg->young_outside_nursery)) { wlog_t *item; diff --git a/c8/stm/sync.c b/c8/stm/sync.c --- a/c8/stm/sync.c +++ b/c8/stm/sync.c @@ -302,6 +302,19 @@ return false; } +static struct stm_priv_segment_info_s* get_inevitable_thread_segment(void) +{ +struct stm_priv_segment_info_s* segment; +int num; +for (num = 1; num < NB_SEGMENTS; num++) { +segment = get_priv_segment(num); +if (segment->transaction_state == TS_INEVITABLE) { +return segment; +} +} +return 0; +} + __attribute__((unused)) static bool _seems_to_be_running_transaction(void) { diff --git a/c8/stm/sync.h b/c8/stm/sync.h --- a/c8/stm/sync.h +++ b/c8/stm/sync.h @@ -30,6 +30,7 @@ static void release_thread_segment(stm_thread_local_t *tl); static void soon_finished_or_inevitable_thread_segment(void); static bool any_soon_finished_or_inevitable_thread_segment(void); +static struct stm_priv_segment_info_s* get_inevitable_thread_segment(void); enum sync_type_e { STOP_OTHERS_UNTIL_MUTEX_UNLOCK, ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-fix-commit-signalling: Fix check for inevitable breaks commit signalling
Author: Tobias Weber Branch: c8-fix-commit-signalling Changeset: r2086:2a092c9c9376 Date: 2017-07-04 15:59 +0200 http://bitbucket.org/pypy/stmgc/changeset/2a092c9c9376/ Log:Fix check for inevitable breaks commit signalling diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1571,7 +1571,7 @@ void _stm_become_inevitable(const char *msg) { -int num_waits = NB_SEGMENTS; //0; // TODO try disable +int num_waits = NB_SEGMENTS; //0; timing_become_inevitable(); @@ -1614,7 +1614,8 @@ } s_mutex_unlock(); goto retry_from_start; -} else { +} +else { EMIT_WAIT_DONE(); if (!_validate_and_turn_inevitable()) { goto retry_from_start; diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -501,7 +501,7 @@ pseg->pub.nursery_mark -= nursery_used; if (pseg->commit_if_not_atomic -&& pseg->transaction_state == TS_INEVITABLE +// && pseg->transaction_state == TS_INEVITABLE // TODO why does this break the mechanism? && pseg->pub.running_thread->self_or_0_if_atomic != 0) { // transaction is inevitable, not atomic, and commit has been signalled by waiting thread: commit immediately pseg->pub.nursery_mark = 0; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-fix-commit-signalling: Signal commit to inevitable transaction if another transaction wants to commit
Author: Tobias Weber Branch: c8-fix-commit-signalling Changeset: r2080:5d95b73a59c9 Date: 2017-06-30 18:30 +0200 http://bitbucket.org/pypy/stmgc/changeset/5d95b73a59c9/ Log:Signal commit to inevitable transaction if another transaction wants to commit diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -366,6 +366,14 @@ static void readd_wb_executed_flags(void); static void check_all_write_barrier_flags(char *segbase, struct list_s *list); +static void signal_commit_to_inevitable_transaction(void) { +struct stm_priv_segment_info_s* inevitable_segement = get_inevitable_thread_segment(); +if (inevitable_segement != 0) { +// the inevitable thread is still running: set its "please commit" flag (is ignored by the inevitable thread if it is atomic) +inevitable_segement->commit_if_not_atomic = true; +} +} + static void wait_for_inevitable(void) { intptr_t detached = 0; @@ -382,6 +390,8 @@ try to detach an inevitable transaction regularly */ detached = fetch_detached_transaction(); if (detached == 0) { +// the inevitable trx was not detached or it was detached but is atomic +signal_commit_to_inevitable_transaction(); EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) goto wait_some_more; @@ -1627,6 +1637,7 @@ stm_spin_loop(); assert(_stm_detached_inevitable_from_thread == 0); +STM_PSEGMENT->commit_if_not_atomic = false; soon_finished_or_inevitable_thread_segment(); STM_PSEGMENT->transaction_state = TS_INEVITABLE; diff --git a/c8/stm/core.h b/c8/stm/core.h --- a/c8/stm/core.h +++ b/c8/stm/core.h @@ -168,6 +168,9 @@ /* For stm_enable_atomic() */ uintptr_t atomic_nesting_levels; + +// TODO signal flag that is checked in throw_away_nursery() for making immediate commit +bool commit_if_not_atomic; }; enum /* safe_point */ { diff --git a/c8/stm/detach.c b/c8/stm/detach.c --- a/c8/stm/detach.c +++ b/c8/stm/detach.c @@ -215,6 +215,7 @@ } } +// TODO write tests, verify is working, verify no overflows with adaptive mode uintptr_t stm_is_atomic(stm_thread_local_t *tl) { assert(STM_SEGMENT->running_thread == tl); diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -500,6 +500,11 @@ pseg->pub.nursery_current = (stm_char *)_stm_nursery_start; pseg->pub.nursery_mark -= nursery_used; +if (pseg->commit_if_not_atomic && pseg->pub.running_thread->self_or_0_if_atomic != 0) { +// not atomic and commit signalled by waiting thread: commit immediately +pseg->pub.nursery_mark = 0; +} + /* free any object left from 'young_outside_nursery' */ if (!tree_is_cleared(pseg->young_outside_nursery)) { wlog_t *item; diff --git a/c8/stm/sync.c b/c8/stm/sync.c --- a/c8/stm/sync.c +++ b/c8/stm/sync.c @@ -293,6 +293,19 @@ return false; } +static struct stm_priv_segment_info_s* get_inevitable_thread_segment(void) +{ +struct stm_priv_segment_info_s* segment; +int num; +for (num = 1; num < NB_SEGMENTS; num++) { +segment = get_priv_segment(num); +if (segment->transaction_state == TS_INEVITABLE) { +return segment; +} +} +return 0; +} + __attribute__((unused)) static bool _seems_to_be_running_transaction(void) { diff --git a/c8/stm/sync.h b/c8/stm/sync.h --- a/c8/stm/sync.h +++ b/c8/stm/sync.h @@ -29,6 +29,7 @@ static void release_thread_segment(stm_thread_local_t *tl); static void soon_finished_or_inevitable_thread_segment(void); static bool any_soon_finished_or_inevitable_thread_segment(void); +static struct stm_priv_segment_info_s* get_inevitable_thread_segment(void); enum sync_type_e { STOP_OTHERS_UNTIL_MUTEX_UNLOCK, ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Merge minor fixes to commit signalling
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2085:e0f9b83d9771 Date: 2017-07-04 12:49 +0200 http://bitbucket.org/pypy/stmgc/changeset/e0f9b83d9771/ Log:Merge minor fixes to commit signalling diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1638,7 +1638,7 @@ void _stm_become_inevitable(const char *msg) { -int num_waits = 0; +int num_waits = NB_SEGMENTS; //0; // TODO try disable timing_become_inevitable(); @@ -1655,8 +1655,6 @@ stm_abort_transaction();/* is already inevitable, abort */ #endif -bool timed_out = false; - s_mutex_lock(); if (any_soon_finished_or_inevitable_thread_segment() && !safe_point_requested()) { @@ -1665,36 +1663,33 @@ /* wait until C_SEGMENT_FREE_OR_SAFE_POINT_REQ is signalled */ EMIT_WAIT(STM_WAIT_OTHER_INEVITABLE); -if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, - 0.54321)) -timed_out = true; +if (!cond_wait_timeout(C_SEGMENT_FREE_OR_SAFE_POINT_REQ, 0.1)) { +s_mutex_unlock(); +/* try to detach another inevitable transaction, but + only after waiting a bit. This is necessary to avoid + deadlocks in some situations, which are hopefully + not too common. We don't want two threads constantly + detaching each other. */ +intptr_t detached = fetch_detached_transaction(); +if (detached != 0) { + EMIT_WAIT_DONE(); + commit_fetched_detached_transaction(detached); +} +goto retry_from_start; +} +num_waits++; } s_mutex_unlock(); - -if (timed_out) { -/* try to detach another inevitable transaction, but - only after waiting a bit. This is necessary to avoid - deadlocks in some situations, which are hopefully - not too common. We don't want two threads constantly - detaching each other. */ -intptr_t detached = fetch_detached_transaction(); -if (detached != 0) { -EMIT_WAIT_DONE(); -commit_fetched_detached_transaction(detached); -} +goto retry_from_start; +} else { +EMIT_WAIT_DONE(); +if (!_validate_and_turn_inevitable()) { +goto retry_from_start; } -else { -num_waits++; -} -goto retry_from_start; } -EMIT_WAIT_DONE(); -if (!_validate_and_turn_inevitable()) -goto retry_from_start; } -else { -if (!_validate_and_turn_inevitable()) -return; +else if (!_validate_and_turn_inevitable()) { +return; } /* There may be a concurrent commit of a detached Tx going on. diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -549,8 +549,10 @@ pseg->pub.nursery_current = (stm_char *)_stm_nursery_start; pseg->pub.nursery_mark -= nursery_used; -if (pseg->commit_if_not_atomic && pseg->pub.running_thread->self_or_0_if_atomic != 0) { -// not atomic and commit signalled by waiting thread: commit immediately +if (pseg->commit_if_not_atomic +&& pseg->transaction_state == TS_INEVITABLE +&& pseg->pub.running_thread->self_or_0_if_atomic != 0) { +// transaction is inevitable, not atomic, and commit has been signalled by waiting thread: commit immediately pseg->pub.nursery_mark = 0; } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Improve backoff parameter calculation
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2083:2f066c0fb56c Date: 2017-07-04 12:38 +0200 http://bitbucket.org/pypy/stmgc/changeset/2f066c0fb56c/ Log:Improve backoff parameter calculation diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -35,7 +35,8 @@ new = STM_MIN_RELATIVE_TRANSACTION_LENGTH; } // the shorter the trx, the more backoff: 1000 at min trx length, proportional decrease to 1 at max trx length (think a/x + b = backoff) -tl->transaction_length_backoff = (int)(0.001 / new - 0.999); +tl->transaction_length_backoff = (int)(1 / (1 * new) + 5); +// printf("thread %d, backoff %d\n", tl->thread_local_counter, tl->transaction_length_backoff); tl->linear_transaction_length_increment = new; } else if (tl->transaction_length_backoff == 0) { // backoff counter is zero, exponential increase up to 1 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Improve backoff duration computation
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2079:50a4a53200e3 Date: 2017-06-27 15:01 +0200 http://bitbucket.org/pypy/stmgc/changeset/50a4a53200e3/ Log:Improve backoff duration computation diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -34,8 +34,8 @@ } else { new = STM_MIN_RELATIVE_TRANSACTION_LENGTH; } -// the shorter the trx, the more backoff -tl->transaction_length_backoff = (int)(1 / new); +// the shorter the trx, the more backoff: 1000 at min trx length, proportional decrease to 1 at max trx length (think a/x + b = backoff) +tl->transaction_length_backoff = (int)(0.001 / new - 0.999); tl->linear_transaction_length_increment = new; } else if (tl->transaction_length_backoff == 0) { // backoff counter is zero, exponential increase up to 1 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-tcp-style-trx-length: Implement TCP style linear transaction length increase after abort, exponential increase only initially or after a constant amount of transactions
Author: Tobias Weber Branch: c8-tcp-style-trx-length Changeset: r2078:91207e4ad1b8 Date: 2017-06-26 12:22 +0200 http://bitbucket.org/pypy/stmgc/changeset/91207e4ad1b8/ Log:Implement TCP style linear transaction length increase after abort, exponential increase only initially or after a constant amount of transactions diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -21,26 +21,32 @@ #define LARGE_FILL_MARK_NURSERY_BYTES 0x10L // #define LARGE_FILL_MARK_NURSERY_BYTES 0x1000L -#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.0001) +// corresponds to ~7 bytes nursery fill +#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.01) static double get_new_transaction_length(stm_thread_local_t *tl, bool aborts) { const int multiplier = 100; double previous = tl->relative_transaction_length; double new = previous; if (aborts) { -tl->transaction_length_backoff = 3; if (previous > STM_MIN_RELATIVE_TRANSACTION_LENGTH) { new = previous / multiplier; } else { -new = 0; +new = STM_MIN_RELATIVE_TRANSACTION_LENGTH; } +// the shorter the trx, the more backoff +tl->transaction_length_backoff = (int)(1 / new); +tl->linear_transaction_length_increment = new; } else if (tl->transaction_length_backoff == 0) { -if (previous - (STM_MIN_RELATIVE_TRANSACTION_LENGTH * 0.1) < 0) { -new = STM_MIN_RELATIVE_TRANSACTION_LENGTH; -} else if (previous < 1) { +// backoff counter is zero, exponential increase up to 1 +if (previous < 1) { new = previous * multiplier; } } else { // not abort and backoff != 0 +// in backoff, linear increase up to 1 +if (previous < 1) { +new = previous + tl->linear_transaction_length_increment; +} tl->transaction_length_backoff -= 1; } return new; diff --git a/c8/stm/setup.c b/c8/stm/setup.c --- a/c8/stm/setup.c +++ b/c8/stm/setup.c @@ -246,9 +246,10 @@ tl->last_associated_segment_num = num + 1; tl->thread_local_counter = ++thread_local_counters; -/* init single thread mode */ +/* init adaptive transaction length mode */ tl->relative_transaction_length = STM_MIN_RELATIVE_TRANSACTION_LENGTH; tl->transaction_length_backoff = 0; +tl->linear_transaction_length_increment = 0; *_get_cpth(tl) = pthread_self(); _init_shadow_stack(tl); diff --git a/c8/stmgc.h b/c8/stmgc.h --- a/c8/stmgc.h +++ b/c8/stmgc.h @@ -92,8 +92,10 @@ /* == adaptive single thread mode == */ /* factor that is multiplied with max transaction length before the start of the next transaction on this thread */ double relative_transaction_length; -/* when zero, transaction length may increase or decrease, otherwise transaction length may only decrease. is (re-)set to some value upon abort and counted down until zero upon successful validation. */ +/* when zero, transaction length may increase exponentially, otherwise transaction length may only increase linearly. is (re-)set to some value upon abort and counted down until zero upon successful validation. */ int transaction_length_backoff; +/* during the backoff, transaction length may increase linearly by this increment on every successful validation */ +double linear_transaction_length_increment; } stm_thread_local_t; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-binary-trx-length-per-thread: Select short trx length to be 100B
Author: Tobias Weber Branch: c8-binary-trx-length-per-thread Changeset: r2077:e264072fb063 Date: 2017-06-15 16:27 +0200 http://bitbucket.org/pypy/stmgc/changeset/e264072fb063/ Log:Select short trx length to be 100B diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -22,7 +22,7 @@ double new = tl->relative_transaction_length; if (aborts) { tl->transaction_length_backoff = 3; -new = (double)DEFAULT_FILL_MARK_NURSERY_BYTES / LARGE_FILL_MARK_NURSERY_BYTES; +new = 100.0 / LARGE_FILL_MARK_NURSERY_BYTES; } else if (tl->transaction_length_backoff == 0) { new = 1; } else { // not abort and backoff != 0 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-binary-trx-length-per-thread: Set short transaction length greater zero
Author: Tobias Weber Branch: c8-binary-trx-length-per-thread Changeset: r2075:953006e6836b Date: 2017-06-12 09:25 +0200 http://bitbucket.org/pypy/stmgc/changeset/953006e6836b/ Log:Set short transaction length greater zero diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -22,7 +22,7 @@ double new = tl->relative_transaction_length; if (aborts) { tl->transaction_length_backoff = 3; -new = 0; +new = 100.0 / LARGE_FILL_MARK_NURSERY_BYTES; } else if (tl->transaction_length_backoff == 0) { new = 1; } else { // not abort and backoff != 0 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-binary-trx-length-per-thread: Set short transaction length to default
Author: Tobias Weber Branch: c8-binary-trx-length-per-thread Changeset: r2076:472cd93faa7e Date: 2017-06-13 15:10 +0200 http://bitbucket.org/pypy/stmgc/changeset/472cd93faa7e/ Log:Set short transaction length to default diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -22,7 +22,7 @@ double new = tl->relative_transaction_length; if (aborts) { tl->transaction_length_backoff = 3; -new = 100.0 / LARGE_FILL_MARK_NURSERY_BYTES; +new = (double)DEFAULT_FILL_MARK_NURSERY_BYTES / LARGE_FILL_MARK_NURSERY_BYTES; } else if (tl->transaction_length_backoff == 0) { new = 1; } else { // not abort and backoff != 0 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-binary-trx-length-per-thread: Implement simple binary adaptive transaction length
Author: Tobias Weber Branch: c8-binary-trx-length-per-thread Changeset: r2074:abbe431338a8 Date: 2017-06-11 18:26 +0200 http://bitbucket.org/pypy/stmgc/changeset/abbe431338a8/ Log:Implement simple binary adaptive transaction length diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -16,30 +16,15 @@ static uintptr_t _stm_nursery_start; #define DEFAULT_FILL_MARK_NURSERY_BYTES (NURSERY_SIZE / 4) - -// #define LARGE_FILL_MARK_NURSERY_BYTES DEFAULT_FILL_MARK_NURSERY_BYTES #define LARGE_FILL_MARK_NURSERY_BYTES 0x10L -// #define LARGE_FILL_MARK_NURSERY_BYTES 0x1000L - -#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.0001) static double get_new_transaction_length(stm_thread_local_t *tl, bool aborts) { -const int multiplier = 100; -double previous = tl->relative_transaction_length; -double new = previous; +double new = tl->relative_transaction_length; if (aborts) { tl->transaction_length_backoff = 3; -if (previous > STM_MIN_RELATIVE_TRANSACTION_LENGTH) { -new = previous / multiplier; -} else { -new = 0; -} +new = 0; } else if (tl->transaction_length_backoff == 0) { -if (previous - (STM_MIN_RELATIVE_TRANSACTION_LENGTH * 0.1) < 0) { -new = STM_MIN_RELATIVE_TRANSACTION_LENGTH; -} else if (previous < 1) { -new = previous * multiplier; -} +new = 1; } else { // not abort and backoff != 0 tl->transaction_length_backoff -= 1; } diff --git a/c8/stm/setup.c b/c8/stm/setup.c --- a/c8/stm/setup.c +++ b/c8/stm/setup.c @@ -247,7 +247,7 @@ tl->thread_local_counter = ++thread_local_counters; /* init single thread mode */ -tl->relative_transaction_length = STM_MIN_RELATIVE_TRANSACTION_LENGTH; +tl->relative_transaction_length = 1; tl->transaction_length_backoff = 0; *_get_cpth(tl) = pthread_self(); ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Merge transaction start instrumentation fix
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2072:0621fb926e22 Date: 2017-06-11 17:03 +0200 http://bitbucket.org/pypy/stmgc/changeset/0621fb926e22/ Log:Merge transaction start instrumentation fix diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1152,8 +1152,6 @@ long _stm_start_transaction(stm_thread_local_t *tl) { -start_timer(); - s_mutex_lock(); #ifdef STM_NO_AUTOMATIC_SETJMP long repeat_count = did_abort;/* test/support.py */ @@ -1161,6 +1159,9 @@ #else long repeat_count = stm_rewind_jmp_setjmp(tl); #endif + +start_timer(); + if (repeat_count) { /* only if there was an abort, we need to reset the memory: */ if (tl->mem_reset_on_abort) @@ -1168,7 +1169,7 @@ tl->mem_bytes_to_reset_on_abort); } -// _do_start_transaction is instrumented as well and pauses for waits +// _do_start_transaction is instrumented as well b/c it needs to pause for waits pause_timer(); _do_start_transaction(tl); continue_timer(); diff --git a/c8/stm/timing.h b/c8/stm/timing.h --- a/c8/stm/timing.h +++ b/c8/stm/timing.h @@ -29,7 +29,7 @@ #define stm_duration_payload(duration_data) \ stm_timing_event_payload_data_t stm_duration_data = \ -{ .duration = &(duration_data) }; \ +{ .duration = &(duration_data) }; \ stm_timing_event_payload_t stm_duration_payload = \ { STM_EVENT_PAYLOAD_DURATION, stm_duration_data }; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-overheads-instrumentation: Fix wrong transaction start measurements when transaction was aborted with longjmp
Author: Tobias Weber Branch: c8-overheads-instrumentation Changeset: r2071:06b84e2a6b84 Date: 2017-06-11 16:25 +0200 http://bitbucket.org/pypy/stmgc/changeset/06b84e2a6b84/ Log:Fix wrong transaction start measurements when transaction was aborted with longjmp diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1151,8 +1151,6 @@ long _stm_start_transaction(stm_thread_local_t *tl) { -start_timer(); - s_mutex_lock(); #ifdef STM_NO_AUTOMATIC_SETJMP long repeat_count = did_abort;/* test/support.py */ @@ -1160,6 +1158,9 @@ #else long repeat_count = stm_rewind_jmp_setjmp(tl); #endif + +start_timer(); + if (repeat_count) { /* only if there was an abort, we need to reset the memory: */ if (tl->mem_reset_on_abort) @@ -1167,7 +1168,7 @@ tl->mem_bytes_to_reset_on_abort); } -// _do_start_transaction is instrumented as well and pauses for waits +// _do_start_transaction is instrumented as well b/c it needs to pause for waits pause_timer(); _do_start_transaction(tl); continue_timer(); diff --git a/c8/stm/timing.h b/c8/stm/timing.h --- a/c8/stm/timing.h +++ b/c8/stm/timing.h @@ -29,7 +29,7 @@ #define stm_duration_payload(duration_data) \ stm_timing_event_payload_data_t stm_duration_data = \ -{ .duration = &(duration_data) }; \ +{ .duration = &(duration_data) }; \ stm_timing_event_payload_t stm_duration_payload = \ { STM_EVENT_PAYLOAD_DURATION, stm_duration_data }; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-overheads-instrumentation: Merge single thread mode events and fixes for timing macros
Author: Tobias Weber Branch: c8-overheads-instrumentation Changeset: r2070:45d8e22cca0d Date: 2017-06-10 11:43 +0200 http://bitbucket.org/pypy/stmgc/changeset/45d8e22cca0d/ Log:Merge single thread mode events and fixes for timing macros diff --git a/c8/stm/timing.h b/c8/stm/timing.h --- a/c8/stm/timing.h +++ b/c8/stm/timing.h @@ -29,20 +29,20 @@ #define stm_duration_payload(duration_data) \ stm_timing_event_payload_data_t stm_duration_data = \ -{ .duration = &duration_data }; \ +{ .duration = &(duration_data) }; \ stm_timing_event_payload_t stm_duration_payload = \ { STM_EVENT_PAYLOAD_DURATION, stm_duration_data }; #define publish_event(thread_local, event) \ (timing_enabled() ? \ -stmcb_timing_event(thread_local, event, &stm_duration_payload) :\ +stmcb_timing_event((thread_local), (event), &stm_duration_payload) :\ (void)0); #define stop_timer_and_publish_for_thread(thread_local, event) \ pause_timer() \ stm_duration_payload(duration) \ -assert(thread_local != NULL); \ -publish_event(thread_local, event) +assert((thread_local) != NULL); \ +publish_event((thread_local), (event)) #define stop_timer_and_publish(event) \ -stop_timer_and_publish_for_thread(STM_SEGMENT->running_thread, event) +stop_timer_and_publish_for_thread(STM_SEGMENT->running_thread, (event)) diff --git a/c8/stmgc.h b/c8/stmgc.h --- a/c8/stmgc.h +++ b/c8/stmgc.h @@ -585,6 +585,10 @@ STM_DURATION_MAJOR_GC_LOG_ONLY, STM_DURATION_MAJOR_GC_FULL, +STM_SINGLE_THREAD_MODE_ON, +STM_SINGLE_THREAD_MODE_OFF, +STM_SINGLE_THREAD_MODE_ADAPTIVE, + _STM_EVENT_N }; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Fix nested measurements of wait time during transaction start
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2066:e425b6d2a050 Date: 2017-06-09 18:09 +0200 http://bitbucket.org/pypy/stmgc/changeset/e425b6d2a050/ Log:Fix nested measurements of wait time during transaction start diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1073,14 +1073,15 @@ static void _do_start_transaction(stm_thread_local_t *tl) { -start_timer(); - assert(!_stm_in_transaction(tl)); tl->wait_event_emitted = 0; acquire_thread_segment(tl); /* GS invalid before this point! */ +// acquiring segment is measured as wait time +start_timer(); + assert(STM_PSEGMENT->safe_point == SP_NO_TRANSACTION); assert(STM_PSEGMENT->transaction_state == TS_NONE); timing_event(tl, STM_TRANSACTION_START); @@ -1127,10 +1128,12 @@ rv++;/* incr it but enter_safe_point_if_requested() aborted */ STM_SEGMENT->transaction_read_version = rv; +pause_timer(); /* Warning: this safe-point may run light finalizers and register commit/abort callbacks if a major GC is triggered here */ enter_safe_point_if_requested(); dprintf(("> start_transaction\n")); +continue_timer(); s_mutex_unlock(); // XXX it's probably possible to not acquire this here @@ -1149,6 +1152,8 @@ long _stm_start_transaction(stm_thread_local_t *tl) { +start_timer(); + s_mutex_lock(); #ifdef STM_NO_AUTOMATIC_SETJMP long repeat_count = did_abort;/* test/support.py */ @@ -1162,10 +1167,17 @@ memcpy(tl->mem_reset_on_abort, tl->mem_stored_for_reset_on_abort, tl->mem_bytes_to_reset_on_abort); } + +// _do_start_transaction is instrumented as well and pauses for waits +pause_timer(); _do_start_transaction(tl); +continue_timer(); STM_SEGMENT->nursery_mark = ((stm_char *)_stm_nursery_start + stm_get_transaction_length(tl)); + +stop_timer_and_publish(STM_DURATION_START_TRX); + return repeat_count; } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-overheads-instrumentation: Fix nested measurement of waiting time and time in validation
Author: Tobias Weber Branch: c8-overheads-instrumentation Changeset: r2067:39e259c124d6 Date: 2017-06-09 18:58 +0200 http://bitbucket.org/pypy/stmgc/changeset/39e259c124d6/ Log:Fix nested measurement of waiting time and time in validation diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -463,7 +463,9 @@ #endif if (STM_PSEGMENT->last_commit_log_entry->next == INEV_RUNNING) { -wait_for_inevitable(); +pause_timer(); +wait_for_inevitable(); // TODO may abort!! timing event lost +continue_timer(); goto retry_from_start; /* redo _stm_validate() now */ } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-overheads-instrumentation: Fix nested measurements of wait time during transaction start
Author: Tobias Weber Branch: c8-overheads-instrumentation Changeset: r2068:6161d44ff649 Date: 2017-06-09 18:58 +0200 http://bitbucket.org/pypy/stmgc/changeset/6161d44ff649/ Log:Fix nested measurements of wait time during transaction start diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1072,14 +1072,15 @@ static void _do_start_transaction(stm_thread_local_t *tl) { -start_timer(); - assert(!_stm_in_transaction(tl)); tl->wait_event_emitted = 0; acquire_thread_segment(tl); /* GS invalid before this point! */ +// acquiring segment is measured as wait time +start_timer(); + assert(STM_PSEGMENT->safe_point == SP_NO_TRANSACTION); assert(STM_PSEGMENT->transaction_state == TS_NONE); timing_event(tl, STM_TRANSACTION_START); @@ -1126,10 +1127,12 @@ rv++;/* incr it but enter_safe_point_if_requested() aborted */ STM_SEGMENT->transaction_read_version = rv; +pause_timer(); /* Warning: this safe-point may run light finalizers and register commit/abort callbacks if a major GC is triggered here */ enter_safe_point_if_requested(); dprintf(("> start_transaction\n")); +continue_timer(); s_mutex_unlock(); // XXX it's probably possible to not acquire this here @@ -1148,6 +1151,8 @@ long _stm_start_transaction(stm_thread_local_t *tl) { +start_timer(); + s_mutex_lock(); #ifdef STM_NO_AUTOMATIC_SETJMP long repeat_count = did_abort;/* test/support.py */ @@ -1161,13 +1166,20 @@ memcpy(tl->mem_reset_on_abort, tl->mem_stored_for_reset_on_abort, tl->mem_bytes_to_reset_on_abort); } + +// _do_start_transaction is instrumented as well and pauses for waits +pause_timer(); _do_start_transaction(tl); +continue_timer(); 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); } + +stop_timer_and_publish(STM_DURATION_START_TRX); + return repeat_count; } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Merge instrumentation bugfixes
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2069:2139691f1c0c Date: 2017-06-09 20:42 +0200 http://bitbucket.org/pypy/stmgc/changeset/2139691f1c0c/ Log:Merge instrumentation bugfixes ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Initialize single thread mode properties of thread local in setup.c
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2063:6074cbac03a5 Date: 2017-05-17 12:22 +0200 http://bitbucket.org/pypy/stmgc/changeset/6074cbac03a5/ Log:Initialize single thread mode properties of thread local in setup.c diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -47,12 +47,7 @@ } static void stm_transaction_length_handle_validation(stm_thread_local_t *tl, bool aborts) { -if (!tl->initialized) { // TODO move to setup.c -tl->relative_transaction_length = STM_MIN_RELATIVE_TRANSACTION_LENGTH; -tl->initialized = true; -} -double new = get_new_transaction_length(tl, aborts); -tl->relative_transaction_length = new; +tl->relative_transaction_length = get_new_transaction_length(tl, aborts); } static uintptr_t stm_get_transaction_length(stm_thread_local_t *tl) { diff --git a/c8/stm/setup.c b/c8/stm/setup.c --- a/c8/stm/setup.c +++ b/c8/stm/setup.c @@ -245,6 +245,11 @@ numbers automatically. */ tl->last_associated_segment_num = num + 1; tl->thread_local_counter = ++thread_local_counters; + +/* init single thread mode */ +tl->relative_transaction_length = STM_MIN_RELATIVE_TRANSACTION_LENGTH; +tl->transaction_length_backoff = 0; + *_get_cpth(tl) = pthread_self(); _init_shadow_stack(tl); set_gs_register(get_segment_base(num + 1)); diff --git a/c8/stmgc.h b/c8/stmgc.h --- a/c8/stmgc.h +++ b/c8/stmgc.h @@ -89,10 +89,11 @@ struct stm_thread_local_s *prev, *next; intptr_t self_or_0_if_atomic; void *creating_pthread[2]; -/* adaptive single thread mode */ +/* == adaptive single thread mode == */ +/* factor that is multiplied with max transaction length before the start of the next transaction on this thread */ double relative_transaction_length; +/* when zero, transaction length may increase or decrease, otherwise transaction length may only decrease. is (re-)set to some value upon abort and counted down until zero upon successful validation. */ int transaction_length_backoff; -bool initialized; } stm_thread_local_t; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Add timing macros to hide internals from user code when generating custom payload events
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2065:b74e3a67f424 Date: 2017-05-17 14:56 +0200 http://bitbucket.org/pypy/stmgc/changeset/b74e3a67f424/ Log:Add timing macros to hide internals from user code when generating custom payload events diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -52,17 +52,8 @@ static uintptr_t stm_get_transaction_length(stm_thread_local_t *tl) { double relative_additional_length = tl->relative_transaction_length; -if (timing_enabled()) { -struct timespec relative_length = { -.tv_sec = (int)relative_additional_length, -.tv_nsec = (int)(fmod(relative_additional_length, 1) * 10), -}; -stm_duration_payload(relative_length); -stmcb_timing_event( -STM_SEGMENT->running_thread, -STM_SINGLE_THREAD_MODE_ADAPTIVE, -&stm_duration_payload); -} +publish_custom_value_event( +relative_additional_length, STM_SINGLE_THREAD_MODE_ADAPTIVE); uintptr_t result = (uintptr_t)(LARGE_FILL_MARK_NURSERY_BYTES * relative_additional_length); // printf("%020" PRIxPTR "\n", result); diff --git a/c8/stm/timing.h b/c8/stm/timing.h --- a/c8/stm/timing.h +++ b/c8/stm/timing.h @@ -29,20 +29,31 @@ #define stm_duration_payload(duration_data) \ stm_timing_event_payload_data_t stm_duration_data = \ -{ .duration = &duration_data }; \ +{ .duration = &(duration_data) }; \ stm_timing_event_payload_t stm_duration_payload = \ { STM_EVENT_PAYLOAD_DURATION, stm_duration_data }; #define publish_event(thread_local, event) \ (timing_enabled() ? \ -stmcb_timing_event(thread_local, event, &stm_duration_payload) :\ +stmcb_timing_event((thread_local), (event), &stm_duration_payload) :\ (void)0); #define stop_timer_and_publish_for_thread(thread_local, event) \ pause_timer() \ stm_duration_payload(duration) \ -assert(thread_local != NULL); \ -publish_event(thread_local, event) +assert((thread_local) != NULL); \ +publish_event((thread_local), (event)) #define stop_timer_and_publish(event) \ -stop_timer_and_publish_for_thread(STM_SEGMENT->running_thread, event) +stop_timer_and_publish_for_thread(STM_SEGMENT->running_thread, (event)) + +#define set_payload(double_value) \ +struct timespec payload_value = { \ +.tv_sec = (int)(double_value), \ +.tv_nsec = (int)(fmod((double_value), 1) * 10), \ +}; + +#define publish_custom_value_event(double_value, event) \ +set_payload((double_value)) \ +stm_duration_payload(payload_value);\ +publish_event(STM_SEGMENT->running_thread, (event)) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Remove min transaction length (is now zero)
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2062:aa3ac5b4c94e Date: 2017-05-16 16:57 +0200 http://bitbucket.org/pypy/stmgc/changeset/aa3ac5b4c94e/ Log:Remove min transaction length (is now zero) diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -16,14 +16,11 @@ static uintptr_t _stm_nursery_start; #define DEFAULT_FILL_MARK_NURSERY_BYTES (NURSERY_SIZE / 4) -// just double the size at max + // #define LARGE_FILL_MARK_NURSERY_BYTES DEFAULT_FILL_MARK_NURSERY_BYTES #define LARGE_FILL_MARK_NURSERY_BYTES 0x10L // #define LARGE_FILL_MARK_NURSERY_BYTES 0x1000L -uintptr_t stm_fill_mark_nursery_bytes = DEFAULT_FILL_MARK_NURSERY_BYTES; -// uintptr_t stm_fill_mark_nursery_bytes = LARGE_FILL_MARK_NURSERY_BYTES; - #define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.0001) static double get_new_transaction_length(stm_thread_local_t *tl, bool aborts) { @@ -71,7 +68,7 @@ STM_SINGLE_THREAD_MODE_ADAPTIVE, &stm_duration_payload); } -uintptr_t result = DEFAULT_FILL_MARK_NURSERY_BYTES + +uintptr_t result = (uintptr_t)(LARGE_FILL_MARK_NURSERY_BYTES * relative_additional_length); // printf("%020" PRIxPTR "\n", result); return result; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Do not set transactions inevitable on start
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2064:9ca9e3e987a3 Date: 2017-05-17 13:43 +0200 http://bitbucket.org/pypy/stmgc/changeset/9ca9e3e987a3/ Log:Do not set transactions inevitable on start diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1164,10 +1164,6 @@ } _do_start_transaction(tl); -if (number_of_segments_in_use() < 2) { -stm_become_inevitable(tl, "single thread mode"); -} - STM_SEGMENT->nursery_mark = ((stm_char *)_stm_nursery_start + stm_get_transaction_length(tl)); return repeat_count; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Remove former transaction length back off mechanism and comment out debug output
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2061:5f7220351ad9 Date: 2017-05-12 17:56 +0200 http://bitbucket.org/pypy/stmgc/changeset/5f7220351ad9/ Log:Remove former transaction length back off mechanism and comment out debug output diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1167,8 +1167,7 @@ if (number_of_segments_in_use() < 2) { stm_become_inevitable(tl, "single thread mode"); } -/* TODO remove: else, 'nursery_mark' was already set -in abort_data_structures_from_segment_num() */ + STM_SEGMENT->nursery_mark = ((stm_char *)_stm_nursery_start + stm_get_transaction_length(tl)); return repeat_count; @@ -1532,22 +1531,6 @@ if (pseg->active_queues) queues_deactivate_all(pseg, /*at_commit=*/false); - -/* 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 diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -73,7 +73,7 @@ } uintptr_t result = DEFAULT_FILL_MARK_NURSERY_BYTES + (uintptr_t)(LARGE_FILL_MARK_NURSERY_BYTES * relative_additional_length); -printf("%020" PRIxPTR "\n", result); +// printf("%020" PRIxPTR "\n", result); return result; } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Fix nested measurement of waiting time and time in validation;
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2060:66afe82c56ce Date: 2017-05-12 16:10 +0200 http://bitbucket.org/pypy/stmgc/changeset/66afe82c56ce/ Log:Fix nested measurement of waiting time and time in validation; fix transaction size was not exponentially reduced in case of a retry diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -464,7 +464,9 @@ #endif if (STM_PSEGMENT->last_commit_log_entry->next == INEV_RUNNING) { -wait_for_inevitable(); +pause_timer(); +wait_for_inevitable(); // TODO may abort!! timing event lost +continue_timer(); goto retry_from_start; /* redo _stm_validate() now */ } @@ -1165,11 +1167,10 @@ if (number_of_segments_in_use() < 2) { stm_become_inevitable(tl, "single thread mode"); } -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 + +/* TODO remove: else, 'nursery_mark' was already set +in abort_data_structures_from_segment_num() */ +STM_SEGMENT->nursery_mark = ((stm_char *)_stm_nursery_start + stm_get_transaction_length(tl)); -} return repeat_count; } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Use double instead of float
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2059:daf9d599a698 Date: 2017-05-12 14:14 +0200 http://bitbucket.org/pypy/stmgc/changeset/daf9d599a698/ Log:Use double instead of float diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -5,6 +5,7 @@ #include "finalizer.h" #include +#include // @@ -23,12 +24,12 @@ uintptr_t stm_fill_mark_nursery_bytes = DEFAULT_FILL_MARK_NURSERY_BYTES; // uintptr_t stm_fill_mark_nursery_bytes = LARGE_FILL_MARK_NURSERY_BYTES; -#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.0001f) +#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.0001) -static float get_new_transaction_length(stm_thread_local_t *tl, bool aborts) { +static double get_new_transaction_length(stm_thread_local_t *tl, bool aborts) { const int multiplier = 100; -float previous = tl->relative_transaction_length; -float new = previous; +double previous = tl->relative_transaction_length; +double new = previous; if (aborts) { tl->transaction_length_backoff = 3; if (previous > STM_MIN_RELATIVE_TRANSACTION_LENGTH) { @@ -49,16 +50,16 @@ } static void stm_transaction_length_handle_validation(stm_thread_local_t *tl, bool aborts) { -if (!tl->initialized) { +if (!tl->initialized) { // TODO move to setup.c tl->relative_transaction_length = STM_MIN_RELATIVE_TRANSACTION_LENGTH; tl->initialized = true; } -float new = get_new_transaction_length(tl, aborts); +double new = get_new_transaction_length(tl, aborts); tl->relative_transaction_length = new; } static uintptr_t stm_get_transaction_length(stm_thread_local_t *tl) { -float relative_additional_length = tl->relative_transaction_length; +double relative_additional_length = tl->relative_transaction_length; if (timing_enabled()) { struct timespec relative_length = { .tv_sec = (int)relative_additional_length, @@ -70,8 +71,10 @@ STM_SINGLE_THREAD_MODE_ADAPTIVE, &stm_duration_payload); } -return DEFAULT_FILL_MARK_NURSERY_BYTES + +uintptr_t result = DEFAULT_FILL_MARK_NURSERY_BYTES + (uintptr_t)(LARGE_FILL_MARK_NURSERY_BYTES * relative_additional_length); +printf("%020" PRIxPTR "\n", result); +return result; } diff --git a/c8/stmgc.h b/c8/stmgc.h --- a/c8/stmgc.h +++ b/c8/stmgc.h @@ -90,7 +90,7 @@ intptr_t self_or_0_if_atomic; void *creating_pthread[2]; /* adaptive single thread mode */ -float relative_transaction_length; +double relative_transaction_length; int transaction_length_backoff; bool initialized; } stm_thread_local_t; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-per-thread: Implement a per thread adaptive single thread mode
Author: Tobias Weber Branch: c8-adaptive-trx-length-per-thread Changeset: r2058:cbb625d908bf Date: 2017-05-07 20:16 +0200 http://bitbucket.org/pypy/stmgc/changeset/cbb625d908bf/ Log:Implement a per thread adaptive single thread mode diff --git a/c8/stm/core.c b/c8/stm/core.c --- a/c8/stm/core.c +++ b/c8/stm/core.c @@ -1167,9 +1167,8 @@ } if (repeat_count == 0) { /* else, 'nursery_mark' was already set in abort_data_structures_from_segment_num() */ -stm_update_transaction_length(); STM_SEGMENT->nursery_mark = ((stm_char *)_stm_nursery_start + - stm_fill_mark_nursery_bytes); +stm_get_transaction_length(tl)); } return repeat_count; } diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -23,61 +23,42 @@ uintptr_t stm_fill_mark_nursery_bytes = DEFAULT_FILL_MARK_NURSERY_BYTES; // uintptr_t stm_fill_mark_nursery_bytes = LARGE_FILL_MARK_NURSERY_BYTES; -#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.01f) -static float stm_relative_transaction_length = STM_MIN_RELATIVE_TRANSACTION_LENGTH; -static int stm_increase_transaction_length_backoff = 0; +#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.0001f) -static void reset_or_decrease_backoff(bool reset) { -int actual_backoff = stm_increase_transaction_length_backoff; -int expected_backoff; -int value = 5; -do { -expected_backoff = actual_backoff; -if (!reset) { -value = actual_backoff - 1; -} -actual_backoff = __atomic_exchange_n( -&stm_increase_transaction_length_backoff, value, __ATOMIC_RELAXED); -} while (expected_backoff != actual_backoff && (reset || actual_backoff > 0)); -} - -static float get_new_transaction_length(bool aborts, float previous) { -const int multiplier = 2; +static float get_new_transaction_length(stm_thread_local_t *tl, bool aborts) { +const int multiplier = 100; +float previous = tl->relative_transaction_length; float new = previous; if (aborts) { -reset_or_decrease_backoff(true); // reset backoff +tl->transaction_length_backoff = 3; if (previous > STM_MIN_RELATIVE_TRANSACTION_LENGTH) { new = previous / multiplier; } else { new = 0; } -} else if (stm_increase_transaction_length_backoff == 0) { +} else if (tl->transaction_length_backoff == 0) { if (previous - (STM_MIN_RELATIVE_TRANSACTION_LENGTH * 0.1) < 0) { new = STM_MIN_RELATIVE_TRANSACTION_LENGTH; } else if (previous < 1) { new = previous * multiplier; } } else { // not abort and backoff != 0 -reset_or_decrease_backoff(false); // decrease backoff by one +tl->transaction_length_backoff -= 1; } return new; } static void stm_transaction_length_handle_validation(stm_thread_local_t *tl, bool aborts) { -float actual = stm_relative_transaction_length; -float expected; -do { -expected = actual; -float new = get_new_transaction_length(aborts, actual); -__atomic_exchange( -&stm_relative_transaction_length, &new, &actual, __ATOMIC_RELAXED); -} while (fabs(actual - expected) > (STM_MIN_RELATIVE_TRANSACTION_LENGTH * 0.1)); +if (!tl->initialized) { +tl->relative_transaction_length = STM_MIN_RELATIVE_TRANSACTION_LENGTH; +tl->initialized = true; +} +float new = get_new_transaction_length(tl, aborts); +tl->relative_transaction_length = new; } -static void stm_update_transaction_length(void) { -float relative_additional_length = stm_relative_transaction_length; -stm_fill_mark_nursery_bytes = DEFAULT_FILL_MARK_NURSERY_BYTES + -(uintptr_t)(LARGE_FILL_MARK_NURSERY_BYTES * relative_additional_length); +static uintptr_t stm_get_transaction_length(stm_thread_local_t *tl) { +float relative_additional_length = tl->relative_transaction_length; if (timing_enabled()) { struct timespec relative_length = { .tv_sec = (int)relative_additional_length, @@ -89,6 +70,8 @@ STM_SINGLE_THREAD_MODE_ADAPTIVE, &stm_duration_payload); } +return DEFAULT_FILL_MARK_NURSERY_BYTES + +(uintptr_t)(LARGE_FILL_MARK_NURSERY_BYTES * relative_additional_length); } diff --git a/c8/stm/nursery.h b/c8/stm/nursery.h --- a/c8/stm/nursery.h +++ b/c8/stm/nursery.h @@ -60,6 +60,6 @@ static uint32_t stm_global_conflicts; static void stm_transaction_length_handle_validation(stm_thread_local_t *tl, bool aborts); -static void stm_update_transaction_length(void); +static uintptr_t stm_get_transaction_length(stm_thread_local_t *tl); #endif diff --git a/c8/stmgc.h b/c8/stmgc.h --- a/c8/stmgc.h +++ b/c8/stmgc.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -88,6 +
[pypy-commit] stmgc c8-adaptive-trx-length-prolonged-backoff: Use simple on off mechanism for the adaptive mode
Author: Tobias Weber Branch: c8-adaptive-trx-length-prolonged-backoff Changeset: r2054:6b4b7aedc3d1 Date: 2017-05-04 12:24 +0200 http://bitbucket.org/pypy/stmgc/changeset/6b4b7aedc3d1/ Log:Use simple on off mechanism for the adaptive mode diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -44,17 +44,9 @@ float new = previous; if (aborts) { reset_or_decrease_backoff(true); // reset backoff -if (previous > 0.01) { -new = previous / 2; -} else if (previous > 0) { -new = 0; -} +new = 0; } else if (stm_increase_transaction_length_backoff == 0) { -if (previous - 0.001 < 0) { -new = 0.01; -} else if (previous < 1) { -new = previous * 2; -} +new = 1; } else { // not abort and backoff != 0 reset_or_decrease_backoff(false); // decrease backoff by one } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-prolonged-backoff: Set exponential base back to two because the effect was insignificant
Author: Tobias Weber Branch: c8-adaptive-trx-length-prolonged-backoff Changeset: r2057:8170562e2157 Date: 2017-05-05 11:39 +0200 http://bitbucket.org/pypy/stmgc/changeset/8170562e2157/ Log:Set exponential base back to two because the effect was insignificant diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -17,13 +17,13 @@ #define DEFAULT_FILL_MARK_NURSERY_BYTES (NURSERY_SIZE / 4) // just double the size at max // #define LARGE_FILL_MARK_NURSERY_BYTES DEFAULT_FILL_MARK_NURSERY_BYTES -#define LARGE_FILL_MARK_NURSERY_BYTES 0x1L +#define LARGE_FILL_MARK_NURSERY_BYTES 0x10L // #define LARGE_FILL_MARK_NURSERY_BYTES 0x1000L uintptr_t stm_fill_mark_nursery_bytes = DEFAULT_FILL_MARK_NURSERY_BYTES; // uintptr_t stm_fill_mark_nursery_bytes = LARGE_FILL_MARK_NURSERY_BYTES; -#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.1f) +#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.01f) static float stm_relative_transaction_length = STM_MIN_RELATIVE_TRANSACTION_LENGTH; static int stm_increase_transaction_length_backoff = 0; @@ -42,7 +42,7 @@ } static float get_new_transaction_length(bool aborts, float previous) { -const int multiplier = 1000; +const int multiplier = 2; float new = previous; if (aborts) { reset_or_decrease_backoff(true); // reset backoff ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-prolonged-backoff: Backed out changeset 6b4b7aedc3d1
Author: Tobias Weber Branch: c8-adaptive-trx-length-prolonged-backoff Changeset: r2055:707bc6a2c0a8 Date: 2017-05-04 12:39 +0200 http://bitbucket.org/pypy/stmgc/changeset/707bc6a2c0a8/ Log:Backed out changeset 6b4b7aedc3d1 diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -44,9 +44,17 @@ float new = previous; if (aborts) { reset_or_decrease_backoff(true); // reset backoff -new = 0; +if (previous > 0.01) { +new = previous / 2; +} else if (previous > 0) { +new = 0; +} } else if (stm_increase_transaction_length_backoff == 0) { -new = 1; +if (previous - 0.001 < 0) { +new = 0.01; +} else if (previous < 1) { +new = previous * 2; +} } else { // not abort and backoff != 0 reset_or_decrease_backoff(false); // decrease backoff by one } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-prolonged-backoff: Set exponential base of trx length modifier to 1000
Author: Tobias Weber Branch: c8-adaptive-trx-length-prolonged-backoff Changeset: r2056:22ebd85e36fd Date: 2017-05-04 17:38 +0200 http://bitbucket.org/pypy/stmgc/changeset/22ebd85e36fd/ Log:Set exponential base of trx length modifier to 1000 diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -17,13 +17,14 @@ #define DEFAULT_FILL_MARK_NURSERY_BYTES (NURSERY_SIZE / 4) // just double the size at max // #define LARGE_FILL_MARK_NURSERY_BYTES DEFAULT_FILL_MARK_NURSERY_BYTES -#define LARGE_FILL_MARK_NURSERY_BYTES 0x100L +#define LARGE_FILL_MARK_NURSERY_BYTES 0x1L // #define LARGE_FILL_MARK_NURSERY_BYTES 0x1000L uintptr_t stm_fill_mark_nursery_bytes = DEFAULT_FILL_MARK_NURSERY_BYTES; // uintptr_t stm_fill_mark_nursery_bytes = LARGE_FILL_MARK_NURSERY_BYTES; -static float stm_relative_transaction_length = 0.01; +#define STM_MIN_RELATIVE_TRANSACTION_LENGTH (0.1f) +static float stm_relative_transaction_length = STM_MIN_RELATIVE_TRANSACTION_LENGTH; static int stm_increase_transaction_length_backoff = 0; static void reset_or_decrease_backoff(bool reset) { @@ -41,19 +42,20 @@ } static float get_new_transaction_length(bool aborts, float previous) { +const int multiplier = 1000; float new = previous; if (aborts) { reset_or_decrease_backoff(true); // reset backoff -if (previous > 0.01) { -new = previous / 2; -} else if (previous > 0) { +if (previous > STM_MIN_RELATIVE_TRANSACTION_LENGTH) { +new = previous / multiplier; +} else { new = 0; } } else if (stm_increase_transaction_length_backoff == 0) { -if (previous - 0.001 < 0) { -new = 0.01; +if (previous - (STM_MIN_RELATIVE_TRANSACTION_LENGTH * 0.1) < 0) { +new = STM_MIN_RELATIVE_TRANSACTION_LENGTH; } else if (previous < 1) { -new = previous * 2; +new = previous * multiplier; } } else { // not abort and backoff != 0 reset_or_decrease_backoff(false); // decrease backoff by one @@ -69,7 +71,7 @@ float new = get_new_transaction_length(aborts, actual); __atomic_exchange( &stm_relative_transaction_length, &new, &actual, __ATOMIC_RELAXED); -} while (fabs(actual - expected) > 0.001); +} while (fabs(actual - expected) > (STM_MIN_RELATIVE_TRANSACTION_LENGTH * 0.1)); } static void stm_update_transaction_length(void) { ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c8-adaptive-trx-length-prolonged-backoff: Prolong the reduction in transaction length for a number of validations after a conflict
Author: Tobias Weber Branch: c8-adaptive-trx-length-prolonged-backoff Changeset: r2053:b8316d20df70 Date: 2017-05-03 11:33 +0200 http://bitbucket.org/pypy/stmgc/changeset/b8316d20df70/ Log:Prolong the reduction in transaction length for a number of validations after a conflict diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c --- a/c8/stm/nursery.c +++ b/c8/stm/nursery.c @@ -23,41 +23,57 @@ uintptr_t stm_fill_mark_nursery_bytes = DEFAULT_FILL_MARK_NURSERY_BYTES; // uintptr_t stm_fill_mark_nursery_bytes = LARGE_FILL_MARK_NURSERY_BYTES; -static float stm_default_relative_transaction_length = 0.01; -static float *stm_relative_transaction_length_pointer = -&stm_default_relative_transaction_length; +static float stm_relative_transaction_length = 0.01; +static int stm_increase_transaction_length_backoff = 0; + +static void reset_or_decrease_backoff(bool reset) { +int actual_backoff = stm_increase_transaction_length_backoff; +int expected_backoff; +int value = 5; +do { +expected_backoff = actual_backoff; +if (!reset) { +value = actual_backoff - 1; +} +actual_backoff = __atomic_exchange_n( +&stm_increase_transaction_length_backoff, value, __ATOMIC_RELAXED); +} while (expected_backoff != actual_backoff && (reset || actual_backoff > 0)); +} static float get_new_transaction_length(bool aborts, float previous) { float new = previous; if (aborts) { +reset_or_decrease_backoff(true); // reset backoff if (previous > 0.01) { new = previous / 2; } else if (previous > 0) { new = 0; } -} else { +} else if (stm_increase_transaction_length_backoff == 0) { if (previous - 0.001 < 0) { new = 0.01; } else if (previous < 1) { new = previous * 2; } +} else { // not abort and backoff != 0 +reset_or_decrease_backoff(false); // decrease backoff by one } return new; } static void stm_transaction_length_handle_validation(stm_thread_local_t *tl, bool aborts) { -float actual = *stm_relative_transaction_length_pointer; +float actual = stm_relative_transaction_length; float expected; do { expected = actual; float new = get_new_transaction_length(aborts, actual); __atomic_exchange( -stm_relative_transaction_length_pointer, &new, &actual, __ATOMIC_RELAXED); +&stm_relative_transaction_length, &new, &actual, __ATOMIC_RELAXED); } while (fabs(actual - expected) > 0.001); } static void stm_update_transaction_length(void) { -float relative_additional_length = *stm_relative_transaction_length_pointer; +float relative_additional_length = stm_relative_transaction_length; stm_fill_mark_nursery_bytes = DEFAULT_FILL_MARK_NURSERY_BYTES + (uintptr_t)(LARGE_FILL_MARK_NURSERY_BYTES * relative_additional_length); if (timing_enabled()) { ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit