Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New: MSG_host_get_pstate() and smpi_get_host_pstate()
[simgrid.git] / src / surf / cpu_cas01.cpp
index 5464386..d5fb355 100644 (file)
@@ -6,7 +6,6 @@
 
 #include "cpu_cas01.hpp"
 #include "cpu_ti.hpp"
-#include "plugins/energy.hpp"
 #include "maxmin_private.hpp"
 #include "simgrid/sg_config.h"
 
@@ -85,7 +84,8 @@ CpuCas01Model::CpuCas01Model() : CpuModel("cpu")
   }
 
   if (getUpdateMechanism() == UM_LAZY) {
-    p_actionHeap = new ActionHeap();
+    p_actionHeap = xbt_heap_new(8, NULL);
+    xbt_heap_set_update_callback(p_actionHeap,  surf_action_lmm_update_index_heap);
     p_modifiedSet = new ActionLmmList();
     p_maxminSystem->keep_track = p_modifiedSet;
   }
@@ -97,7 +97,7 @@ CpuCas01Model::~CpuCas01Model()
   p_maxminSystem = NULL;
 
   if (p_actionHeap)
-    delete p_actionHeap;
+    xbt_heap_free(p_actionHeap);
   delete p_modifiedSet;
 
   surf_cpu_model_pm = NULL;
@@ -117,8 +117,8 @@ CpuPtr CpuCas01Model::createCpu(const char *name, xbt_dynar_t power_peak,
              "Host '%s' declared several times in the platform file",
              name);
   xbt_assert(xbt_dynar_getfirst_as(power_peak, double) > 0.0,
-      "Power has to be >0.0");
-  xbt_assert(core > 0, "Invalid number of cores %d", core);
+      "Power has to be >0.0. Did you forget to specify the mandatory power attribute?");
+  xbt_assert(core > 0, "Invalid number of cores %d. Must be larger than 0", core);
 
   cpu = new CpuCas01(this, name, power_peak, pstate, power_scale, power_trace, core, state_initial, state_trace, cpu_properties);
   xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu);
@@ -230,11 +230,9 @@ void CpuCas01::updateState(tmgr_trace_event_t event_type, double value, double d
     lmm_update_constraint_bound(getModel()->getMaxminSystem(), getConstraint(),
                                 m_core * m_powerScale *
                                 m_powerPeak);
-#ifdef HAVE_TRACING
     TRACE_surf_host_set_power(date, getName(),
                               m_core * m_powerScale *
                               m_powerPeak);
-#endif
     while ((var = lmm_get_var_from_cnst
             (getModel()->getMaxminSystem(), getConstraint(), &elem))) {
       CpuCas01ActionPtr action = static_cast<CpuCas01ActionPtr>(lmm_variable_id(var));
@@ -314,7 +312,7 @@ CpuActionPtr CpuCas01::sleep(double duration)
   lmm_update_variable_weight(getModel()->getMaxminSystem(),
                              action->getVariable(), 0.0);
   if (getModel()->getUpdateMechanism() == UM_LAZY) {     // remove action from the heap
-    action->heapRemove();
+    action->heapRemove(getModel()->getActionHeap());
     // this is necessary for a variable with weight 0 since such
     // variables are ignored in lmm and we need to set its max_duration
     // correctly at the next call to share_resources
@@ -343,14 +341,19 @@ int CpuCas01::getNbPstates()
   return xbt_dynar_length(p_powerPeakList);
 }
 
-void CpuCas01::setPowerPeakAt(int pstate_index)
+void CpuCas01::setPstate(int pstate_index)
 {
   xbt_dynar_t plist = p_powerPeakList;
   xbt_assert((pstate_index <= (int)xbt_dynar_length(plist)), "Invalid parameters (pstate index out of bounds)");
 
-  double new_power_peak = xbt_dynar_get_as(plist, pstate_index, double);
+  double new_pstate = xbt_dynar_get_as(plist, pstate_index, double);
   m_pstate = pstate_index;
-  m_powerPeak = new_power_peak;
+  m_powerPeak = new_pstate;
+}
+
+int CpuCas01::getPstate()
+{
+  return m_pstate;
 }
 
 /**********
@@ -364,6 +367,7 @@ CpuCas01Action::CpuCas01Action(ModelPtr model, double cost, bool failed, double
 {
   m_suspended = 0;
   if (model->getUpdateMechanism() == UM_LAZY) {
+    m_indexHeap = -1;
     m_lastUpdate = surf_get_clock();
     m_lastValue = 0.0;
   }