* under the terms of the license (GNU LGPL) which comes with this package. */
#include "cpu_interface.hpp"
+#include "plugins/energy.hpp"
XBT_LOG_EXTERNAL_CATEGORY(surf_kernel);
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu, surf,
Cpu::Cpu(){
surf_callback_emit(cpuCreatedCallbacks, this);
+ physCpu = NULL;
}
Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
, p_constraintCoreId(NULL)
{
surf_callback_emit(cpuCreatedCallbacks, this);
+ physCpu = NULL;
}
Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
p_constraintCore[i] = lmm_constraint_new(model->getMaxminSystem(), p_constraintCoreId[i], m_powerScale * m_powerPeak);
}
}
+ physCpu = NULL;
}
Cpu::~Cpu(){
Resource::setState(state);
surf_callback_emit(cpuStateChangedCallbacks, this, old, state);
}
+
+void Cpu::setVirtual(Cpu *physCpu)
+{
+ this->physCpu = physCpu;
+ XBT_DEBUG("The CPU is virtual so associate the cpu energy to the physical cpu instead of creating a new one");
+ std::map<Cpu*, CpuEnergy*>::iterator cpu_energy_it = surf_energy->find(physCpu);
+ xbt_assert(cpu_energy_it != surf_energy->end(), "The cpu is not in surf_energy.");
+ (*surf_energy)[this] = cpu_energy_it->second;
+}
+
+Cpu* Cpu::isVirtual(void)
+{
+ return physCpu;
+}
+
/**********
* Action *
**********/
void addTraces(void);
int m_core;
double m_powerPeak; /*< CPU power peak */
- double m_powerScale; /*< Percentage of CPU available */
+ double m_powerScale; /*< Percentage of CPU disponible */
/* Note (hypervisor): */
lmm_constraint_t *p_constraintCore;
void **p_constraintCoreId;
+
+ // ////
+ // Adrien - Oct 2015. Additional code related to VM energy extensions
+ /* TODO:
+ 1./ create a VirtualCpuModel that inherits from CpuModel or create
+ a VirtualCpuCas01Model that inherist from CpuCas01Model
+ => Question: not sure which one is really usefull :( The objective is to
+ be able to create a VirtualCpu instead of a Cpu (i.e. a CpuCas01 to be exact).
+ 2. create VirtualCpu class that inherits from Cpu or create
+ a VirtualCpuCas01 class that inherits from CpuCas01 (same issue as the one described above).
+ Such modifications would enable us to remove the isVirtual method and
+ actually use the polymorphism feature of C++. It will also enable us
+ to overwrite the cpu_energy hashmap in energyCpuCreateCallBack instead of invoking
+ setVirtual().
+ So to make a long story short, it will be cleaner from the software viewpoint
+ and patches welcome ;) - Adrien October 20 2015
+ */
+ Cpu *physCpu = NULL;
+
+ /**
+ * @brief Set the current Cpu as virtual or physical
+ *
+ * @param isVirtual true to indicate this Cpu is virtual, false otherwise
+ */
+ void setVirtual(Cpu *physCpu);
+
+ /**
+ * @brief Learn if this Cpu is physical or virtual
+ *
+ * @return phys CPU if the current Cpu is a VM, null otherwise
+ */
+ Cpu* isVirtual(void);
+
+ // Adrien - Oct 2015. End of additional code related to VM energy extensions
+ // ////
};
/**********
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);
+ // Adrien - October 2015, Changes related to VM energy extensions
+ // Only report/delete and erase if the cpu_energy is related to a physical one
+ if(cpu->isVirtual() == 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()) {
double CpuEnergy::getConsumedEnergy()
{
- if(last_updated < surf_get_clock()) {
+
+ if(last_updated < surf_get_clock()) {
if (cpu->getState() == SURF_RESOURCE_OFF)
update_consumption_off(cpu, this);
else
NULL, // host->state_trace,
NULL); // host->properties,
+ p_cpu->setVirtual(sub_cpu);
+
/* 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 ? */
// vm_ws->cpu_action = surf_cpu_model_pm->extension.cpu.execute(host_PM, GUESTOS_NOISE);
p_action = sub_cpu->execute(0);
- XBT_INFO("Create VM(%s)@PM(%s) with %ld mounted disks", name, sub_ws->getName(), xbt_dynar_length(p_storage));
+ XBT_DEBUG("Create VM(%s)@PM(%s) with %ld mounted disks", name, sub_ws->getName(), xbt_dynar_length(p_storage));
}
/*