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);
}
/* 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();
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();
}
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();
}
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.");
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);
}
}
}
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;
} catch (MsgException e) {
}
- Msg.info("\"" + task.getName() + "\" done ");
+ Msg.info(this.msgName() +" executed task (" + task.getName()+")");
}
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]);
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);
}
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);
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
// 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).
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();
}
*/
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
*
/**
* Destroy the VM
*/
- protected native void destroy();
+ public native void destroy();
(*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;
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);
}
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);