and an instance version that is invoked for this specific object only. For example,
s4u::Actor::on_suspend_cb() adds a callback that is invoked for the suspend of any actor while
s4u::Actor::on_this_suspend_cb() adds a callback for this specific actor only.
+ - Activity::on_suspended_cb() is renamed to Activity::on_suspend_cb(), and fired right before the suspend.
+ - Activity::on_resumed_cb() is renamed to Activity::on_resume_cb(), and fired right before the resume.
New S4U plugins:
- Operation: They are designed to represent workflows, i.e, graphs of repeatable Activities.
- :cpp:func:`Comm::on_send <simgrid::s4u::Comm::on_send_cb>`
:cpp:func:`Comm::on_recv <simgrid::s4u::Comm::on_recv_cb>`
:cpp:func:`Comm::on_completion <simgrid::s4u::Comm::on_completion_cb>`
-- :cpp:func:`CommImpl::on_start <simgrid::s4u::Comm::on_start_cb>`
- :cpp:func:`CommImpl::on_completion <simgrid::s4u::Comm::on_completion_cb>`
+- :cpp:func:`CommImpl::on_start <simgrid::s4u::CommImpl::on_start_cb>`
+ :cpp:func:`CommImpl::on_completion <simgrid::s4u::CommImpl::on_completion_cb>`
- :cpp:func:`Disk::on_creation <simgrid::s4u::Disk::on_creation_cb>`
:cpp:func:`Disk::on_destruction <simgrid::s4u::Disk::on_destruction_cb>`
:cpp:func:`Disk::on_this_destruction <simgrid::s4u::Disk::on_this_destruction_cb>`
:cpp:func:`Exec::on_completion <simgrid::s4u::Exec::on_completion_cb>`
- :cpp:func:`Host::on_creation <simgrid::s4u::Host::on_creation_cb>`
:cpp:func:`Host::on_destruction <simgrid::s4u::Host::on_destruction_cb>`
+ :cpp:func:`Host::on_this_destruction <simgrid::s4u::Host::on_this_destruction_cb>`
:cpp:func:`Host::on_state_change <simgrid::s4u::Host::on_state_change_cb>`
+ :cpp:func:`Host::on_this_state_change <simgrid::s4u::Host::on_this_state_change_cb>`
:cpp:func:`Host::on_speed_change <simgrid::s4u::Host::on_speed_change_cb>`
+ :cpp:func:`Host::on_this_speed_change <simgrid::s4u::Host::on_this_speed_change_cb>`
- :cpp:func:`Io::on_start <simgrid::s4u::Io::on_start_cb>`
:cpp:func:`Io::on_completion <simgrid::s4u::Io::on_completion_cb>`
- :cpp:func:`Link::on_creation <simgrid::s4u::Link::on_creation_cb>`
.. doxygenfunction:: simgrid::s4u::Host::on_creation_cb
.. doxygenfunction:: simgrid::s4u::Host::on_destruction_cb
+ .. doxygenfunction:: simgrid::s4u::Host::on_this_destruction_cb
.. doxygenfunction:: simgrid::s4u::Host::on_speed_change_cb
+ .. doxygenfunction:: simgrid::s4u::Host::on_this_speed_change_cb
.. doxygenfunction:: simgrid::s4u::Host::on_state_change_cb
+ .. doxygenfunction:: simgrid::s4u::Host::on_this_state_change_cb
.. _API_s4u_Link:
}
namespace resource {
class Action;
+class CpuAction;
class CpuImpl;
class Model;
class Resource;
private:
static xbt::signal<void(Activity&)> on_veto;
static xbt::signal<void(Activity const&)> on_completion;
- static xbt::signal<void(Activity const&)> on_suspended;
- static xbt::signal<void(Activity const&)> on_resumed;
+ static xbt::signal<void(Activity const&)> on_suspend;
+ static xbt::signal<void(Activity const&)> on_resume;
public:
/*! Add a callback fired each time that the activity fails to start because of a veto (e.g., unsolved dependency or no
/*! Add a callback fired when the activity completes (either normally, cancelled or failed) */
static void on_completion_cb(const std::function<void(Activity const&)>& cb) { on_completion.connect(cb); }
/*! Add a callback fired when the activity is suspended */
- static void on_suspended_cb(const std::function<void(Activity const&)>& cb) { on_suspended.connect(cb); }
+ static void on_suspend_cb(const std::function<void(Activity const&)>& cb)
+ {
+ on_suspend.connect(cb);
+ }
/*! Add a callback fired when the activity is resumed after being suspended */
- static void on_resumed_cb(const std::function<void(Activity const&)>& cb) { on_resumed.connect(cb); }
+ static void on_resume_cb(const std::function<void(Activity const&)>& cb)
+ {
+ on_resume.connect(cb);
+ }
+
+ XBT_ATTRIB_DEPRECATED_v334("Please use on_suspend_cb() instead") static void on_suspended_cb(
+ const std::function<void(Activity const&)>& cb)
+ {
+ on_suspend.connect(cb);
+ }
+ XBT_ATTRIB_DEPRECATED_v334("Please use on_resume_cb() instead") static void on_resumed_cb(
+ const std::function<void(Activity const&)>& cb)
+ {
+ on_resume.connect(cb);
+ }
XBT_ATTRIB_DEPRECATED_v334("All start() are vetoable now. Please use start() ") void vetoable_start()
{
public:
/** Add a callback fired when a new actor has been created **/
static void on_creation_cb(const std::function<void(Actor&)>& cb) { on_creation.connect(cb); }
- /** Add a callback fired when any actor is suspended**/
+ /** Add a callback fired when any actor is suspended (right before the suspend) **/
static void on_suspend_cb(const std::function<void(Actor const&)>& cb) { on_suspend.connect(cb); }
- /** Add a callback fired when this specific actor is suspended**/
+ /** Add a callback fired when this specific actor is suspended (right before the suspend) **/
void on_this_suspend_cb(const std::function<void(Actor const&)>& cb) { on_this_suspend.connect(cb); }
- /** Add a callback fired when any actor is resumed **/
+ /** Add a callback fired when any actor is resumed (right before the resume) **/
static void on_resume_cb(const std::function<void(Actor const&)>& cb) { on_resume.connect(cb); }
- /** Add a callback fired when any actor is resumed **/
+ /** Add a callback fired when any actor is resumed (right before the resume) **/
void on_this_resume_cb(const std::function<void(Actor const&)>& cb) { on_this_resume.connect(cb); }
/** Add a callback fired when any actor starts sleeping **/
static void on_sleep_cb(const std::function<void(Actor const&)>& cb) { on_sleep.connect(cb); }
#define SIMGRID_S4U_HOST_HPP
#include <simgrid/forward.h>
+#include <simgrid/kernel/resource/Action.hpp>
#include <xbt/Extendable.hpp>
#include <xbt/signal.hpp>
kernel::resource::CpuImpl* pimpl_cpu_ = nullptr;
kernel::routing::NetPoint* pimpl_netpoint_ = nullptr;
+#ifndef DOXYGEN
+ friend kernel::resource::CpuAction; // signal exec_state_changed
+#endif
public:
explicit Host(kernel::resource::HostImpl* pimpl) : pimpl_(pimpl) {}
static xbt::signal<void(Host&)> on_creation;
static xbt::signal<void(Host const&)> on_destruction;
+ xbt::signal<void(Host const&)> on_this_destruction;
+ static xbt::signal<void(kernel::resource::CpuAction&, kernel::resource::Action::State)> on_exec_state_change;
public:
static xbt::signal<void(Host const&)> on_speed_change;
+ xbt::signal<void(Host const&)> on_this_speed_change;
static xbt::signal<void(Host const&)> on_state_change;
+ xbt::signal<void(Host const&)> on_this_state_change;
+
#endif
/** Add a callback fired on each newly created host */
static void on_creation_cb(const std::function<void(Host&)>& cb) { on_creation.connect(cb); }
- /** Add a callback fired when the machine is turned on or off (called AFTER the change) */
+ /** Add a callback fired when any machine is turned on or off (called AFTER the change) */
static void on_state_change_cb(const std::function<void(Host const&)>& cb) { on_state_change.connect(cb); }
- /** Add a callback fired when the speed of the machine is changed (called AFTER the change)
+ /** Add a callback fired when this specific machine is turned on or off (called AFTER the change) */
+ void on_this_state_change_cb(const std::function<void(Host const&)>& cb)
+ {
+ on_this_state_change.connect(cb);
+ }
+ /** Add a callback fired when the speed of any machine is changed (called AFTER the change)
* (either because of a pstate switch or because of an external load event coming from the profile) */
static void on_speed_change_cb(const std::function<void(Host const&)>& cb) { on_speed_change.connect(cb); }
- /** Add a callback fired just before destructing a host */
+ /** Add a callback fired when the speed of this specific machine is changed (called AFTER the change)
+ * (either because of a pstate switch or because of an external load event coming from the profile) */
+ void on_this_speed_change_cb(const std::function<void(Host const&)>& cb)
+ {
+ on_this_speed_change.connect(cb);
+ }
+ /** Add a callback fired just before destructing any host */
static void on_destruction_cb(const std::function<void(Host const&)>& cb) { on_destruction.connect(cb); }
+ /** Add a callback fired just before destructing this specific host */
+ void on_this_destruction_cb(const std::function<void(Host const&)>& cb)
+ {
+ on_this_destruction.connect(cb);
+ }
+ /** Add a callback fired when the state of any exec activity changes */
+ static void on_exec_state_change_cb(
+ const std::function<void(kernel::resource::CpuAction&, kernel::resource::Action::State previous)>& cb)
+ {
+ on_exec_state_change.connect(cb);
+ }
virtual void destroy();
#ifndef DOXYGEN
#include <xbt/graph.h>
#include "src/instr/instr_private.hpp"
+#include "src/kernel/activity/ExecImpl.hpp"
#include "src/kernel/resource/CpuImpl.hpp"
#include "src/kernel/resource/NetworkModel.hpp"
resource_set_utilization("HOST", "speed_used", cpu->get_cname(), action.get_category(), value,
action.get_last_update(), simgrid_get_clock() - action.get_last_update());
- if (const auto* link = dynamic_cast<kernel::resource::StandardLinkImpl*>(resource))
+ else if (const auto* link = dynamic_cast<kernel::resource::StandardLinkImpl*>(resource))
resource_set_utilization("LINK", "bandwidth_used", link->get_cname(), action.get_category(), value,
action.get_last_update(), simgrid_get_clock() - action.get_last_update());
}
}
+static void on_activity_suspend_resume(s4u::Activity const& activity)
+{
+ on_action_state_change(*activity.get_impl()->model_action_, /*ignored*/ kernel::resource::Action::State::STARTED);
+}
+
static void on_platform_created()
{
currentContainer.clear();
s4u::NetZone::on_creation_cb(on_netzone_creation);
- kernel::resource::CpuAction::on_state_change.connect(on_action_state_change);
+ s4u::Host::on_exec_state_change_cb(on_action_state_change);
s4u::Link::on_communication_state_change_cb(on_action_state_change);
+ s4u::Activity::on_suspend_cb(on_activity_suspend_resume);
+ s4u::Activity::on_resume_cb(on_activity_suspend_resume);
if (TRACE_actor_is_enabled()) {
s4u::Actor::on_creation_cb(on_actor_creation);
void ActivityImpl::suspend()
{
- if (model_action_ == nullptr)
+ if (model_action_ == nullptr) {
+ XBT_CRITICAL("POUET");
return;
+ }
XBT_VERB("This activity is suspended (remain: %f)", model_action_->get_remains());
+ s4u::Activity::on_suspend(*get_iface());
model_action_->suspend();
- s4u::Activity::on_suspended(*get_iface());
}
void ActivityImpl::resume()
if (model_action_ == nullptr)
return;
XBT_VERB("This activity is resumed (remain: %f)", model_action_->get_remains());
+ s4u::Activity::on_resume(*get_iface());
model_action_->resume();
- s4u::Activity::on_resumed(*get_iface());
}
void ActivityImpl::cancel()
void CpuImpl::on_speed_change()
{
s4u::Host::on_speed_change(*piface_);
+ piface_->on_this_speed_change(*piface_);
}
CpuImpl* CpuImpl::set_core_count(int core_count)
set_last_value(get_rate());
}
-xbt::signal<void(CpuAction const&, Action::State)> CpuAction::on_state_change;
-
-void CpuAction::suspend()
-{
- Action::State previous = get_state();
- on_state_change(*this, previous);
- Action::suspend();
-}
-
-void CpuAction::resume()
-{
- Action::State previous = get_state();
- on_state_change(*this, previous);
- Action::resume();
-}
-
void CpuAction::set_state(Action::State state)
{
Action::State previous = get_state();
Action::set_state(state);
- on_state_change(*this, previous);
+ s4u::Host::on_exec_state_change(*this, previous);
}
/** @brief returns a list of all CPUs that this action is using */
public:
using Action::Action;
- /** @brief Signal emitted when the action state changes (ready/running/done, etc)
- * Signature: `void(CpuAction const& action, simgrid::kernel::resource::Action::State previous)`
- */
- static xbt::signal<void(CpuAction const&, Action::State)> on_state_change;
-
void set_state(Action::State state) override;
void update_remains_lazy(double now) override;
std::list<CpuImpl*> cpus() const;
-
- void suspend() override;
- void resume() override;
};
} // namespace simgrid::kernel::resource
void HostImpl::destroy()
{
s4u::Host::on_destruction(*this->get_iface());
+ this->get_iface()->on_this_destruction(*this->get_iface());
delete this;
}
s4u::Host::on_state_change_cb(host_state_change);
s4u::Exec::on_start_cb(add_active_exec);
s4u::Activity::on_completion_cb(remove_active_exec);
- s4u::Activity::on_resumed_cb(add_active_activity);
- s4u::Activity::on_suspended_cb(remove_active_activity);
+ s4u::Activity::on_resume_cb(add_active_activity);
+ s4u::Activity::on_suspend_cb(remove_active_activity);
}
double VMModel::next_occurring_event(double now)
#include <simgrid/s4u/VirtualMachine.hpp>
#include <simgrid/simix.hpp>
+#include "src/kernel/activity/ActivityImpl.hpp"
#include "src/kernel/resource/CpuImpl.hpp"
#include "src/simgrid/module.hpp"
/* This callback is fired either when the host changes its state (on/off) ("onStateChange") or its speed
* (because the user changed the pstate, or because of external trace events) ("onSpeedChange") */
-static void on_host_change(simgrid::s4u::Host const& host)
+static void on_host_change(simgrid::s4u::Host const& h)
{
- if (dynamic_cast<simgrid::s4u::VirtualMachine const*>(&host)) // Ignore virtual machines
- return;
-
- auto* host_energy = host.extension<HostEnergy>();
+ auto* host = &h;
+ if (const auto* vm = dynamic_cast<simgrid::s4u::VirtualMachine const*>(host)) // Take the PM of virtual machines
+ host = vm->get_pm();
- host_energy->update();
+ host->extension<HostEnergy>()->update();
}
static void on_host_destruction(simgrid::s4u::Host const& host)
used_hosts_energy, total_energy - used_hosts_energy);
}
+static void on_activity_suspend_resume(simgrid::s4u::Activity const& activity)
+{
+ if (auto* action = dynamic_cast<simgrid::kernel::resource::CpuAction*>(activity.get_impl()->model_action_);
+ action != nullptr)
+ on_action_state_change(*action, /*ignored*/ action->get_state());
+}
+
/* **************************** Public interface *************************** */
/** @ingroup plugin_host_energy
simgrid::s4u::Host::on_state_change_cb(&on_host_change);
simgrid::s4u::Host::on_speed_change_cb(&on_host_change);
simgrid::s4u::Host::on_destruction_cb(&on_host_destruction);
+ simgrid::s4u::Host::on_exec_state_change_cb(&on_action_state_change);
+ simgrid::s4u::VirtualMachine::on_suspend_cb(&on_host_change);
+ simgrid::s4u::VirtualMachine::on_resume_cb(&on_host_change);
+ simgrid::s4u::Exec::on_suspend_cb(on_activity_suspend_resume);
+ simgrid::s4u::Exec::on_resume_cb(on_activity_suspend_resume);
simgrid::s4u::Engine::on_simulation_end_cb(&on_simulation_end);
- simgrid::kernel::resource::CpuAction::on_state_change.connect(&on_action_state_change);
// We may only have one actor on a node. If that actor executes something like
// compute -> recv -> compute
// the recv operation will not trigger a "CpuAction::on_state_change". This means
// fix that. (If the cpu is not idle, this is not required.)
simgrid::s4u::Exec::on_start_cb([](simgrid::s4u::Exec const& activity) {
if (activity.get_host_number() == 1) { // We only run on one host
- simgrid::s4u::Host* host = activity.get_host();
+ simgrid::s4u::Host* host = activity.get_host();
if (const auto* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(host))
host = vm->get_pm();
- xbt_assert(host != nullptr);
host->extension<HostEnergy>()->update();
}
});
xbt::signal<void(Activity&)> Activity::on_veto;
xbt::signal<void(Activity const&)> Activity::on_completion;
-xbt::signal<void(Activity const&)> Activity::on_suspended;
-xbt::signal<void(Activity const&)> Activity::on_resumed;
+xbt::signal<void(Activity const&)> Activity::on_suspend;
+xbt::signal<void(Activity const&)> Activity::on_resume;
std::set<Activity*>* Activity::vetoed_activities_ = nullptr;
xbt::signal<void(Host const&)> Host::on_destruction;
xbt::signal<void(Host const&)> Host::on_state_change;
xbt::signal<void(Host const&)> Host::on_speed_change;
+xbt::signal<void(kernel::resource::CpuAction&, kernel::resource::Action::State)> Host::on_exec_state_change;
#endif
Host* Host::set_cpu(kernel::resource::CpuImpl* cpu)