From 5599d4e76aba57753485b2dbd00e8f8fb0e3c90c Mon Sep 17 00:00:00 2001 From: Takahiro Hirofuchi Date: Fri, 1 Feb 2013 12:22:22 +0100 Subject: [PATCH] add vm_resume and fix minor erros --- src/msg/msg_host.c | 6 ++-- src/msg/msg_vm.c | 57 +++++++++++++++++++++-------------- src/simix/smx_host_private.h | 25 +++++++++++++++ src/simix/smx_smurf_private.h | 1 + src/simix/smx_user.c | 9 ++++++ src/simix/smx_vm.c | 48 +++++++++++++++++++++++------ 6 files changed, 111 insertions(+), 35 deletions(-) diff --git a/src/msg/msg_host.c b/src/msg/msg_host.c index 8098e236b8..1e245b59e9 100644 --- a/src/msg/msg_host.c +++ b/src/msg/msg_host.c @@ -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); } diff --git a/src/msg/msg_vm.c b/src/msg/msg_vm.c index 8831586c36..e9db0531b2 100644 --- a/src/msg/msg_vm.c +++ b/src/msg/msg_vm.c @@ -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 diff --git a/src/simix/smx_host_private.h b/src/simix/smx_host_private.h index 6b03c1708e..d586ea6a99 100644 --- a/src/simix/smx_host_private.h +++ b/src/simix/smx_host_private.h @@ -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 diff --git a/src/simix/smx_smurf_private.h b/src/simix/smx_smurf_private.h index fcd229d69a..bddcc3e0cb 100644 --- a/src/simix/smx_smurf_private.h +++ b/src/simix/smx_smurf_private.h @@ -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 \ diff --git a/src/simix/smx_user.c b/src/simix/smx_user.c index 0c163da302..9a8e06fa37 100644 --- a/src/simix/smx_user.c +++ b/src/simix/smx_user.c @@ -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 */ diff --git a/src/simix/smx_vm.c b/src/simix/smx_vm.c index b55e672acc..b5688cc1d0 100644 --- a/src/simix/smx_vm.c +++ b/src/simix/smx_vm.c @@ -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); -- 2.20.1