Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make field 's4u::Host::pimpl_cpu' private.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 21 Jun 2021 13:31:10 +0000 (15:31 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 22 Jun 2021 15:20:07 +0000 (17:20 +0200)
14 files changed:
include/simgrid/s4u/Host.hpp
src/kernel/activity/CommImpl.cpp
src/kernel/activity/ExecImpl.cpp
src/kernel/activity/IoImpl.cpp
src/kernel/activity/SleepImpl.cpp
src/kernel/activity/SynchroRaw.cpp
src/plugins/vm/VirtualMachineImpl.cpp
src/s4u/s4u_Host.cpp
src/surf/HostImpl.cpp
src/surf/cpu_interface.cpp
src/surf/host_clm03.cpp
src/surf/ptask_L07.cpp
teshsuite/surf/surf_usage/surf_usage.cpp
teshsuite/surf/surf_usage2/surf_usage2.cpp

index 2f6502c..9bb95fa 100644 (file)
@@ -45,6 +45,9 @@ class XBT_PUBLIC Host : public xbt::Extendable<Host> {
   // The private implementation, that never changes
   surf::HostImpl* const pimpl_;
 
+  kernel::resource::CpuImpl* pimpl_cpu_      = nullptr;
+  kernel::routing::NetPoint* pimpl_netpoint_ = nullptr;
+
 public:
   explicit Host(surf::HostImpl* pimpl) : pimpl_(pimpl) {}
 
@@ -83,6 +86,8 @@ public:
   /** Retrieves the name of that host as a C string */
   const char* get_cname() const;
 
+  Host* set_cpu(kernel::resource::CpuImpl* cpu);
+  kernel::resource::CpuImpl* get_cpu() const { return pimpl_cpu_; }
   kernel::routing::NetPoint* get_netpoint() const { return pimpl_netpoint_; }
 
   size_t get_actor_count() const;
@@ -214,15 +219,6 @@ public:
   /** Block the calling actor on an execution located on the called host (with explicit priority) */
   void execute(double flops, double priority) const;
   surf::HostImpl* get_impl() const { return pimpl_; }
-
-private:
-  kernel::routing::NetPoint* pimpl_netpoint_ = nullptr;
-
-public:
-#ifndef DOXYGEN
-  /** DO NOT USE DIRECTLY (@todo: these should be protected, once our code is clean) */
-  kernel::resource::CpuImpl* pimpl_cpu = nullptr;
-#endif
 };
 } // namespace s4u
 } // namespace simgrid
index edd3e5f..2164bc8 100644 (file)
@@ -412,7 +412,7 @@ void CommImpl::wait_for(actor::ActorImpl* issuer, double timeout)
   if (state_ != State::WAITING && state_ != State::RUNNING) {
     finish();
   } else { /* we need a sleep action (even when there is no timeout) to be notified of host failures */
-    resource::Action* sleep = issuer->get_host()->pimpl_cpu->sleep(timeout);
+    resource::Action* sleep = issuer->get_host()->get_cpu()->sleep(timeout);
     sleep->set_activity(this);
 
     if (issuer == src_actor_)
index a687d1d..996b833 100644 (file)
@@ -48,7 +48,7 @@ ExecImpl& ExecImpl::set_hosts(const std::vector<s4u::Host*>& hosts)
 ExecImpl& ExecImpl::set_timeout(double timeout)
 {
   if (timeout >= 0 && not MC_is_active() && not MC_record_replay_is_active()) {
-    timeout_detector_.reset(hosts_.front()->pimpl_cpu->sleep(timeout));
+    timeout_detector_.reset(hosts_.front()->get_cpu()->sleep(timeout));
     timeout_detector_->set_activity(this);
   }
   return *this;
@@ -78,7 +78,7 @@ ExecImpl* ExecImpl::start()
   state_ = State::RUNNING;
   if (not MC_is_active() && not MC_record_replay_is_active()) {
     if (hosts_.size() == 1) {
-      surf_action_ = hosts_.front()->pimpl_cpu->execution_start(flops_amounts_.front());
+      surf_action_ = hosts_.front()->get_cpu()->execution_start(flops_amounts_.front());
       surf_action_->set_sharing_penalty(sharing_penalty_);
       surf_action_->set_category(get_tracing_category());
 
@@ -221,7 +221,7 @@ ActivityImpl* ExecImpl::migrate(s4u::Host* to)
 {
   if (not MC_is_active() && not MC_record_replay_is_active()) {
     resource::Action* old_action = this->surf_action_;
-    resource::Action* new_action = to->pimpl_cpu->execution_start(old_action->get_cost());
+    resource::Action* new_action = to->get_cpu()->execution_start(old_action->get_cost());
     new_action->set_remains(old_action->get_remains());
     new_action->set_activity(this);
     new_action->set_sharing_penalty(old_action->get_sharing_penalty());
index 6f77d52..4f692b2 100644 (file)
@@ -30,7 +30,7 @@ IoImpl::IoImpl()
 IoImpl& IoImpl::set_timeout(double timeout)
 {
   const s4u::Host* host = get_disk()->get_host();
-  timeout_detector_ = host->pimpl_cpu->sleep(timeout);
+  timeout_detector_     = host->get_cpu()->sleep(timeout);
   timeout_detector_->set_activity(this);
   return *this;
 }
index 1b504a8..6316b12 100644 (file)
@@ -32,7 +32,7 @@ SleepImpl& SleepImpl::set_duration(double duration)
 
 SleepImpl* SleepImpl::start()
 {
-  surf_action_ = host_->pimpl_cpu->sleep(duration_);
+  surf_action_ = host_->get_cpu()->sleep(duration_);
   surf_action_->set_activity(this);
   XBT_DEBUG("Create sleep synchronization %p", this);
   return this;
index 96c5f43..2fe2082 100644 (file)
@@ -33,7 +33,7 @@ RawImpl& RawImpl::set_timeout(double timeout)
 
 RawImpl* RawImpl::start()
 {
-  surf_action_ = host_->pimpl_cpu->sleep(timeout_);
+  surf_action_ = host_->get_cpu()->sleep(timeout_);
   surf_action_->set_activity(this);
   return this;
 }
index 61e2e33..876b473 100644 (file)
@@ -156,7 +156,7 @@ double VMModel::next_occurring_event(double now)
     if (ws_vm->get_state() == s4u::VirtualMachine::State::SUSPENDED) // Ignore suspended VMs
       continue;
 
-    const kernel::resource::CpuImpl* cpu = ws_vm->pimpl_cpu;
+    const kernel::resource::CpuImpl* cpu = ws_vm->get_cpu();
 
     // solved_value below is X1 in comment above: what this VM got in the sharing on the PM
     double solved_value = ws_vm->get_vm_impl()->get_action()->get_rate();
@@ -184,7 +184,7 @@ VirtualMachineImpl::VirtualMachineImpl(const std::string& name, s4u::VirtualMach
    * The value for GUESTOS_NOISE corresponds to the cost of the global action associated to the VM.  It corresponds to
    * the cost of a VM running no tasks.
    */
-  action_ = physical_host_->pimpl_cpu->execution_start(0, core_amount_);
+  action_ = physical_host_->get_cpu()->execution_start(0, core_amount_);
 
   // It's empty for now, so it should not request resources in the PM
   update_action_weight();
@@ -288,13 +288,13 @@ void VirtualMachineImpl::set_physical_host(s4u::Host* destination)
   piface_->set_netpoint(destination->get_netpoint());
 
   /* Adapt the speed, pstate and other physical characteristics to the one of our new physical CPU */
-  piface_->pimpl_cpu->reset_vcpu(destination->pimpl_cpu);
+  piface_->get_cpu()->reset_vcpu(destination->get_cpu());
 
   physical_host_ = destination;
 
   /* Update vcpu's action for the new pm */
   /* create a cpu action bound to the pm model at the destination. */
-  kernel::resource::CpuAction* new_cpu_action = destination->pimpl_cpu->execution_start(0, this->core_amount_);
+  kernel::resource::CpuAction* new_cpu_action = destination->get_cpu()->execution_start(0, this->core_amount_);
 
   if (action_->get_remains_no_update() > 0)
     XBT_CRITICAL("FIXME: need copy the state(?), %f", action_->get_remains_no_update());
index 9db6195..b78f2cb 100644 (file)
@@ -32,6 +32,12 @@ xbt::signal<void(Host const&)> Host::on_destruction;
 xbt::signal<void(Host const&)> Host::on_state_change;
 xbt::signal<void(Host const&)> Host::on_speed_change;
 
+Host* Host::set_cpu(kernel::resource::CpuImpl* cpu)
+{
+  pimpl_cpu_ = cpu;
+  return this;
+}
+
 Host* Host::set_netpoint(kernel::routing::NetPoint* netpoint)
 {
   pimpl_netpoint_ = netpoint;
@@ -42,7 +48,7 @@ Host::~Host()
 {
   if (pimpl_netpoint_ != nullptr) // not removed yet by a children class
     Engine::get_instance()->netpoint_unregister(pimpl_netpoint_);
-  delete pimpl_cpu;
+  delete pimpl_cpu_;
 }
 
 /** @brief Fire the required callbacks and destroy the object
@@ -87,7 +93,7 @@ void Host::turn_on()
 {
   if (not is_on()) {
     kernel::actor::simcall([this] {
-      this->pimpl_cpu->turn_on();
+      this->pimpl_cpu_->turn_on();
       this->pimpl_->turn_on();
       on_state_change(*this);
     });
@@ -105,7 +111,7 @@ void Host::turn_off()
           vm->shutdown();
           vm->turn_off();
         }
-      this->pimpl_cpu->turn_off();
+      this->pimpl_cpu_->turn_off();
       this->pimpl_->turn_off(self);
 
       on_state_change(*this);
@@ -115,12 +121,12 @@ void Host::turn_off()
 
 bool Host::is_on() const
 {
-  return this->pimpl_cpu->is_on();
+  return this->pimpl_cpu_->is_on();
 }
 
 int Host::get_pstate_count() const
 {
-  return this->pimpl_cpu->get_pstate_count();
+  return this->pimpl_cpu_->get_pstate_count();
 }
 
 /**
@@ -220,7 +226,7 @@ Host* Host::set_properties(const std::unordered_map<std::string, std::string>& p
  * The profile must contain boolean values. */
 Host* Host::set_state_profile(kernel::profile::Profile* p)
 {
-  kernel::actor::simcall([this, p] { pimpl_cpu->set_state_profile(p); });
+  kernel::actor::simcall([this, p] { pimpl_cpu_->set_state_profile(p); });
   return this;
 }
 /** Specify a profile modeling the external load according to an exhaustive list or a stochastic law.
@@ -231,43 +237,43 @@ Host* Host::set_state_profile(kernel::profile::Profile* p)
  */
 Host* Host::set_speed_profile(kernel::profile::Profile* p)
 {
-  kernel::actor::simcall([this, p] { pimpl_cpu->set_speed_profile(p); });
+  kernel::actor::simcall([this, p] { pimpl_cpu_->set_speed_profile(p); });
   return this;
 }
 
 /** @brief Get the peak processor speed (in flops/s), at the specified pstate  */
 double Host::get_pstate_speed(int pstate_index) const
 {
-  return this->pimpl_cpu->get_pstate_peak_speed(pstate_index);
+  return this->pimpl_cpu_->get_pstate_peak_speed(pstate_index);
 }
 
 double Host::get_speed() const
 {
-  return this->pimpl_cpu->get_speed(1.0);
+  return this->pimpl_cpu_->get_speed(1.0);
 }
 double Host::get_load() const
 {
-  return this->pimpl_cpu->get_load();
+  return this->pimpl_cpu_->get_load();
 }
 double Host::get_available_speed() const
 {
-  return this->pimpl_cpu->get_speed_ratio();
+  return this->pimpl_cpu_->get_speed_ratio();
 }
 
 int Host::get_core_count() const
 {
-  return this->pimpl_cpu->get_core_count();
+  return this->pimpl_cpu_->get_core_count();
 }
 
 Host* Host::set_core_count(int core_count)
 {
-  kernel::actor::simcall([this, core_count] { this->pimpl_cpu->set_core_count(core_count); });
+  kernel::actor::simcall([this, core_count] { this->pimpl_cpu_->set_core_count(core_count); });
   return this;
 }
 
 Host* Host::set_pstate_speed(const std::vector<double>& speed_per_state)
 {
-  kernel::actor::simcall([this, &speed_per_state] { pimpl_cpu->set_pstate_speed(speed_per_state); });
+  kernel::actor::simcall([this, &speed_per_state] { pimpl_cpu_->set_pstate_speed(speed_per_state); });
   return this;
 }
 
@@ -295,14 +301,14 @@ Host* Host::set_pstate_speed(const std::vector<std::string>& speed_per_state)
 /** @brief Set the pstate at which the host should run */
 Host* Host::set_pstate(int pstate_index)
 {
-  kernel::actor::simcall([this, pstate_index] { this->pimpl_cpu->set_pstate(pstate_index); });
+  kernel::actor::simcall([this, pstate_index] { this->pimpl_cpu_->set_pstate(pstate_index); });
   return this;
 }
 
 /** @brief Retrieve the pstate at which the host is currently running */
 int Host::get_pstate() const
 {
-  return this->pimpl_cpu->get_pstate();
+  return this->pimpl_cpu_->get_pstate();
 }
 
 Host* Host::set_coordinates(const std::string& coords)
index 3d6f180..e81edd4 100644 (file)
@@ -159,7 +159,7 @@ void HostImpl::seal()
     return;
   }
   // seals host's CPU
-  get_iface()->pimpl_cpu->seal();
+  get_iface()->get_cpu()->seal();
   sealed_ = true;
 
   /* seal its disks */
index 8a9a5c1..ec58d4a 100644 (file)
@@ -54,7 +54,7 @@ CpuImpl::CpuImpl(s4u::Host* host, const std::vector<double>& speed_per_pstate)
 {
   speed_.scale    = 1;
   speed_.peak     = speed_per_pstate_.front();
-  host->pimpl_cpu = this;
+  host->set_cpu(this);
 }
 
 void CpuImpl::reset_vcpu(CpuImpl* that)
index 59d813d..ef0e7fc 100644 (file)
@@ -62,7 +62,7 @@ kernel::resource::Action* HostCLM03Model::execute_parallel(const std::vector<s4u
    * create the respective surf actions */
   auto net_model = host_list[0]->get_netpoint()->get_englobing_zone()->get_network_model();
   if ((host_list.size() == 1) && (has_cost(bytes_amount, 0) <= 0) && (has_cost(flops_amount, 0) > 0)) {
-    action = host_list[0]->pimpl_cpu->execution_start(flops_amount[0]);
+    action = host_list[0]->get_cpu()->execution_start(flops_amount[0]);
   } else if ((host_list.size() == 1) && (has_cost(flops_amount, 0) <= 0)) {
     action = net_model->communicate(host_list[0], host_list[0], bytes_amount[0], rate);
   } else if ((host_list.size() == 2) && (has_cost(flops_amount, 0) <= 0) && (has_cost(flops_amount, 1) <= 0)) {
index 30a4f9e..169d528 100644 (file)
@@ -193,10 +193,10 @@ L07Action::L07Action(kernel::resource::Model* model, const std::vector<s4u::Host
    * communication either */
   double bound = std::numeric_limits<double>::max();
   for (size_t i = 0; i < host_list.size(); i++) {
-    model->get_maxmin_system()->expand(host_list[i]->pimpl_cpu->get_constraint(), get_variable(),
+    model->get_maxmin_system()->expand(host_list[i]->get_cpu()->get_constraint(), get_variable(),
                                        (flops_amount == nullptr ? 0.0 : flops_amount[i]));
     if (flops_amount && flops_amount[i] > 0)
-      bound = std::min(bound, host_list[i]->pimpl_cpu->get_speed(1.0) * host_list[i]->pimpl_cpu->get_speed_ratio() /
+      bound = std::min(bound, host_list[i]->get_cpu()->get_speed(1.0) * host_list[i]->get_cpu()->get_speed_ratio() /
                                   flops_amount[i]);
   }
   if (bound < std::numeric_limits<double>::max())
index 5cf04a0..e9be9ca 100644 (file)
@@ -52,9 +52,9 @@ int main(int argc, char** argv)
   simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B");
 
   /* Let's do something on it */
-  const simgrid::kernel::resource::Action* actionA = hostA->pimpl_cpu->execution_start(1000.0);
-  const simgrid::kernel::resource::Action* actionB = hostB->pimpl_cpu->execution_start(1000.0);
-  const simgrid::kernel::resource::Action* actionC = hostB->pimpl_cpu->sleep(7.32);
+  const simgrid::kernel::resource::Action* actionA = hostA->get_cpu()->execution_start(1000.0);
+  const simgrid::kernel::resource::Action* actionB = hostB->get_cpu()->execution_start(1000.0);
+  const simgrid::kernel::resource::Action* actionC = hostB->get_cpu()->sleep(7.32);
 
   simgrid::kernel::resource::Action::State stateActionA = actionA->get_state();
   simgrid::kernel::resource::Action::State stateActionB = actionB->get_state();
index e52a0e4..34119a3 100644 (file)
@@ -34,9 +34,9 @@ int main(int argc, char** argv)
   simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B");
 
   /* Let's do something on it */
-  hostA->pimpl_cpu->execution_start(1000.0);
-  hostB->pimpl_cpu->execution_start(1000.0);
-  hostB->pimpl_cpu->sleep(7.32);
+  hostA->get_cpu()->execution_start(1000.0);
+  hostB->get_cpu()->execution_start(1000.0);
+  hostB->get_cpu()->sleep(7.32);
 
   const_sg_netzone_t as_zone = sg_zone_get_by_name("AS0");
   auto net_model             = as_zone->get_impl()->get_network_model();