From 902f44b9e3ebc4440e3dd623c2683a65cf418b75 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 15 Feb 2017 16:31:53 +0100 Subject: [PATCH] new callback: s4u::onTimeAdvance --- ChangeLog | 1 + include/simgrid/s4u/engine.hpp | 10 ++++++---- src/s4u/s4u_engine.cpp | 1 + src/surf/surf_c_bindings.cpp | 4 +++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index b84978d171..eb0827bbf7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,7 @@ SimGrid (3.15) UNRELEASED; urgency=low - New callbacks: - s4u::onPlatformCreated: right before the simulation starts - s4u::onSimulationEnd: right after the main simulation loop + - s4u::onTimeAdvance: right after a clock change (time is discrete) - 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 diff --git a/include/simgrid/s4u/engine.hpp b/include/simgrid/s4u/engine.hpp index 71d5df2a51..413f7ef92e 100644 --- a/include/simgrid/s4u/engine.hpp +++ b/include/simgrid/s4u/engine.hpp @@ -105,13 +105,15 @@ private: static s4u::Engine *instance_; }; -/** Callback called when the platform is created (ie, the xml file parsed), - * right before the actual simulation starts. - */ +/** Callback fired when the platform is created (ie, the xml file parsed), + * right before the actual simulation starts. */ extern XBT_PRIVATE xbt::signal onPlatformCreated; -/** Callback called when the main simulation loop ends, just before MSG_run (or similar) ends */ +/** Callback fired when the main simulation loop ends, just before MSG_run (or similar) ends */ extern XBT_PRIVATE xbt::signal onSimulationEnd; + +/** Callback fired when the time jumps into the future */ +extern XBT_PRIVATE xbt::signal onTimeAdvance; }} // namespace simgrid::s4u #endif /* SIMGRID_S4U_ENGINE_HPP */ diff --git a/src/s4u/s4u_engine.cpp b/src/s4u/s4u_engine.cpp index a39f436e60..085e4e6471 100644 --- a/src/s4u/s4u_engine.cpp +++ b/src/s4u/s4u_engine.cpp @@ -25,6 +25,7 @@ namespace simgrid { namespace s4u { xbt::signal onPlatformCreated; xbt::signal onSimulationEnd; +xbt::signal onTimeAdvance; Engine *Engine::instance_ = nullptr; /* That singleton is awful, but I don't see no other solution right now. */ diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index 35b61cb1a3..1b00946611 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -4,6 +4,7 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include "simgrid/s4u/engine.hpp" #include "src/instr/instr_private.h" #include "src/plugins/vm/VirtualMachineImpl.hpp" @@ -120,7 +121,7 @@ double surf_solve(double max_date) /* FIXME: Moved this test to here to avoid stopping simulation if there are actions running on cpus and all cpus are with availability = 0. * This may cause an infinite loop if one cpu has a trace with periodicity = 0 and the other a trace with periodicity > 0. * The options are: all traces with same periodicity(0 or >0) or we need to change the way how the events are managed */ - if (time_delta == -1.0) { + if (time_delta < 0) { XBT_DEBUG("No next event at all. Bail out now."); return -1.0; } @@ -134,6 +135,7 @@ double surf_solve(double max_date) for (auto model : *all_existing_models) { model->updateActionsState(NOW, time_delta); } + simgrid::s4u::onTimeAdvance(time_delta); TRACE_paje_dump_buffer (0); -- 2.20.1