X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f4ed74ca6d4a744d2956a4f2906c897e1886cefd..6477acea9a90af165c0d8325449e8537b5709457:/src/surf/plugins/energy.cpp diff --git a/src/surf/plugins/energy.cpp b/src/surf/plugins/energy.cpp index 8be806887d..a8e9398935 100644 --- a/src/surf/plugins/energy.cpp +++ b/src/surf/plugins/energy.cpp @@ -46,7 +46,6 @@ To simulate the energy-related elements, first call the #sg_energy_plugin_init() and then use the following function to retrieve the consumption of a given host: #MSG_host_get_consumed_energy(). */ -XBT_LOG_EXTERNAL_CATEGORY(surf_kernel); XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_energy, surf, "Logging specific to the SURF energy plugin"); @@ -56,32 +55,28 @@ static void energyCpuCreatedCallback(Cpu *cpu){ (*surf_energy)[cpu] = new CpuEnergy(cpu); } -static void update_consumption_running(Cpu *cpu, CpuEnergy *cpu_energy) { + +/* Computes the consumption so far. Called lazily on need. */ +static void update_consumption(Cpu *cpu, CpuEnergy *cpu_energy) { double cpu_load = lmm_constraint_get_usage(cpu->getConstraint()) / cpu->m_powerPeak; double start_time = cpu_energy->last_updated; double finish_time = surf_get_clock(); double previous_energy = cpu_energy->total_energy; - double energy_this_step = cpu_energy->getCurrentWattsValue(cpu_load)*(finish_time-start_time); - - cpu_energy->total_energy = previous_energy + energy_this_step; - cpu_energy->last_updated = finish_time; - XBT_DEBUG("[cpu_update_energy] period=[%.2f-%.2f]; current power peak=%.0E flop/s; consumption change: %.2f J -> %.2f J", - start_time, finish_time, cpu->m_powerPeak, previous_energy, energy_this_step); -} -static void update_consumption_off(Cpu *cpu, CpuEnergy *cpu_energy) { - double start_time = cpu_energy->last_updated; - double finish_time = surf_get_clock(); + double instantaneous_consumption; + if (cpu->getState() == SURF_RESOURCE_OFF) + instantaneous_consumption = cpu_energy->watts_off; + else + instantaneous_consumption = cpu_energy->getCurrentWattsValue(cpu_load); - double previous_energy = cpu_energy->total_energy; - double energy_this_step = cpu_energy->watts_off*(finish_time-start_time); + double energy_this_step = instantaneous_consumption*(finish_time-start_time); cpu_energy->total_energy = previous_energy + energy_this_step; cpu_energy->last_updated = finish_time; - XBT_DEBUG("[cpu_update_energy] off period=[%.2f-%.2f]; consumption change: %.2f J -> %.2f J", - start_time, finish_time, previous_energy, energy_this_step); + XBT_DEBUG("[cpu_update_energy] period=[%.2f-%.2f]; current power peak=%.0E flop/s; consumption change: %.2f J -> %.2f J", + start_time, finish_time, cpu->m_powerPeak, previous_energy, energy_this_step); } static void energyCpuDestructedCallback(Cpu *cpu){ @@ -89,34 +84,31 @@ static void energyCpuDestructedCallback(Cpu *cpu){ xbt_assert(cpu_energy_it != surf_energy->end(), "The cpu is not in surf_energy."); CpuEnergy *cpu_energy = cpu_energy_it->second; - if (cpu->getState() == SURF_RESOURCE_OFF) - update_consumption_off(cpu, cpu_energy); - else - update_consumption_running(cpu, cpu_energy); - - XBT_INFO("Total energy of host %s: %f Joules", cpu->getName(), cpu_energy->getConsumedEnergy()); - delete cpu_energy_it->second; - surf_energy->erase(cpu_energy_it); + update_consumption(cpu, cpu_energy); + + // Do nothing if that's a virtual CPU, only act for physical CPUs + if(cpu->getPhysicalCPU() == NULL){ + XBT_INFO("Total energy of host %s: %f Joules", cpu->getName(), cpu_energy->getConsumedEnergy()); + delete cpu_energy_it->second; + surf_energy->erase(cpu_energy_it); + } + } static void energyCpuActionStateChangedCallback(CpuAction *action, e_surf_action_state_t old, e_surf_action_state_t cur){ Cpu *cpu = getActionCpu(action); + CpuEnergy *cpu_energy = (*surf_energy)[cpu]; - if(cpu_energy->last_updated < surf_get_clock()) { - update_consumption_running(cpu, cpu_energy); - } + if(cpu_energy->last_updated < surf_get_clock()) + update_consumption(cpu, cpu_energy); } static void energyStateChangedCallback(Cpu *cpu, e_surf_resource_state_t oldState, e_surf_resource_state_t newState){ CpuEnergy *cpu_energy = (*surf_energy)[cpu]; - if(cpu_energy->last_updated < surf_get_clock()) { - if (oldState == SURF_RESOURCE_OFF) - update_consumption_off(cpu, cpu_energy); - else - update_consumption_running(cpu, cpu_energy); - } + if(cpu_energy->last_updated < surf_get_clock()) + update_consumption(cpu, cpu_energy); } static void sg_energy_plugin_exit() @@ -144,8 +136,8 @@ void sg_energy_plugin_init() { * */ CpuEnergy::CpuEnergy(Cpu *ptr) - : cpu(ptr) { + cpu = ptr; total_energy = 0; power_range_watts_list = getWattsRangeList(); last_updated = surf_get_clock(); @@ -212,13 +204,11 @@ double CpuEnergy::getCurrentWattsValue(double cpu_load) double CpuEnergy::getConsumedEnergy() { - if(last_updated < surf_get_clock()) { - if (cpu->getState() == SURF_RESOURCE_OFF) - update_consumption_off(cpu, this); - else - update_consumption_running(cpu, this); - } - return total_energy; + + if(last_updated < surf_get_clock()) + update_consumption(cpu, this); + return total_energy; + } xbt_dynar_t CpuEnergy::getWattsRangeList()