From 1fbd3090585708e05603e5c708c6a37412227f51 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 17 Oct 2016 21:53:36 +0200 Subject: [PATCH] Kill HostImpl::cpu_. Use the one of the s4u::Host --- src/s4u/s4u_host.cpp | 2 +- src/simix/smx_host.cpp | 2 +- src/surf/HostImpl.cpp | 34 +++++----------------------------- src/surf/HostImpl.hpp | 13 ++----------- src/surf/plugins/energy.cpp | 12 ++++++------ src/surf/sg_platf.cpp | 2 +- src/surf/virtual_machine.cpp | 12 ++++++------ 7 files changed, 22 insertions(+), 55 deletions(-) diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index 5675bf1dca..79cc9fc924 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -98,7 +98,7 @@ void Host::turnOn() { if (isOff()) { simgrid::simix::kernelImmediate([&]{ this->extension()->turnOn(); - this->pimpl_->turnOn(); + this->pimpl_cpu->turnOn(); }); } } diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index 57a50270eb..9977669cbf 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -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) { diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 877fce9ddf..76fce25f35 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -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; diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index a47d5660d0..6ae01d5f5c 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -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 */ diff --git a/src/surf/plugins/energy.cpp b/src/surf/plugins/energy.cpp index 48c724f6dd..9474751829 100644 --- a/src/surf/plugins/energy.cpp +++ b/src/surf/plugins/energy.cpp @@ -65,19 +65,18 @@ simgrid::xbt::Extension 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()) diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 7693e7c71b..9294509daa 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -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); diff --git a/src/surf/virtual_machine.cpp b/src/surf/virtual_machine.cpp index 1e01169b06..7c22bc5ad9 100644 --- a/src/surf/virtual_machine.cpp +++ b/src/surf/virtual_machine.cpp @@ -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(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); -- 2.20.1