From abdc951defbcde044cf222da256ad85491a28340 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 15 Feb 2017 16:19:28 +0100 Subject: [PATCH] new signal s4u::Host::onSpeedChange: when pstate is changed (or similar) --- ChangeLog | 6 ++++-- include/simgrid/s4u/host.hpp | 3 +++ src/s4u/s4u_host.cpp | 1 + src/surf/cpu_cas01.cpp | 2 +- src/surf/cpu_interface.cpp | 1 + src/surf/plugins/host_energy.cpp | 14 +++++++------- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2af5b4a087..b84978d171 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,8 +17,10 @@ SimGrid (3.15) UNRELEASED; urgency=low S4U - New callbacks: - - simgrid::s4u::onPlatformCreated: right before the simulation starts - - simgrid::s4u::onSimulationEnd: right after the main simulation loop + - s4u::onPlatformCreated: right before the simulation starts + - s4u::onSimulationEnd: right after the main simulation loop + - s4u::Host::onSpeedChange: when the pstate is changed, or when an + event from the availability_file changes the avail speed. - Links are now usable from s4u -- target_date=March 20 2017 -- Da SimGrid team diff --git a/include/simgrid/s4u/host.hpp b/include/simgrid/s4u/host.hpp index 5251f3d139..ad4c0a0f91 100644 --- a/include/simgrid/s4u/host.hpp +++ b/include/simgrid/s4u/host.hpp @@ -124,6 +124,9 @@ public: static simgrid::xbt::signal onDestruction; /*** Called when the machine is turned on or off */ static simgrid::xbt::signal onStateChange; + /*** Called when the speed of the machine is changed + * (either because of a pstate switch or because of an external load event coming from the profile) */ + static simgrid::xbt::signal onSpeedChange; }; }} // namespace simgrid::s4u diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index ebf38232c0..0c91112668 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -40,6 +40,7 @@ namespace s4u { simgrid::xbt::signal Host::onCreation; simgrid::xbt::signal Host::onDestruction; simgrid::xbt::signal Host::onStateChange; +simgrid::xbt::signal Host::onSpeedChange; Host::Host(const char* name) : name_(name) diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index 04db0b1160..f9835fabc7 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -114,7 +114,7 @@ void CpuCas01::onSpeedChange() { CpuCas01Action* action = static_cast(lmm_variable_id(var)); lmm_update_variable_bound(model()->getMaxminSystem(), action->getVariable(), speed_.scale * speed_.peak); - } + } Cpu::onSpeedChange(); } diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index 260f49cdd6..768c4190f0 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -177,6 +177,7 @@ double Cpu::getAvailableSpeed() void Cpu::onSpeedChange() { TRACE_surf_host_set_speed(surf_get_clock(), cname(), coresAmount_ * speed_.scale * speed_.peak); + s4u::Host::onSpeedChange(*host_); } int Cpu::coreCount() diff --git a/src/surf/plugins/host_energy.cpp b/src/surf/plugins/host_energy.cpp index 7a3029a10b..8aa4cc0478 100644 --- a/src/surf/plugins/host_energy.cpp +++ b/src/surf/plugins/host_energy.cpp @@ -57,8 +57,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_energy, surf, "Logging specific to the SURF namespace simgrid { namespace energy { -class XBT_PRIVATE HostEnergy; - class PowerRange { public: double idle; @@ -286,7 +284,9 @@ static void onActionStateChange(simgrid::surf::CpuAction* action, simgrid::surf: } } -static void onHostStateChange(simgrid::s4u::Host& host) +/* This callback is fired either when the host change its state (on/off) or its speed + * (because the user changed the pstate, or because of external trace events) */ +static void onHostChange(simgrid::s4u::Host& host) { if (dynamic_cast(&host)) // Ignore virtual machines return; @@ -309,9 +309,8 @@ static void onHostDestruction(simgrid::s4u::Host& host) /* **************************** Public interface *************************** */ /** \ingroup SURF_plugin_energy - * \brief Enable energy plugin - * \details Enable energy plugin to get joules consumption of each cpu. You should call this function before - * #MSG_init(). + * \brief Enable host energy plugin + * \details Enable energy plugin to get joules consumption of each cpu. Call this function before #MSG_init(). */ void sg_host_energy_plugin_init() { @@ -321,7 +320,8 @@ void sg_host_energy_plugin_init() HostEnergy::EXTENSION_ID = simgrid::s4u::Host::extension_create(); simgrid::s4u::Host::onCreation.connect(&onCreation); - simgrid::s4u::Host::onStateChange.connect(&onHostStateChange); + simgrid::s4u::Host::onStateChange.connect(&onHostChange); + simgrid::s4u::Host::onSpeedChange.connect(&onHostChange); simgrid::s4u::Host::onDestruction.connect(&onHostDestruction); simgrid::surf::CpuAction::onStateChange.connect(&onActionStateChange); } -- 2.20.1