X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c8997e63383c66e43ffde29d356fdddb65d65d81..6a07d63f0f7ce92c6e77881af3ca2fd1113f1fd1:/src/surf/plugins/energy.cpp diff --git a/src/surf/plugins/energy.cpp b/src/surf/plugins/energy.cpp index 16100e8c07..c0aa3570ce 100644 --- a/src/surf/plugins/energy.cpp +++ b/src/surf/plugins/energy.cpp @@ -65,17 +65,17 @@ simgrid::xbt::Extension HostEnergy::EXTENSION_ID /* Computes the consumption so far. Called lazily on need. */ void HostEnergy::update() { - simgrid::surf::HostImplem* 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->p_speed.peak == 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->p_speed.peak; + / 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; @@ -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->p_speed.peak, 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::HostImplem* 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::HostImplem *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::HostImplem* 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::HostImplem* surf_host = host.extension(); + simgrid::surf::HostImpl* surf_host = host.extension(); if (dynamic_cast(surf_host)) return; HostEnergy *host_energy = host.extension();