From d2eccd8b07aad6831e902b9749f8f5c23163b249 Mon Sep 17 00:00:00 2001 From: alebre Date: Wed, 24 Apr 2013 16:55:13 +0200 Subject: [PATCH] Java bindings - Adrien --- examples/java/cloud/Cloud.java | 8 +-- examples/java/cloud/Master.java | 28 ++++---- examples/java/cloud/Slave.java | 8 +-- .../msg/cloud/masterslave_virtual_machines.c | 8 ++- src/bindings/java/jmsg_vm.c | 2 +- src/bindings/java/jmsg_vm.h | 4 +- src/bindings/java/org/simgrid/msg/VM.java | 65 +++++++++++++++++-- src/bindings/java/smx_context_java.c | 25 ++++--- src/msg/msg_vm.c | 3 +- 9 files changed, 109 insertions(+), 42 deletions(-) diff --git a/examples/java/cloud/Cloud.java b/examples/java/cloud/Cloud.java index fd0a566fcb..eba9d07ad0 100644 --- a/examples/java/cloud/Cloud.java +++ b/examples/java/cloud/Cloud.java @@ -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(); diff --git a/examples/java/cloud/Master.java b/examples/java/cloud/Master.java index 72bf8db379..a832cacde8 100644 --- a/examples/java/cloud/Master.java +++ b/examples/java/cloud/Master.java @@ -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 vms = new ArrayList(); // 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); } } } diff --git a/examples/java/cloud/Slave.java b/examples/java/cloud/Slave.java index 01e646ff89..527f989a94 100644 --- a/examples/java/cloud/Slave.java +++ b/examples/java/cloud/Slave.java @@ -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()+")"); } diff --git a/examples/msg/cloud/masterslave_virtual_machines.c b/examples/msg/cloud/masterslave_virtual_machines.c index e0d4374f26..ee927e379c 100644 --- a/examples/msg/cloud/masterslave_virtual_machines.c +++ b/examples/msg/cloud/masterslave_virtual_machines.c @@ -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(¶ms, 0, sizeof(params)); + params.ramsize = 1L * 1024 * 1024 * 1024; // 1Gbytes + MSG_host_set_params(vm, ¶ms); + MSG_vm_start(vm); xbt_dynar_push(vms, &vm); diff --git a/src/bindings/java/jmsg_vm.c b/src/bindings/java/jmsg_vm.c index c870ff913f..8948b57fb0 100644 --- a/src/bindings/java/jmsg_vm.c +++ b/src/bindings/java/jmsg_vm.c @@ -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); diff --git a/src/bindings/java/jmsg_vm.h b/src/bindings/java/jmsg_vm.h index b7466c70d4..808fbd71f7 100644 --- a/src/bindings/java/jmsg_vm.h +++ b/src/bindings/java/jmsg_vm.h @@ -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 diff --git a/src/bindings/java/org/simgrid/msg/VM.java b/src/bindings/java/org/simgrid/msg/VM.java index eb61988e92..675da0bf11 100644 --- a/src/bindings/java/org/simgrid/msg/VM.java +++ b/src/bindings/java/org/simgrid/msg/VM.java @@ -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; iSetLongField(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; diff --git a/src/msg/msg_vm.c b/src/msg/msg_vm.c index 90cfaccf27..9ec992333e 100644 --- a/src/msg/msg_vm.c +++ b/src/msg/msg_vm.c @@ -177,7 +177,7 @@ msg_vm_t MSG_vm_create(msg_host_t ind_pm, const char *name, s_ws_params_t params; memset(¶ms, 0, sizeof(params)); params.ramsize = ramsize; - params.overcommit = 0; + //params.overcommit = 0; simcall_host_set_params(vm, ¶ms); } @@ -659,7 +659,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); -- 2.20.1