Changeset: c1c01118282f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c1c01118282f
Modified Files:
        monetdb5/mal/mal.c
        monetdb5/mal/mal_client.h
        monetdb5/mal/mal_instruction.h
        monetdb5/mal/mal_recycle.c
        monetdb5/mal/mal_recycle.h
Branch: default
Log Message:

Cleanup recycler and make debugging thread safe.


diffs (truncated from 606 to 300 lines):

diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -324,7 +324,7 @@ void mal_exit(void){
         * Before continuing we should make sure that all clients
         * (except the console) have left the scene.
         */
-       RECYCLEshutdown(mal_clients); /* remove any left over intermediates */
+       RECYCLEdrop(mal_clients); /* remove any left over intermediates */
        stopProfiling();
        stopHeartbeat();
        stopMALdataflow();
diff --git a/monetdb5/mal/mal_client.h b/monetdb5/mal/mal_client.h
--- a/monetdb5/mal/mal_client.h
+++ b/monetdb5/mal/mal_client.h
@@ -165,9 +165,6 @@ typedef struct CLIENT {
         */
        int             actions;
        lng             totaltime;      /* sum of elapsed processing times */
-       /* recycler administration */
-       lng             time0;  /* last query start */
-       int             recent; /* last MAL instruction */
 
        jmp_buf exception_buf;
        int exception_buf_initialized;
diff --git a/monetdb5/mal/mal_instruction.h b/monetdb5/mal/mal_instruction.h
--- a/monetdb5/mal/mal_instruction.h
+++ b/monetdb5/mal/mal_instruction.h
@@ -145,7 +145,7 @@ typedef struct MALBLK {
        lng recid;                                      /* Recycler identifier 
*/
        lng legid;                                      /* Octopus control */
        sht trap;                                       /* call debugger when 
called */
-       lng runtime;                                    /* average execution 
time of block in ticks */
+       lng runtime;                            /* average execution time of 
block in ticks */
        int calls;                                      /* number of calls */
        lng optimize;                           /* total optimizer time */
 } *MalBlkPtr, MalBlkRecord;
diff --git a/monetdb5/mal/mal_recycle.c b/monetdb5/mal/mal_recycle.c
--- a/monetdb5/mal/mal_recycle.c
+++ b/monetdb5/mal/mal_recycle.c
@@ -76,30 +76,15 @@ MalBlkPtr recycleBlk = NULL;
 #define getbit(x,i) ( x & ((lng)1 << i) )
 #define neg(x) ( (x)?FALSE:TRUE)
 
-
-/* ADM_ALL: infinite case, admission of all instructions subject to cache 
limits*/
-
-lng recycleSearchTime = 0;     /* cache search time in ms*/
-int recycleMaxInterest = REC_MAX_INTEREST;
-
-/* REUSE_COVER: exploit potential range overlap */
-int reusePolicy = REUSE_COVER; 
-
-/*     evict items with smallest profit= weight * cost / lifetime adds aging 
to the benefit policy */
-
 int recycleCacheLimit=0; /* No limit by default */
 
-
 /*
  * Monitoring the Recycler
  */
-lng recyclerMemoryUsed = 0;
-int monitorRecycler = 0;
-       /*       1: print statistics for RecyclerPool only
-                2: print stat at the end of each query */
-
+static lng recyclerMemoryUsed = 0;
 static lng recycled=0;
 static lng statements =0;
+static lng recycleSearchTime =0;       /* cache search time in ms*/
 
 /*
  * The profiler record is re-used to store recycler information.
@@ -122,6 +107,8 @@ static lng statements =0;
 static str bindRef = 0, bind_idxRef = 0, sqlRef = 0;
 static str subselectRef = 0, thetasubselectRef = 0, likesubselectRef = 0;
 static void RECYCLEexitImpl(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr p, RuntimeProfile prof);
+static void RECYCLEdumpInternal(stream *s);
+
 /*
  * The Recycle catalog is a global structure, which should be
  * protected with locks when updated.
@@ -175,7 +162,7 @@ RECYCLEgarbagecollect(MalBlkPtr mb, Inst
 
        for(j=0; j< q->argc; j++){
                v= &getVarConstant(mb,getArg(q,j));
-               if(getArgType(mb,q,j)==TYPE_bat || isaBatType(getArgType(mb, 
q,j)) ){
+               if(isaBatType(getArgType(mb, q,j)) ){
                        if( v->val.bval ){
                                BBPdecref(ABS(v->val.bval), TRUE);
                                if (!BBP_lrefs(v->val.bval)){
@@ -243,9 +230,6 @@ int chooseVictims(Client cntxt, int *lea
                        wben[mpos] = wben[newtop-1];
                        wben[newtop-1] = tmp;
                        tot_ben += recycleProfit(tmpl);
-#ifdef _DEBUG_CACHE_
-                       mnstr_printf(cntxt->fdout,"#Don't drop instruction %d, 
credit %f\n" , tmpl,tmp);
-#endif
                }
                else break;
        }
@@ -275,7 +259,7 @@ int chooseVictims(Client cntxt, int *lea
 }
 
 
-static void RECYCLEcleanCache(Client cntxt, lng wr0){
+static void RECYCLEcleanCache(Client cntxt, lng wr0,lng clk){
        int j,i,l,ltop,v,vtop;
        InstrPtr p;
        InstrPtr *old, *newstmt;
@@ -283,7 +267,7 @@ static void RECYCLEcleanCache(Client cnt
        int k, *leaves, *vm;
        int limit, idx;
        size_t mem;
-       int cont, reserve;
+       int cont;
        lng oldclk, wr;
        dbl minben, ben;
        bte *used;
@@ -296,38 +280,29 @@ newpass:
        wr = wr0;
        used = (bte*)GDKzalloc(recycleBlk->vtop);
 
-       /* set all used variables */
+       /* set all variables used */
        for (i = 0; i < recycleBlk->stop; i++){
                p = recycleBlk->stmt[i];
                for( j = p->retc ; j< p->argc; j++)
                        if (used[getArg(p,j)]<2)  used[getArg(p,j)]++;
        }
 
-       /* find the leaves, ignore the most recent instruction */
+       /* find the leaves */
        lmask = (bit*)GDKzalloc(recycleBlk->stop);
-       ltop = 0; reserve = 0;
+       ltop = 0; 
        for (i = 0; i < recycleBlk->stop; i++){
                p = recycleBlk->stmt[i];
                for( j = 0; j < p->retc ; j++)
                        if (used[getArg(p,j)]) goto skip;
-               if (i == cntxt->recent){
-                       reserve = i;
-                       continue;
-               }
                lmask[i] = 1;
                ltop++;
                skip:;
        }
 
 
-       if (ltop == 0 ){  /* ensure at least 1 entry to evict */
-               if (reserve){
-                       lmask[reserve] = 1;
-                       ltop++;
-               } else {        
-                       GDKfree(lmask);
-                       return;
-               }
+       if (ltop == 0 ){  
+               GDKfree(lmask);
+               return;
        }
        leaves = (int *)GDKzalloc(sizeof(int)*ltop);
        l = 0;
@@ -335,7 +310,7 @@ newpass:
                if (lmask[i]) leaves[l++] = i;
        GDKfree(lmask);
 
-       /* find the oldest */
+       /* find the oldest leave */
        oldclk = recycleBlk->profiler[leaves[0]].clk;
        idx = 0;
        for (l = 0; l < ltop; l++){
@@ -346,33 +321,22 @@ newpass:
                }
        }
 
-       /* protect leaves from current query invocation */
-
-       if ( oldclk < cntxt->time0) {
-
-#ifdef _DEBUG_CACHE_
-                       
mnstr_printf(cntxt->fdout,"#RECYCLEcleanCache:Fresh-protected "LLFMT" leaves:", 
cntxt->time0);
-                       for (l = 0; l < ltop; l++)
-                               mnstr_printf(cntxt->fdout,"%3d("LLFMT") \t",
-                                       
leaves[l],recycleBlk->profiler[leaves[l]].clk);
-                       mnstr_printf(cntxt->fdout,"\n");
-#endif
+       /* protect leaves from current the query invocation */
+       if ( oldclk < clk) {
                l = 0;
-               for (j = 0; j < ltop; j++){
-                       if (recycleBlk->profiler[leaves[j]].clk < cntxt->time0)
+               for (j = 0; j < ltop; j++)
+                       if (recycleBlk->profiler[leaves[j]].clk < clk)
                                leaves[l++] = leaves[j];
-               }
                ltop = l;
        }
 
 
 #ifdef _DEBUG_CACHE_
-        mnstr_printf(cntxt->fdout,"#RECYCLEcleanCache: policy=PROFIT 
usedmem="LLFMT"\n", recyclerMemoryUsed);
-               mnstr_printf(cntxt->fdout,"#Target memory "LLFMT"KB Available 
"LLFMT"KB\n", wr,monet_memory -recyclerMemoryUsed);
+        mnstr_printf(cntxt->fdout,"#RECYCLEcleanCache: usedmem="LLFMT" target 
memory freed "LLFMT"\n", recyclerMemoryUsed,wr);
         mnstr_printf(cntxt->fdout,"#Candidates for 
eviction\n#LRU\t\tTicks\tLife\tSZ\tCnt\tWgt\tBen\tProf)\n");
                for (l = 0; l < ltop; l++)
-               mnstr_printf(cntxt->fdout,"#%3d "LLFMT"\t"LLFMT"\t %5.2f\t 
"LLFMT"\t%3d\t%5.1f\n",
-                       leaves[l],recycleBlk->profiler[leaves[l]].clk,
+               mnstr_printf(cntxt->fdout,"#%3d "LLFMT"\t"LLFMT"\t"LLFMT"\t 
%5.2f\t "LLFMT"\t%3d\t%5.1f\n",
+                       leaves[l],clk,recycleBlk->profiler[leaves[l]].clk,
                        recycleBlk->profiler[leaves[l]].ticks,
                        recycleLife(leaves[l]),
                        recycleBlk->profiler[leaves[l]].wbytes,
@@ -401,7 +365,6 @@ newpass:
                for (l = 0; l < ltop; l++)
                        if ( recycleBlk->profiler[leaves[l]].wbytes > 0 )
                                leaves[k++] = leaves[l];
-/*                             mnstr_printf(cntxt->fdout,"ltop %d k 
%d\n",ltop, k); */
                if ( k > 0 )
                        ltop = k;
                vtop = chooseVictims(cntxt,leaves, ltop, recyclerMemoryUsed + 
wr - monet_memory );
@@ -463,22 +426,8 @@ newpass:
 
        GDKfree(dmask);
        if (cont) goto newpass;
-
 }
 
-/*
- * To avoid a polution of the recycle cache, we do not store any
- * intruction for which there is not function/command/pattern implementation.
- * Likewise, we avoid all simple constant assigments.
- */
-int
-RECYCLEinterest(InstrPtr p){
-       if (p->recycle <= REC_NO_INTEREST )
-               return 0;
-       return getFunctionId(p) != NULL;
-}
-
-
 #ifdef _DEBUG_CACHE_
 static void
 RECYCLEsync(InstrPtr p)
@@ -563,7 +512,6 @@ RECYCLEkeep(Client cntxt, MalBlkPtr mb, 
        recycleBlk->profiler[i].rbytes = rd;
        recycleBlk->profiler[i].wbytes = wr;
        recyclerMemoryUsed += wr;
-       cntxt->recent = i;
 
 #ifdef _DEBUG_CACHE_
        RECYCLEsync(q);
@@ -594,7 +542,7 @@ RECYCLEfind(Client cntxt, MalBlkPtr mb, 
 {
        int i, j;
        InstrPtr q;
-       //lng clk = GDKusec();
+       lng clk = GDKusec();
 
        (void) mb;
        if( recycleBlk == 0)
@@ -603,20 +551,20 @@ RECYCLEfind(Client cntxt, MalBlkPtr mb, 
        (void) cntxt;
        for (i=0; i<recycleBlk->stop; i++) {
                q = getInstrPtr(recycleBlk,i);
-               if ((getFunctionId(p) != getFunctionId(q)) ||
-                       (p->argc != q->argc-1) ||
-                       (getModuleId(p) != getModuleId(q)))
+               if (getFunctionId(p) != getFunctionId(q) ||
+                       getModuleId(p) != getModuleId(q) ||
+                       p->argc != q->argc ||
+                       p->retc != q->retc )
                                continue;
                for (j=p->retc; j<p->argc; j++)
                        if( VALcmp( &s->stk[getArg(p,j)], 
&getVarConstant(recycleBlk,getArg(q,j))))
                                break;
-               if (j == p->argc)
-#ifdef _DEBUG_CACHE_
-                       if ( q->token != NOOPsymbol )
-#endif
+               if (j == p->argc){
+                       recycleSearchTime = GDKusec()-clk;
                        return i;
+               }
        }
-       //recycleSearchTime = GDKusec()-clk;
+       recycleSearchTime = GDKusec()-clk;
        return -1;
 }
 
@@ -881,7 +829,6 @@ RECYCLEreuse(Client cntxt, MalBlkPtr mb,
                recycleBlk->profiler[i].clk = GDKusec();
                if ( !( getModuleId(p) == sqlRef && ( bindRef == 
getFunctionId(p) || bind_idxRef == getFunctionId(p))))
                        recycled++;
-               cntxt->recent = i;
                MT_lock_unset(&recycleLock, "recycle");
                return i;
                notfound:
@@ -896,8 +843,8 @@ RECYCLEreuse(Client cntxt, MalBlkPtr mb,
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to