From 0d3435ca1d4f53502149245466a60dfeacd536f0 Mon Sep 17 00:00:00 2001 From: Bruno Donassolo Date: Mon, 1 Mar 2021 19:20:22 +0100 Subject: [PATCH] Avoid using surf_network_model global Get network model from NetZoneImpl instead of using the global. First step to remove global model variables. Extra: clang-format modified files. --- include/simgrid/kernel/routing/NetZoneImpl.hpp | 1 + src/kernel/activity/CommImpl.cpp | 8 +++++++- src/kernel/routing/NetZoneImpl.cpp | 2 +- src/surf/network_ib.cpp | 15 ++++++++------- teshsuite/surf/surf_usage/surf_usage.cpp | 18 +++++++++++------- teshsuite/surf/surf_usage2/surf_usage2.cpp | 6 +++++- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/include/simgrid/kernel/routing/NetZoneImpl.hpp b/include/simgrid/kernel/routing/NetZoneImpl.hpp index fcb69c98c4..0765aa427e 100644 --- a/include/simgrid/kernel/routing/NetZoneImpl.hpp +++ b/include/simgrid/kernel/routing/NetZoneImpl.hpp @@ -103,6 +103,7 @@ public: resource::NetworkModel* network_model_; + resource::NetworkModel* get_network_model() const { return network_model_; } const s4u::NetZone* get_iface() const { return &piface_; } s4u::NetZone* get_iface() { return &piface_; } unsigned int get_table_size() const { return vertices_.size(); } diff --git a/src/kernel/activity/CommImpl.cpp b/src/kernel/activity/CommImpl.cpp index 469cfdb8f3..f8de83ad91 100644 --- a/src/kernel/activity/CommImpl.cpp +++ b/src/kernel/activity/CommImpl.cpp @@ -6,6 +6,7 @@ #include "src/kernel/activity/CommImpl.hpp" #include "simgrid/Exception.hpp" #include "simgrid/kernel/resource/Action.hpp" +#include "simgrid/kernel/routing/NetPoint.hpp" #include "simgrid/modelchecker.h" #include "simgrid/s4u/Host.hpp" #include "src/kernel/activity/MailboxImpl.hpp" @@ -430,7 +431,12 @@ CommImpl* CommImpl::start() from_ = from_ != nullptr ? from_ : src_actor_->get_host(); to_ = to_ != nullptr ? to_ : dst_actor_->get_host(); - surf_action_ = surf_network_model->communicate(from_, to_, size_, rate_); + /* FIXME[donassolo]: getting the network_model from the origin host + * Soon we need to change this function to first get the routes and later + * create the respective surf actions */ + auto* net_model = from_->get_netpoint()->get_englobing_zone()->get_network_model(); + + surf_action_ = net_model->communicate(from_, to_, size_, rate_); surf_action_->set_activity(this); surf_action_->set_category(get_tracing_category()); state_ = State::RUNNING; diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index d0a894ac72..70bcd205e1 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -68,7 +68,7 @@ int NetZoneImpl::get_host_count() const s4u::Link* NetZoneImpl::create_link(const std::string& name, const std::vector& bandwidths, s4u::Link::SharingPolicy policy) { - auto* l = surf_network_model->create_link(name, bandwidths, policy); + auto* l = network_model_->create_link(name, bandwidths, policy); return l->get_iface(); } diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index 12ae79771f..f04b3fbe56 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -4,6 +4,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "src/surf/network_ib.hpp" +#include "simgrid/kernel/routing/NetPoint.hpp" #include "simgrid/sg_config.hpp" #include "src/surf/HostImpl.hpp" #include "src/surf/xml/platf.hpp" @@ -20,8 +21,8 @@ static void IB_create_host_callback(simgrid::s4u::Host const& host) using simgrid::kernel::resource::NetworkIBModel; static int id = 0; - - ((NetworkIBModel*)surf_network_model)->active_nodes.emplace(host.get_name(), IBNode(id)); + auto* ibModel = static_cast(host.get_netpoint()->get_englobing_zone()->get_network_model()); + ibModel->active_nodes.emplace(host.get_name(), IBNode(id)); id++; } @@ -29,21 +30,21 @@ static void IB_action_state_changed_callback(simgrid::kernel::resource::NetworkA simgrid::kernel::resource::Action::State /*previous*/) { using simgrid::kernel::resource::IBNode; - using simgrid::kernel::resource::NetworkIBModel; if (action.get_state() != simgrid::kernel::resource::Action::State::FINISHED) return; - std::pair pair = ((NetworkIBModel*)surf_network_model)->active_comms[&action]; + auto* ibModel = static_cast(action.get_model()); + std::pair pair = ibModel->active_comms[&action]; XBT_DEBUG("IB callback - action %p finished", &action); - ((NetworkIBModel*)surf_network_model)->updateIBfactors(&action, pair.first, pair.second, 1); + ibModel->updateIBfactors(&action, pair.first, pair.second, 1); - ((NetworkIBModel*)surf_network_model)->active_comms.erase(&action); + ibModel->active_comms.erase(&action); } static void IB_action_init_callback(simgrid::kernel::resource::NetworkAction& action) { - auto* ibModel = static_cast(surf_network_model); + auto* ibModel = static_cast(action.get_model()); auto* act_src = &ibModel->active_nodes.at(action.get_src().get_name()); auto* act_dst = &ibModel->active_nodes.at(action.get_dst().get_name()); diff --git a/teshsuite/surf/surf_usage/surf_usage.cpp b/teshsuite/surf/surf_usage/surf_usage.cpp index f6d4a8ecff..b7b46d6d66 100644 --- a/teshsuite/surf/surf_usage/surf_usage.cpp +++ b/teshsuite/surf/surf_usage/surf_usage.cpp @@ -6,6 +6,8 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/host.h" +#include "simgrid/kernel/routing/NetZoneImpl.hpp" // full type for NetZoneImpl object +#include "simgrid/zone.h" #include "src/surf/cpu_interface.hpp" #include "src/surf/network_interface.hpp" #include "surf/surf.hpp" @@ -40,8 +42,11 @@ int main(int argc, char** argv) xbt_assert(argc > 1, "Usage: %s platform.xml\n", argv[0]); parse_platform_file(argv[1]); + sg_netzone_t as_zone = sg_zone_get_by_name("AS0"); + simgrid::kernel::resource::NetworkModel* net_model = as_zone->get_impl()->get_network_model(); + XBT_DEBUG("CPU model: %p", surf_cpu_model_pm); - XBT_DEBUG("Network model: %p", surf_network_model); + XBT_DEBUG("Network model: %p", net_model); simgrid::s4u::Host* hostA = sg_host_by_name("Cpu A"); simgrid::s4u::Host* hostB = sg_host_by_name("Cpu B"); @@ -60,7 +65,7 @@ int main(int argc, char** argv) XBT_INFO("actionC state: %s", string_action(stateActionC)); /* Let's do something on it */ - surf_network_model->communicate(hostA, hostB, 150.0, -1.0); + net_model->communicate(hostA, hostB, 150.0, -1.0); surf_solve(-1.0); do { @@ -83,7 +88,7 @@ int main(int argc, char** argv) action.unref(); } - action_list = surf_network_model->get_failed_action_set(); + action_list = net_model->get_failed_action_set(); while (not action_list->empty()) { simgrid::kernel::resource::Action& action = action_list->front(); XBT_INFO(" Network Failed action"); @@ -91,16 +96,15 @@ int main(int argc, char** argv) action.unref(); } - action_list = surf_network_model->get_finished_action_set(); + action_list = net_model->get_finished_action_set(); while (not action_list->empty()) { simgrid::kernel::resource::Action& action = action_list->front(); XBT_INFO(" Network Done action"); XBT_DEBUG("\t * Done : %p", &action); action.unref(); } - } while ( - (surf_network_model->get_started_action_set()->size() || surf_cpu_model_pm->get_started_action_set()->size()) && - surf_solve(-1.0) >= 0.0); + } while ((net_model->get_started_action_set()->size() || surf_cpu_model_pm->get_started_action_set()->size()) && + surf_solve(-1.0) >= 0.0); XBT_DEBUG("Simulation Terminated"); diff --git a/teshsuite/surf/surf_usage2/surf_usage2.cpp b/teshsuite/surf/surf_usage2/surf_usage2.cpp index 8f3e1a04f2..4984d793af 100644 --- a/teshsuite/surf/surf_usage2/surf_usage2.cpp +++ b/teshsuite/surf/surf_usage2/surf_usage2.cpp @@ -6,6 +6,8 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/host.h" +#include "simgrid/kernel/routing/NetZoneImpl.hpp" // full type for NetZoneImpl object +#include "simgrid/zone.h" #include "src/surf/cpu_interface.hpp" #include "src/surf/network_interface.hpp" #include "src/surf/surf_interface.hpp" @@ -35,7 +37,9 @@ int main(int argc, char** argv) hostB->pimpl_cpu->execution_start(1000.0); hostB->pimpl_cpu->sleep(7.32); - surf_network_model->communicate(hostA, hostB, 150.0, -1.0); + sg_netzone_t as_zone = sg_zone_get_by_name("AS0"); + simgrid::kernel::resource::NetworkModel* net_model = as_zone->get_impl()->get_network_model(); + net_model->communicate(hostA, hostB, 150.0, -1.0); surf_solve(-1.0); /* Takes traces into account. Returns 0.0 */ do { -- 2.20.1