]> AND Public Git Repository - simgrid.git/blobdiff - src/kernel/resource/VirtualMachineImpl.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce scope for temporary variables.
[simgrid.git] / src / kernel / resource / VirtualMachineImpl.cpp
index 9288d0bc963e2a9f022def6a59af28d4ded7f04f..e698ccbd961b278949ea279f72c99e30720dd2d3 100644 (file)
@@ -27,8 +27,7 @@ void surf_vm_model_init_HL13(simgrid::kernel::resource::CpuModel* cpu_pm_model)
   engine->add_model(vm_model, {cpu_pm_model});
   std::shared_ptr<simgrid::kernel::resource::CpuModel> cpu_model_vm;
 
-  auto cpu_optim = simgrid::config::get_value<std::string>("cpu/optim");
-  if (cpu_optim == "TI") {
+  if (simgrid::config::get_value<std::string>("cpu/optim") == "TI") {
     cpu_model_vm = std::make_shared<simgrid::kernel::resource::CpuTiModel>("VmCpu_TI");
   } else {
     cpu_model_vm = std::make_shared<simgrid::kernel::resource::CpuCas01Model>("VmCpu_Cas01");
@@ -184,10 +183,15 @@ Action* VMModel::execute_thread(const s4u::Host* host, double flops_amount, int
 
 VirtualMachineImpl::VirtualMachineImpl(const std::string& name, s4u::VirtualMachine* piface,
                                        simgrid::s4u::Host* host_PM, int core_amount, size_t ramsize)
-    : HostImpl(name), piface_(piface), physical_host_(host_PM), core_amount_(core_amount), ramsize_(ramsize)
+    : VirtualMachineImpl(name, host_PM, core_amount, ramsize)
+{
+  set_piface(piface);
+}
+
+VirtualMachineImpl::VirtualMachineImpl(const std::string& name, simgrid::s4u::Host* host_PM, int core_amount,
+                                       size_t ramsize)
+    : HostImpl(name), physical_host_(host_PM), core_amount_(core_amount), ramsize_(ramsize)
 {
-  /* Register this VM to the list of all VMs */
-  allVms_.push_back(piface);
   /* We create cpu_action corresponding to a VM process on the host operating system. */
   /* TODO: we have to periodically input GUESTOS_NOISE to the system? how ?
    * The value for GUESTOS_NOISE corresponds to the cost of the global action associated to the VM.  It corresponds to
@@ -200,12 +204,19 @@ VirtualMachineImpl::VirtualMachineImpl(const std::string& name, s4u::VirtualMach
   XBT_VERB("Create VM(%s)@PM(%s)", name.c_str(), physical_host_->get_cname());
 }
 
+void VirtualMachineImpl::set_piface(s4u::VirtualMachine* piface)
+{
+  xbt_assert(not piface_, "Pointer to interface already configured for this VM (%s)", get_cname());
+  piface_ = piface;
+  /* Register this VM to the list of all VMs */
+  allVms_.push_back(piface);
+}
+
 /** @brief A physical host does not disappear in the current SimGrid code, but a VM may disappear during a simulation */
 void VirtualMachineImpl::vm_destroy()
 {
   /* I was already removed from the allVms set if the VM was destroyed cleanly */
-  auto iter = find(allVms_.begin(), allVms_.end(), piface_);
-  if (iter != allVms_.end())
+  if (auto iter = find(allVms_.begin(), allVms_.end(), piface_); iter != allVms_.end())
     allVms_.erase(iter);
 
   /* Free the cpu_action of the VM. */
@@ -230,8 +241,8 @@ void VirtualMachineImpl::start()
   if (physical_host_->extension<s4u::VmHostExt>() == nullptr)
     physical_host_->extension_set(new s4u::VmHostExt());
 
-  size_t pm_ramsize = physical_host_->extension<s4u::VmHostExt>()->ramsize;
-  if (pm_ramsize &&
+  if (size_t pm_ramsize = physical_host_->extension<s4u::VmHostExt>()->ramsize;
+      pm_ramsize &&
       not physical_host_->extension<s4u::VmHostExt>()->overcommit) { /* Need to verify that we don't overcommit */
     /* Retrieve the memory occupied by the VMs on that host. Yep, we have to traverse all VMs of all hosts for that */
     size_t total_ramsize_of_vms = 0;
@@ -350,8 +361,7 @@ void VirtualMachineImpl::set_physical_host(s4u::Host* destination)
     XBT_CRITICAL("FIXME: need copy the state(?), %f", action_->get_remains_no_update());
 
   /* keep the bound value of the cpu action of the VM. */
-  double old_bound = action_->get_bound();
-  if (old_bound > 0) {
+  if (double old_bound = action_->get_bound(); old_bound > 0) {
     XBT_DEBUG("migrate VM(%s): set bound (%f) at %s", vm_name.c_str(), old_bound, pm_name_dst.c_str());
     new_cpu_action->set_bound(old_bound);
   }