Changeset: 5be1b63b5632 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/5be1b63b5632
Modified Files:
        monetdb5/mal/mal_profiler.c
        monetdb5/mal/mal_runtime.c
Branch: default
Log Message:

Reduce relying on locking the workingset global when not needed.
In the profiler, we wait a short while for all threads to be
ready to use the locking when profiling is active.


diffs (97 lines):

diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c
--- a/monetdb5/mal/mal_profiler.c
+++ b/monetdb5/mal/mal_profiler.c
@@ -632,13 +632,23 @@ openProfilerStream(Client cntxt)
        // Ignore the JSON rendering mode, use compiled time version
 
        /* show all in progress instructions for stethoscope startup */
-       /* this code is not thread safe, because the inprogress administration 
may change concurrently */
-       MT_lock_set(&mal_delayLock);
-       for(j = 0; j <THREADS; j++)
-       if(workingset[j].mb)
-               /* show the event */
-               profilerEvent(workingset[j].cntxt, workingset[j].mb, 
workingset[j].stk, workingset[j].pci, 1);
-       MT_lock_unset(&mal_delayLock);
+       /* wait a short time for instructions to finish updating there thread 
admin
+        * and then follow the locking scheme */
+
+       MT_sleep_ms(200);
+
+       MT_lock_set(&mal_profileLock);
+       for(j = 0; j <THREADS; j++){
+               Client c = 0; MalBlkPtr m=0; MalStkPtr s = 0; InstrPtr p = 0;
+               c = workingset[j].cntxt;
+               m = workingset[j].mb;
+               s = workingset[j].stk;
+               p =  workingset[j].pci;
+               if( c && m && s && p )
+                       /* show the event  assuming the quadruple is aligned*/
+                       profilerEvent(c, m, s, p, 1);
+       }
+       MT_lock_unset(&mal_profileLock);
        return MAL_SUCCEED;
 }
 
diff --git a/monetdb5/mal/mal_runtime.c b/monetdb5/mal/mal_runtime.c
--- a/monetdb5/mal/mal_runtime.c
+++ b/monetdb5/mal/mal_runtime.c
@@ -373,7 +373,7 @@ mal_runtime_reset(void)
 /*
  * Each MAL instruction is executed by a single thread, which means we can
  * keep a simple working set around to make Stethscope attachement easy.
- * It can also be used to later shutdown each thread safely.
+ * The entries are privately accessed and only can be influenced by a starting 
stehoscope to emit work in progress.
  */
 Workingset workingset[THREADS];
 
@@ -386,12 +386,19 @@ runtimeProfileBegin(Client cntxt, MalBlk
        assert(pci);
        /* keep track on the instructions taken in progress for stethoscope*/
        if( tid < THREADS){
-               MT_lock_set(&mal_delayLock);
-               workingset[tid].cntxt = cntxt;
-               workingset[tid].mb = mb;
-               workingset[tid].stk = stk;
-               workingset[tid].pci = pci;
-               MT_lock_unset(&mal_delayLock);
+               if( malProfileMode) {
+                       MT_lock_set(&mal_profileLock);
+                       workingset[tid].cntxt = cntxt;
+                       workingset[tid].mb = mb;
+                       workingset[tid].stk = stk;
+                       workingset[tid].pci = pci;
+                       MT_lock_unset(&mal_profileLock);
+               } else{
+                       workingset[tid].cntxt = cntxt;
+                       workingset[tid].mb = mb;
+                       workingset[tid].stk = stk;
+                       workingset[tid].pci = pci;
+               }
        }
        /* always collect the MAL instruction execution time */
        pci->clock = prof->ticks = GDKusec();
@@ -410,11 +417,19 @@ runtimeProfileExit(Client cntxt, MalBlkP
 
        /* keep track on the instructions in progress*/
        if ( tid < THREADS) {
-               MT_lock_set(&mal_delayLock);
-               workingset[tid].mb = 0;
-               workingset[tid].stk = 0;
-               workingset[tid].pci = 0;
-               MT_lock_unset(&mal_delayLock);
+               if( malProfileMode) {
+                       MT_lock_set(&mal_profileLock);
+                       workingset[tid].cntxt = 0;
+                       workingset[tid].mb = 0;
+                       workingset[tid].stk = 0;
+                       workingset[tid].pci = 0;
+                       MT_lock_unset(&mal_profileLock);
+               } else{
+                       workingset[tid].cntxt = 0;
+                       workingset[tid].mb = 0;
+                       workingset[tid].stk = 0;
+                       workingset[tid].pci = 0;
+               }
        }
 
        /* always collect the MAL instruction execution time */
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to