X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/4a6c8108ddea55a6c199759bac3bd4f8ca4daf2c..dbae853c4de0c0d66c97c961c370448bee5e1ab4:/src/simix/libsmx.cpp diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 4c4bf39c65..95f8dfa7d2 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -17,6 +17,7 @@ #include +#include #include #include "mc/mc.h" @@ -24,8 +25,8 @@ #include "src/kernel/activity/SynchroComm.hpp" #include "src/mc/mc_forward.hpp" #include "src/mc/mc_replay.h" +#include "src/plugins/vm/VirtualMachineImpl.hpp" #include "src/simix/smx_host_private.h" -#include "src/surf/VirtualMachineImpl.hpp" #include "xbt/ex.h" #include @@ -96,15 +97,12 @@ smx_activity_t simcall_execution_start(const char *name, * amount between each pair of hosts * \param amount the SURF action amount * \param rate the SURF action rate + * \param timeout timeout * \return A new SIMIX execution synchronization */ -smx_activity_t simcall_execution_parallel_start(const char *name, - int host_nb, - sg_host_t *host_list, - double *flops_amount, - double *bytes_amount, - double amount, - double rate) +smx_activity_t simcall_execution_parallel_start(const char* name, int host_nb, sg_host_t* host_list, + double* flops_amount, double* bytes_amount, double amount, double rate, + double timeout) { int i,j; /* checking for infinite values */ @@ -121,11 +119,8 @@ smx_activity_t simcall_execution_parallel_start(const char *name, xbt_assert(std::isfinite(amount), "amount is not finite!"); xbt_assert(std::isfinite(rate), "rate is not finite!"); - return simcall_BODY_execution_parallel_start(name, host_nb, host_list, - flops_amount, - bytes_amount, - amount, rate); - + return simcall_BODY_execution_parallel_start(name, host_nb, host_list, flops_amount, bytes_amount, amount, rate, + timeout); } /** @@ -180,20 +175,19 @@ e_smx_state_t simcall_execution_wait(smx_activity_t execution) return (e_smx_state_t) simcall_BODY_execution_wait(execution); } - /** * \ingroup simix_vm_management * \brief Create a VM on the given physical host. * * \param name VM name - * \param host Physical host + * \param dest Physical host on which to create the VM * * \return The host object of the VM */ -sg_host_t simcall_vm_create(const char *name, sg_host_t phys_host) +sg_host_t simcall_vm_create(const char* name, sg_host_t dest) { - return simgrid::simix::kernelImmediate([&name, &phys_host] { - sg_host_t host = surf_vm_model->createVM(name, phys_host); + return simgrid::simix::kernelImmediate([&name, &dest] { + sg_host_t host = new simgrid::s4u::VirtualMachine(name, dest); host->extension_set(new simgrid::simix::Host()); return host; @@ -225,19 +219,27 @@ int simcall_vm_get_state(sg_host_t vm) /** * \ingroup simix_vm_management - * \brief Get the name of the physical host on which the given VM runs. + * \brief Get the physical host on which the given VM runs. * * \param vm VM - * \return The name of the physical host + * \return The physical host */ void *simcall_vm_get_pm(sg_host_t vm) { - return simgrid::simix::kernelImmediate(std::bind(SIMIX_vm_get_pm, vm)); + return simgrid::simix::kernelImmediate( + [vm]() { return static_cast(vm)->pimpl_vm_->getPm(); }); } +/** + * @brief Function to set the CPU bound of the given SIMIX VM host. + * + * @param host the vm host (a sg_host_t) + * @param bound bound (a double) + */ void simcall_vm_set_bound(sg_host_t vm, double bound) { - simgrid::simix::kernelImmediate(std::bind(SIMIX_vm_set_bound, vm, bound)); + simgrid::simix::kernelImmediate( + [vm, bound]() { static_cast(vm)->pimpl_vm_->setBound(bound); }); } /** @@ -293,7 +295,23 @@ void simcall_vm_save(sg_host_t vm) */ void simcall_vm_restore(sg_host_t vm) { - simcall_BODY_vm_restore(vm); + simgrid::simix::kernelImmediate([vm]() { + if (SIMIX_vm_get_state(vm) != SURF_VM_STATE_SAVED) + THROWF(vm_error, 0, "VM(%s) was not saved", vm->name().c_str()); + + XBT_DEBUG("restore VM(%s), where %d processes exist", vm->name().c_str(), + xbt_swag_size(sg_host_simix(vm)->process_list)); + + /* jump to vm_ws_restore() */ + static_cast(vm)->pimpl_vm_->restore(); + + smx_actor_t smx_process, smx_process_safe; + xbt_swag_foreach_safe(smx_process, smx_process_safe, sg_host_simix(vm)->process_list) + { + XBT_DEBUG("resume %s", smx_process->name.c_str()); + SIMIX_process_resume(smx_process); + } + }); } /** @@ -315,26 +333,24 @@ void simcall_vm_shutdown(sg_host_t vm) */ void simcall_vm_destroy(sg_host_t vm) { - simgrid::simix::kernelImmediate(std::bind(SIMIX_vm_destroy, vm)); -} + simgrid::simix::kernelImmediate([vm]() { + /* this code basically performs a similar thing like SIMIX_host_destroy() */ + XBT_DEBUG("destroy %s", vm->name().c_str()); -/** - * \ingroup simix_vm_management - * \brief Encompassing simcall to prevent the removal of the src or the dst node at the end of a VM migration - * The simcall actually invokes the following calls: - * simcall_vm_migrate(vm, dst_pm); - * simcall_vm_resume(vm); - * - * It is called at the end of the migration_rx_fun function from msg/msg_vm.c - * - * \param vm VM to migrate - * \param src_pm Source physical host - * \param dst_pmt Destination physical host - */ -void simcall_vm_migratefrom_resumeto(sg_host_t vm, sg_host_t src_pm, sg_host_t dst_pm) -{ - simgrid::simix::kernelImmediate(std::bind( - SIMIX_vm_migratefrom_resumeto, vm, src_pm, dst_pm)); + /* FIXME: this is really strange that everything fails if the next line is removed. + * This is as if we shared these data with the PM, which definitely should not be the case... + * + * We need to test that suspending a VM does not suspends the processes running on its PM, for example. + * Or we need to simplify this code enough to make it actually readable (but this sounds harder than testing) + */ + vm->extension_set(nullptr); + + /* Don't free these things twice: they are the ones of my physical host */ + vm->pimpl_cpu = nullptr; + vm->pimpl_netcard = nullptr; + + vm->destroy(); + }); } /** @@ -399,8 +415,6 @@ void simcall_process_join(smx_actor_t process, double timeout) */ void simcall_process_suspend(smx_actor_t process) { - xbt_assert(process, "Invalid parameters"); - simcall_BODY_process_suspend(process); }