Changeset: 2ab66fee0861 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2ab66fee0861
Added Files:
        monetdb5/scheduler/run_mutation.c
        monetdb5/scheduler/run_mutation.h
        monetdb5/scheduler/run_mutation.mal
Modified Files:
        monetdb5/modules/mal/mal_init.mal
        monetdb5/scheduler/Makefile.ag
        monetdb5/scheduler/Tests/mutation00.mal
        monetdb5/scheduler/Tests/mutation00.stable.out
Branch: mutation
Log Message:

A first step in detecting expensive operations
that would become the target of mutation replacement.


diffs (289 lines):

diff --git a/monetdb5/modules/mal/mal_init.mal 
b/monetdb5/modules/mal/mal_init.mal
--- a/monetdb5/modules/mal/mal_init.mal
+++ b/monetdb5/modules/mal/mal_init.mal
@@ -118,6 +118,7 @@ include transaction;
 # @-
 # scheduler components
 include run_isolate;
+include run_mutation;
 include run_memo;
 include run_octopus;
 include srvpool;
diff --git a/monetdb5/scheduler/Makefile.ag b/monetdb5/scheduler/Makefile.ag
--- a/monetdb5/scheduler/Makefile.ag
+++ b/monetdb5/scheduler/Makefile.ag
@@ -30,6 +30,7 @@ lib_scheduler = {
        SOURCES = \
                run_adder.c run_adder.h \
                run_isolate.c run_isolate.h \
+               run_mutation.c run_mutation.h \
                run_memo.c run_memo.h \
                run_octopus.c run_octopus.h \
                srvpool.c srvpool.h \
@@ -39,8 +40,8 @@ lib_scheduler = {
 headers_mal = {
        HEADERS = mal
        DIR = libdir/monetdb5
-       SOURCES = run_adder.mal run_isolate.mal run_memo.mal run_octopus.mal 
srvpool.mal
+       SOURCES = run_adder.mal run_isolate.mal run_mutation.mal run_memo.mal 
run_octopus.mal srvpool.mal
 }
 
 EXTRA_DIST_DIR = Tests
-EXTRA_DIST = run_adder.mal run_isolate.mal run_memo.mal run_octopus.mal 
srvpool.mal
+EXTRA_DIST = run_adder.mal run_isolate.mal run_mutation.mal run_memo.mal 
run_octopus.mal srvpool.mal
diff --git a/monetdb5/scheduler/Tests/mutation00.mal 
b/monetdb5/scheduler/Tests/mutation00.mal
--- a/monetdb5/scheduler/Tests/mutation00.mal
+++ b/monetdb5/scheduler/Tests/mutation00.mal
@@ -2,11 +2,6 @@
 
 # The mutation scheduler picks a plan from a specific pool
 # possibly after performing introspection and plan mutation
-function scheduler.mutation(m:str,f:str)(mn:str,fn:str);
-       mn := m;
-       fn := f;
-       return (mn,fn);
-end mutation;
 
 function initialize():bat[:oid,:lng];
        b:= bat.new(:oid,:lng);
@@ -33,22 +28,17 @@ end initialize;
 function query();
        t0:= alarm.usec();
        b:= initialize();
+barrier z:= language.dataflow();
+       sum1 := aggr.sum(b);
+       sum2 := aggr.sum(b);
+       sum3 := aggr.sum(b);
+exit z;
        t1:= alarm.usec();
-       t := t1-t0;
-       io.printf("#%d\n",t);
-       sum := aggr.sum(b);
-       t0:= alarm.usec();
-       t := t0-t1;
-       io.printf("#%d\n",t);
-       cnt := aggr.count(b);
-       t1:= alarm.usec();
-       t := t1-t0;
-       io.printf("#%d\n",t);
+       t2 := t1-t0;
+       io.printf("#%d\n",t2);
 end query;
 
-function evolution(mod:str,fcn:str);
-       (m,f):= scheduler.mutation(mod,fcn);
-       language.call(m,f);
-end evolution;
-
-evolution("user","query");
+#multiple calls should produce more parallel plans.
+scheduler.mutation("user","query");
+scheduler.mutation("user","query");
+scheduler.mutation("user","query");
diff --git a/monetdb5/scheduler/Tests/mutation00.stable.out 
b/monetdb5/scheduler/Tests/mutation00.stable.out
--- a/monetdb5/scheduler/Tests/mutation00.stable.out
+++ b/monetdb5/scheduler/Tests/mutation00.stable.out
@@ -18,11 +18,6 @@ stdout of test 'mutation00` in directory
 # MonetDB/GIS module loaded
 # MonetDB/JAQL module loaded
 # MonetDB/SQL module loaded
-function scheduler.mutation(m:str,f:str) (mn:str,fn:str);
-    mn := m;
-    fn := f;
-    return (mn,fn) := (mn,fn);
-end mutation;
 function user.initialize():bat[:oid,:lng];
     b := bat.new(:oid,:lng);
     INT_MAX := 2147483647;
@@ -44,30 +39,23 @@ end initialize;
 function user.query():void;
     t0 := alarm.usec();
     b := user.initialize();
+barrier z := language.dataflow();
+    sum1 := aggr.sum(b);
+    sum2 := aggr.sum(b);
+    sum3 := aggr.sum(b);
+exit z;
     t1 := alarm.usec();
-    t := calc.-(t1,t0);
-    io.printf("#%d\n",t);
-    sum := aggr.sum(b);
-    t0 := alarm.usec();
-    t := calc.-(t0,t1);
-    io.printf("#%d\n",t);
-    cnt := aggr.count(b);
-    t1 := alarm.usec();
-    t := calc.-(t1,t0);
-    io.printf("#%d\n",t);
+    t2 := calc.-(t1,t0);
+    io.printf("#%d\n",t2);
 end query;
-function user.evolution(mod:str,fcn:str):void;
-    (m,f) := scheduler.mutation(mod,fcn);
-    language.call(m,f);
-end evolution;
 function user.main():void;
 # example framework for a mutation based execution stack 
 # The mutation scheduler picks a plan from a specific pool 
 # possibly after performing introspection and plan mutation 
-    user.evolution("user","query");
-end main;
-function user.main():void;
-    user.query();
+#multiple calls should produce more parallel plans. 
+    scheduler.mutation("user","query");
+    scheduler.mutation("user","query");
+    scheduler.mutation("user","query");
 end main;
 
 # 09:42:41 >  
diff --git a/monetdb5/scheduler/run_mutation.c 
b/monetdb5/scheduler/run_mutation.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/scheduler/run_mutation.c
@@ -0,0 +1,72 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2013 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+/*
+ * @f run_mutation
+ * @a M. Kersten, M. Gawade
+ * Run mutated query plans
+ * The infrastructure to adapatively create multi-processor parallel plans.
+ */
+#include "monetdb_config.h"
+#include "run_mutation.h"
+
+str
+RUNmutation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
+{
+       str modnme = *(str*) getArgReference(stk,p,1);
+       str fcnnme = *(str*) getArgReference(stk,p,2);
+       int i, target = 0;
+       MalBlkPtr nb=0;
+       Symbol s= 0;
+       str msg;
+
+       (void) mb;
+
+       DEBUG_MUTATION{
+               mnstr_printf(cntxt->fdout,"#mutation %s.%s\n",modnme,fcnnme);
+       } else
+               (void) cntxt;
+
+       s = findSymbol(cntxt->nspace, modnme, fcnnme);
+       if (s == NULL || (nb= s->def) == NULL)
+               throw(MAL, "scheduler.mutation", SEMANTIC_OPERATION_MISSING);
+
+       // if called the first time, just execute the call
+       if ( nb->calls == 0){
+               initProfiler(nb);
+               msg = runMAL(cntxt, nb,0,0);
+               return msg;
+       }
+       
+       // Find an expensive instruction to replace
+       if ( nb->profiler && nb->calls)
+       for ( i = 0; i < nb->stop ; i++) {
+               p = getInstrPtr(nb,i);
+               if ( p->barrier)
+                       continue;       // ignore block structures
+               if ( nb->profiler[i].ticks/nb->calls > 
nb->profiler[target].ticks/nb->calls)
+                       target = i;
+       }
+       DEBUG_MUTATION if ( nb->profiler && target) {
+               mnstr_printf(cntxt->fdout,"#mutation target instruction %d cost 
"LLFMT"\n", target, nb->profiler[target].ticks/nb->calls);
+       }
+       /* At this point we have a target instruction to be replaced */
+       msg = runMAL(cntxt, nb, 0, 0);
+       return msg;
+}
diff --git a/monetdb5/scheduler/run_mutation.h 
b/monetdb5/scheduler/run_mutation.h
new file mode 100644
--- /dev/null
+++ b/monetdb5/scheduler/run_mutation.h
@@ -0,0 +1,42 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2013 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+#ifndef _RUN_MUTATION
+#define _RUN_MUTATION
+#include "mal.h"
+#include "mal_instruction.h"
+#include "mal_interpreter.h"
+#include "mal_client.h"
+
+#define DEBUG_RUN_MUTATION
+
+#ifdef WIN32
+#if !defined(LIBMAL) && !defined(LIBATOMS) && !defined(LIBKERNEL) && 
!defined(LIBMAL) && !defined(LIBOPTIMIZER) && !defined(LIBSCHEDULER) && 
!defined(LIBMONETDB5)
+#define run_mutation_export extern __declspec(dllimport)
+#else
+#define run_mutation_export extern __declspec(dllexport)
+#endif
+#else
+#define run_mutation_export extern
+#endif
+
+#define DEBUG_MUTATION if(1)
+run_mutation_export str RUNmutation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr p);
+#endif /* MAL_RUN_MUTATION */
+
diff --git a/monetdb5/scheduler/run_mutation.mal 
b/monetdb5/scheduler/run_mutation.mal
new file mode 100644
--- /dev/null
+++ b/monetdb5/scheduler/run_mutation.mal
@@ -0,0 +1,21 @@
+# The contents of this file are subject to the MonetDB Public License
+# Version 1.1 (the "License"); you may not use this file except in
+# compliance with the License. You may obtain a copy of the License at
+# http://www.monetdb.org/Legal/MonetDBLicense
+#
+# Software distributed under the License is distributed on an "AS IS"
+# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+# License for the specific language governing rights and limitations
+# under the License.
+#
+# The Original Code is the MonetDB Database System.
+#
+# The Initial Developer of the Original Code is CWI.
+# Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+# Copyright August 2008-2013 MonetDB B.V.
+# All Rights Reserved.
+
+pattern scheduler.mutation(mod:str, fcn:str)
+address RUNmutation
+comment "Generate an adaptive plan and execute it";
+
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to