Author: Armin Rigo <[email protected]>
Branch: timelog
Changeset: r1118:3acb2c19742b
Date: 2014-03-29 16:49 +0100
http://bitbucket.org/pypy/stmgc/changeset/3acb2c19742b/

Log:    Getting started

diff --git a/c7/stm/timelog.c b/c7/stm/timelog.c
new file mode 100644
--- /dev/null
+++ b/c7/stm/timelog.c
@@ -0,0 +1,17 @@
+#ifndef _STM_CORE_H_
+# error "must be compiled via stmgc.c"
+#endif
+
+
+stm_timelog_t *stm_fetch_and_remove_timelog(stm_thread_local_t *tl)
+{
+    stm_timelog_t *tlog = tl->last_tlog;
+    tl->last_tlog = NULL;
+    return tlog;
+}
+
+void stm_free_timelog(stm_timelog_t *tlog)
+{
+    OPT_ASSERT(tlog != NULL);
+    free(tlog);
+}
diff --git a/c7/stmgc.c b/c7/stmgc.c
--- a/c7/stmgc.c
+++ b/c7/stmgc.c
@@ -31,3 +31,4 @@
 #include "stm/extra.c"
 #include "stm/fprintcolor.c"
 #include "stm/weakref.c"
+#include "stm/timelog.c"
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -70,6 +70,7 @@
     int associated_segment_num;
     struct stm_thread_local_s *prev, *next;
     void *creating_pthread[2];
+    struct stm_timelog_s *last_tlog;
 } stm_thread_local_t;
 
 /* this should use llvm's coldcc calling convention,
@@ -336,6 +337,35 @@
                                             const char *msg);
 
 
+/* ---------- timelogs ---------- */
+
+enum {
+    STLOG_REASON_UNKNOWN,
+    STLOG_REASON_ABORT_SELF,
+    STLOG_REASON_ABORT_OTHER,
+    STLOG_REASON_PAUSE,
+};
+enum {
+    STLOG_CONTENTION_NONE,
+    STLOG_CONTENTION_WRITE_WRITE,
+    STLOG_CONTENTION_WRITE_READ,
+    STLOG_CONTENTION_INEVITABLE,
+};
+
+typedef struct stm_timelog_s {
+    uint8_t reason;
+    uint8_t contention;
+    int user;
+    double time_lost;
+    //stm_traceback_t *traceback_self;
+    //stm_traceback_t *traceback_other;
+} stm_timelog_t;
+
+/* XXX maybe inline these functions if they turn out to be trivial */
+stm_timelog_t *stm_fetch_and_remove_timelog(stm_thread_local_t *);
+void stm_free_timelog(stm_timelog_t *);
+
+
 /* ==================== END ==================== */
 
 #endif
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -98,6 +98,26 @@
 
 int stm_can_move(object_t *);
 void stm_call_on_abort(stm_thread_local_t *, void *key, void callback(void *));
+
+#define STLOG_REASON_UNKNOWN ...
+#define STLOG_REASON_ABORT_SELF ...
+#define STLOG_REASON_ABORT_OTHER ...
+#define STLOG_REASON_PAUSE ...
+#define STLOG_CONTENTION_NONE ...
+#define STLOG_CONTENTION_WRITE_WRITE ...
+#define STLOG_CONTENTION_WRITE_READ ...
+#define STLOG_CONTENTION_INEVITABLE ...
+
+typedef struct {
+    uint8_t reason;
+    uint8_t contention;
+    int user;
+    double time_lost;
+    ...;
+} stm_timelog_t;
+
+stm_timelog_t *stm_fetch_and_remove_timelog(stm_thread_local_t *);
+void stm_free_timelog(stm_timelog_t *);
 """)
 
 
@@ -517,3 +537,7 @@
         tl = self.tls[self.current_thread]
         if lib._check_become_globally_unique_transaction(tl):
             raise Conflict()
+
+    def fetch_and_remove_timelog(self):
+        tl = self.tls[self.current_thread]
+        return lib.stm_fetch_and_remove_timelog(tl)
diff --git a/c7/test/test_timelog.py b/c7/test/test_timelog.py
new file mode 100644
--- /dev/null
+++ b/c7/test/test_timelog.py
@@ -0,0 +1,26 @@
+import py, time
+from support import *
+
+
+class TestTimeLog(BaseTest):
+
+    def test_empty(self):
+        self.start_transaction()
+        tlog = self.fetch_and_remove_timelog()
+        assert tlog == ffi.NULL
+
+    def test_simple_abort(self):
+        self.start_transaction()
+        start = time.time()
+        while abs(time.time() - start) <= 0.05:
+            pass
+        self.abort_transaction()
+        #
+        self.start_transaction()
+        tlog = self.fetch_and_remove_timelog()
+        assert tlog != ffi.NULL
+        assert tlog.reason == lib.STLOG_REASON_UNKNOWN
+        assert tlog.contention == lib.STLOG_CONTENTION_NONE
+        assert tlog.user == 0
+        assert 0.0499 <= tlog.time_lost < 1.0
+        lib.stm_free_timelog(tlog)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to