Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add "attach" attribute to storage tag in platform description
[simgrid.git] / src / surf / cpu_cas01.cpp
index 1174ac2..c746e9a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009-2011, 2013. The SimGrid Team.
+/* Copyright (c) 2009-2011, 2013-2014. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -171,7 +171,7 @@ void CpuCas01Model::addTraces()
     xbt_assert(host, "Host %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
 
-    host->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(host));
+    host->setStateEvent(tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(host)));
   }
 
   xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
@@ -181,8 +181,7 @@ void CpuCas01Model::addTraces()
     xbt_assert(host, "Host %s undefined", elm);
     xbt_assert(trace, "Trace %s undefined", trace_name);
 
-    host->p_powerEvent =
-        tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(host));
+    host->setPowerEvent(tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(host)));
   }
 }
 
@@ -203,7 +202,7 @@ CpuCas01::CpuCas01(CpuCas01ModelPtr model, const char *name, xbt_dynar_t powerPe
   XBT_DEBUG("CPU create: peak=%f, pstate=%d", m_powerPeak, m_pstate);
 
   m_core = core;
-  m_stateCurrent = stateInitial;
+  setState(stateInitial);
   if (powerTrace)
     p_powerEvent = tmgr_history_add_trace(history, powerTrace, 0.0, 0, static_cast<ResourcePtr>(this));
 
@@ -212,7 +211,27 @@ CpuCas01::CpuCas01(CpuCas01ModelPtr model, const char *name, xbt_dynar_t powerPe
 }
 
 CpuCas01::~CpuCas01(){
-  xbt_dynar_free(&p_powerPeakList);
+  if (getModel() == surf_cpu_model_pm)
+    xbt_dynar_free(&p_powerPeakList);
+}
+
+void CpuCas01::setStateEvent(tmgr_trace_event_t stateEvent)
+{
+  p_stateEvent = stateEvent;
+}
+
+void CpuCas01::setPowerEvent(tmgr_trace_event_t powerEvent)
+{
+  p_powerEvent = powerEvent;
+}
+
+xbt_dynar_t CpuCas01::getPowerPeakList(){
+  return p_powerPeakList;
+}
+
+int CpuCas01::getPState()
+{
+  return m_pstate;
 }
 
 bool CpuCas01::isUsed()
@@ -230,7 +249,7 @@ void CpuCas01::updateState(tmgr_trace_event_t event_type, double value, double d
        xbt_assert(m_core == 1, "FIXME: add power scaling code also for constraint_core[i]");
 
     m_powerScale = value;
-    lmm_update_constraint_bound(surf_cpu_model_pm->getMaxminSystem(), getConstraint(),
+    lmm_update_constraint_bound(getModel()->getMaxminSystem(), getConstraint(),
                                 m_core * m_powerScale *
                                 m_powerPeak);
 #ifdef HAVE_TRACING
@@ -239,10 +258,10 @@ void CpuCas01::updateState(tmgr_trace_event_t event_type, double value, double d
                               m_powerPeak);
 #endif
     while ((var = lmm_get_var_from_cnst
-            (surf_cpu_model_pm->getMaxminSystem(), getConstraint(), &elem))) {
+            (getModel()->getMaxminSystem(), getConstraint(), &elem))) {
       CpuCas01ActionPtr action = static_cast<CpuCas01ActionPtr>(static_cast<ActionPtr>(lmm_variable_id(var)));
 
-      lmm_update_variable_bound(surf_cpu_model_pm->getMaxminSystem(),
+      lmm_update_variable_bound(getModel()->getMaxminSystem(),
                                 action->getVariable(),
                                 m_powerScale * m_powerPeak);
     }
@@ -253,15 +272,15 @@ void CpuCas01::updateState(tmgr_trace_event_t event_type, double value, double d
     xbt_assert(m_core == 1, "FIXME: add state change code also for constraint_core[i]");
 
     if (value > 0) {
-      if(m_stateCurrent == SURF_RESOURCE_OFF)
+      if(getState() == SURF_RESOURCE_OFF)
         xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
-      m_stateCurrent = SURF_RESOURCE_ON;
+      setState(SURF_RESOURCE_ON);
     } else {
       lmm_constraint_t cnst = getConstraint();
 
-      m_stateCurrent = SURF_RESOURCE_OFF;
+      setState(SURF_RESOURCE_OFF);
 
-      while ((var = lmm_get_var_from_cnst(surf_cpu_model_pm->getMaxminSystem(), cnst, &elem))) {
+      while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), cnst, &elem))) {
         ActionPtr action = static_cast<ActionPtr>(lmm_variable_id(var));
 
         if (action->getState() == SURF_ACTION_RUNNING ||
@@ -286,7 +305,7 @@ CpuActionPtr CpuCas01::execute(double size)
 {
 
   XBT_IN("(%s,%g)", getName(), size);
-  CpuCas01ActionPtr action = new CpuCas01Action(surf_cpu_model_pm, size, m_stateCurrent != SURF_RESOURCE_ON,
+  CpuCas01ActionPtr action = new CpuCas01Action(getModel(), size, getState() != SURF_RESOURCE_ON,
                                                              m_powerScale * m_powerPeak, getConstraint());
 
   XBT_OUT();
@@ -299,7 +318,7 @@ CpuActionPtr CpuCas01::sleep(double duration)
     duration = MAX(duration, MAXMIN_PRECISION);
 
   XBT_IN("(%s,%g)", getName(), duration);
-  CpuCas01ActionPtr action = new CpuCas01Action(surf_cpu_model_pm, 1.0, m_stateCurrent != SURF_RESOURCE_ON,
+  CpuCas01ActionPtr action = new CpuCas01Action(getModel(), 1.0, getState() != SURF_RESOURCE_ON,
                                                       m_powerScale * m_powerPeak, getConstraint());
 
 
@@ -314,14 +333,14 @@ CpuActionPtr CpuCas01::sleep(double duration)
     action->getStateSet()->push_back(*action);
   }
 
-  lmm_update_variable_weight(surf_cpu_model_pm->getMaxminSystem(),
+  lmm_update_variable_weight(getModel()->getMaxminSystem(),
                              action->getVariable(), 0.0);
-  if (surf_cpu_model_pm->getUpdateMechanism() == UM_LAZY) {     // remove action from the heap
-    action->heapRemove(surf_cpu_model_pm->getActionHeap());
+  if (getModel()->getUpdateMechanism() == UM_LAZY) {     // remove action from the heap
+    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
-    surf_cpu_model_pm->getModifiedSet()->push_front(*action);
+    getModel()->getModifiedSet()->push_front(*action);
   }
 
   XBT_OUT();
@@ -365,9 +384,7 @@ CpuCas01Action::CpuCas01Action(ModelPtr model, double cost, bool failed, double
                     lmm_variable_new(model->getMaxminSystem(), static_cast<ActionPtr>(this),
                     1.0, power, 1))
 {
-  m_suspended = 0;     /* Should be useless because of the
-                                                          calloc but it seems to help valgrind... */
-
+  m_suspended = 0;
   if (model->getUpdateMechanism() == UM_LAZY) {
     m_indexHeap = -1;
     m_lastUpdate = surf_get_clock();