From: Frederic Suter Date: Mon, 9 Jul 2018 15:31:36 +0000 (+0200) Subject: attempt to fully trace ptasks X-Git-Tag: v3_21~505 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b1801e7056930569752cf33757134cb44d32cfac attempt to fully trace ptasks --- diff --git a/include/simgrid/s4u/Link.hpp b/include/simgrid/s4u/Link.hpp index e1832a8b22..fd692f5933 100644 --- a/include/simgrid/s4u/Link.hpp +++ b/include/simgrid/s4u/Link.hpp @@ -6,6 +6,7 @@ #ifndef S4U_LINK_HPP_ #define S4U_LINK_HPP_ +#include #include #include #include @@ -91,7 +92,8 @@ public: static simgrid::xbt::signal on_communicate; /** @brief Callback signal fired when a communication changes it state (ready/done/cancel) */ - static simgrid::xbt::signal on_communication_state_change; + static simgrid::xbt::signal + 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); } diff --git a/src/instr/instr_platform.cpp b/src/instr/instr_platform.cpp index 7a6c2b0e57..695fcb9f3b 100644 --- a/src/instr/instr_platform.cpp +++ b/src/instr/instr_platform.cpp @@ -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(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(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(action->get_variable()->get_constraint(i)->get_id()); + simgrid::surf::Cpu* cpu = dynamic_cast(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(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); diff --git a/src/plugins/link_energy.cpp b/src/plugins/link_energy.cpp index 2057c0ed59..28a60208b8 100644 --- a/src/plugins/link_energy.cpp +++ b/src/plugins/link_energy.cpp @@ -198,12 +198,13 @@ void sg_link_energy_plugin_init() link.extension()->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()->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()->update(); + } + }); simgrid::s4u::Link::on_communicate.connect(&on_communicate); simgrid::s4u::on_simulation_end.connect(&on_simulation_end); diff --git a/src/s4u/s4u_Link.cpp b/src/s4u/s4u_Link.cpp index a49d92dcb6..dad2525683 100644 --- a/src/s4u/s4u_Link.cpp +++ b/src/s4u/s4u_Link.cpp @@ -23,7 +23,8 @@ simgrid::xbt::signal Link::on_destruction; simgrid::xbt::signal Link::on_state_change; simgrid::xbt::signal Link::on_bandwidth_change; simgrid::xbt::signal Link::on_communicate; -simgrid::xbt::signal Link::on_communication_state_change; +simgrid::xbt::signal + Link::on_communication_state_change; Link* Link::by_name(std::string name) { diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index 0f1a3ab114..68cb4f24b6 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -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 CpuAction::cpus() { std::list retlist; diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index eb78f298b8..97fd3e8bce 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -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; diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index 337170fe73..056d773712 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -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 */ diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index ebad9d316e..bffa33376d 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -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++) {