Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sanitize the surf API
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 7 Feb 2016 22:27:36 +0000 (23:27 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 7 Feb 2016 22:27:39 +0000 (23:27 +0100)
updateState() and friends don't need to have the current date passed
as an parameter: they can use surf_get_time() on the rare cases where
they need it.

This makes the surf_solve loop rather ugly as the code is not ready to
jump to the right time to handle events yet. Will soon be fixed.

17 files changed:
src/surf/cpu_cas01.cpp
src/surf/cpu_cas01.hpp
src/surf/cpu_ti.cpp
src/surf/cpu_ti.hpp
src/surf/host_interface.hpp
src/surf/host_ptask_L07.cpp
src/surf/host_ptask_L07.hpp
src/surf/network_cm02.cpp
src/surf/network_cm02.hpp
src/surf/network_interface.hpp
src/surf/network_ns3.cpp
src/surf/network_ns3.hpp
src/surf/storage_interface.cpp
src/surf/storage_interface.hpp
src/surf/surf_c_bindings.cpp
src/surf/surf_interface.hpp
teshsuite/surf/trace_usage/trace_usage.cpp

index 08a68e8..7b28ade 100644 (file)
@@ -183,7 +183,7 @@ void CpuCas01::onSpeedChange() {
   Cpu::onSpeedChange();
 }
 
-void CpuCas01::updateState(tmgr_trace_iterator_t event_type, double value, double date)
+void CpuCas01::updateState(tmgr_trace_iterator_t event_type, double value)
 {
   lmm_variable_t var = NULL;
   lmm_element_t elem = NULL;
@@ -206,6 +206,7 @@ void CpuCas01::updateState(tmgr_trace_iterator_t event_type, double value, doubl
       turnOn();
     } else {
       lmm_constraint_t cnst = getConstraint();
+      double date = surf_get_clock();
 
       turnOff();
 
index 59d9930..ff12def 100644 (file)
@@ -47,7 +47,7 @@ public:
         int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
         int initiallyOn, tmgr_trace_t stateTrace) ;
   ~CpuCas01();
-  void updateState(tmgr_trace_iterator_t event_type, double value, double date) override;
+  void updateState(tmgr_trace_iterator_t event_type, double value) override;
   CpuAction *execution_start(double size) override;
   CpuAction *sleep(double duration) override;
 
index 01beca9..2f97c5b 100644 (file)
@@ -561,8 +561,7 @@ void CpuTi::set_speed_trace(tmgr_trace_t trace)
   }
 }
 
-void CpuTi::updateState(tmgr_trace_iterator_t event_type,
-                        double value, double date)
+void CpuTi::updateState(tmgr_trace_iterator_t event_type, double value)
 {
   CpuTiAction *action;
 
@@ -571,10 +570,9 @@ void CpuTi::updateState(tmgr_trace_iterator_t event_type,
     CpuTiTgmr *trace;
     s_tmgr_event_t val;
 
-    XBT_DEBUG("Finish trace date: %f value %f date %f", surf_get_clock(),
-           value, date);
+    XBT_DEBUG("Finish trace date: value %f", value);
     /* update remaining of actions and put in modified cpu swag */
-    updateRemainingAmount(date);
+    updateRemainingAmount(surf_get_clock());
 
     modified(true);
 
@@ -599,6 +597,7 @@ void CpuTi::updateState(tmgr_trace_iterator_t event_type,
       turnOn();
     } else {
       turnOff();
+      double date = surf_get_clock();
 
       /* put all action running on cpu to failed */
       for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
index d4d305a..9538984 100644 (file)
@@ -120,8 +120,10 @@ public:
 
   void set_speed_trace(tmgr_trace_t trace);
 
-  void updateState(tmgr_trace_iterator_t event_type, double value, double date) override;
+  void updateState(tmgr_trace_iterator_t event_type, double value) override;
   void updateActionsFinishTime(double now);
+  void updateRemainingAmount(double now);
+
   bool isUsed() override;
   CpuAction *execution_start(double size) override;
   CpuAction *sleep(double duration) override;
@@ -136,7 +138,6 @@ public:
 
   double current_frequency;
 
-  void updateRemainingAmount(double now);
 public:
   boost::intrusive::list_member_hook<> cpu_ti_hook;
 };
index a6f84f2..9ab3f50 100644 (file)
@@ -229,7 +229,7 @@ public:
   virtual int fileMove(surf_file_t fd, const char* fullpath);
 
   bool isUsed() override {DIE_IMPOSSIBLE;} // FIXME: Host should not be a Resource
-  void updateState(tmgr_trace_iterator_t event_type, double value, double date) override
+  void updateState(tmgr_trace_iterator_t event_type, double value) override
     {THROW_IMPOSSIBLE;} // FIXME: Host should not be a Resource
 
 public:
index d77a0f7..54ad084 100644 (file)
@@ -480,7 +480,7 @@ bool LinkL07::isUsed(){
   return lmm_constraint_used(getModel()->getMaxminSystem(), getConstraint());
 }
 
-void CpuL07::updateState(tmgr_trace_iterator_t triggered, double value, double /*date*/){
+void CpuL07::updateState(tmgr_trace_iterator_t triggered, double value){
   XBT_DEBUG("Updating cpu %s (%p) with value %g", getName(), this, value);
   if (triggered == p_speedEvent) {
     m_speedScale = value;
@@ -497,13 +497,13 @@ void CpuL07::updateState(tmgr_trace_iterator_t triggered, double value, double /
   }
 }
 
-void LinkL07::updateState(tmgr_trace_iterator_t triggered, double value, double date) {
-  XBT_DEBUG("Updating link %s (%p) with value=%f for date=%g", getName(), this, value, date);
+void LinkL07::updateState(tmgr_trace_iterator_t triggered, double value) {
+  XBT_DEBUG("Updating link %s (%p) with value=%f", getName(), this, value);
   if (triggered == m_bandwidth.event) {
-    updateBandwidth(value, date);
+    updateBandwidth(value);
     tmgr_trace_event_unref(&m_bandwidth.event);
   } else if (triggered == m_latency.event) {
-    updateLatency(value, date);
+    updateLatency(value);
     tmgr_trace_event_unref(&m_latency.event);
   } else if (triggered == m_stateEvent) {
     if (value > 0)
@@ -516,13 +516,13 @@ void LinkL07::updateState(tmgr_trace_iterator_t triggered, double value, double
   }
 }
 
-void LinkL07::updateBandwidth(double value, double date)
+void LinkL07::updateBandwidth(double value)
 {
   m_bandwidth.peak = value;
   lmm_update_constraint_bound(getModel()->getMaxminSystem(), getConstraint(), m_bandwidth.peak * m_bandwidth.scale);
 }
 
-void LinkL07::updateLatency(double value, double date)
+void LinkL07::updateLatency(double value)
 {
   lmm_variable_t var = NULL;
   L07Action *action;
index 18a3d3f..1e1064d 100644 (file)
@@ -99,7 +99,7 @@ public:
      int core, int initiallyOn, tmgr_trace_t state_trace);
   ~CpuL07();
   bool isUsed() override;
-  void updateState(tmgr_trace_iterator_t event_type, double value, double date) override;
+  void updateState(tmgr_trace_iterator_t event_type, double value) override;
   Action *execution_start(double size) override;
   Action *sleep(double duration) override;
 protected:
@@ -118,9 +118,9 @@ public:
           e_surf_link_sharing_policy_t policy);
   ~LinkL07(){ };
   bool isUsed() override;
-  void updateState(tmgr_trace_iterator_t event_type, double value, double date) override;
-  void updateBandwidth(double value, double date=surf_get_clock()) override;
-  void updateLatency(double value, double date=surf_get_clock()) override;
+  void updateState(tmgr_trace_iterator_t event_type, double value) override;
+  void updateBandwidth(double value) override;
+  void updateLatency(double value) override;
 };
 
 /**********
index 7adf7b1..c3be602 100644 (file)
@@ -170,10 +170,7 @@ NetworkCm02Model::NetworkCm02Model()
   } else if (!strcmp(optim, "Lazy")) {
     p_updateMechanism = UM_LAZY;
     m_selectiveUpdate = 1;
-    xbt_assert((select == 1)
-               ||
-               (xbt_cfg_is_default_value
-                (_sg_cfg_set, "network/maxmin_selective_update")),
+    xbt_assert((select == 1) || (xbt_cfg_is_default_value(_sg_cfg_set, "network/maxmin_selective_update")),
                "Disabling selective update while using the lazy update mechanism is dumb!");
   } else {
     xbt_die("Unsupported optimization (%s) for this model", optim);
@@ -545,16 +542,15 @@ NetworkCm02Link::NetworkCm02Link(NetworkCm02Model *model, const char *name, xbt_
 
 
 
-void NetworkCm02Link::updateState(tmgr_trace_iterator_t triggered,
-                                      double value, double date)
+void NetworkCm02Link::updateState(tmgr_trace_iterator_t triggered, double value)
 {
 
   /* Find out which of my iterators was triggered, and react accordingly */
   if (triggered == m_bandwidth.event) {
-    updateBandwidth(value, date);
+    updateBandwidth(value);
     tmgr_trace_event_unref(&m_bandwidth.event);
   } else if (triggered == m_latency.event) {
-    updateLatency(value, date);
+    updateLatency(value);
     tmgr_trace_event_unref(&m_latency.event);
   } else if (triggered == m_stateEvent) {
     if (value > 0)
@@ -562,6 +558,7 @@ void NetworkCm02Link::updateState(tmgr_trace_iterator_t triggered,
     else {
       lmm_variable_t var = NULL;
       lmm_element_t elem = NULL;
+      double now = surf_get_clock();
 
       turnOff();
       while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), getConstraint(), &elem))) {
@@ -569,7 +566,7 @@ void NetworkCm02Link::updateState(tmgr_trace_iterator_t triggered,
 
         if (action->getState() == SURF_ACTION_RUNNING ||
             action->getState() == SURF_ACTION_READY) {
-          action->setFinishTime(date);
+          action->setFinishTime(now);
           action->setState(SURF_ACTION_FAILED);
         }
       }
@@ -584,7 +581,7 @@ void NetworkCm02Link::updateState(tmgr_trace_iterator_t triggered,
        getConstraint());
 }
 
-void NetworkCm02Link::updateBandwidth(double value, double date){
+void NetworkCm02Link::updateBandwidth(double value{
   double delta = sg_weight_S_parameter / value - sg_weight_S_parameter /
                  (m_bandwidth.peak * m_bandwidth.scale);
   lmm_variable_t var = NULL;
@@ -599,7 +596,7 @@ void NetworkCm02Link::updateBandwidth(double value, double date){
                               getConstraint(),
                               sg_bandwidth_factor *
                               (m_bandwidth.peak * m_bandwidth.scale));
-  TRACE_surf_link_set_bandwidth(date, getName(), sg_bandwidth_factor * m_bandwidth.peak * m_bandwidth.scale);
+  TRACE_surf_link_set_bandwidth(surf_get_clock(), getName(), sg_bandwidth_factor * m_bandwidth.peak * m_bandwidth.scale);
   if (sg_weight_S_parameter > 0) {
     while ((var = lmm_get_var_from_cnst_safe(getModel()->getMaxminSystem(), getConstraint(), &elem, &nextelem, &numelem))) {
       action = (NetworkCm02Action*) lmm_variable_id(var);
@@ -610,7 +607,7 @@ void NetworkCm02Link::updateBandwidth(double value, double date){
   }
 }
 
-void NetworkCm02Link::updateLatency(double value, double date){
+void NetworkCm02Link::updateLatency(double value){
   double delta = value - m_latency.peak;
   lmm_variable_t var = NULL;
   lmm_element_t elem = NULL;
index a5c4284..e4fa8f6 100644 (file)
@@ -82,9 +82,9 @@ public:
                              double lat_initial,
                              tmgr_trace_t lat_trace,
                                e_surf_link_sharing_policy_t policy);
-  void updateState(tmgr_trace_iterator_t event_type, double value, double date) override;
-  void updateBandwidth(double value, double date=surf_get_clock()) override;
-  void updateLatency(double value, double date=surf_get_clock()) override;
+  void updateState(tmgr_trace_iterator_t event_type, double value) override;
+  void updateBandwidth(double value) override;
+  void updateLatency(double value) override;
   virtual void gapAppend(double /*size*/, const Link* /*link*/, NetworkAction * /*action*/) {};
 
 
index e199d1d..cba3892 100644 (file)
@@ -218,13 +218,13 @@ public:
   virtual double getBandwidth();
 
   /** @brief Update the bandwidth in bytes per second of current Link */
-  virtual void updateBandwidth(double value, double date=surf_get_clock())=0;
+  virtual void updateBandwidth(double value)=0;
 
   /** @brief Get the latency in seconds of current Link */
   virtual double getLatency();
 
   /** @brief Update the latency in seconds of current Link */
-  virtual void updateLatency(double value, double date=surf_get_clock())=0;
+  virtual void updateLatency(double value)=0;
 
   /** @brief The sharing policy is a @{link e_surf_link_sharing_policy_t::EType} (0: FATPIPE, 1: SHARED, 2: FULLDUPLEX) */
   virtual int sharingPolicy();
index 0006945..2143f2c 100644 (file)
@@ -401,9 +401,9 @@ NetworkNS3Link::~NetworkNS3Link()
 {
 }
 
-void NetworkNS3Link::updateState(tmgr_trace_iterator_t event_type, double value, double date)
+void NetworkNS3Link::updateState(tmgr_trace_iterator_t event_type, double value)
 {
-
+  THROW_UNIMPLEMENTED;
 }
 
 /**********
index 57c31ab..bbcbb1c 100644 (file)
@@ -70,9 +70,9 @@ public:
                double bw_initial, double lat_initial);
   ~NetworkNS3Link();
 
-  void updateState(tmgr_trace_iterator_t event_type, double value, double date);
-  void updateBandwidth(double value, double date=surf_get_clock()){THROW_UNIMPLEMENTED;}
-  void updateLatency(double value, double date=surf_get_clock()){THROW_UNIMPLEMENTED;}
+  void updateState(tmgr_trace_iterator_t event_type, double value) override;
+  void updateBandwidth(double value) override {THROW_UNIMPLEMENTED;}
+  void updateLatency(double value) override {THROW_UNIMPLEMENTED;}
 
 //private:
  int m_created;
index 7cc21ff..866fd71 100644 (file)
@@ -140,7 +140,7 @@ bool Storage::isUsed()
   return false;
 }
 
-void Storage::updateState(tmgr_trace_iterator_t /*event_type*/, double /*value*/, double /*date*/)
+void Storage::updateState(tmgr_trace_iterator_t /*event_type*/, double /*value*/)
 {
   THROW_UNIMPLEMENTED;
 }
index 2bcd3b6..60ec6c6 100644 (file)
@@ -147,7 +147,7 @@ public:
    * @param value [description]
    * @param date [description]
    */
-  void updateState(tmgr_trace_iterator_t event_type, double value, double date) override;
+  void updateState(tmgr_trace_iterator_t event_type, double value) override;
 
   void turnOn() override;
   void turnOff() override;
index 16ead87..b6a24be 100644 (file)
@@ -44,7 +44,7 @@ void surf_presolve(void)
 
     while ((event = future_evt_set->pop_leq(next_event_date, &value, &resource))) {
       if (value >= 0){
-        resource->updateState(event, value, NOW);
+        resource->updateState(event, value);
       }
     }
   }
@@ -68,7 +68,7 @@ double surf_solve(double max_date)
   if(!host_that_restart)
     host_that_restart = xbt_dynar_new(sizeof(char*), NULL);
 
-  if (max_date != -1.0 && max_date != NOW) {
+  if (max_date > 0.0 && max_date != NOW) {
     surf_min = max_date - NOW;
   }
 
@@ -96,8 +96,8 @@ double surf_solve(double max_date)
     if(! surf_network_model->shareResourcesIsIdempotent()){ // NS3, I see you
       if (next_event_date!=-1.0 && surf_min!=-1.0) {
         surf_min = MIN(next_event_date - NOW, surf_min);
-      } else{
-        surf_min = MAX(next_event_date - NOW, surf_min);
+      } else {
+        surf_min = MAX(next_event_date - NOW, surf_min); // Get the positive component
       }
 
       XBT_DEBUG("Run the NS3 network at most %fs", surf_min);
@@ -124,10 +124,14 @@ double surf_solve(double max_date)
         surf_min = next_event_date - NOW;
         XBT_DEBUG("This event will modify model state. Next event set to %f", surf_min);
       }
+      // FIXME: I'm too lame to update NOW live, so I change it and restore it so that the real update with surf_min will work
+      double round_start = NOW;
+      NOW = next_event_date;
       /* update state of the corresponding resource to the new value. Does not touch lmm.
          It will be modified if needed when updating actions */
-      XBT_DEBUG("Calling update_resource_state for resource %s with min %f", resource->getName(), surf_min);
-      resource->updateState(event, value, next_event_date);
+      XBT_DEBUG("Calling update_resource_state for resource %s", resource->getName());
+      resource->updateState(event, value);
+      NOW = round_start;
     }
   }
 
index d0739e7..aff65e2 100644 (file)
@@ -417,9 +417,8 @@ public:
    *
    * @param event_type [TODO]
    * @param value [TODO]
-   * @param date [TODO]
    */
-  virtual void updateState(tmgr_trace_iterator_t event_type, double value, double date)=0;
+  virtual void updateState(tmgr_trace_iterator_t event_type, double value)=0;
 
   /** @brief Check if the current Resource is used (if it currently serves an action) */
   virtual bool isUsed()=0;
index c9fb7e4..d7e3efe 100644 (file)
@@ -24,7 +24,7 @@ class DummyTestResource
 public:
   DummyTestResource(const char *name) : Resource(nullptr,name) {}
   bool isUsed() override {return false;}
-  void updateState(tmgr_trace_iterator_t it, double date, double value) override {}
+  void updateState(tmgr_trace_iterator_t it, double value) override {}
 };
 
 static void test(void)