X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/42409cb20c956bea7e678f4db5f17d27ee2bc422..6a07d63f0f7ce92c6e77881af3ca2fd1113f1fd1:/src/surf/plugins/energy.cpp diff --git a/src/surf/plugins/energy.cpp b/src/surf/plugins/energy.cpp index c7ad3f8ecb..c0aa3570ce 100644 --- a/src/surf/plugins/energy.cpp +++ b/src/surf/plugins/energy.cpp @@ -7,11 +7,11 @@ #include #include -#include -#include -#include -#include -#include +#include "simgrid/plugins/energy.h" +#include "simgrid/simix.hpp" +#include "src/surf/plugins/energy.hpp" +#include "src/surf/cpu_interface.hpp" +#include "src/surf/virtual_machine.hpp" /** @addtogroup SURF_plugin_energy @@ -65,17 +65,17 @@ simgrid::xbt::Extension HostEnergy::EXTENSION_ID /* Computes the consumption so far. Called lazily on need. */ void HostEnergy::update() { - simgrid::surf::Host* surf_host = host->extension(); + simgrid::surf::HostImpl* surf_host = host->extension(); double start_time = this->last_updated; double finish_time = surf_get_clock(); double cpu_load; - if (surf_host->p_cpu->m_speedPeak == 0) + if (surf_host->p_cpu->speed_.peak == 0) // Some users declare a pstate of speed 0 flops (eg 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->p_cpu->getConstraint()) - / surf_host->p_cpu->m_speedPeak; + / surf_host->p_cpu->speed_.peak; if (cpu_load > 1) // A machine with a load > 1 consumes as much as a fully loaded machine, not mores cpu_load = 1; @@ -83,7 +83,7 @@ void HostEnergy::update() double previous_energy = this->total_energy; double instantaneous_consumption; - if (host->is_off()) + if (host->isOff()) instantaneous_consumption = this->watts_off; else instantaneous_consumption = this->getCurrentWattsValue(cpu_load); @@ -94,7 +94,7 @@ void HostEnergy::update() 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->p_cpu->m_speedPeak, previous_energy, energy_this_step); + surf_host->getName(), start_time, finish_time, surf_host->p_cpu->speed_.peak, previous_energy, energy_this_step); } HostEnergy::HostEnergy(simgrid::s4u::Host *ptr) : @@ -199,27 +199,33 @@ void HostEnergy::initWattsRangeList() /* **************************** events callback *************************** */ static void onCreation(simgrid::s4u::Host& host) { - simgrid::surf::Host* surf_host = host.extension(); + simgrid::surf::HostImpl* surf_host = host.extension(); if (dynamic_cast(surf_host)) // Ignore virtual machines return; host.extension_set(new HostEnergy(&host)); } static void onActionStateChange(simgrid::surf::CpuAction *action, e_surf_action_state_t previous) { - const char *name = getActionCpu(action)->getName(); - simgrid::surf::Host *host = sg_host_by_name(name)->extension(); - simgrid::surf::VirtualMachine *vm = dynamic_cast(host); - if (vm) // If it's a VM, take the corresponding PM - host = vm->getPm()->extension(); - - HostEnergy *host_energy = host->p_host->extension(); - - if(host_energy->last_updated < surf_get_clock()) - host_energy->update(); + std::list cpus = getActionCpus(action); + for(simgrid::surf::Cpu* cpu : cpus) { + const char *name = cpu->getName(); + sg_host_t sghost = sg_host_by_name(name); + if(sghost == NULL) + continue; + simgrid::surf::HostImpl *host = sghost->extension(); + simgrid::surf::VirtualMachine *vm = dynamic_cast(host); + if (vm) // If it's a VM, take the corresponding PM + host = vm->getPm()->extension(); + + HostEnergy *host_energy = host->p_host->extension(); + + if(host_energy->last_updated < surf_get_clock()) + host_energy->update(); + } } static void onHostStateChange(simgrid::s4u::Host &host) { - simgrid::surf::Host* surf_host = host.extension(); + simgrid::surf::HostImpl* surf_host = host.extension(); if (dynamic_cast(surf_host)) // Ignore virtual machines return; @@ -231,7 +237,7 @@ static void onHostStateChange(simgrid::s4u::Host &host) { static void onHostDestruction(simgrid::s4u::Host& host) { // Ignore virtual machines - simgrid::surf::Host* surf_host = host.extension(); + simgrid::surf::HostImpl* surf_host = host.extension(); if (dynamic_cast(surf_host)) return; HostEnergy *host_energy = host.extension();