Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
surf_cpu_model_pm: remove global
authorBruno Donassolo <bruno.donassolo@inria.fr>
Thu, 4 Mar 2021 13:15:23 +0000 (14:15 +0100)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Tue, 9 Mar 2021 14:17:12 +0000 (15:17 +0100)
doc/doxygen/inside_extending.doc
include/simgrid/kernel/routing/NetZoneImpl.hpp
src/include/surf/surf.hpp
src/kernel/routing/NetZoneImpl.cpp
src/surf/cpu_cas01.cpp
src/surf/cpu_interface.cpp
src/surf/cpu_ti.cpp
src/surf/host_clm03.cpp
src/surf/ptask_L07.cpp
teshsuite/surf/surf_usage/surf_usage.cpp

index 54f7dcc..a8f97d8 100644 (file)
@@ -36,6 +36,7 @@ For instance, if you want to add a new cup model called `Plop`, create two files
 cpu_plop.hpp and cpu_plop_cpp which contains classes CpuPlopModel, CpuPlop and
 CpuPlopAction implementing respectively the interfaces CpuModel, Cpu and
 CpuAction. You also need to define an initializing function like this:
+FIXME[donassolo]: update doc
 
 ~~~~
 void surf_cpu_model_init_plop()
@@ -256,4 +257,4 @@ catch (std::runtime_error& e) {
 You should not do something like that. Please work instead to make XML
 avoidable, ie to make the C++ interface nice and usable.
 
-*/
\ No newline at end of file
+*/
index be08422..c9b6ea9 100644 (file)
@@ -72,6 +72,7 @@ class XBT_PUBLIC NetZoneImpl : public xbt::PropertyHolder {
   routing::NetPoint* netpoint_ = nullptr;                                 // Our representative in the father NetZone
   resource::NetworkModel* network_model_;
   resource::CpuModel* cpu_model_vm_;
+  resource::CpuModel* cpu_model_pm_;
 
 protected:
   explicit NetZoneImpl(NetZoneImpl* father, const std::string& name, resource::NetworkModel* network_model);
@@ -103,8 +104,13 @@ public:
   /* FIXME: protect the following fields once the construction madness is sorted out */
   RoutingMode hierarchy_ = RoutingMode::unset;
 
+  /** @brief Retrieves the network model associated to this NetZone */
   resource::NetworkModel* get_network_model() const { return network_model_; }
+  /** @brief Retrieves the CPU model for virtual machines associated to this NetZone */
   resource::CpuModel* get_cpu_vm_model() const { return cpu_model_vm_; }
+  /** @brief Retrieves the CPU model for physical machines associated to this NetZone */
+  resource::CpuModel* get_cpu_pm_model() const { return cpu_model_pm_; }
+
   const s4u::NetZone* get_iface() const { return &piface_; }
   s4u::NetZone* get_iface() { return &piface_; }
   unsigned int get_table_size() const { return vertices_.size(); }
index 6ac26dc..9f55cd8 100644 (file)
@@ -8,11 +8,6 @@
 
 #include "simgrid/forward.h"
 
-/** @ingroup SURF_models
- *  @brief The CPU model object for the physical machine layer
- */
-XBT_PUBLIC_DATA simgrid::kernel::resource::CpuModel* surf_cpu_model_pm;
-
 /** @ingroup SURF_models
  *  @brief The host model
  *
index 618f26e..da9e717 100644 (file)
@@ -29,6 +29,8 @@ NetZoneImpl::NetZoneImpl(NetZoneImpl* father, const std::string& name, resource:
     cpu_model_vm_ = static_cast<simgrid::kernel::resource::CpuModel*>(
         models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM][0]);
   }
+  cpu_model_pm_ = static_cast<simgrid::kernel::resource::CpuModel*>(
+      models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM][0]);
   XBT_DEBUG("NetZone '%s' created with the id '%u'", get_cname(), netpoint_->id());
 }
 
@@ -86,7 +88,7 @@ s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vector<d
   auto* res = new s4u::Host(name);
   res->set_netpoint(new NetPoint(name, NetPoint::Type::Host, this));
 
-  surf_cpu_model_pm->create_cpu(res, speed_per_pstate)->set_core_count(core_amount)->seal();
+  cpu_model_pm_->create_cpu(res, speed_per_pstate)->set_core_count(core_amount)->seal();
 
   return res;
 }
index 3c2ee5c..0d56ffe 100644 (file)
@@ -36,8 +36,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.");
-
   if (cpu_optim_opt == "TI") {
     simgrid::kernel::resource::CpuTiModel::create_pm_vm_models();
     return;
@@ -49,8 +47,8 @@ void surf_cpu_model_init_Cas01()
   else
     algo = simgrid::kernel::resource::Model::UpdateAlgo::FULL;
 
-  surf_cpu_model_pm = 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_pm = new simgrid::kernel::resource::CpuCas01Model(algo);
+  models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM].push_back(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);
 }
@@ -76,7 +74,6 @@ CpuCas01Model::CpuCas01Model(Model::UpdateAlgo algo) : CpuModel(algo)
 
 CpuCas01Model::~CpuCas01Model()
 {
-  surf_cpu_model_pm = nullptr;
 }
 
 Cpu* CpuCas01Model::create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate)
index f114741..840c9a8 100644 (file)
@@ -11,8 +11,6 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_cpu, ker_resource, "CPU resource, fueling execution activites");
 
-simgrid::kernel::resource::CpuModel* surf_cpu_model_pm;
-
 namespace simgrid {
 namespace kernel {
 namespace resource {
index ad330fa..f31b334 100644 (file)
@@ -269,10 +269,8 @@ 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.");
-
-  surf_cpu_model_pm = new CpuTiModel();
-  models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM].push_back(surf_cpu_model_pm);
+  auto cpu_model_pm = new CpuTiModel();
+  models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM].push_back(cpu_model_pm);
   auto cpu_model_vm = new CpuTiModel();
   models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM].push_back(cpu_model_vm);
 }
@@ -284,7 +282,6 @@ CpuTiModel::CpuTiModel() : CpuModel(Model::UpdateAlgo::FULL)
 
 CpuTiModel::~CpuTiModel()
 {
-  surf_cpu_model_pm = nullptr;
 }
 
 Cpu* CpuTiModel::create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate)
@@ -408,7 +405,7 @@ void CpuTi::update_actions_finish_time(double now)
   sum_priority_ = 0.0;
   for (CpuTiAction const& action : action_set_) {
     /* action not running, skip it */
-    if (action.get_state_set() != surf_cpu_model_pm->get_started_action_set())
+    if (action.get_state_set() != get_model()->get_started_action_set())
       continue;
 
     /* bogus priority, skip it */
@@ -425,7 +422,7 @@ void CpuTi::update_actions_finish_time(double now)
   for (CpuTiAction& action : action_set_) {
     double min_finish = -1;
     /* action not running, skip it */
-    if (action.get_state_set() != surf_cpu_model_pm->get_started_action_set())
+    if (action.get_state_set() != get_model()->get_started_action_set())
       continue;
 
     /* verify if the action is really running on cpu */
index 340dc2a..e22365b 100644 (file)
@@ -20,7 +20,6 @@ void surf_host_model_init_current_default()
 
 void surf_host_model_init_compound()
 {
-  xbt_assert(surf_cpu_model_pm, "No CPU model defined yet!");
   /* 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 */
index f0bf356..3fa7c27 100644 (file)
@@ -19,7 +19,6 @@ XBT_LOG_EXTERNAL_CATEGORY(xbt_cfg);
 void surf_host_model_init_ptask_L07()
 {
   XBT_CINFO(xbt_cfg, "Switching to the L07 model to handle parallel tasks.");
-  xbt_assert(not surf_cpu_model_pm, "Cannot switch to ptasks: CPU model already defined");
 
   surf_host_model = new simgrid::surf::HostL07Model();
   all_existing_models.push_back(surf_host_model);
@@ -36,7 +35,7 @@ HostL07Model::HostL07Model() : HostModel()
   network_model_ = std::make_unique<NetworkL07Model>(this, maxmin_system);
   models_by_type[simgrid::kernel::resource::Model::Type::NETWORK].push_back(network_model_.get());
   cpu_model_pm_     = std::make_unique<CpuL07Model>(this, maxmin_system);
-  surf_cpu_model_pm = cpu_model_pm_.get();
+  models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM].push_back(cpu_model_pm_.get());
 }
 
 HostL07Model::~HostL07Model() {}
index b7b46d6..9e43b7b 100644 (file)
@@ -44,8 +44,9 @@ int main(int argc, char** argv)
 
   sg_netzone_t as_zone                               = sg_zone_get_by_name("AS0");
   simgrid::kernel::resource::NetworkModel* net_model = as_zone->get_impl()->get_network_model();
+  simgrid::kernel::resource::CpuModel* cpu_model_pm  = as_zone->get_impl()->get_cpu_pm_model();
 
-  XBT_DEBUG("CPU model: %p", surf_cpu_model_pm);
+  XBT_DEBUG("CPU model: %p", cpu_model_pm);
   XBT_DEBUG("Network model: %p", net_model);
   simgrid::s4u::Host* hostA = sg_host_by_name("Cpu A");
   simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B");
@@ -72,7 +73,7 @@ int main(int argc, char** argv)
     XBT_INFO("Next Event : %g", surf_get_clock());
     XBT_DEBUG("\t CPU actions");
 
-    simgrid::kernel::resource::Action::StateSet* action_list = surf_cpu_model_pm->get_failed_action_set();
+    simgrid::kernel::resource::Action::StateSet* action_list = cpu_model_pm->get_failed_action_set();
     while (not action_list->empty()) {
       simgrid::kernel::resource::Action& action = action_list->front();
       XBT_INFO("   CPU Failed action");
@@ -80,7 +81,7 @@ int main(int argc, char** argv)
       action.unref();
     }
 
-    action_list = surf_cpu_model_pm->get_finished_action_set();
+    action_list = cpu_model_pm->get_finished_action_set();
     while (not action_list->empty()) {
       simgrid::kernel::resource::Action& action = action_list->front();
       XBT_INFO("   CPU Done action");
@@ -103,7 +104,7 @@ int main(int argc, char** argv)
       XBT_DEBUG("\t * Done : %p", &action);
       action.unref();
     }
-  } while ((net_model->get_started_action_set()->size() || surf_cpu_model_pm->get_started_action_set()->size()) &&
+  } while ((net_model->get_started_action_set()->size() || cpu_model_pm->get_started_action_set()->size()) &&
            surf_solve(-1.0) >= 0.0);
 
   XBT_DEBUG("Simulation Terminated");