Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
merge from the java bindings work
authorTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Wed, 24 Apr 2013 16:01:23 +0000 (18:01 +0200)
committerTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Wed, 24 Apr 2013 16:01:23 +0000 (18:01 +0200)
Merge branch 'hypervisor' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid into hypervisor

examples/java/cloud/Cloud.java
examples/java/cloud/Master.java
examples/java/cloud/Slave.java
examples/msg/cloud/masterslave_virtual_machines.c
src/bindings/java/jmsg_vm.c
src/bindings/java/jmsg_vm.h
src/bindings/java/org/simgrid/msg/VM.java
src/bindings/java/smx_context_java.c
src/msg/msg_vm.c

index fd0a566..eba9d07 100644 (file)
@@ -16,7 +16,7 @@ import org.simgrid.msg.MsgException;
 public class Cloud {
        public static final double task_comp_size = 10;
        public static final double task_comm_size = 10;
-
+       public static final int hostNB = 3 ; 
        public static void main(String[] args) throws MsgException {       
            Msg.init(args); 
            
@@ -27,12 +27,12 @@ public class Cloud {
            }
            /* Construct the platform */
                Msg.createEnvironment(args[0]);
-                 /* Retrieve the 5 first hosts of the platform file */
                Host[] hosts = Host.all();
-               if (hosts.length < 5) {
-                       Msg.info("I need at least 10 hosts in the platform file, but " + args[0] + " contains only " + hosts.length + " hosts");
+               if (hosts.length < hostNB+1) {
+                       Msg.info("I need at least "+ (hostNB+1) +"  hosts in the platform file, but " + args[0] + " contains only " + hosts.length + " hosts");
                        System.exit(42);
                }
+               Msg.info("Start"+ hostNB +"  hosts");
                new Master(hosts[0],"Master",hosts).start();
                /* Execute the simulation */
                Msg.run();
index 72bf8db..a832cac 100644 (file)
@@ -23,16 +23,18 @@ public class Master extends Process {
                this.hosts = hosts;
        }
        public void main(String[] args) throws MsgException {
-               int slavesCount = 5;
+               int slavesCount = Cloud.hostNB;
                
                ArrayList<VM> vms = new ArrayList<VM>();
                
                // Create one VM per host and bind a process inside each one. 
                for (int i = 0; i < slavesCount; i++) {
-                       VM vm = new VM(hosts[i],"VM_"+i);
+                       Msg.info("create VM0"+i);       
+                       VM vm = new VM(hosts[i+1],"VM0"+i);
                        vm.start();
                        vms.add(vm);
                        Slave slave = new Slave(vm,i);
+                       Msg.info("Put Worker "+slave.msgName()+ " on "+vm.getName());
                        slave.start();
        
                }
@@ -41,15 +43,16 @@ public class Master extends Process {
                Msg.info("Send a first batch of work to everyone");
                workBatch(slavesCount);
                
-               Msg.info("Now suspend all VMs, just for fun");
+               Msg.info("Suspend all VMs");
                for (int i = 0; i < vms.size(); i++) {
+                       Msg.info("Suspend "+vms.get(i).getName());
                        vms.get(i).suspend();
                }
                
                Msg.info("Wait a while");
                waitFor(2);
                
-               Msg.info("Enough. Let's resume everybody.");
+               Msg.info("Resume all VMs.");
                for (int i = 0; i < vms.size(); i++) {
                        vms.get(i).resume();
                }
@@ -63,10 +66,12 @@ public class Master extends Process {
                        Slave slave = new Slave(vm,i + vms.size());
                        slave.start();
                }
+       
+               workBatch(slavesCount * 2);
                
-               Msg.info("Migrate everyone to the second host.");
+               Msg.info("Migrate everyone to "+hosts[2].getName());
                for (int i = 0; i < vms.size(); i++) {
-                       vms.get(i).migrate(hosts[1]);
+                       vms.get(i).migrate(hosts[2]);
                }
                
 //             Msg.info("Suspend everyone, move them to the third host, and resume them.");
@@ -76,25 +81,26 @@ public class Master extends Process {
                for (int i = 0; i < vms.size(); i++) {
                        VM vm = vms.get(i);
        //              vm.suspend();
-                       vm.migrate(hosts[2]);
+                       vm.migrate(hosts[3]);
                //      vm.resume();
                }
                
-               workBatch(slavesCount * 2);
+       
                
                Msg.info("Let's shut down the simulation and kill everyone.");
                
                for (int i = 0; i < vms.size(); i++) {
                        vms.get(i).shutdown();
+                       vms.get(i).destroy();
                }                               
                Msg.info("Master done.");
        }
        
        public void workBatch(int slavesCount) throws MsgException {
                for (int i = 0; i < slavesCount; i++) {
-                       Task task = new Task("Task_" + i, Cloud.task_comp_size, Cloud.task_comm_size);
-                       Msg.info("Sending to " + i);
-                       task.send("slave_" + i);
+                       Task task = new Task("Task0" + i, Cloud.task_comp_size, Cloud.task_comm_size);
+                       Msg.info("Sending to WRK0" + i);
+                       task.send("MBOX:WRK0" + i);
                }
        }
 }
index 01e646f..527f989 100644 (file)
@@ -15,15 +15,15 @@ import org.simgrid.msg.Task;
 public class Slave extends Process {
        private int number;
        public Slave(Host host, int number) {
-               super(host,"Slave " + number,null);
+               super(host,"WRK0" + number,null);
                this.number = number;
        }
        public void main(String[] args) throws MsgException {
+               Msg.info(this.msgName() +" is listenning on MBOX:WRK0"+ number);
                while(true) {                   
-                       Msg.info("Receiving on " + "slave_" + number);
                        Task task;
                         try {
-                                task = Task.receive("slave_"+number);
+                                task = Task.receive("MBOX:WRK0"+number);
                         } catch (MsgException e) {
                                 Msg.debug("Received failed. I'm done. See you!");
                                 break;
@@ -38,7 +38,7 @@ public class Slave extends Process {
                        } catch (MsgException e) {
 
                        }
-                       Msg.info("\"" + task.getName() + "\" done ");
+                       Msg.info(this.msgName() +" executed task (" + task.getName()+")");
                }
 
                
index 34f10b3..ab8c47d 100644 (file)
@@ -53,7 +53,7 @@ int master_fun(int argc, char *argv[])
   msg_host_t *pms = xbt_new(msg_host_t, workers_count);
   xbt_dynar_t vms = xbt_dynar_new(sizeof(msg_vm_t), NULL);
 
-  /* Retrive the PMs that will launch worker processes. */
+  /* Retrieve the PMs that will launch worker processes. */
   for (i = 1; i < argc; i++)
     pms[i - 1] = MSG_get_host_by_name(argv[i]);
 
@@ -73,6 +73,12 @@ int master_fun(int argc, char *argv[])
 
     XBT_INFO("create %s", vm_name);
     msg_vm_t vm = MSG_vm_create_core(pms[i], vm_name);
+
+    s_ws_params_t params;
+    memset(&params, 0, sizeof(params));
+    params.ramsize = 1L * 1024 * 1024 * 1024; // 1Gbytes
+    MSG_host_set_params(vm, &params);
+
     MSG_vm_start(vm);
     xbt_dynar_push(vms, &vm);
 
index c870ff9..8948b57 100644 (file)
@@ -109,7 +109,7 @@ Java_org_simgrid_msg_VM_shutdown(JNIEnv *env, jobject jvm) {
 }
 
 JNIEXPORT void JNICALL
-Java_org_simgrid_msg_VM_migrate(JNIEnv *env, jobject jvm, jobject jhost) {
+Java_org_simgrid_msg_VM_internalmig(JNIEnv *env, jobject jvm, jobject jhost) {
   msg_vm_t vm = jvm_get_native(env,jvm);
   msg_host_t host = jhost_get_native(env, jhost);
 
index b7466c7..808fbd7 100644 (file)
@@ -105,11 +105,11 @@ JNIEXPORT void JNICALL
 Java_org_simgrid_msg_VM_start(JNIEnv *env, jobject jvm);
 /**
  * Class                       org_simgrid_msg_VM
- * Method                      migrate
+ * Method                      nativeMigrate
  * Signature   (Lorg/simgrid/msg/Host;)V
  */
 JNIEXPORT void JNICALL
-Java_org_simgrid_msg_VM_migrate(JNIEnv *env, jobject jvm, jobject jhost);
+Java_org_simgrid_msg_VM_internalmig(JNIEnv *env, jobject jvm, jobject jhost);
 /**
  * Class                       org_simgrid_msg_VM
  * Method                      suspend
index eb61988..675da0b 100644 (file)
@@ -21,6 +21,9 @@ public class VM extends Host{
        // GetByName is inherited from the super class Host
        
 
+        private static VM[] vms=null;    
+    private Host currentHost; 
+    
        /* Constructors / destructors */
     /**
         * Create a `basic' VM (i.e. 1 core, 1GB of RAM, other values are not taken into account).
@@ -36,9 +39,35 @@ public class VM extends Host{
                         long netCap, String diskPath, long diskSize){
                super();
                super.name = name; 
+               this.currentHost = host; 
                create(host, name, nCore, ramSize, netCap, diskPath, diskSize);
+               VM.addVM(this);
        }
 
+       private static void addVM(VM vm){
+               VM[] vmsN=null; 
+               int i=0;
+               if(VM.vms == null)
+                       vmsN = new VM[1]; 
+               else
+                       vmsN = new VM[vms.length+1]; 
+               
+               for (i=0; i<vmsN.length-1 ; i ++){
+                       vmsN[i]=vms[i]; 
+               } 
+               vmsN[i]=vm;
+               vms=vmsN;
+       }
+   public static VM[] all(){
+               return vms;
+       }
+       public static VM getVMByName(String name){
+               for (int i=0 ; i < vms.length ; i++){
+                         if (vms[i].getName().equals(name))
+                                       return vms[i];          
+               }
+               return null; 
+       }
        protected void finalize() {
                destroy();
        }
@@ -98,14 +127,36 @@ public class VM extends Host{
         */
        public native void shutdown();
        
+       /**  
+        * Invoke native migration routine
+       */
+       public native void internalmig(Host destination);
+
        
-       /** Immediately change the host on which all processes are running
-        *
-        * No migration cost occurs. If you want to simulate this too, you want to use a
-        * Task.send() before or after, depending on whether you want to do cold or hot
-        * migration.
+       /** Change the host on which all processes are running
+        * (pre-copy is implemented)
         */     
-       public native void migrate(Host destination);
+       public void migrate(Host destination){
+//             String[] argsRx = new String[5];
+//             argsRx[1] = this.getName();
+//             argsRx[2] = this.currentHost.getName();
+//             argsRx[3] = destination.getName();
+//             argsRx[0] =  "__pr_mig_rx:"+argsRx[1]+"("+argsRx[2]+"-"+argsRx[3]+")";
+//             argsRx[4] = null; // TODO: Why ? 
+//             
+//             //Process rx = new Process(destination, argsRx[0], argsRx );
+//             
+//             String[] argsTx = new String[5];
+//             argsTx[1] = this.getName();
+//             argsTx[2] = this.currentHost.getName();
+//             argsTx[3] = destination.getName();
+//             argsTx[0] =  "__pr_mig_tx:"+argsTx[1]+"("+argsTx[2]+"-"+argsTx[3]+")";
+//             argsTx[4] = null; // TODO: Why ? 
+//             
+//             //Process tx = new Process(this.currentHost, argsTx[0], argsRx ); 
+//             
+               this.internalmig(destination);
+       }
        
        /** Immediately suspend the execution of all processes within the given VM
         *
@@ -146,7 +197,7 @@ public class VM extends Host{
        /**
         * Destroy the VM
         */
-       protected native void destroy();
+       public native void destroy();
 
        
 
index 92005a4..8b13218 100644 (file)
@@ -111,18 +111,23 @@ static void* smx_ctx_java_thread_run(void *data) {
     (*env)->SetLongField(env, context->jprocess, jprocess_field_Process_bind,
                          (intptr_t)process);
   }
-  xbt_assert((context->jprocess != NULL), "Process not created...");
-  //wait for the process to be able to begin
-  //TODO: Cache it
+
+  // Adrien, ugly path, just to bypass creation of context at low levels
+  // (i.e such as for the VM migration for instance)
+  if(context->jprocess != NULL){
+       xbt_assert((context->jprocess != NULL), "Process not created...");
+       //wait for the process to be able to begin
+       //TODO: Cache it
        jfieldID jprocess_field_Process_startTime = jxbt_get_sfield(env, "org/simgrid/msg/Process", "startTime", "D");
-  jdouble startTime =  (*env)->GetDoubleField(env, context->jprocess, jprocess_field_Process_startTime);
-  if (startTime > MSG_get_clock()) {
-       MSG_process_sleep(startTime - MSG_get_clock());
+       jdouble startTime =  (*env)->GetDoubleField(env, context->jprocess, jprocess_field_Process_startTime);
+       if (startTime > MSG_get_clock()) {
+               MSG_process_sleep(startTime - MSG_get_clock());
+       }
+       //Execution of the "run" method.
+       jmethodID id = jxbt_get_smethod(env, "org/simgrid/msg/Process", "run", "()V");
+       xbt_assert( (id != NULL), "Method not found...");
+       (*env)->CallVoidMethod(env, context->jprocess, id);
   }
-  //Execution of the "run" method.
-  jmethodID id = jxbt_get_smethod(env, "org/simgrid/msg/Process", "run", "()V");
-  xbt_assert( (id != NULL), "Method not found...");
-  (*env)->CallVoidMethod(env, context->jprocess, id);
   smx_ctx_java_stop((smx_context_t)context);
 
   return NULL;
index 3a17289..a5331a5 100644 (file)
@@ -177,7 +177,7 @@ msg_vm_t MSG_vm_create(msg_host_t ind_pm, const char *name,
     s_ws_params_t params;
     memset(&params, 0, sizeof(params));
     params.ramsize = ramsize;
-    params.overcommit = 0;
+    //params.overcommit = 0;
     simcall_host_set_params(vm, &params);
   }
 
@@ -665,7 +665,6 @@ static void do_migration(msg_vm_t vm, msg_host_t src_pm, msg_host_t dst_pm)
     argv[2] = xbt_strdup(sg_host_name(src_pm));
     argv[3] = xbt_strdup(sg_host_name(dst_pm));
     argv[4] = NULL;
-
     msg_process_t pr = MSG_process_create_with_arguments(pr_name, migration_tx_fun, NULL, src_pm, nargvs - 1, argv);
 
     xbt_free(pr_name);