Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add vm_resume and fix minor erros
authorTakahiro Hirofuchi <thirofuchi@debian.(none)>
Fri, 1 Feb 2013 11:22:22 +0000 (12:22 +0100)
committerTakahiro Hirofuchi <thirofuchi@debian.(none)>
Fri, 1 Feb 2013 11:22:22 +0000 (12:22 +0100)
src/msg/msg_host.c
src/msg/msg_vm.c
src/simix/smx_host_private.h
src/simix/smx_smurf_private.h
src/simix/smx_user.c
src/simix/smx_vm.c

index 8098e23..1e245b5 100644 (file)
@@ -122,10 +122,10 @@ void __MSG_host_destroy(msg_host_priv_t host) {
   if (msg_global->max_channel > 0)
     free(host->mailboxes);
 #endif
-  if (xbt_swag_size(host->vms) > 0 ) {
-    XBT_VERB("Host shut down, but it still hosts %d VMs. They will be leaked.",xbt_swag_size(host->vms));
+  if (xbt_dynar_length(host->vms) > 0 ) {
+    XBT_VERB("Host shut down, but it still hosts %d VMs. They will be leaked.", xbt_dynar_length(host->vms));
   }
-  xbt_swag_free(host->vms);
+  xbt_dynar_free(&host->vms);
   free(host);
 }
 
index 8831586..e9db053 100644 (file)
@@ -160,6 +160,13 @@ int MSG_vm_is_running(msg_vm_t vm) {
 
 // TODO Implement the functions for the different state
 
+
+/** @brief Immediately kills all processes within the given VM. Any memory that they allocated will be leaked.
+ *  @ingroup msg_VMs
+ *
+ * No extra delay occurs. If you want to simulate this too, you want to
+ * use a #MSG_process_sleep() or something. I'm not quite sure.
+ */
 void MSG_vm_shutdown(msg_vm_t vm)
 {
   /* msg_vm_t equals to msg_host_t */
@@ -244,6 +251,7 @@ void MSG_vm_suspend(msg_vm_t vm)
   #ifdef HAVE_TRACING
   TRACE_msg_vm_suspend(vm);
   #endif
+
 #if 0
   unsigned int cpt;
   msg_process_t process;
@@ -254,28 +262,33 @@ void MSG_vm_suspend(msg_vm_t vm)
 #endif
 }
 
-//
-//
-///** @brief Immediately resumes the execution of all processes within the given VM.
-// *  @ingroup msg_VMs
-// *
-// * No resume cost occurs. If you want to simulate this too, you want to
-// * use a \ref MSG_file_read() before or after, depending on the exact semantic
-// * of VM resume to you.
-// */
-//void MSG_vm_resume(msg_vm_t vm) {
-//  unsigned int cpt;
-//  msg_process_t process;
-//  xbt_dynar_foreach(vm->processes,cpt,process) {
-//    XBT_DEBUG("resume process %s of host %s",MSG_process_get_name(process),MSG_host_get_name(MSG_process_get_host(process)));
-//    MSG_process_resume(process);
-//  }
-//
-//  #ifdef HAVE_TRACING
-//  TRACE_msg_vm_resume(vm);
-//  #endif
-//}
-//
+
+
+/** @brief Resume the execution of the VM. All processes on the VM run again.
+ *  @ingroup msg_VMs
+ *
+ * No resume cost occurs. If you want to simulate this too, you want to
+ * use a \ref MSG_file_read() before or after, depending on the exact semantic
+ * of VM resume to you.
+ */
+void MSG_vm_resume(msg_vm_t vm)
+{
+  simcall_vm_resume(vm);
+
+  #ifdef HAVE_TRACING
+  TRACE_msg_vm_resume(vm);
+  #endif
+
+#if 0
+  unsigned int cpt;
+  msg_process_t process;
+  xbt_dynar_foreach(vm->processes,cpt,process) {
+    XBT_DEBUG("resume process %s of host %s",MSG_process_get_name(process),MSG_host_get_name(MSG_process_get_host(process)));
+    MSG_process_resume(process);
+  }
+#endif
+}
+
 //
 ///**
 // * \ingroup msg_VMs
index 6b03c17..d586ea6 100644 (file)
@@ -85,5 +85,30 @@ void SIMIX_pre_set_category(smx_simcall_t simcall, smx_action_t action,
 void SIMIX_set_category(smx_action_t action, const char *category);
 #endif
 
+
+
+/* vm related stuff */
+smx_host_t SIMIX_vm_create(const char *name, smx_host_t ind_phys_host);
+smx_host_t SIMIX_pre_vm_create(smx_simcall_t simcall, const char *name, smx_host_t ind_phys_host);
+
+void SIMIX_vm_start(smx_host_t ind_vm);
+void SIMIX_pre_vm_start(smx_simcall_t simcall, smx_host_t ind_vm);
+
+void SIMIX_set_vm_state(smx_host_t ind_vm, int state);
+void SIMIX_prev_set_vm_state(smx_host_t ind_vm, int state);
+
+int SIMIX_get_vm_state(smx_host_t ind_vm);
+int SIMIX_pre_vm_state(smx_host_t ind_vm);
+
+void SIMIX_vm_suspend(smx_host_t ind_vm);
+void SIMIX_pre_vm_suspend(smx_simcall_t simcall, smx_host_t ind_vm);
+
+void SIMIX_vm_shutdown(smx_host_t ind_vm, smx_process_t issuer);
+void SIMIX_pre_vm_shutdown(smx_simcall_t simcall, smx_host_t ind_vm);
+
+void SIMIX_vm_destroy(smx_host_t ind_vm);
+void SIMIX_pre_vm_destroy(smx_simcall_t simcall, smx_host_t ind_vm);
+
+
 #endif
 
index fcd229d..bddcc3e 100644 (file)
@@ -280,6 +280,7 @@ ACTION(SIMCALL_VM_SET_STATE, vm_set_state, WITHOUT_ANSWER, TVOID(result), TSPEC(
 ACTION(SIMCALL_VM_GET_STATE, vm_get_state, WITH_ANSWER, TINT(result), TSPEC(ind_vm, smx_host_t)) sep \
 ACTION(SIMCALL_VM_DESTROY, vm_destroy, WITHOUT_ANSWER, TVOID(result), TSPEC(ind_vm, smx_host_t)) sep \
 ACTION(SIMCALL_VM_SUSPEND, vm_suspend, WITHOUT_ANSWER, TVOID(result), TSPEC(vm, smx_host_t)) sep \
+ACTION(SIMCALL_VM_RESUME, vm_resume, 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_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 \
 ACTION(SIMCALL_PROCESS_KILL, process_kill, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
index 0c163da..9a8e06f 100644 (file)
@@ -296,6 +296,15 @@ void simcall_vm_suspend(smx_host_t vm)
   simcall_BODY_vm_suspend(vm);
 }
 
+void simcall_vm_resume(smx_host_t vm)
+{
+  /*
+   * simcall_BODY_ is defined in src/simix/smx_smurf_private.h.
+   * This function will jump to SIMIX_pre_vm_resume.
+   **/
+  simcall_BODY_vm_resume(vm);
+}
+
 void simcall_vm_shutdown(smx_host_t vm)
 {
   /* will jump to SIMIX_pre_vm_shutdown */
index b55e672..b5688cc 100644 (file)
@@ -11,8 +11,7 @@
 #include "mc/mc.h"
 
 //If you need to log some stuffs, just uncomment these two lines and uses XBT_DEBUG for instance
-//XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_vm, simix,
-//                                "Logging specific to SIMIX (vms)");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_vm, simix, "Logging specific to SIMIX (vms)");
 
 /* **** create a VM **** */
 
@@ -65,7 +64,7 @@ void SIMIX_vm_start(smx_host_t ind_vm){
 }
 
 void SIMIX_pre_vm_start(smx_simcall_t simcall, smx_host_t ind_vm){
-   SIMIX_vm_start(vm);
+   SIMIX_vm_start(ind_vm);
 }
 
 /* ***** set/get state of a VM ***** */
@@ -84,9 +83,9 @@ int SIMIX_pre_vm_state(smx_host_t ind_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.
+ * \brief Function to suspend a SIMIX VM host. This function stops the exection of the
+ * VM. All the processes on this VM will pause. The state of the VM is
+ * perserved. We can later resume it again.
  *
  * \param host the vm host to suspend (a smx_host_t)
  */
@@ -99,6 +98,7 @@ void SIMIX_vm_suspend(smx_host_t ind_vm)
   smx_process_t smx_process, smx_process_safe;
   xbt_swag_foreach_safe(smx_process, smx_process_safe, SIMIX_host_priv(ind_vm)->process_list) {
          XBT_DEBUG("suspend %s", SIMIX_host_get_name(ind_vm));
+        /* FIXME: calling a simcall from the SIMIX layer is strange. */
          simcall_process_suspend(smx_process);
   }
 
@@ -110,6 +110,33 @@ void SIMIX_pre_vm_suspend(smx_simcall_t simcall, smx_host_t ind_vm){
    SIMIX_vm_suspend(ind_vm);
 }
 
+/**
+ * \brief Function to resume a SIMIX VM host. This function restart the execution of the
+ * VM. All the processes on this VM will run again. 
+ *
+ * \param host the vm host to resume (a smx_host_t)
+ */
+void SIMIX_vm_resume(smx_host_t ind_vm)
+{
+  /* TODO: check state */
+
+  XBT_DEBUG("%lu processes in the VM", xbt_swag_size(SIMIX_host_priv(ind_vm)->process_list));
+
+  smx_process_t smx_process, smx_process_safe;
+  xbt_swag_foreach_safe(smx_process, smx_process_safe, SIMIX_host_priv(ind_vm)->process_list) {
+         XBT_DEBUG("resume %s", SIMIX_host_get_name(ind_vm));
+        /* FIXME: calling a simcall from the SIMIX layer is strange. */
+         simcall_process_resume(smx_process);
+  }
+
+  /* TODO: Using the variable of the MSG layer is not clean. */
+  SIMIX_set_vm_state(ind_vm, msg_vm_state_resumeed);
+}
+
+void SIMIX_pre_vm_resume(smx_simcall_t simcall, smx_host_t ind_vm){
+   SIMIX_vm_resume(ind_vm);
+}
+
 /**
  * \brief Function to shutdown 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
@@ -117,7 +144,7 @@ void SIMIX_pre_vm_suspend(smx_simcall_t simcall, smx_host_t ind_vm){
  *
  * \param host the vm host to shutdown (a smx_host_t)
  */
-void SIMIX_vm_shutdown(smx_host_t ind_vm)
+void SIMIX_vm_shutdown(smx_host_t ind_vm, smx_process_t issuer)
 {
   /* TODO: check state */
 
@@ -126,7 +153,8 @@ void SIMIX_vm_shutdown(smx_host_t ind_vm)
   smx_process_t smx_process, smx_process_safe;
   xbt_swag_foreach_safe(smx_process, smx_process_safe, SIMIX_host_priv(ind_vm)->process_list) {
          XBT_DEBUG("kill %s", SIMIX_host_get_name(ind_vm));
-         simcall_process_kill(smx_process);
+
+        SIMIX_process_kill(smx_process, issuer);
   }
 
   /* TODO: Using the variable of the MSG layer is not clean. */
@@ -134,7 +162,7 @@ void SIMIX_vm_shutdown(smx_host_t ind_vm)
 }
 
 void SIMIX_pre_vm_shutdown(smx_simcall_t simcall, smx_host_t ind_vm){
-   SIMIX_vm_shutdown(ind_vm);
+   SIMIX_vm_shutdown(ind_vm, simcall->issuer);
 }
 
 /**
@@ -147,7 +175,7 @@ void SIMIX_vm_destroy(smx_host_t ind_vm)
   /* this code basically performs a similar thing like SIMIX_host_destroy() */
 
   xbt_assert((ind_vm != NULL), "Invalid parameters");
-  char *hostname = SIMIX_host_get_name(ind_vm);
+  const char *hostname = SIMIX_host_get_name(ind_vm);
 
   smx_host_priv_t host_priv = SIMIX_host_priv(ind_vm);