Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill HostImpl::cpu_. Use the one of the s4u::Host
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 17 Oct 2016 19:53:36 +0000 (21:53 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 17 Oct 2016 19:53:36 +0000 (21:53 +0200)
src/s4u/s4u_host.cpp
src/simix/smx_host.cpp
src/surf/HostImpl.cpp
src/surf/HostImpl.hpp
src/surf/plugins/energy.cpp
src/surf/sg_platf.cpp
src/surf/virtual_machine.cpp

index 5675bf1..79cc9fc 100644 (file)
@@ -98,7 +98,7 @@ void Host::turnOn() {
   if (isOff()) {
     simgrid::simix::kernelImmediate([&]{
       this->extension<simgrid::simix::Host>()->turnOn();
-      this->pimpl_->turnOn();
+      this->pimpl_cpu->turnOn();
     });
   }
 }
index 57a5027..9977669 100644 (file)
@@ -84,7 +84,7 @@ void SIMIX_host_off(sg_host_t h, smx_actor_t issuer)
   xbt_assert((host != nullptr), "Invalid parameters");
 
   if (h->isOn()) {
-    h->pimpl_->turnOff();
+    h->pimpl_cpu->turnOff();
 
     /* Clean Simulator data */
     if (xbt_swag_size(host->process_list) != 0) {
index 877fce9..76fce25 100644 (file)
@@ -37,7 +37,7 @@ void HostModel::adjustWeightOfDummyCpuActions()
   /* iterate for all virtual machines */
   for (VirtualMachine *ws_vm : VirtualMachine::allVms_) {
 
-    Cpu *cpu = ws_vm->cpu_;
+    Cpu* cpu = ws_vm->piface_->pimpl_cpu;
 
     int is_active = lmm_constraint_used(cpu->getModel()->getMaxminSystem(), cpu->getConstraint());
 
@@ -98,19 +98,14 @@ Action* HostModel::executeParallelTask(int host_nb, simgrid::s4u::Host** host_li
 /************
  * Resource *
  ************/
-HostImpl::HostImpl(simgrid::surf::HostModel *model, const char *name, xbt_dynar_t storage, Cpu *cpu)
- : Resource(model, name)
- , PropertyHolder(nullptr)
- , storage_(storage), cpu_(cpu)
+HostImpl::HostImpl(simgrid::surf::HostModel* model, const char* name, xbt_dynar_t storage)
+    : Resource(model, name), PropertyHolder(nullptr), storage_(storage)
 {
   params_.ramsize = 0;
 }
 
-HostImpl::HostImpl(simgrid::surf::HostModel *model, const char *name, lmm_constraint_t constraint,
-                 xbt_dynar_t storage, Cpu *cpu)
- : Resource(model, name, constraint)
- , PropertyHolder(nullptr)
- , storage_(storage), cpu_(cpu)
+HostImpl::HostImpl(simgrid::surf::HostModel* model, const char* name, lmm_constraint_t constraint, xbt_dynar_t storage)
+    : Resource(model, name, constraint), PropertyHolder(nullptr), storage_(storage)
 {
   params_.ramsize = 0;
 }
@@ -126,25 +121,6 @@ void HostImpl::attach(simgrid::s4u::Host* host)
   piface_ = host;
 }
 
-bool HostImpl::isOn() const {
-  return cpu_->isOn();
-}
-bool HostImpl::isOff() const {
-  return cpu_->isOff();
-}
-void HostImpl::turnOn(){
-  if (isOff()) {
-    cpu_->turnOn();
-    simgrid::s4u::Host::onStateChange(*this->piface_);
-  }
-}
-void HostImpl::turnOff(){
-  if (isOn()) {
-    cpu_->turnOff();
-    simgrid::s4u::Host::onStateChange(*this->piface_);
-  }
-}
-
 simgrid::surf::Storage *HostImpl::findStorageOnMountList(const char* mount)
 {
   simgrid::surf::Storage *st = nullptr;
index a47d566..6ae01d5 100644 (file)
@@ -74,9 +74,8 @@ public:
    * @param model HostModel associated to this Host
    * @param name The name of the Host
    * @param storage The Storage associated to this Host
-   * @param cpu The Cpu associated to this Host
    */
-  HostImpl(HostModel *model, const char *name, xbt_dynar_t storage, Cpu *cpu);
+  HostImpl(HostModel* model, const char* name, xbt_dynar_t storage);
 
   /**
    * @brief Host constructor
@@ -85,10 +84,8 @@ public:
    * @param name The name of the Host
    * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
    * @param storage The Storage associated to this Host
-   * @param cpu The Cpu associated to this Host
    */
-  HostImpl(HostModel *model, const char *name,
-      lmm_constraint_t constraint, xbt_dynar_t storage, Cpu *cpu);
+  HostImpl(HostModel* model, const char* name, lmm_constraint_t constraint, xbt_dynar_t storage);
 
   /* Host destruction logic */
   /**************************/
@@ -102,11 +99,6 @@ public:
   }
   void attach(simgrid::s4u::Host* host);
 
-  bool isOn() const override;
-  bool isOff() const override;
-  void turnOn() override;
-  void turnOff() override;
-
   /** @brief Return the storage of corresponding mount point */
   virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
 
@@ -220,7 +212,6 @@ public:
 
 public:
   xbt_dynar_t storage_        = nullptr;
-  Cpu* cpu_                   = nullptr;
   simgrid::s4u::Host* piface_ = nullptr;
 
   /** @brief Get the list of virtual machines on the current Host */
index 48c724f..9474751 100644 (file)
@@ -65,19 +65,18 @@ simgrid::xbt::Extension<simgrid::s4u::Host, HostEnergy> HostEnergy::EXTENSION_ID
 /* Computes the consumption so far.  Called lazily on need. */
 void HostEnergy::update()
 {
-  simgrid::surf::HostImpl* surf_host = host->pimpl_;
   double start_time = this->last_updated;
   double finish_time = surf_get_clock();
   double cpu_load;
-  if (surf_host->cpu_->getPstateSpeedCurrent() <= 0)
+  if (host->pimpl_cpu->getPstateSpeedCurrent() <= 0)
     // Some users declare a pstate of speed 0 flops (e.g., to model boot time).
     // We consider that the machine is then fully loaded. That's arbitrary but it avoids a NaN
     cpu_load = 1;
   else
-    cpu_load = lmm_constraint_get_usage(surf_host->cpu_->getConstraint()) / surf_host->cpu_->getPstateSpeedCurrent();
+    cpu_load = lmm_constraint_get_usage(host->pimpl_cpu->getConstraint()) / host->pimpl_cpu->getPstateSpeedCurrent();
 
   /** Divide by the number of cores here **/
-  cpu_load /= surf_host->cpu_->coreCount();
+  cpu_load /= host->pimpl_cpu->coreCount();
 
   if (cpu_load > 1) // A machine with a load > 1 consumes as much as a fully loaded machine, not more
     cpu_load = 1;
@@ -103,8 +102,9 @@ void HostEnergy::update()
   this->total_energy = previous_energy + energy_this_step;
   this->last_updated = finish_time;
 
-  XBT_DEBUG("[update_energy of %s] period=[%.2f-%.2f]; current power peak=%.0E flop/s; consumption change: %.2f J -> %.2f J",
-      surf_host->getName(), start_time, finish_time, surf_host->cpu_->speed_.peak, previous_energy, energy_this_step);
+  XBT_DEBUG(
+      "[update_energy of %s] period=[%.2f-%.2f]; current power peak=%.0E flop/s; consumption change: %.2f J -> %.2f J",
+      host->name().c_str(), start_time, finish_time, host->pimpl_cpu->speed_.peak, previous_energy, energy_this_step);
 }
 
 HostEnergy::HostEnergy(simgrid::s4u::Host *ptr) : host(ptr), last_updated(surf_get_clock())
index 7693e7c..9294509 100644 (file)
@@ -111,7 +111,7 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host)
   if (host->speed_trace)
     cpu->setSpeedTrace(host->speed_trace);
 
-  simgrid::surf::HostImpl* hi = new simgrid::surf::HostImpl(surf_host_model, host->id, mount_list, cpu);
+  simgrid::surf::HostImpl* hi = new simgrid::surf::HostImpl(surf_host_model, host->id, mount_list);
   hi->attach(h);
   xbt_lib_set(storage_lib, host->id, ROUTING_STORAGE_HOST_LEVEL, (void*)mount_list);
 
index 1e01169..7c22bc5 100644 (file)
@@ -78,7 +78,7 @@ double VMModel::nextOccuringEvent(double now)
 
   /* iterate for all virtual machines */
   for (VirtualMachine *ws_vm : VirtualMachine::allVms_) {
-    Cpu *cpu = ws_vm->cpu_;
+    Cpu* cpu = ws_vm->piface_->pimpl_cpu;
     xbt_assert(cpu, "cpu-less host");
 
     double solved_value = ws_vm->action_->getVariable()->value;
@@ -104,7 +104,7 @@ double VMModel::nextOccuringEvent(double now)
  ************/
 
 VirtualMachine::VirtualMachine(HostModel* model, const char* name, simgrid::s4u::Host* host_PM)
-    : HostImpl(model, name, nullptr /*constraint*/, nullptr /*storage*/, nullptr /*cpu*/), hostPM_(host_PM)
+    : HostImpl(model, name, nullptr /*constraint*/, nullptr /*storage*/), hostPM_(host_PM)
 {
   /* Register this VM to the list of all VMs */
   allVms_.push_back(this);
@@ -124,9 +124,9 @@ VirtualMachine::VirtualMachine(HostModel* model, const char* name, simgrid::s4u:
   // Roughly, create a vcpu resource by using the values of the sub_cpu one.
   CpuCas01 *sub_cpu = dynamic_cast<CpuCas01*>(host_PM->pimpl_cpu);
 
-  cpu_ = surf_cpu_model_vm->createCpu(piface_, sub_cpu->getSpeedPeakList(), 1 /*cores*/);
+  piface_->pimpl_cpu = surf_cpu_model_vm->createCpu(piface_, sub_cpu->getSpeedPeakList(), 1 /*cores*/);
   if (sub_cpu->getPState() != 0)
-    cpu_->setPState(sub_cpu->getPState());
+    piface_->pimpl_cpu->setPState(sub_cpu->getPState());
 
   /* We create cpu_action corresponding to a VM process on the host operating system. */
   /* FIXME: TODO: we have to periodically input GUESTOS_NOISE to the system? how ? */
@@ -146,8 +146,6 @@ VirtualMachine::~VirtualMachine()
   /* Free the cpu_action of the VM. */
   XBT_ATTRIB_UNUSED int ret = action_->unref();
   xbt_assert(ret == 1, "Bug: some resource still remains");
-
-  delete cpu_;
 }
 
 e_surf_vm_state_t VirtualMachine::getState() {
@@ -158,12 +156,14 @@ void VirtualMachine::setState(e_surf_vm_state_t state) {
   vmState_ = state;
 }
 void VirtualMachine::turnOn() {
+  THROW_DEADCODE;
   if (isOff()) {
     Resource::turnOn();
     onVmStateChange(this);
   }
 }
 void VirtualMachine::turnOff() {
+  THROW_DEADCODE;
   if (isOn()) {
     Resource::turnOff();
     onVmStateChange(this);