Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix conflict - Adrien
authorAd(rien) L <adrien.lebre@inria.fr>
Tue, 20 Oct 2015 12:51:28 +0000 (14:51 +0200)
committerAd(rien) L <adrien.lebre@inria.fr>
Tue, 20 Oct 2015 12:51:28 +0000 (14:51 +0200)
src/surf/cpu_interface.cpp
src/surf/cpu_interface.hpp
src/surf/plugins/energy.cpp
src/surf/vm_hl13.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 *
  **********/
index 7cdd244..6ac0ad9 100644 (file)
@@ -197,11 +197,46 @@ public:
   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
+   // ////
 };
 
 /**********
index 0f66da9..d1d871f 100644 (file)
@@ -87,13 +87,19 @@ static void energyCpuDestructedCallback(Cpu *cpu){
   CpuEnergy *cpu_energy = cpu_energy_it->second;
   update_consumption(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())
@@ -200,9 +206,11 @@ double CpuEnergy::getCurrentWattsValue(double cpu_load)
 
 double CpuEnergy::getConsumedEnergy()
 {
+
        if(last_updated < surf_get_clock())
                update_consumption(cpu, this);
        return total_energy;
+
 }
 
 xbt_dynar_t CpuEnergy::getWattsRangeList()
index acb25b8..86000b2 100644 (file)
@@ -245,12 +245,14 @@ VMHL13::VMHL13(VMModel *model, const char* name, xbt_dict_t props,
       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));
 }
 
 /*