Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
inline a static function called only once
[simgrid.git] / src / surf / cpu_cas01.cpp
index b58815c..564d49b 100644 (file)
@@ -6,23 +6,12 @@
 
 #include "cpu_cas01.hpp"
 #include "cpu_ti.hpp"
-#include "plugins/energy.hpp"
 #include "maxmin_private.hpp"
 #include "simgrid/sg_config.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_cas, surf_cpu,
                                 "Logging specific to the SURF CPU IMPROVED module");
 
-/*************
- * CallBacks *
- *************/
-
-static void cpu_define_callbacks()
-{
-  sg_platf_host_add_cb(cpu_parse_init);
-  sg_platf_postparse_add_cb(cpu_add_traces);
-}
-
 /*********
  * Model *
  *********/
@@ -41,7 +30,9 @@ void surf_cpu_model_init_Cas01()
   surf_cpu_model_pm = new CpuCas01Model();
   surf_cpu_model_vm  = new CpuCas01Model();
 
-  cpu_define_callbacks();
+  sg_platf_host_add_cb(cpu_parse_init);
+  sg_platf_postparse_add_cb(cpu_add_traces);
+
   ModelPtr model_pm = surf_cpu_model_pm;
   ModelPtr model_vm = surf_cpu_model_vm;
   xbt_dynar_push(model_list, &model_pm);
@@ -114,15 +105,16 @@ CpuPtr CpuCas01Model::createCpu(const char *name, xbt_dynar_t power_peak,
                           xbt_dict_t cpu_properties)
 {
   CpuPtr cpu = NULL;
-  xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)),
+  sg_host_t host = sg_host_by_name(name);
+  xbt_assert(!sg_host_surfcpu(host),
              "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);
+  sg_host_surfcpu_set(host, cpu);
 
   return cpu;
 }
@@ -145,7 +137,7 @@ void CpuCas01Model::addTraces()
   /* connect all traces relative to hosts */
   xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
-    CpuCas01Ptr host = static_cast<CpuCas01Ptr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)));
+    CpuCas01Ptr host = static_cast<CpuCas01Ptr>(sg_host_surfcpu(sg_host_by_name(elm)));
 
     xbt_assert(host, "Host %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
@@ -155,7 +147,7 @@ void CpuCas01Model::addTraces()
 
   xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
     tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
-    CpuCas01Ptr host = static_cast<CpuCas01Ptr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)));
+    CpuCas01Ptr host = static_cast<CpuCas01Ptr>(sg_host_surfcpu(sg_host_by_name(elm)));
 
     xbt_assert(host, "Host %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
@@ -231,11 +223,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));
@@ -344,14 +334,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;
 }
 
 /**********