Update of /cvsroot/monetdb/MonetDB5/src/mal
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21654/mal

Modified Files:
        mal_instruction.mx mal_interpreter.mx mal_recycle.mx 
        mal_stack.mx 
Log Message:
The generic recycler framework.
The recycler optimizer marks all variables that are potential useful
for recycling. This applies to expressions over constants and side-effect free
operations.
The instruction is also marked as relevant to be monitored.
The recycle version is set such that it become automatically initialized.

The interpreter has been wrapped with calls to the recycler, looking
for a cheap way to get the result. If not, the instruction is executed
and the result values become available for recycling.
Currently, all values are retained. The timing and other properties
are now available for more precise policies.

Note, the recycler works on identical execution of instructions only.
For example, optimization of select calls against stored results
should still be handled in a specialized operation, which redirects
the search against the base table to one already kept.


Index: mal_interpreter.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_interpreter.mx,v
retrieving revision 1.214
retrieving revision 1.215
diff -u -d -r1.214 -r1.215
--- mal_interpreter.mx  1 Mar 2008 22:52:36 -0000       1.214
+++ mal_interpreter.mx  2 Mar 2008 11:20:51 -0000       1.215
@@ -1466,9 +1466,9 @@
 The recycler works for any variable and relies on policy functions
 registered.
 @= MALrecyclerStart
-       if( !mb->version  || !RECYCLEentry(mb,stk,pci) )
+       if( !pci->recycle  || !mb->version  || !RECYCLEentry(mb,stk,pci) )
 @= MALrecyclerExit
-       if( mb->version )
+       if( pci->recycle && mb->version )
                RECYCLEexit(mb,stk,pci);
 @}
 @-
@@ -1615,10 +1615,12 @@
                if( mb->profiler != NULL && mb->profiler[stkpc].trace)
                {
                        ppc= stkpc;
-                       mb->profiler[ppc].clk= GDKusec();
-                       time(&mb->profiler[ppc].clock);
+                       stk->clk= GDKusec();
+                       time(&stk->clock);
+                       mb->profiler[ppc].clock= stk->clock;
 #ifdef HAVE_TIMES
-                       times(&mb->profiler[ppc].timer);
+                       times(&stk->timer);
+                       mb->profiler[ppc].timer= stk->timer;
 #endif
                }
        }
@@ -1632,7 +1634,7 @@
        {
                newclk= GDKusec();
                mb->profiler[ppc].counter++;
-               mb->profiler[ppc].ticks = (long) (newclk - 
mb->profiler[ppc].clk);
+               mb->profiler[ppc].ticks = (long) (newclk - stk->clk);
                mb->profiler[ppc].clk += mb->profiler[ppc].clk;
                if( pci){
                        mb->profiler[ppc].ibytes= getVolume(stk,pci,0);

Index: mal_recycle.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_recycle.mx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- mal_recycle.mx      2 Mar 2008 08:45:03 -0000       1.3
+++ mal_recycle.mx      2 Mar 2008 11:20:51 -0000       1.4
@@ -196,6 +196,8 @@
        (void) mb;
        (void) stk;
        (void) pci;
+       if( recycleBlk == 0)
+               return MAL_SUCCEED;
        mal_set_lock(recycleLock,"recycle");
        recycleBlk->version = 0;
        recycleUsers--;
@@ -248,36 +250,34 @@
 
 static void RECYCLEnew(MalBlkPtr mb, MalStkPtr s, InstrPtr p)
 {
-       int i, j, c, bid; 
-       ValPtr v, v1;
+       int i, j, c; 
+       ValRecord *v;
        InstrPtr q;
        
        RECYCLEspace();
        q = copyInstruction(p);
 #ifdef _DEBUG_RECYCLE_
-       stream_printf(GDKout,"add instruction\n");
-       printInstruction(GDKout,mb,p,LIST_MAL_ALL);
+       stream_printf(GDKout,"RECYLEnew \n");
 #endif
        for(i = 0; i< p->argc; i++){
                j = getArg(p,i);
                v = &s->stk[j];
-               c = fndConstant(recycleBlk, v);
-               if ( c < 0 ){ 
-                       v1 = VALnew();
-                       VALcopy(v1,v);
-                       c = defConstant(recycleBlk, v1->vtype, v1);
-                       if (v->vtype == TYPE_bat){
-                               bid = *(int*)VALget(v);
-                               BBPincref(bid,TRUE);
-                       }
-               }
+               c = defConstant(recycleBlk, v->vtype, v);
+               if (v->vtype == TYPE_bat)
+                       BBPincref( *(int*)VALget(v), TRUE);
                setArg(q,i,c);
-               if( i < p->retc )
+               if( i < p->retc ){
+                       mb->var[j]->recycle= c;
                        setVarKept(mb, j);
+                       setVarUsed(mb,j);
+               }
        }
        i= recycleBlk->stop;
        pushInstruction(recycleBlk,q);
        recycleBlk->profiler[i].counter =1;
+#ifdef _DEBUG_RECYCLE_
+       printFunction(GDKout,recycleBlk,LIST_MAL_ALL);
+#endif
 }
 
 /* compare values in ValRecords, return 0 on equal */
@@ -315,26 +315,21 @@
        int i, cnt=0;
        ValPtr lhs,rhs;
 
-#ifdef _DEBUG_RECYCLE_
-       stream_printf(GDKout,"enter RECYCLEentry\n");
-       printInstruction(GDKout,mb,p, LIST_MAL_ALL);
-#endif
        for(i=0;i< p->retc; i++)
        if( isVarKept(mb, getArg(p,i)) ){
                cnt++;
 #ifdef _DEBUG_RECYCLE_
+               printInstruction(GDKout,mb,p, LIST_MAL_ALL);
                stream_printf(GDKout,"RECYCLEentry found %d -> 
%d\n",getArg(p,i),
-                mb->var[i]->recycle);
+                       mb->var[getArg(p,i)]->recycle);
 #endif
                lhs= &stk->stk[getArg(p,i)];
-               rhs= &stk->stk[mb->var[i]->recycle];
+               rhs= &getVarConstant(recycleBlk, mb->var[getArg(p,i)]->recycle);
                VALcopy(lhs,rhs);
                if( lhs->vtype == TYPE_bat)
                        BBPincref(lhs->val.br.id, TRUE);
        }
-#ifdef _DEBUG_RECYCLE_
-       stream_printf(GDKout,"RECYCLEentry returns %d\n",cnt == p->retc);
-#endif
+       stk->clk= GDKusec();
        return cnt == p->retc;
 }
 
@@ -347,15 +342,22 @@
 void
 RECYCLEexit(MalBlkPtr mb, MalStkPtr stk, InstrPtr p){
        int i,keepit= FALSE;
+       lng clk;
        
-#ifdef _DEBUG_RECYCLE_
-       stream_printf(GDKout,"enter RECYCLEexit\n");
-       printInstruction(GDKout,mb,p, LIST_MAL_ALL);
-#endif
        for(i=0; i<p->retc; i++)
        if( isVarRecycled(mb, getArg(p,i)) && !isVarKept(mb,getArg(p,i))){
 #ifdef _DEBUG_RECYCLE_
-               stream_printf(GDKout,"keep arg %d \n",i);
+               stream_printf(GDKout,"RECYCLEexit keep arg %d \n",i);
+               printInstruction(GDKout,mb,p, LIST_MAL_ALL);
+#endif
[EMAIL PROTECTED]
+This is the place where we should call recycle optimization routines.
+It can use the timing information gathered from the previous call,
+which is stored in the stack frame to avoid concurrency problems.
[EMAIL PROTECTED]
+               clk= GDKusec()-stk->clk;
+#ifdef _DEBUG_RECYCLE_
+               stream_printf(GDKout,"RECYCLEexit time %d \n",clk);
 #endif
                keepit= TRUE;
        }

Index: mal_stack.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_stack.mx,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- mal_stack.mx        11 Jan 2008 10:41:33 -0000      1.39
+++ mal_stack.mx        2 Mar 2008 11:20:53 -0000       1.40
@@ -57,6 +57,10 @@
 #include "gdk.h"
 #include "gdk_system.h"
 
+#ifdef HAVE_SYS_TIMES_H
+#include <sys/times.h>
+#endif
+
 #define STACKINCR   128
 #define MAXGLOBALS  4 * STACKINCR
 #define MAXSHARES   2
@@ -68,6 +72,15 @@
        short keepAlive;        /* do not garbage collect when set */
        short garbageCollect; /* stack needs garbage collection */
        MT_Lock stklock;        /* used for parallel processing */
[EMAIL PROTECTED]
+It is handy to administer the timing in the stack frame
+for use in profiling and recylcing instructions.
[EMAIL PROTECTED]
+#ifdef HAVE_TIMES
+    struct tms timer;   /* timing information */
+#endif
+       time_t clock;           /* seconds since epoch */
+       lng clk;                        /* micro seconds */
        int shares;                     /* number of processes locked onto this 
stack */
        int childs[MAXSHARES]; /* not used */
        char cmd;               /* debugger communication */

Index: mal_instruction.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/mal/mal_instruction.mx,v
retrieving revision 1.300
retrieving revision 1.301
diff -u -d -r1.300 -r1.301
--- mal_instruction.mx  1 Mar 2008 23:56:05 -0000       1.300
+++ mal_instruction.mx  2 Mar 2008 11:20:50 -0000       1.301
@@ -363,6 +363,7 @@
        bit gc;                 /* garbage control flags */
        bit polymorphic;        /* complex type analysis */
        bit varargs;            /* variable number of arguments or targets */
+       bit recycle;    /* under the control of the recycler */
        int jump;               /* controlflow program counter */
        MALfcn fcn;             /* resolved function address */
        struct MALBLK *blk;     /* resolved MAL function address */
@@ -964,6 +965,7 @@
        p->blk = NULL;
        p->polymorphic = 0;
        p->varargs = 0;
+       p->recycle = 0;
        p->argc = 1;
        p->retc = 1;
        p->argv[0] = -1;        /* watch out for direct use in variable table */


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to