Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
please sonar (protected fields) and coding standards (uppercase enum)
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 11 Apr 2019 12:14:12 +0000 (14:14 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 11 Apr 2019 12:14:12 +0000 (14:14 +0200)
include/simgrid/kernel/resource/Action.hpp
src/kernel/resource/Action.cpp
src/surf/cpu_cas01.cpp
src/surf/cpu_ti.cpp
src/surf/network_cm02.cpp
src/surf/ptask_L07.cpp
src/surf/storage_n11.cpp

index 92ca580..a11053f 100644 (file)
@@ -75,9 +75,9 @@ public:
   };
 
   enum class SuspendStates {
   };
 
   enum class SuspendStates {
-    not_suspended = 0, /**< Action currently not suspended **/
-    suspended,
-    sleeping
+    RUNNING = 0, /**< Action currently not suspended **/
+    SUSPENDED,
+    SLEEPING
   };
 
   /**
   };
 
   /**
@@ -176,8 +176,10 @@ public:
   /** @brief Resume the current Action */
   virtual void resume();
 
   /** @brief Resume the current Action */
   virtual void resume();
 
+  /** @brief Returns true if the current action is suspended */
+  bool is_suspended() const { return suspended_ == SuspendStates::SUSPENDED; }
   /** @brief Returns true if the current action is running */
   /** @brief Returns true if the current action is running */
-  bool is_suspended();
+  bool is_running() const { return suspended_ == SuspendStates::RUNNING; }
 
   /** @brief Get the maximum duration of the current action */
   double get_max_duration() const { return max_duration_; }
 
   /** @brief Get the maximum duration of the current action */
   double get_max_duration() const { return max_duration_; }
@@ -200,10 +202,9 @@ public:
 
   simgrid::kernel::resource::Model* get_model() const { return model_; }
 
 
   simgrid::kernel::resource::Model* get_model() const { return model_; }
 
-protected:
-  StateSet* state_set_;
-
 private:
 private:
+  StateSet* state_set_;
+  Action::SuspendStates suspended_ = Action::SuspendStates::RUNNING;
   int refcount_            = 1;
   double sharing_priority_ = 1.0;             /**< priority (1.0 by default) */
   double max_duration_   = NO_MAX_DURATION; /*< max_duration (may fluctuate until the task is completed) */
   int refcount_            = 1;
   double sharing_priority_ = 1.0;             /**< priority (1.0 by default) */
   double max_duration_   = NO_MAX_DURATION; /*< max_duration (may fluctuate until the task is completed) */
@@ -236,9 +237,9 @@ public:
 
   double get_last_value() const { return last_value_; }
   void set_last_value(double val) { last_value_ = val; }
 
   double get_last_value() const { return last_value_; }
   void set_last_value(double val) { last_value_ = val; }
+  void set_suspend_state(Action::SuspendStates state) { suspended_ = state; }
 
 protected:
 
 protected:
-  Action::SuspendStates suspended_ = Action::SuspendStates::not_suspended;
 };
 
 } // namespace resource
 };
 
 } // namespace resource
index cf86b5c..ee1c70a 100644 (file)
@@ -155,7 +155,7 @@ bool Action::unref()
 void Action::suspend()
 {
   XBT_IN("(%p)", this);
 void Action::suspend()
 {
   XBT_IN("(%p)", this);
-  if (suspended_ != SuspendStates::sleeping) {
+  if (suspended_ != SuspendStates::SLEEPING) {
     get_model()->get_maxmin_system()->update_variable_weight(get_variable(), 0.0);
     if (get_model()->get_update_algorithm() == Model::UpdateAlgo::LAZY) {
       get_model()->get_action_heap().remove(this);
     get_model()->get_maxmin_system()->update_variable_weight(get_variable(), 0.0);
     if (get_model()->get_update_algorithm() == Model::UpdateAlgo::LAZY) {
       get_model()->get_action_heap().remove(this);
@@ -164,7 +164,7 @@ void Action::suspend()
         update_remains_lazy(surf_get_clock());
       }
     }
         update_remains_lazy(surf_get_clock());
       }
     }
-    suspended_ = SuspendStates::suspended;
+    suspended_ = SuspendStates::SUSPENDED;
   }
   XBT_OUT();
 }
   }
   XBT_OUT();
 }
@@ -172,20 +172,15 @@ void Action::suspend()
 void Action::resume()
 {
   XBT_IN("(%p)", this);
 void Action::resume()
 {
   XBT_IN("(%p)", this);
-  if (suspended_ != SuspendStates::sleeping) {
+  if (suspended_ != SuspendStates::SLEEPING) {
     get_model()->get_maxmin_system()->update_variable_weight(get_variable(), get_priority());
     get_model()->get_maxmin_system()->update_variable_weight(get_variable(), get_priority());
-    suspended_ = SuspendStates::not_suspended;
+    suspended_ = SuspendStates::RUNNING;
     if (get_model()->get_update_algorithm() == Model::UpdateAlgo::LAZY)
       get_model()->get_action_heap().remove(this);
   }
   XBT_OUT();
 }
 
     if (get_model()->get_update_algorithm() == Model::UpdateAlgo::LAZY)
       get_model()->get_action_heap().remove(this);
   }
   XBT_OUT();
 }
 
-bool Action::is_suspended()
-{
-  return suspended_ == SuspendStates::suspended;
-}
-
 double Action::get_remains()
 {
   XBT_IN("(%p)", this);
 double Action::get_remains()
 {
   XBT_IN("(%p)", this);
index 114e9e1..1508df7 100644 (file)
@@ -184,7 +184,7 @@ CpuAction* CpuCas01::sleep(double duration)
 
   // FIXME: sleep variables should not consume 1.0 in System::expand()
   action->set_max_duration(duration);
 
   // FIXME: sleep variables should not consume 1.0 in System::expand()
   action->set_max_duration(duration);
-  action->suspended_ = kernel::resource::Action::SuspendStates::sleeping;
+  action->set_suspend_state(kernel::resource::Action::SuspendStates::SLEEPING);
   if (duration == NO_MAX_DURATION)
     action->set_state(simgrid::kernel::resource::Action::State::IGNORED);
 
   if (duration == NO_MAX_DURATION)
     action->set_state(simgrid::kernel::resource::Action::State::IGNORED);
 
index 2ef2169..05556af 100644 (file)
@@ -444,7 +444,7 @@ void CpuTi::update_actions_finish_time(double now)
       continue;
 
     /* action suspended, skip it */
       continue;
 
     /* action suspended, skip it */
-    if (action.suspended_ != kernel::resource::Action::SuspendStates::not_suspended)
+    if (not action.is_running())
       continue;
 
     sum_priority_ += 1.0 / action.get_priority();
       continue;
 
     sum_priority_ += 1.0 / action.get_priority();
@@ -457,7 +457,7 @@ void CpuTi::update_actions_finish_time(double now)
       continue;
 
     /* verify if the action is really running on cpu */
       continue;
 
     /* verify if the action is really running on cpu */
-    if (action.suspended_ == kernel::resource::Action::SuspendStates::not_suspended && action.get_priority() > 0) {
+    if (action.is_running() && action.get_priority() > 0) {
       /* total area needed to finish the action. Used in trace integration */
       double total_area = (action.get_remains() * sum_priority_ * action.get_priority()) / speed_.peak;
 
       /* total area needed to finish the action. Used in trace integration */
       double total_area = (action.get_remains() * sum_priority_ * action.get_priority()) / speed_.peak;
 
@@ -517,7 +517,7 @@ void CpuTi::update_remaining_amount(double now)
       continue;
 
     /* action suspended, skip it */
       continue;
 
     /* action suspended, skip it */
-    if (action.suspended_ != kernel::resource::Action::SuspendStates::not_suspended)
+    if (not action.is_running())
       continue;
 
     /* action don't need update */
       continue;
 
     /* action don't need update */
@@ -556,7 +556,7 @@ CpuAction *CpuTi::sleep(double duration)
   CpuTiAction* action = new CpuTiAction(this, 1.0);
 
   action->set_max_duration(duration);
   CpuTiAction* action = new CpuTiAction(this, 1.0);
 
   action->set_max_duration(duration);
-  action->suspended_ = kernel::resource::Action::SuspendStates::sleeping;
+  action->set_suspend_state(kernel::resource::Action::SuspendStates::SLEEPING);
   if (duration == NO_MAX_DURATION)
     action->set_state(simgrid::kernel::resource::Action::State::IGNORED);
 
   if (duration == NO_MAX_DURATION)
     action->set_state(simgrid::kernel::resource::Action::State::IGNORED);
 
@@ -613,8 +613,8 @@ void CpuTiAction::cancel()
 void CpuTiAction::suspend()
 {
   XBT_IN("(%p)", this);
 void CpuTiAction::suspend()
 {
   XBT_IN("(%p)", this);
-  if (suspended_ != Action::SuspendStates::sleeping) {
-    suspended_ = Action::SuspendStates::suspended;
+  if (is_running()) {
+    set_suspend_state(Action::SuspendStates::SUSPENDED);
     get_model()->get_action_heap().remove(this);
     cpu_->set_modified(true);
   }
     get_model()->get_action_heap().remove(this);
     cpu_->set_modified(true);
   }
@@ -624,8 +624,8 @@ void CpuTiAction::suspend()
 void CpuTiAction::resume()
 {
   XBT_IN("(%p)", this);
 void CpuTiAction::resume()
 {
   XBT_IN("(%p)", this);
-  if (suspended_ != Action::SuspendStates::sleeping) {
-    suspended_ = Action::SuspendStates::not_suspended;
+  if (is_suspended()) {
+    set_suspend_state(Action::SuspendStates::RUNNING);
     cpu_->set_modified(true);
   }
   XBT_OUT();
     cpu_->set_modified(true);
   }
   XBT_OUT();
index 5bc6070..0145c1f 100644 (file)
@@ -420,10 +420,10 @@ void NetworkCm02Link::set_latency(double value)
 
 void NetworkCm02Action::update_remains_lazy(double now)
 {
 
 void NetworkCm02Action::update_remains_lazy(double now)
 {
-  if (suspended_ != Action::SuspendStates::not_suspended)
+  if (not is_running())
     return;
 
     return;
 
-  double delta        = now - get_last_update();
+  double delta = now - get_last_update();
 
   if (get_remains_no_update() > 0) {
     XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", this, get_remains_no_update(),
 
   if (get_remains_no_update() > 0) {
     XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", this, get_remains_no_update(),
index e296241..2be272c 100644 (file)
@@ -271,7 +271,7 @@ kernel::resource::Action* CpuL07::sleep(double duration)
 {
   L07Action *action = static_cast<L07Action*>(execution_start(1.0));
   action->set_max_duration(duration);
 {
   L07Action *action = static_cast<L07Action*>(execution_start(1.0));
   action->set_max_duration(duration);
-  action->suspended_ = kernel::resource::Action::SuspendStates::sleeping;
+  action->set_suspend_state(kernel::resource::Action::SuspendStates::SLEEPING);
   get_model()->get_maxmin_system()->update_variable_weight(action->get_variable(), 0.0);
 
   return action;
   get_model()->get_maxmin_system()->update_variable_weight(action->get_variable(), 0.0);
 
   return action;
@@ -405,7 +405,7 @@ void L07Action::updateBound()
   }
   double lat_bound = kernel::resource::NetworkModel::cfg_tcp_gamma / (2.0 * lat_current);
   XBT_DEBUG("action (%p) : lat_bound = %g", this, lat_bound);
   }
   double lat_bound = kernel::resource::NetworkModel::cfg_tcp_gamma / (2.0 * lat_current);
   XBT_DEBUG("action (%p) : lat_bound = %g", this, lat_bound);
-  if ((latency_ <= 0.0) && (suspended_ == Action::SuspendStates::not_suspended)) {
+  if ((latency_ <= 0.0) && is_running()) {
     if (rate_ < 0)
       get_model()->get_maxmin_system()->update_variable_bound(get_variable(), lat_bound);
     else
     if (rate_ < 0)
       get_model()->get_maxmin_system()->update_variable_bound(get_variable(), lat_bound);
     else
index f550883..1b4095a 100644 (file)
@@ -146,9 +146,9 @@ void StorageN11Action::cancel()
 void StorageN11Action::suspend()
 {
   XBT_IN("(%p)", this);
 void StorageN11Action::suspend()
 {
   XBT_IN("(%p)", this);
-  if (suspended_ != Action::SuspendStates::sleeping) {
+  if (is_running()) {
     get_model()->get_maxmin_system()->update_variable_weight(get_variable(), 0.0);
     get_model()->get_maxmin_system()->update_variable_weight(get_variable(), 0.0);
-    suspended_ = Action::SuspendStates::suspended;
+    set_suspend_state(Action::SuspendStates::SUSPENDED);
   }
   XBT_OUT();
 }
   }
   XBT_OUT();
 }