+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->extension<simgrid::surf::HostImpl>();
+ double start_time = this->last_updated;
+ double finish_time = surf_get_clock();
+ double cpu_load;
+ 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->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;
+
+ double previous_energy = this->total_energy;
+
+ double instantaneous_consumption;
+ if (host->isOff())
+ instantaneous_consumption = this->watts_off;
+ else
+ instantaneous_consumption = this->getCurrentWattsValue(cpu_load);
+
+ double energy_this_step = instantaneous_consumption*(finish_time-start_time);
+
+ 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->p_cpu->speed_.peak, previous_energy, energy_this_step);
+}
+
+HostEnergy::HostEnergy(simgrid::s4u::Host *ptr) :