From 598f97dc55ad76b3253cd2e591d96eb8fe785674 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 13 Sep 2019 16:20:06 +0200 Subject: [PATCH] move some global signals to the Engine --- ChangeLog | 6 ++++++ include/simgrid/s4u/Engine.hpp | 32 ++++++++++++++++---------------- src/bindings/lua/lua_platf.cpp | 4 ++-- src/instr/instr_config.cpp | 6 +++--- src/instr/instr_platform.cpp | 2 +- src/plugins/host_energy.cpp | 2 +- src/plugins/link_energy.cpp | 3 +-- src/s4u/s4u_Engine.cpp | 10 +++++----- src/simix/smx_global.cpp | 6 +++--- src/surf/network_ns3.cpp | 2 +- src/surf/sg_platf.cpp | 6 +++--- src/surf/surf_c_bindings.cpp | 2 +- src/surf/xml/surfxml_sax_cb.cpp | 2 +- 13 files changed, 44 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index ba6035e585..921805ec78 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,12 @@ S4U: - Actor::on_destruction is now called in the destructor Actor::on_termination new signal called when the actor terminates its code. + - Global signals are now part of the Engine: + - on_platform_creation: after config settings, before the XML parsing + - on_platform_created: right after the XML parsing + - on_time_advance: each time the clock advances + - on_simulation_end: after simulation, before cleanups + - on_deadlock: as the name implies. MSG: - convert a new set of functions to the S4U C interface and move the old MSG diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index 941b7cde68..242a9799ce 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -154,27 +154,27 @@ public: */ void set_config(const std::string& str); -private: - kernel::EngineImpl* const pimpl; - static Engine* instance_; -}; + /** Callback fired when the platform is created (ie, the xml file parsed), + * right before the actual simulation starts. */ + static xbt::signal on_platform_created; -/** Callback fired when the platform is created (ie, the xml file parsed), - * right before the actual simulation starts. */ -extern XBT_PUBLIC xbt::signal on_platform_created; + /** Callback fired when the platform is about to be created + * (ie, after any configuration change and just before the resource creation) */ + static xbt::signal on_platform_creation; -/** Callback fired when the platform is about to be created - * (ie, after any configuration change and just before the resource creation) */ -extern XBT_PUBLIC xbt::signal on_platform_creation; + /** Callback fired when the main simulation loop ends, just before the end of Engine::run() */ + static xbt::signal on_simulation_end; -/** Callback fired when the main simulation loop ends, just before the end of Engine::run() */ -extern XBT_PUBLIC xbt::signal on_simulation_end; + /** Callback fired when the time jumps into the future */ + static xbt::signal on_time_advance; -/** Callback fired when the time jumps into the future */ -extern XBT_PUBLIC xbt::signal on_time_advance; + /** Callback fired when the time cannot advance because of inter-actors deadlock */ + static xbt::signal on_deadlock; -/** Callback fired when the time cannot advance because of inter-actors deadlock */ -extern XBT_PUBLIC xbt::signal on_deadlock; +private: + kernel::EngineImpl* const pimpl; + static Engine* instance_; +}; #ifndef DOXYGEN /* Internal use only, no need to expose it */ template XBT_PRIVATE void get_filtered_netzones_recursive(s4u::NetZone* current, std::vector* whereto) diff --git a/src/bindings/lua/lua_platf.cpp b/src/bindings/lua/lua_platf.cpp index eba4663362..404887ff22 100644 --- a/src/bindings/lua/lua_platf.cpp +++ b/src/bindings/lua/lua_platf.cpp @@ -65,14 +65,14 @@ static simgrid::s4u::Link::SharingPolicy link_policy_get_by_name(const char* pol int console_open(lua_State*) { sg_platf_init(); - simgrid::s4u::on_platform_creation(); + simgrid::s4u::Engine::on_platform_creation(); return 0; } int console_close(lua_State*) { - simgrid::s4u::on_platform_created(); + simgrid::s4u::Engine::on_platform_created(); sg_platf_exit(); return 0; } diff --git a/src/instr/instr_config.cpp b/src/instr/instr_config.cpp index 415e3baa95..ff20f26bfa 100644 --- a/src/instr/instr_config.cpp +++ b/src/instr/instr_config.cpp @@ -294,9 +294,9 @@ void TRACE_global_init() 6); /* Connect callbacks */ - simgrid::s4u::on_platform_creation.connect(TRACE_start); - simgrid::s4u::on_deadlock.connect(TRACE_end); - simgrid::s4u::on_simulation_end.connect(TRACE_end); + simgrid::s4u::Engine::on_platform_creation.connect(TRACE_start); + simgrid::s4u::Engine::on_deadlock.connect(TRACE_end); + simgrid::s4u::Engine::on_simulation_end.connect(TRACE_end); } static void print_line(const char* option, const char* desc, const char* longdesc) diff --git a/src/instr/instr_platform.cpp b/src/instr/instr_platform.cpp index 9ce839a27c..fa042a83ac 100644 --- a/src/instr/instr_platform.cpp +++ b/src/instr/instr_platform.cpp @@ -355,7 +355,7 @@ void instr_define_callbacks() // always need the callbacks to zones (we need only the root zone), to create the rootContainer and the rootType // properly if (TRACE_needs_platform()) { - simgrid::s4u::on_platform_created.connect(instr_on_platform_created); + simgrid::s4u::Engine::on_platform_created.connect(instr_on_platform_created); simgrid::s4u::Host::on_creation.connect(instr_host_on_creation); simgrid::s4u::Host::on_speed_change.connect(instr_host_on_speed_change); simgrid::s4u::Link::on_creation.connect(instr_link_on_creation); diff --git a/src/plugins/host_energy.cpp b/src/plugins/host_energy.cpp index 2dd43f54f3..2d9f84b5c7 100644 --- a/src/plugins/host_energy.cpp +++ b/src/plugins/host_energy.cpp @@ -489,7 +489,7 @@ void sg_host_energy_plugin_init() simgrid::s4u::Host::on_state_change.connect(&on_host_change); simgrid::s4u::Host::on_speed_change.connect(&on_host_change); simgrid::s4u::Host::on_destruction.connect(&on_host_destruction); - simgrid::s4u::on_simulation_end.connect(&on_simulation_end); + simgrid::s4u::Engine::on_simulation_end.connect(&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 diff --git a/src/plugins/link_energy.cpp b/src/plugins/link_energy.cpp index bdf842b688..20c9873599 100644 --- a/src/plugins/link_energy.cpp +++ b/src/plugins/link_energy.cpp @@ -186,7 +186,6 @@ int sg_link_energy_is_inited() */ void sg_link_energy_plugin_init() { - if (LinkEnergy::EXTENSION_ID.valid()) return; LinkEnergy::EXTENSION_ID = simgrid::s4u::Link::extension_create(); @@ -213,7 +212,7 @@ void sg_link_energy_plugin_init() }); simgrid::s4u::Link::on_communicate.connect(&on_communicate); - simgrid::s4u::on_simulation_end.connect(&on_simulation_end); + simgrid::s4u::Engine::on_simulation_end.connect(&on_simulation_end); } /** @ingroup plugin_energy diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index 64cb7f62bd..5339a77f3e 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -28,11 +28,11 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_engine, s4u, "Logging specific to S4U (engin namespace simgrid { namespace s4u { -xbt::signal on_platform_creation; -xbt::signal on_platform_created; -xbt::signal on_simulation_end; -xbt::signal on_time_advance; -xbt::signal on_deadlock; +xbt::signal Engine::on_platform_creation; +xbt::signal Engine::on_platform_created; +xbt::signal Engine::on_simulation_end; +xbt::signal Engine::on_time_advance; +xbt::signal Engine::on_deadlock; Engine* Engine::instance_ = nullptr; /* That singleton is awful, but I don't see no other solution right now. */ diff --git a/src/simix/smx_global.cpp b/src/simix/smx_global.cpp index 30f3d47102..4028e9a21a 100644 --- a/src/simix/smx_global.cpp +++ b/src/simix/smx_global.cpp @@ -238,7 +238,7 @@ void SIMIX_global_init(int *argc, char **argv) #endif /* register a function to be called by SURF after the environment creation */ sg_platf_init(); - simgrid::s4u::on_platform_created.connect(surf_presolve); + simgrid::s4u::Engine::on_platform_created.connect(surf_presolve); simgrid::s4u::Storage::on_creation.connect([](simgrid::s4u::Storage const& storage) { sg_storage_t s = simgrid::s4u::Storage::by_name(storage.get_name()); @@ -522,10 +522,10 @@ void SIMIX_run() XBT_CRITICAL("Oops! Deadlock or code not perfectly clean."); } SIMIX_display_process_status(); - simgrid::s4u::on_deadlock(); + simgrid::s4u::Engine::on_deadlock(); xbt_abort(); } - simgrid::s4u::on_simulation_end(); + simgrid::s4u::Engine::on_simulation_end(); } double SIMIX_timer_next() diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index db21de9cd2..933b4df7f7 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -165,7 +165,7 @@ NetworkNS3Model::NetworkNS3Model() : NetworkModel(Model::UpdateAlgo::FULL) }); surf::on_cluster.connect(&clusterCreation_cb); - s4u::on_platform_created.connect(&postparse_cb); + s4u::Engine::on_platform_created.connect(&postparse_cb); s4u::NetZone::on_route_creation.connect(&routeCreation_cb); } diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 4201ba0b49..b91dbb05a6 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -51,13 +51,13 @@ static simgrid::kernel::routing::NetZoneImpl* routing_get_current() /** Module management function: creates all internal data structures */ void sg_platf_init() { - simgrid::s4u::on_platform_created.connect(check_disk_attachment); + simgrid::s4u::Engine::on_platform_created.connect(check_disk_attachment); } /** Module management function: frees all internal data structures */ void sg_platf_exit() { simgrid::surf::on_cluster.disconnect_slots(); - simgrid::s4u::on_platform_created.disconnect_slots(); + simgrid::s4u::Engine::on_platform_created.disconnect_slots(); /* make sure that we will reinit the models while loading the platf once reinited */ surf_parse_models_setup_already_called = 0; @@ -548,7 +548,7 @@ static void surf_config_models_setup() simgrid::kernel::routing::NetZoneImpl* sg_platf_new_Zone_begin(simgrid::kernel::routing::ZoneCreationArgs* zone) { if (not surf_parse_models_setup_already_called) { - simgrid::s4u::on_platform_creation(); + simgrid::s4u::Engine::on_platform_creation(); /* Initialize the surf models. That must be done after we got all config, and before we need the models. * That is, after the last tag, if any, and before the first of cluster|peer|zone|trace|trace_connect diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index b0a82806f6..3b80a2d730 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -143,7 +143,7 @@ double surf_solve(double max_date) for (auto const& model : all_existing_models) model->update_actions_state(NOW, time_delta); - simgrid::s4u::on_time_advance(time_delta); + simgrid::s4u::Engine::on_time_advance(time_delta); TRACE_paje_dump_buffer(false); diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index e5f1c15b0b..ce18fa9a58 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -409,7 +409,7 @@ void STag_surfxml_platform() { surf_parsed_filename.c_str(), version); } void ETag_surfxml_platform(){ - simgrid::s4u::on_platform_created(); + simgrid::s4u::Engine::on_platform_created(); } void STag_surfxml_host(){ -- 2.20.1