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);
}
// 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 */
#ifdef HAVE_TRACING
TRACE_msg_vm_suspend(vm);
#endif
+
#if 0
unsigned int cpt;
msg_process_t process;
#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
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
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 \
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 */
#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 **** */
}
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 ***** */
}
/**
- * \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)
*/
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);
}
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
*
* \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 */
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. */
}
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);
}
/**
/* 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);