Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add VM energy extensions - Adrien
[simgrid.git] / src / surf / cpu_interface.cpp
index c28f8cc..03cea6d 100644 (file)
@@ -5,6 +5,7 @@
  * 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,
@@ -143,6 +144,7 @@ void CpuModel::updateActionsStateFull(double now, double delta)
 
 Cpu::Cpu(){
   surf_callback_emit(cpuCreatedCallbacks, this);
+  physCpu = NULL; 
 }
 
 Cpu::Cpu(Model *model, const char *name, xbt_dict_t props,
@@ -155,6 +157,7 @@ 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,
@@ -182,6 +185,7 @@ 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(){
@@ -223,6 +227,21 @@ void Cpu::setState(e_surf_resource_state_t state)
   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 *
  **********/