From: Frederic Suter Date: Wed, 6 Dec 2017 11:23:29 +0000 (+0100) Subject: isolate VM migration parameters from others X-Git-Tag: v3.18~126 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/1933a95e2b0981f030408fa642adc48877934c75 isolate VM migration parameters from others - overcommit is in VMHostExt - ncpus is the pimpl coreAmount - ramsize is added to the pimpl with get/set methods at different levels Remarks: - MSG_vm_(get/set)_params are no longer used - the vm_params_t structure should (IMHO) become an extension decicated to migration in the plugin --- diff --git a/examples/msg/cloud-capping/cloud-capping.c b/examples/msg/cloud-capping/cloud-capping.c index e84ac2c258..b27d11ec34 100644 --- a/examples/msg/cloud-capping/cloud-capping.c +++ b/examples/msg/cloud-capping/cloud-capping.c @@ -246,10 +246,7 @@ static int master_main(int argc, char *argv[]) vm0 = MSG_vm_create_core(pm0, "VM0"); - s_vm_params_t params; - memset(¶ms, 0, sizeof(params)); - params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes - MSG_vm_set_params(vm0, ¶ms); + MSG_vm_set_ramsize(vm0, 1e9); // 1GB MSG_vm_start(vm0); cpu_speed = MSG_host_get_speed(pm0); diff --git a/examples/msg/cloud-masterworker/cloud-masterworker.c b/examples/msg/cloud-masterworker/cloud-masterworker.c index 86449a44ee..12044addc3 100644 --- a/examples/msg/cloud-masterworker/cloud-masterworker.c +++ b/examples/msg/cloud-masterworker/cloud-masterworker.c @@ -83,10 +83,7 @@ static int master_fun(int argc, char *argv[]) XBT_INFO("create %s on PM(%s)", vm_name, MSG_host_get_name(pm)); msg_vm_t vm = MSG_vm_create_core(pm, vm_name); - s_vm_params_t params; - memset(¶ms, 0, sizeof(params)); - params.ramsize = 1L * 1024 * 1024 * 1024; // 1Gbytes - MSG_vm_set_params(vm, ¶ms); + MSG_vm_set_ramsize(vm, 1L * 1024 * 1024 * 1024); // 1GiB MSG_vm_start(vm); xbt_dynar_push(vms, &vm); diff --git a/examples/msg/cloud-migration/cloud-migration.c b/examples/msg/cloud-migration/cloud-migration.c index 29b10c9794..5fd214347b 100644 --- a/examples/msg/cloud-migration/cloud-migration.c +++ b/examples/msg/cloud-migration/cloud-migration.c @@ -55,25 +55,21 @@ static int master_main(int argc, char *argv[]) msg_host_t pm0 = MSG_host_by_name("Fafard"); msg_host_t pm1 = MSG_host_by_name("Tremblay"); msg_host_t pm2 = MSG_host_by_name("Bourassa"); - s_vm_params_t params; - memset(¶ms, 0, sizeof(params)); msg_vm_t vm0 = MSG_vm_create_core(pm0, "VM0"); - params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes - MSG_vm_set_params(vm0, ¶ms); + MSG_vm_set_ramsize(vm0, 1e9); // 1Gbytes MSG_vm_start(vm0); - XBT_INFO("Test: Migrate a VM with %llu Mbytes RAM", params.ramsize / 1000 / 1000); + XBT_INFO("Test: Migrate a VM with %zu Mbytes RAM", MSG_vm_get_ramsize(vm0) / 1000 / 1000); vm_migrate(vm0, pm1); MSG_vm_destroy(vm0); vm0 = MSG_vm_create_core(pm0, "VM0"); - params.ramsize = 1L * 1000 * 1000 * 100; // 100Mbytes - MSG_vm_set_params(vm0, ¶ms); + MSG_vm_set_ramsize(vm0, 1e8); // 100Mbytes MSG_vm_start(vm0); - XBT_INFO("Test: Migrate a VM with %llu Mbytes RAM", params.ramsize / 1000 / 1000); + XBT_INFO("Test: Migrate a VM with %zu Mbytes RAM", MSG_vm_get_ramsize(vm0) / 1000 / 1000); vm_migrate(vm0, pm1); MSG_vm_destroy(vm0); @@ -81,9 +77,8 @@ static int master_main(int argc, char *argv[]) vm0 = MSG_vm_create_core(pm0, "VM0"); msg_vm_t vm1 = MSG_vm_create_core(pm0, "VM1"); - params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes - MSG_vm_set_params(vm0, ¶ms); - MSG_vm_set_params(vm1, ¶ms); + MSG_vm_set_ramsize(vm0, 1e9); // 1Gbytes + MSG_vm_set_ramsize(vm1, 1e9); // 1Gbytes MSG_vm_start(vm0); MSG_vm_start(vm1); @@ -98,9 +93,8 @@ static int master_main(int argc, char *argv[]) vm0 = MSG_vm_create_core(pm0, "VM0"); vm1 = MSG_vm_create_core(pm0, "VM1"); - params.ramsize = 1L * 1000 * 1000 * 1000; // 1Gbytes - MSG_vm_set_params(vm0, ¶ms); - MSG_vm_set_params(vm1, ¶ms); + MSG_vm_set_ramsize(vm0, 1e9); // 1Gbytes + MSG_vm_set_ramsize(vm1, 1e9); // 1Gbytes MSG_vm_start(vm0); MSG_vm_start(vm1); diff --git a/examples/msg/cloud-simple/cloud-simple.c b/examples/msg/cloud-simple/cloud-simple.c index 76dbf948de..f576b25990 100644 --- a/examples/msg/cloud-simple/cloud-simple.c +++ b/examples/msg/cloud-simple/cloud-simple.c @@ -234,10 +234,7 @@ static int master_main(int argc, char *argv[]) " network one"); XBT_INFO("### Relocate VM0 between PM0 and PM1"); vm0 = MSG_vm_create_core(pm0, "VM0"); - s_vm_params_t params; - memset(¶ms, 0, sizeof(params)); - params.ramsize = 1L * 1024 * 1024 * 1024; // 1Gbytes - MSG_vm_set_params(vm0, ¶ms); + MSG_vm_set_ramsize(vm0, 1L * 1024 * 1024 * 1024); // 1GiB MSG_vm_start(vm0); launch_communication_worker((msg_host_t)vm0, pm2); diff --git a/include/simgrid/datatypes.h b/include/simgrid/datatypes.h index 815e9370d5..d52d21f7e5 100644 --- a/include/simgrid/datatypes.h +++ b/include/simgrid/datatypes.h @@ -10,12 +10,7 @@ #include "simgrid/forward.h" struct vm_params { - int ncpus; - sg_size_t ramsize; - int overcommit; - - /* The size of other states than memory pages, which is out-of-scope of dirty - * page tracking. */ + /* The size of other states than memory pages, which is out-of-scope of dirty page tracking. */ sg_size_t devsize; int skip_stage1; int skip_stage2; diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index 068e469e54..b4e5304ac0 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -469,6 +469,8 @@ XBT_PUBLIC(int) MSG_vm_is_suspended(msg_vm_t vm); XBT_PUBLIC(const char*) MSG_vm_get_name(msg_vm_t vm); XBT_PUBLIC(void) MSG_vm_get_params(msg_vm_t vm, vm_params_t params); XBT_PUBLIC(void) MSG_vm_set_params(msg_vm_t vm, vm_params_t params); +XBT_PUBLIC(void) MSG_vm_set_ramsize(msg_vm_t vm, size_t size); +XBT_PUBLIC(size_t) MSG_vm_get_ramsize(msg_vm_t vm); // TODO add VDI later XBT_PUBLIC(msg_vm_t) MSG_vm_create_core(msg_host_t location, const char *name); diff --git a/include/simgrid/s4u/VirtualMachine.hpp b/include/simgrid/s4u/VirtualMachine.hpp index 0d6023d321..d736b50d57 100644 --- a/include/simgrid/s4u/VirtualMachine.hpp +++ b/include/simgrid/s4u/VirtualMachine.hpp @@ -36,6 +36,7 @@ XBT_PUBLIC_CLASS VirtualMachine : public s4u::Host public: explicit VirtualMachine(const char* name, s4u::Host* hostPm, int coreAmount); + explicit VirtualMachine(const char* name, s4u::Host* hostPm, int coreAmount, size_t ramsize); // No copy/move VirtualMachine(VirtualMachine const&) = delete; @@ -43,15 +44,15 @@ public: private: virtual ~VirtualMachine(); - public: void start(); bool isMigrating(); void getParameters(vm_params_t params); void setParameters(vm_params_t params); - double getRamsize(); simgrid::s4u::Host* getPm(); + size_t getRamsize(); + void setRamsize(size_t ramsize); e_surf_vm_state_t getState(); diff --git a/src/msg/msg_vm.cpp b/src/msg/msg_vm.cpp index 00d1d02f14..06abe65bd7 100644 --- a/src/msg/msg_vm.cpp +++ b/src/msg/msg_vm.cpp @@ -59,6 +59,15 @@ void MSG_vm_get_params(msg_vm_t vm, vm_params_t params) vm->getParameters(params); } +void MSG_vm_set_ramsize(msg_vm_t vm, size_t size) +{ + vm->setRamsize(size); +} +size_t MSG_vm_get_ramsize(msg_vm_t vm) +{ + return vm->getRamsize(); +} + /* **** Check state of a VM **** */ static inline int __MSG_vm_is_state(msg_vm_t vm, e_surf_vm_state_t state) { @@ -113,18 +122,15 @@ msg_vm_t MSG_vm_create(msg_host_t pm, const char* name, int coreAmount, int rams /* For the moment, intensity_rate is the percentage against the migration bandwidth */ - msg_vm_t vm = new simgrid::s4u::VirtualMachine(name, pm, coreAmount); + msg_vm_t vm = new simgrid::s4u::VirtualMachine(name, pm, coreAmount, static_cast(ramsize) * 1024 * 1024); s_vm_params_t params; - params.ncpus = 0; - params.ramsize = static_cast(ramsize) * 1024 * 1024; - params.overcommit = 0; params.devsize = 0; params.skip_stage1 = 0; params.skip_stage2 = 0; params.max_downtime = 0.03; params.mig_speed = static_cast(mig_netspeed) * 1024 * 1024; // mig_speed params.dp_intensity = static_cast(dp_intensity) / 100; - params.dp_cap = params.ramsize * 0.9; // assume working set memory is 90% of ramsize + params.dp_cap = vm->getRamsize() * 0.9; // assume working set memory is 90% of ramsize XBT_DEBUG("migspeed : %f intensity mem : %d", params.mig_speed, dp_intensity); vm->setParameters(¶ms); @@ -142,7 +148,11 @@ msg_vm_t MSG_vm_create_core(msg_host_t pm, const char* name) xbt_assert(sg_host_by_name(name) == nullptr, "Cannot create a VM named %s: this name is already used by an host or a VM", name); - return new simgrid::s4u::VirtualMachine(name, pm, 1); + msg_vm_t vm = new simgrid::s4u::VirtualMachine(name, pm, 1); + s_vm_params_t params; + memset(¶ms, 0, sizeof(params)); + vm->setParameters(¶ms); + return vm; } /** @brief Create a new VM object with the default parameters, but with a specified amount of cores * @ingroup msg_VMs* @@ -154,7 +164,11 @@ msg_vm_t MSG_vm_create_multicore(msg_host_t pm, const char* name, int coreAmount xbt_assert(sg_host_by_name(name) == nullptr, "Cannot create a VM named %s: this name is already used by an host or a VM", name); - return new simgrid::s4u::VirtualMachine(name, pm, coreAmount); + msg_vm_t vm = new simgrid::s4u::VirtualMachine(name, pm, coreAmount); + s_vm_params_t params; + memset(¶ms, 0, sizeof(params)); + vm->setParameters(¶ms); + return vm; } /** @brief Destroy a VM. Destroy the VM object from the simulation. @@ -509,7 +523,7 @@ static int migration_tx_fun(int argc, char *argv[]) double host_speed = ms->vm->pimpl_vm_->getPm()->getSpeed(); s_vm_params_t params; ms->vm->getParameters(¶ms); - const sg_size_t ramsize = params.ramsize; + const sg_size_t ramsize = ms->vm->getRamsize(); const sg_size_t devsize = params.devsize; const int skip_stage1 = params.skip_stage1; int skip_stage2 = params.skip_stage2; diff --git a/src/plugins/vm/VirtualMachineImpl.cpp b/src/plugins/vm/VirtualMachineImpl.cpp index ce764f6be8..87e2badd9e 100644 --- a/src/plugins/vm/VirtualMachineImpl.cpp +++ b/src/plugins/vm/VirtualMachineImpl.cpp @@ -114,8 +114,8 @@ double VMModel::nextOccuringEvent(double now) ************/ VirtualMachineImpl::VirtualMachineImpl(simgrid::s4u::VirtualMachine* piface, simgrid::s4u::Host* host_PM, - int coreAmount) - : HostImpl(piface), hostPM_(host_PM), coreAmount_(coreAmount) + int coreAmount, size_t ramsize) + : HostImpl(piface), hostPM_(host_PM), coreAmount_(coreAmount), ramsize_(ramsize) { /* Register this VM to the list of all VMs */ allVms_.push_back(piface); @@ -124,9 +124,6 @@ VirtualMachineImpl::VirtualMachineImpl(simgrid::s4u::VirtualMachine* piface, sim /* TODO: we have to periodically input GUESTOS_NOISE to the system? how ? */ action_ = host_PM->pimpl_cpu->execution_start(0, coreAmount); - /* Initialize the VM parameters */ - params_.ramsize = 0; - XBT_VERB("Create VM(%s)@PM(%s)", piface->getCname(), hostPM_->getCname()); } @@ -295,11 +292,6 @@ void VirtualMachineImpl::setPm(s4u::Host* destination) XBT_DEBUG("migrate VM(%s): change PM (%s to %s)", vm_name, pm_name_src, pm_name_dst); } -sg_size_t VirtualMachineImpl::getRamsize() -{ - return params_.ramsize; -} - void VirtualMachineImpl::setBound(double bound) { action_->setBound(bound); diff --git a/src/plugins/vm/VirtualMachineImpl.hpp b/src/plugins/vm/VirtualMachineImpl.hpp index 771747bdaa..f0af82eeff 100644 --- a/src/plugins/vm/VirtualMachineImpl.hpp +++ b/src/plugins/vm/VirtualMachineImpl.hpp @@ -53,7 +53,7 @@ XBT_PUBLIC_CLASS VirtualMachineImpl : public surf::HostImpl friend simgrid::s4u::VirtualMachine; public: - explicit VirtualMachineImpl(s4u::VirtualMachine * piface, s4u::Host * host, int coreAmount); + explicit VirtualMachineImpl(s4u::VirtualMachine * piface, s4u::Host * host, int coreAmount, size_t ramsize); ~VirtualMachineImpl(); /** @brief Suspend the VM */ @@ -71,7 +71,8 @@ public: /** @brief Get the physical machine hosting the VM */ s4u::Host* getPm(); - sg_size_t getRamsize(); + sg_size_t getRamsize() { return ramsize_; } + void setRamsize(sg_size_t ramsize) { ramsize_ = ramsize; } virtual void setBound(double bound); @@ -97,6 +98,7 @@ private: simgrid::s4u::Host* hostPM_; s_vm_params_t params_; int coreAmount_; + size_t ramsize_ = 0; e_surf_vm_state_t vmState_ = SURF_VM_STATE_CREATED; }; diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index 3dd17c2970..5b0ade8efc 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -15,7 +15,12 @@ namespace simgrid { namespace s4u { VirtualMachine::VirtualMachine(const char* name, s4u::Host* pm, int coreAmount) - : Host(name), pimpl_vm_(new vm::VirtualMachineImpl(this, pm, coreAmount)) + : VirtualMachine(name, pm, coreAmount, 0) +{ +} + +VirtualMachine::VirtualMachine(const char* name, s4u::Host* pm, int coreAmount, size_t ramsize) + : Host(name), pimpl_vm_(new vm::VirtualMachineImpl(this, pm, coreAmount, ramsize)) { XBT_DEBUG("Create VM %s", name); @@ -91,19 +96,27 @@ bool VirtualMachine::isMigrating() { return pimpl_vm_ && pimpl_vm_->isMigrating; } -double VirtualMachine::getRamsize() -{ - return pimpl_vm_->params_.ramsize; -} + simgrid::s4u::Host* VirtualMachine::getPm() { return pimpl_vm_->getPm(); } + e_surf_vm_state_t VirtualMachine::getState() { return pimpl_vm_->getState(); } +size_t VirtualMachine::getRamsize() +{ + return pimpl_vm_->getRamsize(); +} + +void VirtualMachine::setRamsize(size_t ramsize) +{ + pimpl_vm_->setRamsize(ramsize); +} + /** @brief Retrieve a copy of the parameters of that VM/PM * @details The ramsize and overcommit fields are used on the PM too */ void VirtualMachine::getParameters(vm_params_t params)