/* 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
}
// 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.
//}
//
-/** @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;
simdata->vm = NULL;
}
- #ifdef HAVE_TRACING
- TRACE_msg_vm_end(vm);
- #endif
-
-
xbt_dynar_free(&vm->processes);
xbt_free(vm);
#endif
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 \
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 */
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);
}
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