Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Get rid of surf_cpu_model_vm.
authorBruno Donassolo <bruno.donassolo@inria.fr>
Thu, 4 Mar 2021 10:41:49 +0000 (11:41 +0100)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Tue, 9 Mar 2021 14:17:12 +0000 (15:17 +0100)
- Add cpu_model_vm to NetZoneImpl. By now, it gets the global pointer in
models_by_type if available
- Separate CPU in CPU_PM and CPU_VM.
- Move next_occurring_event call to CPU_VM models to surf_solve. One step
closer to centralizing the models management

12 files changed:
include/simgrid/kernel/resource/Model.hpp
include/simgrid/kernel/routing/NetZoneImpl.hpp
src/include/surf/surf.hpp
src/kernel/routing/NetZoneImpl.cpp
src/plugins/vm/VirtualMachineImpl.cpp
src/plugins/vm/VirtualMachineImpl.hpp
src/plugins/vm/s4u_VirtualMachine.cpp
src/surf/cpu_cas01.cpp
src/surf/cpu_interface.cpp
src/surf/cpu_ti.cpp
src/surf/sg_platf.cpp
src/surf/surf_c_bindings.cpp

index 48e1175..fac93ac 100644 (file)
@@ -24,7 +24,8 @@ public:
   enum class Type {
     HOST,    /**< Host models: see surf_host_model_description for more details */
     NETWORK, /**< Network models: see surf_network_model_description for more details */
-    CPU,     /**< CPU models: see surf_cpu_model_description for more details */
+    CPU_PM,  /**< CPU model for physical machines: see surf_cpu_model_description for more details */
+    CPU_VM,  /**< CPU model for virtual machines: see surf_cpu_model_description for more details */
     DISK,    /**< Disk models: see surf_disk_model_description for more details */
     VM       /**< VM model */
   };
index 85cf2b5..be08422 100644 (file)
@@ -71,6 +71,7 @@ class XBT_PUBLIC NetZoneImpl : public xbt::PropertyHolder {
   std::map<std::pair<NetPoint*, NetPoint*>, BypassRoute*> bypass_routes_; // src x dst -> route
   routing::NetPoint* netpoint_ = nullptr;                                 // Our representative in the father NetZone
   resource::NetworkModel* network_model_;
+  resource::CpuModel* cpu_model_vm_;
 
 protected:
   explicit NetZoneImpl(NetZoneImpl* father, const std::string& name, resource::NetworkModel* network_model);
@@ -103,6 +104,7 @@ public:
   RoutingMode hierarchy_ = RoutingMode::unset;
 
   resource::NetworkModel* get_network_model() const { return network_model_; }
+  resource::CpuModel* get_cpu_vm_model() const { return cpu_model_vm_; }
   const s4u::NetZone* get_iface() const { return &piface_; }
   s4u::NetZone* get_iface() { return &piface_; }
   unsigned int get_table_size() const { return vertices_.size(); }
index 772465a..6ac26dc 100644 (file)
  */
 XBT_PUBLIC_DATA simgrid::kernel::resource::CpuModel* surf_cpu_model_pm;
 
-/** @ingroup SURF_models
- *  @brief The CPU model object for the virtual machine layer
- */
-XBT_PUBLIC_DATA simgrid::kernel::resource::CpuModel* surf_cpu_model_vm;
-
 /** @ingroup SURF_models
  *  @brief The host model
  *
index 70bcd20..618f26e 100644 (file)
@@ -25,6 +25,10 @@ NetZoneImpl::NetZoneImpl(NetZoneImpl* father, const std::string& name, resource:
              "Refusing to create a second NetZone called '%s'.", get_cname());
 
   netpoint_ = new NetPoint(name_, NetPoint::Type::NetZone, father_);
+  if (models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM].size() > 0) {
+    cpu_model_vm_ = static_cast<simgrid::kernel::resource::CpuModel*>(
+        models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM][0]);
+  }
   XBT_DEBUG("NetZone '%s' created with the id '%u'", get_cname(), netpoint_->id());
 }
 
index 4fde708..4c7d7b1 100644 (file)
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_vm, ker_resource, "Virtual Machines, containing actors and mobile accross hosts");
 
-simgrid::vm::VMModel* surf_vm_model = nullptr;
-
 void surf_vm_model_init_HL13()
 {
-  if (surf_cpu_model_vm != nullptr)
-    surf_vm_model = new simgrid::vm::VMModel();
+  /* FIXME[donassolo]: this smells bad, but works
+   * (the constructor saves its pointer in all_existing_models and models_by_type :O).
+   * We need a manager for these models */
+  new simgrid::vm::VMModel();
 }
 
 namespace simgrid {
@@ -149,13 +149,12 @@ double VMModel::next_occurring_event(double now)
     double solved_value = ws_vm->get_impl()->get_action()->get_variable()->get_value();
     XBT_DEBUG("assign %f to vm %s @ pm %s", solved_value, ws_vm->get_cname(), ws_vm->get_pm()->get_cname());
 
-    xbt_assert(cpu->get_model() == surf_cpu_model_vm);
     kernel::lmm::System* vcpu_system = cpu->get_model()->get_maxmin_system();
     vcpu_system->update_constraint_bound(cpu->get_constraint(), virt_overhead * solved_value);
   }
 
-  /* 2. Ready. Get the next occurring event */
-  return surf_cpu_model_vm->next_occurring_event(now);
+  /* actual next occurring event is determined by VM CPU model at surf_solve */
+  return -1.0;
 }
 
 /************
index a6c8206..899922b 100644 (file)
@@ -103,6 +103,4 @@ public:
 }
 }
 
-XBT_PUBLIC_DATA simgrid::vm::VMModel* surf_vm_model;
-
 #endif /* VM_INTERFACE_HPP_ */
index c8046e0..3647064 100644 (file)
@@ -4,6 +4,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/Exception.hpp"
+#include "simgrid/kernel/routing/NetPoint.hpp"
 #include "simgrid/s4u/Actor.hpp"
 #include "simgrid/vm.h"
 #include "src/include/surf/surf.hpp"
@@ -41,7 +42,8 @@ VirtualMachine::VirtualMachine(const std::string& name, s4u::Host* physical_host
   for (int i = 0; i < physical_host->get_pstate_count(); i++)
     speeds.push_back(physical_host->get_pstate_speed(i));
 
-  surf_cpu_model_vm->create_cpu(this, speeds)->set_core_count(core_amount)->seal();
+  // FIXME[donassolo]: shoud this be done at the Impl class???
+  physical_host->get_netpoint()->get_englobing_zone()->get_cpu_vm_model()->create_cpu(this, speeds)->set_core_count(core_amount)->seal();
   if (physical_host->get_pstate() != 0)
     set_pstate(physical_host->get_pstate());
 
index 7841e71..3c2ee5c 100644 (file)
@@ -37,7 +37,6 @@ static simgrid::config::Flag<std::string>
 void surf_cpu_model_init_Cas01()
 {
   xbt_assert(surf_cpu_model_pm == nullptr, "CPU model already initialized. This should not happen.");
-  xbt_assert(surf_cpu_model_vm == nullptr, "CPU model already initialized. This should not happen.");
 
   if (cpu_optim_opt == "TI") {
     simgrid::kernel::resource::CpuTiModel::create_pm_vm_models();
@@ -51,7 +50,9 @@ void surf_cpu_model_init_Cas01()
     algo = simgrid::kernel::resource::Model::UpdateAlgo::FULL;
 
   surf_cpu_model_pm = new simgrid::kernel::resource::CpuCas01Model(algo);
-  surf_cpu_model_vm = new simgrid::kernel::resource::CpuCas01Model(algo);
+  models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM].push_back(surf_cpu_model_pm);
+  auto cpu_model_vm = new simgrid::kernel::resource::CpuCas01Model(algo);
+  models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM].push_back(cpu_model_vm);
 }
 
 namespace simgrid {
@@ -61,7 +62,6 @@ namespace resource {
 CpuCas01Model::CpuCas01Model(Model::UpdateAlgo algo) : CpuModel(algo)
 {
   all_existing_models.push_back(this);
-  models_by_type[simgrid::kernel::resource::Model::Type::CPU].push_back(this);
 
   bool select = config::get_value<bool>("cpu/maxmin-selective-update");
 
index eafa003..f114741 100644 (file)
@@ -12,7 +12,6 @@
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_cpu, ker_resource, "CPU resource, fueling execution activites");
 
 simgrid::kernel::resource::CpuModel* surf_cpu_model_pm;
-simgrid::kernel::resource::CpuModel* surf_cpu_model_vm;
 
 namespace simgrid {
 namespace kernel {
@@ -57,6 +56,7 @@ Cpu::Cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate)
 {
   speed_.scale = 1;
   speed_.peak     = speed_per_pstate_.front();
+  // FIXME[donassolo]: don't set here.. everytime I take half an hour to discover where it comes
   host->pimpl_cpu = this;
 }
 
index 3dca750..ad330fa 100644 (file)
@@ -270,16 +270,16 @@ int CpuTiProfile::binary_search(const std::vector<double>& array, double a)
 void CpuTiModel::create_pm_vm_models()
 {
   xbt_assert(surf_cpu_model_pm == nullptr, "CPU model already initialized. This should not happen.");
-  xbt_assert(surf_cpu_model_vm == nullptr, "CPU model already initialized. This should not happen.");
 
   surf_cpu_model_pm = new CpuTiModel();
-  surf_cpu_model_vm = new CpuTiModel();
+  models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM].push_back(surf_cpu_model_pm);
+  auto cpu_model_vm = new CpuTiModel();
+  models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM].push_back(cpu_model_vm);
 }
 
 CpuTiModel::CpuTiModel() : CpuModel(Model::UpdateAlgo::FULL)
 {
   all_existing_models.push_back(this);
-  models_by_type[simgrid::kernel::resource::Model::Type::CPU].push_back(this);
 }
 
 CpuTiModel::~CpuTiModel()
index 4d91bb4..9dbd579 100644 (file)
@@ -475,6 +475,8 @@ static void surf_config_models_setup()
   surf_host_model_description[host_id].model_init_preparse();
 
   XBT_DEBUG("Call vm_model_init");
+  // FIXME[donassolo]: maybe remove it, find a way to create the object and leave the
+  // dependency with surf_cpu_model_vm explicity
   surf_vm_model_init_HL13();
 
   XBT_DEBUG("Call disk_model_init");
index 728cdd0..a47a841 100644 (file)
@@ -80,7 +80,7 @@ double surf_solve(double max_date)
 
   // following the order it was done in HostCLM03Model->next_occurring_event
   XBT_DEBUG("Looking for next event in CPU models");
-  surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::CPU], time_delta);
+  surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM], time_delta);
   XBT_DEBUG("Looking for next event in network models");
   surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::NETWORK], time_delta);
   XBT_DEBUG("Looking for next event in disk models");
@@ -88,6 +88,7 @@ double surf_solve(double max_date)
 
   XBT_DEBUG("Looking for next event in virtual models");
   surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::VM], time_delta);
+  surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM], time_delta);
 
   XBT_DEBUG("Min for resources (remember that NS3 don't update that value): %f", time_delta);