From d5e80f361a8e20f8080faabf65bb2021c46f6656 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Mon, 14 May 2018 21:19:07 +0200 Subject: [PATCH] yet another callbacks network_interface is TRACE-free \o/ --- include/simgrid/s4u/Host.hpp | 1 + src/instr/instr_platform.cpp | 16 ++++++++++++++++ src/s4u/s4u_Host.cpp | 6 +++++- src/surf/cpu_interface.cpp | 4 ---- src/surf/network_interface.cpp | 6 +----- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index d2d2cbf9d2..0a3c3c94a7 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -90,6 +90,7 @@ public: bool isOff() { return not isOn(); } double getSpeed(); + double get_available_speed(); int getCoreCount(); std::map* getProperties(); const char* getProperty(const char* key); diff --git a/src/instr/instr_platform.cpp b/src/instr/instr_platform.cpp index c445875d57..0ac5fd97ba 100644 --- a/src/instr/instr_platform.cpp +++ b/src/instr/instr_platform.cpp @@ -13,6 +13,7 @@ #include "simgrid/s4u/VirtualMachine.hpp" #include "src/surf/cpu_interface.hpp" #include "src/surf/network_interface.hpp" +#include "src/surf/surf_interface.hpp" #include "src/surf/xml/platf_private.hpp" #include "surf/surf.hpp" #include "xbt/graph.h" @@ -231,6 +232,13 @@ static void instr_host_on_creation(simgrid::s4u::Host& host) } } +static void instr_host_on_speed_change(simgrid::s4u::Host* host) +{ + simgrid::instr::Container::by_name(host->get_cname()) + ->get_variable("power") + ->set_event(surf_get_clock(), host->getCoreCount() * host->get_available_speed()); +} + static void instr_cpu_action_on_state_change(simgrid::surf::CpuAction* action, simgrid::kernel::resource::Action::State /* previous */) { @@ -252,6 +260,12 @@ static void instr_link_on_communication_state_change(simgrid::kernel::resource:: 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()) + ->get_variable("bandwidth") + ->set_event(surf_get_clock(), sg_bandwidth_factor * link.bandwidth()); +} static void instr_netpoint_on_creation(simgrid::kernel::routing::NetPoint* netpoint) { @@ -369,7 +383,9 @@ void instr_define_callbacks() if (TRACE_needs_platform()) { simgrid::s4u::on_platform_created.connect(instr_on_platform_created); simgrid::s4u::Host::onCreation.connect(instr_host_on_creation); + simgrid::s4u::Host::onSpeedChange.connect(instr_host_on_speed_change); simgrid::s4u::Link::on_creation.connect(instr_link_on_creation); + simgrid::s4u::Link::on_bandwidth_change.connect(instr_link_on_bandwidth_change); } simgrid::s4u::NetZone::onCreation.connect(instr_netzone_on_creation); simgrid::s4u::NetZone::onSeal.connect(instr_netzone_on_seal); diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index bd963f4da1..0e9445657c 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -207,6 +207,10 @@ double Host::getSpeed() { return pimpl_cpu->getSpeed(1.0); } +double Host::get_available_speed() +{ + return pimpl_cpu->get_available_speed(); +} /** @brief Returns the number of core of the processor. */ int Host::getCoreCount() @@ -409,7 +413,7 @@ int sg_host_core_count(sg_host_t host) double sg_host_get_available_speed(sg_host_t host) { - return host->pimpl_cpu->get_available_speed(); + return host->get_available_speed(); } /** @brief Returns the number of power states for a host. diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index ebe52e9cb8..e18c775b77 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -133,10 +133,6 @@ double Cpu::get_available_speed() } void Cpu::onSpeedChange() { - if (TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) - instr::Container::by_name(get_cname()) - ->get_variable("power") - ->set_event(surf_get_clock(), coresAmount_ * speed_.scale * speed_.peak); s4u::Host::onSpeedChange(*host_); } diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index 7391e1d8c4..c57f111915 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -5,7 +5,6 @@ #include "network_interface.hpp" #include "simgrid/sg_config.hpp" -#include "src/instr/instr_private.hpp" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals #include "src/surf/surf_interface.hpp" #include "surf/surf.hpp" @@ -177,6 +176,7 @@ void LinkImpl::turn_on() s4u::Link::on_state_change(this->piface_); } } + void LinkImpl::turn_off() { if (is_on()) { @@ -187,10 +187,6 @@ void LinkImpl::turn_off() void LinkImpl::on_bandwidth_change() { - if (TRACE_categorized() || TRACE_uncategorized() || TRACE_platform()) - instr::Container::by_name(get_cname()) - ->get_variable("bandwidth") - ->set_event(surf_get_clock(), sg_bandwidth_factor * bandwidth_.scale * bandwidth_.peak); s4u::Link::on_bandwidth_change(this->piface_); } -- 2.20.1