Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
attempt to fully trace ptasks
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 9 Jul 2018 15:31:36 +0000 (17:31 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 9 Jul 2018 15:31:36 +0000 (17:31 +0200)
include/simgrid/s4u/Link.hpp
src/instr/instr_platform.cpp
src/plugins/link_energy.cpp
src/s4u/s4u_Link.cpp
src/surf/cpu_interface.cpp
src/surf/network_ib.cpp
src/surf/network_interface.cpp
src/surf/ptask_L07.cpp

index e1832a8..fd692f5 100644 (file)
@@ -6,6 +6,7 @@
 #ifndef S4U_LINK_HPP_
 #define S4U_LINK_HPP_
 
+#include <simgrid/kernel/resource/Action.hpp>
 #include <simgrid/link.h>
 #include <string>
 #include <unordered_map>
@@ -91,7 +92,8 @@ public:
   static simgrid::xbt::signal<void(kernel::resource::NetworkAction*, s4u::Host* src, s4u::Host* dst)> on_communicate;
 
   /** @brief Callback signal fired when a communication changes it state (ready/done/cancel) */
-  static simgrid::xbt::signal<void(kernel::resource::NetworkAction*)> on_communication_state_change;
+  static simgrid::xbt::signal<void(kernel::resource::NetworkAction*, kernel::resource::Action::State)>
+      on_communication_state_change;
 
   // Deprecated methods
   XBT_ATTRIB_DEPRECATED_v323("Please use Link::by_name()") static Link* byName(const char* name) { return by_name(name); }
index 7a6c2b0..695fcb9 100644 (file)
@@ -232,27 +232,31 @@ static void instr_host_on_speed_change(simgrid::s4u::Host& host)
       ->set_event(surf_get_clock(), host.get_core_count() * host.get_available_speed());
 }
 
-static void instr_cpu_action_on_state_change(simgrid::surf::CpuAction* action,
-                                             simgrid::kernel::resource::Action::State /* previous */)
-{
-  simgrid::surf::Cpu* cpu = static_cast<simgrid::surf::Cpu*>(action->get_variable()->get_constraint(0)->get_id());
-  TRACE_surf_resource_set_utilization("HOST", "power_used", cpu->get_cname(), action->get_category(),
-                                      action->get_variable()->get_value(), action->get_last_update(),
-                                      SIMIX_get_clock() - action->get_last_update());
-}
-
-static void instr_link_on_communication_state_change(simgrid::kernel::resource::NetworkAction* action)
+static void instr_action_on_state_change(simgrid::kernel::resource::Action* action,
+                                         simgrid::kernel::resource::Action::State /* previous */)
 {
   int n = action->get_variable()->get_number_of_constraint();
 
   for (int i = 0; i < n; i++) {
-    simgrid::kernel::lmm::Constraint* constraint = action->get_variable()->get_constraint(i);
-    simgrid::kernel::resource::LinkImpl* link = static_cast<simgrid::kernel::resource::LinkImpl*>(constraint->get_id());
-    double value = action->get_variable()->get_value() * action->get_variable()->get_constraint_weight(i);
-    TRACE_surf_resource_set_utilization("LINK", "bandwidth_used", link->get_cname(), action->get_category(), value,
-                                        action->get_last_update(), SIMIX_get_clock() - action->get_last_update());
+    /* Beware of composite actions: ptasks put links and cpus together. Extra pb: we cannot dynamic_cast from void* */
+    simgrid::kernel::resource::Resource* resource =
+        static_cast<simgrid::kernel::resource::Resource*>(action->get_variable()->get_constraint(i)->get_id());
+    simgrid::surf::Cpu* cpu = dynamic_cast<simgrid::surf::Cpu*>(resource);
+
+    if (cpu != nullptr)
+      TRACE_surf_resource_set_utilization("HOST", "power_used", cpu->get_cname(), action->get_category(),
+                                          action->get_variable()->get_value(), action->get_last_update(),
+                                          SIMIX_get_clock() - action->get_last_update());
+    simgrid::kernel::resource::LinkImpl* link = dynamic_cast<simgrid::kernel::resource::LinkImpl*>(resource);
+
+    if (link != nullptr) {
+      double value = action->get_variable()->get_value() * action->get_variable()->get_constraint_weight(i);
+      TRACE_surf_resource_set_utilization("LINK", "bandwidth_used", link->get_cname(), action->get_category(), value,
+                                          action->get_last_update(), SIMIX_get_clock() - action->get_last_update());
+    }
   }
 }
+
 static void instr_link_on_bandwidth_change(simgrid::s4u::Link& link)
 {
   simgrid::instr::Container::by_name(link.get_cname())
@@ -357,8 +361,8 @@ void instr_define_callbacks()
   }
   simgrid::s4u::NetZone::on_creation.connect(instr_netzone_on_creation);
 
-  simgrid::surf::CpuAction::on_state_change.connect(instr_cpu_action_on_state_change);
-  simgrid::s4u::Link::on_communication_state_change.connect(instr_link_on_communication_state_change);
+  simgrid::surf::CpuAction::on_state_change.connect(instr_action_on_state_change);
+  simgrid::s4u::Link::on_communication_state_change.connect(instr_action_on_state_change);
 
   if (TRACE_actor_is_enabled()) {
     simgrid::s4u::Actor::on_creation.connect(instr_actor_on_creation);
index 2057c0e..28a6020 100644 (file)
@@ -198,12 +198,13 @@ void sg_link_energy_plugin_init()
                link.extension<LinkEnergy>()->get_consumed_energy());
   });
 
-  simgrid::s4u::Link::on_communication_state_change.connect([](simgrid::kernel::resource::NetworkAction* action) {
-    for (simgrid::kernel::resource::LinkImpl* link : action->links()) {
-      if (link != nullptr)
-        link->piface_.extension<LinkEnergy>()->update();
-    }
-  });
+  simgrid::s4u::Link::on_communication_state_change.connect(
+      [](simgrid::kernel::resource::NetworkAction* action, simgrid::kernel::resource::Action::State /* previous */) {
+        for (simgrid::kernel::resource::LinkImpl* link : action->links()) {
+          if (link != nullptr)
+            link->piface_.extension<LinkEnergy>()->update();
+        }
+      });
 
   simgrid::s4u::Link::on_communicate.connect(&on_communicate);
   simgrid::s4u::on_simulation_end.connect(&on_simulation_end);
index a49d92d..dad2525 100644 (file)
@@ -23,7 +23,8 @@ simgrid::xbt::signal<void(Link&)> Link::on_destruction;
 simgrid::xbt::signal<void(Link&)> Link::on_state_change;
 simgrid::xbt::signal<void(Link&)> Link::on_bandwidth_change;
 simgrid::xbt::signal<void(kernel::resource::NetworkAction*, Host* src, Host* dst)> Link::on_communicate;
-simgrid::xbt::signal<void(kernel::resource::NetworkAction*)> Link::on_communication_state_change;
+simgrid::xbt::signal<void(kernel::resource::NetworkAction*, kernel::resource::Action::State)>
+    Link::on_communication_state_change;
 
 Link* Link::by_name(std::string name)
 {
index 0f1a3ab..68cb4f2 100644 (file)
@@ -186,6 +186,7 @@ void CpuAction::set_state(Action::State state)
   Action::set_state(state);
   on_state_change(this, previous);
 }
+
 /** @brief returns a list of all CPUs that this action is using */
 std::list<Cpu*> CpuAction::cpus() {
   std::list<Cpu*> retlist;
index eb78f29..97fd3e8 100644 (file)
@@ -27,7 +27,8 @@ static void IB_create_host_callback(simgrid::s4u::Host& host){
   ((NetworkIBModel*)surf_network_model)->active_nodes.insert({host.get_name(), act});
 }
 
-static void IB_action_state_changed_callback(simgrid::kernel::resource::NetworkAction* action)
+static void IB_action_state_changed_callback(simgrid::kernel::resource::NetworkAction* action,
+                                             simgrid::kernel::resource::Action::State /*previous*/)
 {
   using simgrid::kernel::resource::IBNode;
   using simgrid::kernel::resource::NetworkIBModel;
index 337170f..056d773 100644 (file)
@@ -166,7 +166,7 @@ void NetworkAction::set_state(Action::State state)
   Action::State previous = get_state();
   Action::set_state(state);
   if (previous != state) // Trigger only if the state changed
-    s4u::Link::on_communication_state_change(this);
+    s4u::Link::on_communication_state_change(this, previous);
 }
 
 /** @brief returns a list of all Links that this action is using */
index ebad9d3..bffa333 100644 (file)
@@ -25,7 +25,6 @@ void surf_host_model_init_ptask_L07()
   all_existing_models.push_back(surf_host_model);
 }
 
-
 namespace simgrid {
 namespace surf {
 
@@ -146,6 +145,7 @@ L07Action::L07Action(kernel::resource::Model* model, int host_nb, sg_host_t* hos
   int nb_link = 0;
   int nb_used_host = 0; /* Only the hosts with something to compute (>0 flops) are counted) */
   double latency = 0.0;
+  this->set_last_update();
 
   this->hostList_->reserve(host_nb);
   for (int i = 0; i < host_nb; i++) {