Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move NetCard to its own header file
[simgrid.git] / src / surf / surf_interface.cpp
index f90440d..3062d0c 100644 (file)
@@ -4,19 +4,18 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "src/internal_config.h"
-#include "surf_private.h"
 #include "surf_interface.hpp"
-#include "network_interface.hpp"
 #include "cpu_interface.hpp"
-#include "src/surf/HostImpl.hpp"
-#include "src/simix/smx_host_private.h"
-#include "surf_routing.hpp"
-#include "simgrid/sg_config.h"
 #include "mc/mc.h"
-#include "virtual_machine.hpp"
-#include "src/instr/instr_private.h" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
+#include "network_interface.hpp"
 #include "simgrid/s4u/engine.hpp"
+#include "simgrid/sg_config.h"
+#include "src/instr/instr_private.h" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
+#include "src/internal_config.h"
+#include "src/kernel/routing/NetCard.hpp"
+#include "src/simix/smx_host_private.h"
+#include "src/surf/HostImpl.hpp"
+#include "surf_private.h"
 #include <vector>
 
 XBT_LOG_NEW_CATEGORY(surf, "All SURF categories");
@@ -345,7 +344,6 @@ void surf_exit()
     delete model;
   delete all_existing_models;
   xbt_dynar_free(&model_list_invoke);
-  routing_exit();
 
   simgrid::surf::surfExitCallbacks();
 
@@ -528,20 +526,11 @@ void Model::updateActionsStateFull(double /*now*/, double /*delta*/)
 namespace simgrid {
 namespace surf {
 
-Resource::Resource(Model *model, const char *name)
-  : name_(xbt_strdup(name))
-  , model_(model)
-{}
-
-Resource::Resource(Model *model, const char *name, lmm_constraint_t constraint)
-  : name_(xbt_strdup(name))
-  , model_(model)
-  , constraint_(constraint)
+Resource::Resource(Model* model, const char* name, lmm_constraint_t constraint)
+    : name_(name), model_(model), constraint_(constraint)
 {}
 
-Resource::~Resource() {
-  xbt_free((void*)name_);
-}
+Resource::~Resource() = default;
 
 bool Resource::isOn() const {
   return isOn_;
@@ -565,11 +554,11 @@ Model *Resource::getModel() const {
 }
 
 const char *Resource::getName() const {
-  return name_;
+  return name_.c_str();
 }
 
 bool Resource::operator==(const Resource &other) const {
-  return strcmp(name_, other.name_);
+  return name_ == other.name_;
 }
 
 lmm_constraint_t Resource::getConstraint() const {
@@ -600,14 +589,13 @@ void surf_action_lmm_update_index_heap(void *action, int i) {
 namespace simgrid {
 namespace surf {
 
-void Action::initialize(simgrid::surf::Model *model, double cost, bool failed,
-                        lmm_variable_t var)
+Action::Action(simgrid::surf::Model* model, double cost, bool failed) : Action(model, cost, failed, nullptr)
+{
+}
+
+Action::Action(simgrid::surf::Model* model, double cost, bool failed, lmm_variable_t var)
+    : remains_(cost), start_(surf_get_clock()), cost_(cost), model_(model), variable_(var)
 {
-  remains_ = cost;
-  start_ = surf_get_clock();
-  cost_ = cost;
-  model_ = model;
-  variable_ = var;
   if (failed)
     stateSet_ = getModel()->getFailedActionSet();
   else
@@ -616,16 +604,6 @@ void Action::initialize(simgrid::surf::Model *model, double cost, bool failed,
   stateSet_->push_back(*this);
 }
 
-Action::Action(simgrid::surf::Model *model, double cost, bool failed)
-{
-  initialize(model, cost, failed);
-}
-
-Action::Action(simgrid::surf::Model *model, double cost, bool failed, lmm_variable_t var)
-{
-  initialize(model, cost, failed, var);
-}
-
 Action::~Action() {
   xbt_free(category_);
 }
@@ -705,9 +683,7 @@ void Action::setData(void* data)
 
 void Action::setCategory(const char *category)
 {
-  XBT_IN("(%p,%s)", this, category);
   category_ = xbt_strdup(category);
-  XBT_OUT();
 }
 
 void Action::ref(){
@@ -716,11 +692,9 @@ void Action::ref(){
 
 void Action::setMaxDuration(double duration)
 {
-  XBT_IN("(%p,%g)", this, duration);
   maxDuration_ = duration;
   if (getModel()->getUpdateMechanism() == UM_LAZY)      // remove action from the heap
     heapRemove(getModel()->getActionHeap());
-  XBT_OUT();
 }
 
 void Action::gapRemove() {}
@@ -769,9 +743,14 @@ void Action::suspend()
   XBT_IN("(%p)", this);
   if (suspended_ != 2) {
     lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), 0.0);
-    suspended_ = 1;
-    if (getModel()->getUpdateMechanism() == UM_LAZY)
+    if (getModel()->getUpdateMechanism() == UM_LAZY){
       heapRemove(getModel()->getActionHeap());
+      if (getModel()->getUpdateMechanism() == UM_LAZY  && stateSet_ == getModel()->getRunningActionSet() && priority_ > 0){
+        //If we have a lazy model, we need to update the remaining value accordingly
+        updateRemainingLazy(surf_get_clock());
+      }
+    }
+    suspended_ = 1;
   }
   XBT_OUT();
 }