Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add vm_suspend stuff
authorTakahiro Hirofuchi <thirofuchi@debian.(none)>
Thu, 31 Jan 2013 22:40:37 +0000 (23:40 +0100)
committerTakahiro Hirofuchi <thirofuchi@debian.(none)>
Thu, 31 Jan 2013 22:40:37 +0000 (23:40 +0100)
src/msg/msg_vm.c
src/simix/smx_smurf_private.h
src/simix/smx_user.c
src/simix/smx_vm.c

index aebd0c3..680dbe5 100644 (file)
@@ -164,9 +164,9 @@ void MSG_vm_shutdown(msg_vm_t vm)
   /* msg_vm_t equals to msg_host_t */
   simcall_vm_shutdown(vm);
 
-  #ifdef HAVE_TRACING
-  TRACE_msg_vm_kill(vm);
-  #endif
+  // #ifdef HAVE_TRACING
+  // TRACE_msg_vm_(vm);
+  // #endif
 }
 
 
@@ -228,25 +228,31 @@ void MSG_vm_shutdown(msg_vm_t vm)
 //  vm->location = destination;
 //}
 //
-///** @brief Immediately suspend the execution of all processes within the given VM.
-// *  @ingroup msg_VMs
-// *
-// * No suspension cost occurs. If you want to simulate this too, you want to
-// * use a \ref MSG_file_write() before or after, depending on the exact semantic
-// * of VM suspend to you.
-// */
-//void MSG_vm_suspend(msg_vm_t vm) {
-//  unsigned int cpt;
-//  msg_process_t process;
-//  xbt_dynar_foreach(vm->processes,cpt,process) {
-//    XBT_DEBUG("suspend process %s of host %s",MSG_process_get_name(process),MSG_host_get_name(MSG_process_get_host(process)));
-//    MSG_process_suspend(process);
-//  }
-//
-//  #ifdef HAVE_TRACING
-//  TRACE_msg_vm_suspend(vm);
-//  #endif
-//}
+
+/** @brief Immediately suspend the execution of all processes within the given VM.
+ *  @ingroup msg_VMs
+ *
+ * No suspension cost occurs. If you want to simulate this too, you want to
+ * use a \ref MSG_file_write() before or after, depending on the exact semantic
+ * of VM suspend to you.
+ */
+void MSG_vm_suspend(msg_vm_t vm)
+{
+  simcall_vm_suspend(vm);
+
+  #ifdef HAVE_TRACING
+  TRACE_msg_vm_suspend(vm);
+  #endif
+#if 0
+  unsigned int cpt;
+  msg_process_t process;
+  xbt_dynar_foreach(vm->processes,cpt,process) {
+    XBT_DEBUG("suspend process %s of host %s",MSG_process_get_name(process),MSG_host_get_name(MSG_process_get_host(process)));
+    MSG_process_suspend(process);
+  }
+#endif
+}
+
 //
 //
 ///** @brief Immediately resumes the execution of all processes within the given VM.
@@ -295,13 +301,20 @@ void MSG_vm_shutdown(msg_vm_t vm)
 //}
 //
 
-/** @brief Destroy a VM.
+/** @brief Destroy a VM. Destroy the VM object from the simulation.
  *  @ingroup msg_VMs
  */
 void MSG_vm_destroy(msg_vm_t vm)
 {
+  /* First, terminate all processes on the VM */
+  simcall_vm_shutdown(vm);
+
+  /* Then, destroy the VM object */
   simcall_vm_destroy(vm);
-  /* TOOD: do we have to do something for processes? */
+
+  #ifdef HAVE_TRACING
+  TRACE_msg_vm_end(vm);
+  #endif
 
 #if 0
   unsigned int cpt;
@@ -312,11 +325,6 @@ void MSG_vm_destroy(msg_vm_t vm)
     simdata->vm = NULL;
   }
 
-  #ifdef HAVE_TRACING
-  TRACE_msg_vm_end(vm);
-  #endif
-
-
   xbt_dynar_free(&vm->processes);
   xbt_free(vm);
 #endif
index 4596562..9dd156f 100644 (file)
@@ -278,6 +278,7 @@ ACTION(SIMCALL_VM_CREATE, vm_create, WITH_ANSWER, TPTR(result), TSTRING(name), T
 ACTION(SIMCALL_VM_START, vm_start, WITHOUT_ANSWER, TVOID(result), TSPEC(phys_host, smx_host_t)) sep \
 ACTION(SIMCALL_VM_SET_STATE, vm_set_state, WITHOUT_ANSWER, TVOID(result), TSPEC(vm, smx_host_t), TINT(state)) sep \
 ACTION(SIMCALL_VM_GET_STATE, vm_get_state, WITH_ANSWER, TINT(result), TSPEC(vm, smx_host_t)) sep \
+ACTION(SIMCALL_VM_SUSPEND, vm_suspend, WITHOUT_ANSWER, TVOID(result), TSPEC(vm, smx_host_t)) sep \
 ACTION(SIMCALL_VM_SHUTDOWN, vm_shutdown, WITHOUT_ANSWER, TVOID(result), TSPEC(vm, smx_host_t)) sep \
 ACTION(SIMCALL_VM_DESTROY, vm_destroy, WITHOUT_ANSWER, TVOID(result), TSPEC(vm, smx_host_t)) sep \
 ACTION(SIMCALL_PROCESS_CREATE, process_create, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t*), TSTRING(name), TSPEC(code, xbt_main_func_t), TPTR(data), TSTRING(hostname), TDOUBLE(kill_time), TINT(argc), TSPEC(argv, char**), TSPEC(properties, xbt_dict_t), TINT(auto_restart)) sep \
index 79a9fb1..79fd644 100644 (file)
@@ -292,6 +292,12 @@ void simcall_vm_start(smx_host_t vm)
   simcall_BODY_set_vm_state(vm, msg_vm_state_running);
 }
 
+void simcall_vm_suspend(smx_host_t vm)
+{
+  /* will jump to SIMIX_pre_vm_suspend */
+  simcall_BODY_vm_suspend(vm);
+}
+
 void simcall_vm_shutdown(smx_host_t vm)
 {
   /* will jump to SIMIX_pre_vm_shutdown */
@@ -300,7 +306,10 @@ void simcall_vm_shutdown(smx_host_t vm)
 
 void simcall_vm_destroy(smx_host_t vm)
 {
-  /* will jump to SIMIX_pre_vm_destroy */
+  /*
+   * simcall_BODY_ is defined in src/simix/smx_smurf_private.h.
+   * This function will jump to SIMIX_pre_vm_destroy.
+   **/
   simcall_BODY_vm_destroy(vm);
 }
 
index 57e3717..2191b50 100644 (file)
@@ -81,6 +81,32 @@ int SIMIX_pre_vm_state(smx_host_t vm){
        return SIMIX_get_vm_state(vm);
 }
 
+/**
+ * \brief Function to suspend a SIMIX VM host. This function powers off the
+ * VM. All the processes on this VM will be killed. But, the state of the VM is
+ * perserved. We can later start it again.
+ *
+ * \param host the vm host to suspend (a smx_host_t)
+ */
+void SIMIX_vm_suspend(smx_host_t host)
+{
+  /* TODO: check state */
+
+  XBT_DEBUG("%lu processes in the VM", xbt_swag_size(SIMIX_host_priv(host)->process_list));
+
+  smx_process_t smx_process, smx_process_safe;
+  xbt_swag_foreach_safe(smx_process, smx_process_safe, SIMIX_host_priv(host)->process_list) {
+         XBT_DEBUG("suspend %s", SIMIX_host_get_name(host));
+         simcall_process_suspend(smx_process);
+  }
+
+  /* TODO: Using the variable of the MSG layer is not clean. */
+  SIMIX_set_vm_state(host, msg_vm_state_suspended);
+}
+
+void SIMIX_pre_vm_suspend(smx_simcall_t simcall, smx_host_t vm){
+   SIMIX_vm_suspend(vm);
+}
 
 /**
  * \brief Function to shutdown a SIMIX VM host. This function powers off the