Author: Remi Meier
Branch: 
Changeset: r1113:9afe044b265f
Date: 2014-03-28 13:15 +0100
http://bitbucket.org/pypy/stmgc/changeset/9afe044b265f/

Log:    more statistics, try harder to avoid GIL

diff --git a/c7/demo/Makefile b/c7/demo/Makefile
--- a/c7/demo/Makefile
+++ b/c7/demo/Makefile
@@ -33,6 +33,6 @@
 
 
 release-htm-%: %.c ../../htm-c7/stmgc.? ../../htm-c7/htm.h
-       clang -I.. -pthread -g -DNDEBUG -O2 $< -o release-htm-$* 
../../htm-c7/stmgc.c -Wall -DUSE_HTM
+       clang -I.. -pthread -g  -O2 $< -o release-htm-$* ../../htm-c7/stmgc.c 
-Wall -DUSE_HTM
 
 
diff --git a/c7/demo/demo_simple.c b/c7/demo/demo_simple.c
--- a/c7/demo/demo_simple.c
+++ b/c7/demo/demo_simple.c
@@ -10,7 +10,7 @@
 #  include "stmgc.h"
 #endif
 
-#define ITERS 10000000
+#define ITERS 1000000
 #define NTHREADS    2
 
 
@@ -52,12 +52,15 @@
     stm_register_thread_local(&stm_thread_local);
     tl_counter = 0;
 
+    object_t *tmp;
     int i = 0;
     while (i < ITERS) {
         stm_start_inevitable_transaction(&stm_thread_local);
         tl_counter++;
-        if (i % 5 == 0)
-            gl_counter++;
+        if (i % 500 < 250)
+            STM_PUSH_ROOT(stm_thread_local, stm_allocate(16));//gl_counter++;
+        else
+            STM_POP_ROOT(stm_thread_local, tmp);
         stm_commit_transaction();
         i++;
     }
diff --git a/htm-c7/htm.h b/htm-c7/htm.h
--- a/htm-c7/htm.h
+++ b/htm-c7/htm.h
@@ -67,6 +67,7 @@
 
 static __attribute__((__always_inline__)) inline int 
mutex_locked(pthread_mutex_t* mut)
 {
+    /* HACK: pthread internals! */
     return !!mut->__data.__lock;
 }
 
diff --git a/htm-c7/stmgc.c b/htm-c7/stmgc.c
--- a/htm-c7/stmgc.c
+++ b/htm-c7/stmgc.c
@@ -9,7 +9,7 @@
 //struct stm_segment_info_s _stm_segment;
 __thread struct stm_segment_info_s* _stm_segment;
 
-#define TRANSIENT_RETRY_MAX 10
+#define TRANSIENT_RETRY_MAX 100
 #define GIL_RETRY_MAX 10
 
 #define ABORT_GIL_LOCKED 1
@@ -17,6 +17,10 @@
 
 static __thread int gil_transactions = 0;
 static __thread int htm_transactions = 0;
+static __thread int gil_retry_acquire = 0;
+static __thread int gil_spin_retry_acquire = 0;
+static __thread int transient_retry_acquire = 0;
+static __thread int persistent_acquire = 0;
 
 __thread struct htm_transaction_info_s _htm_info __attribute__((aligned(64)));
 
@@ -32,13 +36,14 @@
 }
 
 static int spin_and_acquire_gil(stm_thread_local_t *tl) {
-    int n = 5;
+    int n = 500;
     while (n-- > 0) {
         if (!mutex_locked(&_stm_gil))
             return 0;
         smp_spinloop();
     }
 
+    gil_spin_retry_acquire++;
     acquire_gil(tl);
     return 1;
 }
@@ -61,10 +66,10 @@
     _htm_info.retry_counter = 0;
     _htm_info.use_gil = 0;
 
-    if (mutex_locked(&_stm_gil)) {
-        if (spin_and_acquire_gil(tl))
-            return;
-    }
+    /* if (mutex_locked(&_stm_gil)) { */
+    /*     if (spin_and_acquire_gil(tl)) */
+    /*         return; */
+    /* } */
 
     int status;
     int transient_retry_counter = TRANSIENT_RETRY_MAX;
@@ -84,7 +89,7 @@
             /* adjust_transaction_length(pc) */
         }
 
-        if (mutex_locked(&_stm_gil)) {
+        if ((status & XBEGIN_XABORT) && XBEGIN_XABORT_ARG(status) == 
ABORT_GIL_LOCKED) {
             gil_retry_counter--;
             if (gil_retry_counter > 0) {
                 if (spin_and_acquire_gil(tl)) {
@@ -94,8 +99,10 @@
                     goto transaction_retry;
                 }
             }
+            gil_retry_acquire++;
             acquire_gil(tl);
         } else if (is_persistent(status)) {
+            persistent_acquire++;
             acquire_gil(tl);
         } else {
             /* transient abort */
@@ -105,6 +112,7 @@
                 smp_spinloop();
                 goto transaction_retry;
             }
+            transient_retry_acquire++;
             acquire_gil(tl);
         }
 
@@ -287,9 +295,14 @@
 
 void stm_unregister_thread_local(stm_thread_local_t *tl) {
     fprintf(stderr,
-            "in %p\ngil_transactions: %d\nhtm_transactions: %d\nratio: %f\n",
+            "== in %p 
==\ngil_transactions:\t%d\nhtm_transactions:\t%d\nratio:\t\t\t=%f\n"
+            "gil_spin_retry_acquire:\t%d\n"
+            "gil_retry_acquire:\t%d\npersistent_acquire:\t%d\n"
+            "transient_retry_acquire:%d\n",
             tl, gil_transactions, htm_transactions,
-            (float)gil_transactions / (float)htm_transactions);
+            (float)gil_transactions / (float)htm_transactions,
+            gil_spin_retry_acquire,
+            gil_retry_acquire, persistent_acquire, transient_retry_acquire);
     //free(tl->shadowstack_base);
 
     list_free(objects_pointing_to_nursery);
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to