Author: Armin Rigo <[email protected]>
Branch: c7-fork
Changeset: r1075:75893b92af4e
Date: 2014-03-19 09:10 +0100
http://bitbucket.org/pypy/stmgc/changeset/75893b92af4e/

Log:    Seems to work now; clean up intermediate attempts

diff --git a/c7/demo/demo_random.c b/c7/demo/demo_random.c
--- a/c7/demo/demo_random.c
+++ b/c7/demo/demo_random.c
@@ -10,11 +10,11 @@
 #include "stmgc.h"
 
 #define NUMTHREADS 3
-#define STEPS_PER_THREAD 300
-#define THREAD_STARTS 300 // how many restarts of threads
+#define STEPS_PER_THREAD 500
+#define THREAD_STARTS 1000 // how many restarts of threads
 #define PREBUILT_ROOTS 3
 #define MAXROOTS 1000
-#define FORKS 1
+#define FORKS 3
 
 // SUPPORT
 struct node_s;
diff --git a/c7/stm/core.c b/c7/stm/core.c
--- a/c7/stm/core.c
+++ b/c7/stm/core.c
@@ -164,13 +164,11 @@
     STM_SEGMENT->transaction_read_version = 1;
 }
 
-void _stm_start_transaction(stm_thread_local_t *tl, stm_jmpbuf_t *jmpbuf,
-                            int already_got_the_lock)
+void _stm_start_transaction(stm_thread_local_t *tl, stm_jmpbuf_t *jmpbuf)
 {
-    if (!already_got_the_lock) {
-        assert(!_stm_in_transaction(tl));
-        s_mutex_lock();
-    }
+    assert(!_stm_in_transaction(tl));
+
+    s_mutex_lock();
 
   retry:
     if (jmpbuf == NULL) {
@@ -449,7 +447,7 @@
     /* cannot access STM_SEGMENT or STM_PSEGMENT from here ! */
 }
 
-void _stm_commit_transaction(int keep_the_lock_at_the_end)
+void stm_commit_transaction(void)
 {
     assert(!_has_mutex());
     assert(STM_PSEGMENT->safe_point == SP_RUNNING);
@@ -508,8 +506,7 @@
     _finish_transaction();
     /* cannot access STM_SEGMENT or STM_PSEGMENT from here ! */
 
-    if (!keep_the_lock_at_the_end)
-        s_mutex_unlock();
+    s_mutex_unlock();
 }
 
 void stm_abort_transaction(void)
diff --git a/c7/stm/pages.c b/c7/stm/pages.c
--- a/c7/stm/pages.c
+++ b/c7/stm/pages.c
@@ -25,10 +25,6 @@
 static void teardown_pages(void)
 {
     memset(&pages_ctl, 0, sizeof(pages_ctl));
-}
-
-static void teardown_pages_1(void)
-{
     memset(pages_privatized, 0, sizeof(pages_privatized));
 }
 
diff --git a/c7/stm/setup.c b/c7/stm/setup.c
--- a/c7/stm/setup.c
+++ b/c7/stm/setup.c
@@ -14,8 +14,25 @@
     return result;
 }
 
-static void do_or_redo_setup_after_fork(void)
+void stm_setup(void)
 {
+    /* Check that some values are acceptable */
+    assert(NB_SEGMENTS <= NB_SEGMENTS_MAX);
+    assert(4096 <= ((uintptr_t)STM_SEGMENT));
+    assert((uintptr_t)STM_SEGMENT == (uintptr_t)STM_PSEGMENT);
+    assert(((uintptr_t)STM_PSEGMENT) + sizeof(*STM_PSEGMENT) <= 8192);
+    assert(2 <= FIRST_READMARKER_PAGE);
+    assert(FIRST_READMARKER_PAGE * 4096UL <= READMARKER_START);
+    assert(READMARKER_START < READMARKER_END);
+    assert(READMARKER_END <= 4096UL * FIRST_OBJECT_PAGE);
+    assert(FIRST_OBJECT_PAGE < NB_PAGES);
+    assert((NB_PAGES * 4096UL) >> 8 <= (FIRST_OBJECT_PAGE * 4096UL) >> 4);
+    assert((END_NURSERY_PAGE * 4096UL) >> 8 <=
+           (FIRST_READMARKER_PAGE * 4096UL));
+    assert(_STM_FAST_ALLOC <= NB_NURSERY_PAGES * 4096);
+
+    stm_object_pages = setup_mmap("initial stm_object_pages mmap()");
+
     /* The segment 0 is not used to run transactions, but contains the
        shared copy of the pages.  We mprotect all pages before so that
        accesses fail, up to and including the pages corresponding to the
@@ -68,43 +85,25 @@
        so a null read marker means "not read" whatever the
        current transaction_read_version is.
     */
-    setup_nursery();
-}
-
-void stm_setup(void)
-{
-    /* Check that some values are acceptable */
-    assert(NB_SEGMENTS <= NB_SEGMENTS_MAX);
-    assert(4096 <= ((uintptr_t)STM_SEGMENT));
-    assert((uintptr_t)STM_SEGMENT == (uintptr_t)STM_PSEGMENT);
-    assert(((uintptr_t)STM_PSEGMENT) + sizeof(*STM_PSEGMENT) <= 8192);
-    assert(2 <= FIRST_READMARKER_PAGE);
-    assert(FIRST_READMARKER_PAGE * 4096UL <= READMARKER_START);
-    assert(READMARKER_START < READMARKER_END);
-    assert(READMARKER_END <= 4096UL * FIRST_OBJECT_PAGE);
-    assert(FIRST_OBJECT_PAGE < NB_PAGES);
-    assert((NB_PAGES * 4096UL) >> 8 <= (FIRST_OBJECT_PAGE * 4096UL) >> 4);
-    assert((END_NURSERY_PAGE * 4096UL) >> 8 <=
-           (FIRST_READMARKER_PAGE * 4096UL));
-    assert(_STM_FAST_ALLOC <= NB_NURSERY_PAGES * 4096);
-
-    stm_object_pages = setup_mmap("initial stm_object_pages mmap()");
-
-    do_or_redo_setup_after_fork();
 
     setup_sync();
+    setup_nursery();
     setup_gcpage();
     setup_pages();
     setup_forksupport();
 }
 
-static void do_or_redo_teardown_after_fork(void)
+void stm_teardown(void)
 {
+    /* This function is called during testing, but normal programs don't
+       need to call it. */
+    assert(!_has_mutex());
+
     long i;
     for (i = 1; i <= NB_SEGMENTS; i++) {
         struct stm_priv_segment_info_s *pr = get_priv_segment(i);
-        LIST_FREE(pr->objects_pointing_to_nursery);
-        LIST_FREE(pr->large_overflow_objects);
+        assert(pr->objects_pointing_to_nursery == NULL);
+        assert(pr->large_overflow_objects == NULL);
         list_free(pr->modified_old_objects);
         list_free(pr->young_weakrefs);
         list_free(pr->old_weakrefs);
@@ -113,22 +112,10 @@
         tree_free(pr->callbacks_on_abort);
     }
 
-    teardown_core();
-    teardown_sync_1();
-    teardown_pages_1();
-}
-
-void stm_teardown(void)
-{
-    /* This function is called during testing, but normal programs don't
-       need to call it. */
-    assert(!_has_mutex());
-
-    do_or_redo_teardown_after_fork();
-
     munmap(stm_object_pages, TOTAL_MEMORY);
     stm_object_pages = NULL;
 
+    teardown_core();
     teardown_sync();
     teardown_gcpage();
     teardown_pages();
diff --git a/c7/stm/sync.c b/c7/stm/sync.c
--- a/c7/stm/sync.c
+++ b/c7/stm/sync.c
@@ -36,10 +36,6 @@
     char reserved[192];
 } sync_ctl __attribute__((aligned(64)));
 
-#ifndef NDEBUG
-static bool _safe_points_requested = false;
-#endif
-
 
 static void setup_sync(void)
 {
@@ -63,15 +59,8 @@
         if (pthread_cond_destroy(&sync_ctl.cond[i]) != 0)
             stm_fatalerror("cond destroy: %m");
     }
-}
 
-static void teardown_sync_1(void)
-{
     memset(&sync_ctl, 0, sizeof(sync_ctl));
-#ifndef NDEBUG
-    _safe_points_requested = false;
-#endif
-    pause_signalled = false;
 }
 
 #ifndef NDEBUG
@@ -263,6 +252,10 @@
 /************************************************************/
 
 
+#ifndef NDEBUG
+static bool _safe_points_requested = false;
+#endif
+
 static void signal_everybody_to_pause_running(void)
 {
     assert(_safe_points_requested == false);
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -78,8 +78,7 @@
 object_t *_stm_allocate_slowpath(ssize_t);
 object_t *_stm_allocate_external(ssize_t);
 void _stm_become_inevitable(const char*);
-void _stm_start_transaction(stm_thread_local_t *, stm_jmpbuf_t *, int);
-void _stm_commit_transaction(int);
+void _stm_start_transaction(stm_thread_local_t *, stm_jmpbuf_t *);
 void _stm_collectable_safe_point(void);
 
 /* for tests, but also used in duhton: */
@@ -258,19 +257,17 @@
    stm_jmpbuf_t). */
 #define STM_START_TRANSACTION(tl, jmpbuf)  ({                   \
     while (__builtin_setjmp(jmpbuf) == 1) { /*redo setjmp*/ }   \
-    _stm_start_transaction(tl, &jmpbuf, 0);                     \
+    _stm_start_transaction(tl, &jmpbuf);                        \
 })
 
 /* Start an inevitable transaction, if it's going to return from the
    current function immediately. */
 static inline void stm_start_inevitable_transaction(stm_thread_local_t *tl) {
-    _stm_start_transaction(tl, NULL, 0);
+    _stm_start_transaction(tl, NULL);
 }
 
 /* Commit a transaction. */
-static inline void stm_commit_transaction(void) {
-    _stm_commit_transaction(0);
-}
+void stm_commit_transaction(void);
 
 /* Abort the currently running transaction. */
 void stm_abort_transaction(void) __attribute__((noreturn));
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to