[pypy-commit] stmgc c7-refactor: Better debug prints. Fix next test.

arigo noreply at buildbot.pypy.org
Mon Feb 24 15:09:19 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: c7-refactor
Changeset: r827:f19ec8c06cfd
Date: 2014-02-24 15:09 +0100
http://bitbucket.org/pypy/stmgc/changeset/f19ec8c06cfd/

Log:	Better debug prints. Fix next test.

diff --git a/c7/stm/core.c b/c7/stm/core.c
--- a/c7/stm/core.c
+++ b/c7/stm/core.c
@@ -13,6 +13,7 @@
 {
     assert(_running_transaction());
     assert(!_is_in_nursery(obj));
+    dprintf(("write_slowpath %p\n", obj));
 
     /* is this an object from the same transaction, outside the nursery? */
     if ((obj->stm_flags & -GCFLAG_OVERFLOW_NUMBER_bit0) ==
diff --git a/c7/stm/list.c b/c7/stm/list.c
--- a/c7/stm/list.c
+++ b/c7/stm/list.c
@@ -11,10 +11,9 @@
 {
     uintptr_t initial_allocation = 32;
     struct list_s *lst = malloc(LIST_SETSIZE(initial_allocation));
-    if (lst == NULL) {
-        perror("out of memory in list_create");
-        abort();
-    }
+    if (lst == NULL)
+        stm_fatalerror("out of memory in list_create\n");   /* XXX */
+
     lst->count = 0;
     lst->last_allocated = initial_allocation - 1;
     return lst;
@@ -24,10 +23,9 @@
 {
     nalloc = LIST_OVERCNT(nalloc);
     lst = realloc(lst, LIST_SETSIZE(nalloc));
-    if (lst == NULL) {
-        perror("out of memory in _list_grow");
-        abort();
-    }
+    if (lst == NULL)
+        stm_fatalerror("out of memory in _list_grow\n");   /* XXX */
+
     lst->last_allocated = nalloc - 1;
     return lst;
 }
diff --git a/c7/stm/pages.c b/c7/stm/pages.c
--- a/c7/stm/pages.c
+++ b/c7/stm/pages.c
@@ -30,6 +30,20 @@
 /************************************************************/
 
 
+static void d_remap_file_pages(char *addr, size_t size, ssize_t pgoff)
+{
+    dprintf(("remap_file_pages: 0x%lx bytes: (seg%ld %p) --> (seg%ld %p)\n",
+             (long)size,
+             (long)((addr - stm_object_pages) / 4096UL) / NB_PAGES,
+             (void *)((addr - stm_object_pages) % (4096UL * NB_PAGES)),
+             (long)pgoff / NB_PAGES,
+             (void *)((pgoff % NB_PAGES) * 4096UL)));
+
+    int res = remap_file_pages(addr, size, 0, pgoff, 0);
+    if (UNLIKELY(res < 0))
+        stm_fatalerror("remap_file_pages: %m\n");
+}
+
 static void pages_initialize_shared(uintptr_t pagenum, uintptr_t count)
 {
     /* call remap_file_pages() to make all pages in the range(pagenum,
@@ -39,13 +53,8 @@
     assert(_has_mutex_pages());
     for (i = 1; i < NB_SEGMENTS; i++) {
         char *segment_base = get_segment_base(i);
-        int res = remap_file_pages(segment_base + pagenum * 4096UL,
-                                   count * 4096UL,
-                                   0, pagenum, 0);
-        if (res != 0) {
-            perror("remap_file_pages");
-            abort();
-        }
+        d_remap_file_pages(segment_base + pagenum * 4096UL,
+                           count * 4096UL, pagenum);
     }
     for (i = 0; i < count; i++)
         flag_page_private[pagenum + i] = SHARED_PAGE;
@@ -83,11 +92,7 @@
     void *localpg = stm_object_pages + localpgoff * 4096UL;
     void *otherpg = stm_object_pages + otherpgoff * 4096UL;
 
-    int res = remap_file_pages(localpg, count * 4096, 0, pgoff2, 0);
-    if (res < 0) {
-        perror("remap_file_pages");
-        abort();
-    }
+    d_remap_file_pages(localpg, count * 4096, pgoff2);
     uintptr_t i;
     if (full) {
         for (i = 0; i < count; i++) {
@@ -117,7 +122,7 @@
 
     for (; pagenum < pagestop; pagenum++) {
         uint8_t prev = flag_page_private[pagenum];
-        if (prev == SHARED_PAGE) {
+        if (prev == PRIVATE_PAGE) {
             if (pagenum > page_start_range) {
                 privatize_range(page_start_range,
                                 pagenum - page_start_range, full);
@@ -125,7 +130,7 @@
             page_start_range = pagenum + 1;
         }
         else {
-            assert(prev == PRIVATE_PAGE);
+            assert(prev == SHARED_PAGE);
         }
     }
 
diff --git a/c7/stm/setup.c b/c7/stm/setup.c
--- a/c7/stm/setup.c
+++ b/c7/stm/setup.c
@@ -22,10 +22,8 @@
     stm_object_pages = mmap(NULL, TOTAL_MEMORY,
                             PROT_READ | PROT_WRITE,
                             MAP_PAGES_FLAGS, -1, 0);
-    if (stm_object_pages == MAP_FAILED) {
-        perror("stm_object_pages mmap");
-        abort();
-    }
+    if (stm_object_pages == MAP_FAILED)
+        stm_fatalerror("initial stm_object_pages mmap() failed: %m\n");
 
     long i;
     for (i = 0; i < NB_SEGMENTS; i++) {
diff --git a/c7/stm/sync.c b/c7/stm/sync.c
--- a/c7/stm/sync.c
+++ b/c7/stm/sync.c
@@ -32,36 +32,29 @@
 static void setup_sync(void)
 {
     if (pthread_mutex_init(&sync_ctl.global_mutex, NULL) != 0 ||
-         pthread_cond_init(&sync_ctl.global_cond, NULL) != 0) {
-        perror("mutex/cond initialization");
-        abort();
-    }
+         pthread_cond_init(&sync_ctl.global_cond, NULL) != 0)
+        stm_fatalerror("mutex/cond initialization: %m\n");
 }
 
 static void teardown_sync(void)
 {
     if (pthread_mutex_destroy(&sync_ctl.global_mutex) != 0 ||
-         pthread_cond_destroy(&sync_ctl.global_cond) != 0) {
-        perror("mutex/cond destroy");
-        abort();
-    }
+         pthread_cond_destroy(&sync_ctl.global_cond) != 0)
+        stm_fatalerror("mutex/cond destroy: %m\n");
+
     memset(&sync_ctl, 0, sizeof(sync_ctl.in_use));
 }
 
 static void set_gs_register(char *value)
 {
-    if (syscall(SYS_arch_prctl, ARCH_SET_GS, (uint64_t)value) != 0) {
-        perror("syscall(arch_prctl, ARCH_SET_GS)");
-        abort();
-    }
+    if (UNLIKELY(syscall(SYS_arch_prctl, ARCH_SET_GS, (uint64_t)value) != 0))
+        stm_fatalerror("syscall(arch_prctl, ARCH_SET_GS): %m\n");
 }
 
 static inline void mutex_lock(void)
 {
-    if (UNLIKELY(pthread_mutex_lock(&sync_ctl.global_mutex) != 0)) {
-        perror("pthread_mutex_lock");
-        abort();
-    }
+    if (UNLIKELY(pthread_mutex_lock(&sync_ctl.global_mutex) != 0))
+        stm_fatalerror("pthread_mutex_lock: %m\n");
 
     if (STM_PSEGMENT->transaction_state == TS_MUST_ABORT)
         abort_with_mutex();
@@ -72,10 +65,8 @@
     assert(STM_PSEGMENT->safe_point == SP_NO_TRANSACTION ||
            STM_PSEGMENT->safe_point == SP_RUNNING);
 
-    if (UNLIKELY(pthread_mutex_unlock(&sync_ctl.global_mutex) != 0)) {
-        perror("pthread_mutex_unlock");
-        abort();
-    }
+    if (UNLIKELY(pthread_mutex_unlock(&sync_ctl.global_mutex) != 0))
+        stm_fatalerror("pthread_mutex_unlock: %m\n");
 }
 
 static inline bool _has_mutex(void)
@@ -97,10 +88,8 @@
 #endif
 
     if (UNLIKELY(pthread_cond_wait(&sync_ctl.global_cond,
-                                   &sync_ctl.global_mutex) != 0)) {
-        perror("pthread_cond_wait");
-        abort();
-    }
+                                   &sync_ctl.global_mutex) != 0))
+        stm_fatalerror("pthread_cond_wait: %m\n");
 
     if (STM_PSEGMENT->transaction_state == TS_MUST_ABORT)
         abort_with_mutex();
@@ -108,10 +97,8 @@
 
 static inline void cond_broadcast(void)
 {
-    if (UNLIKELY(pthread_cond_broadcast(&sync_ctl.global_cond) != 0)) {
-        perror("pthread_cond_broadcast");
-        abort();
-    }
+    if (UNLIKELY(pthread_cond_broadcast(&sync_ctl.global_cond) != 0))
+        stm_fatalerror("pthread_cond_broadcast: %m\n");
 }
 
 static void acquire_thread_segment(stm_thread_local_t *tl)


More information about the pypy-commit mailing list