[pypy-commit] stmgc marker: Fixes, see comment in marker.c

arigo noreply at buildbot.pypy.org
Fri Apr 18 11:32:49 CEST 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: marker
Changeset: r1162:80d12fdc0b89
Date: 2014-04-18 11:32 +0200
http://bitbucket.org/pypy/stmgc/changeset/80d12fdc0b89/

Log:	Fixes, see comment in marker.c

diff --git a/c7/stm/core.c b/c7/stm/core.c
--- a/c7/stm/core.c
+++ b/c7/stm/core.c
@@ -620,6 +620,9 @@
                        (int)pseg->transaction_state);
     }
 
+    /* look up and preserve the marker information as a string */
+    marker_fetch_expand(pseg);
+
     /* throw away the content of the nursery */
     long bytes_in_nursery = throw_away_nursery(pseg);
 
diff --git a/c7/stm/core.h b/c7/stm/core.h
--- a/c7/stm/core.h
+++ b/c7/stm/core.h
@@ -158,6 +158,9 @@
 #ifndef NDEBUG
     pthread_t running_pthread;
 #endif
+
+    /* Temporarily stores the marker information */
+    char marker_self[_STM_MARKER_LEN];
 };
 
 enum /* safe_point */ {
diff --git a/c7/stm/marker.c b/c7/stm/marker.c
--- a/c7/stm/marker.c
+++ b/c7/stm/marker.c
@@ -8,25 +8,39 @@
                             char *outputbuf, size_t outputbufsize);
 
 
-void marker_fetch(stm_thread_local_t *tl,
-                  enum stm_time_e attribute_to, double time)
+static void marker_fetch_expand(struct stm_priv_segment_info_s *pseg)
 {
-    tl->longest_marker_state = attribute_to;
-    tl->longest_marker_time = time;
+    pseg->marker_self[0] = 0;
 
     if (stmcb_expand_marker != NULL) {
+        stm_thread_local_t *tl = pseg->pub.running_thread;
         struct stm_shadowentry_s *current = tl->shadowstack - 1;
         struct stm_shadowentry_s *base = tl->shadowstack_base;
         while (--current >= base) {
             uintptr_t x = (uintptr_t)current->ss;
             if (x & 1) {
                 /* the stack entry is an odd number */
-                tl->longest_marker_self[0] = 0;
                 stmcb_expand_marker(x, current[1].ss,
-                                    tl->longest_marker_self,
-                                    sizeof(tl->longest_marker_self));
+                                    pseg->marker_self, _STM_MARKER_LEN);
                 break;
             }
         }
     }
 }
+
+static void marker_copy(stm_thread_local_t *tl,
+                        struct stm_priv_segment_info_s *pseg,
+                        enum stm_time_e attribute_to, double time)
+{
+    /* Copies the marker information from pseg to tl.  This is called
+       indirectly from abort_with_mutex(), but only if the lost time is
+       greater than that of the previous recorded marker.  By contrast,
+       pseg->marker_self has been filled already in all cases.  The
+       reason for the two steps is that we must fill pseg->marker_self
+       earlier than now (some objects may be GCed), but we only know
+       here the total time it gets attributed.
+    */
+    tl->longest_marker_state = attribute_to;
+    tl->longest_marker_time = time;
+    memcpy(tl->longest_marker_self, pseg->marker_self, _STM_MARKER_LEN);
+}
diff --git a/c7/stm/marker.h b/c7/stm/marker.h
--- a/c7/stm/marker.h
+++ b/c7/stm/marker.h
@@ -1,3 +1,5 @@
 
-void marker_fetch(stm_thread_local_t *tl,
-                  enum stm_time_e attribute_to, double time);
+static void marker_fetch_expand(struct stm_priv_segment_info_s *pseg);
+static void marker_copy(stm_thread_local_t *tl,
+                        struct stm_priv_segment_info_s *pseg,
+                        enum stm_time_e attribute_to, double time);
diff --git a/c7/stm/timing.c b/c7/stm/timing.c
--- a/c7/stm/timing.c
+++ b/c7/stm/timing.c
@@ -40,12 +40,10 @@
     tl->timing[STM_TIME_RUN_CURRENT] = 0.0f;
 
     if (attribute_to != STM_TIME_RUN_COMMITTED &&
-            time_this_transaction > tl->longest_marker_time) {
-        assert(tl->shadowstack ==
-               STM_PSEGMENT->shadowstack_at_start_of_transaction);
-        tl->shadowstack = STM_PSEGMENT->shadowstack_at_abort;
-        marker_fetch(tl, attribute_to, time_this_transaction);
-        tl->shadowstack = STM_PSEGMENT->shadowstack_at_start_of_transaction;
+            time_this_transaction * 0.99 > tl->longest_marker_time) {
+        struct stm_priv_segment_info_s *pseg =
+            get_priv_segment(STM_SEGMENT->segment_num);
+        marker_copy(tl, pseg, attribute_to, time_this_transaction);
     }
 }
 
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -73,6 +73,8 @@
     _STM_TIME_N
 };
 
+#define _STM_MARKER_LEN  80
+
 typedef struct stm_thread_local_s {
     /* every thread should handle the shadow stack itself */
     struct stm_shadowentry_s *shadowstack, *shadowstack_base;
@@ -93,8 +95,8 @@
     /* the marker with the longest associated time so far */
     enum stm_time_e longest_marker_state;
     double longest_marker_time;
-    char longest_marker_self[80];
-    char longest_marker_other[80];
+    char longest_marker_self[_STM_MARKER_LEN];
+    char longest_marker_other[_STM_MARKER_LEN];
     /* the next fields are handled internally by the library */
     int associated_segment_num;
     struct stm_thread_local_s *prev, *next;


More information about the pypy-commit mailing list