From: Martin Quinson Date: Thu, 22 Dec 2016 22:37:22 +0000 (+0100) Subject: finish the cleanup of the netcard list container X-Git-Tag: v3_14~7 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/12db8a46fc2350fc54dc04b12fc5580239ef23c4 finish the cleanup of the netcard list container - move it from global to the engine - use a std::unordered_map instead of a xbt_dict. Its order being harder to predict, this forces to sort the list in the routing integration tests. I'm not completely happy about the register/unregister functions being public, but I cannot find anything better, and it's later already... --- diff --git a/include/simgrid/s4u/engine.hpp b/include/simgrid/s4u/engine.hpp index 62b41648c8..8db94fb73a 100644 --- a/include/simgrid/s4u/engine.hpp +++ b/include/simgrid/s4u/engine.hpp @@ -75,6 +75,8 @@ public: /** @brief Retrieve the netcard of the given name (or nullptr if not found) */ simgrid::kernel::routing::NetCard* netcardByNameOrNull(const char* name); void netcardList(std::vector * list); + void netcardRegister(simgrid::kernel::routing::NetCard*); + void netcardUnregister(simgrid::kernel::routing::NetCard*); template void registerFunction(const char* name) diff --git a/include/surf/surf_routing.h b/include/surf/surf_routing.h index edeb6ef899..725f8a1cb1 100644 --- a/include/surf/surf_routing.h +++ b/include/surf/surf_routing.h @@ -15,8 +15,6 @@ SG_BEGIN_DECL() XBT_PUBLIC_DATA(int) SIMIX_STORAGE_LEVEL; //Simix storage level -XBT_PUBLIC_DATA(xbt_dict_t) netcards_dict; - XBT_PUBLIC_DATA(xbt_lib_t) storage_lib; XBT_PUBLIC_DATA(int) ROUTING_STORAGE_LEVEL; //Routing storage level XBT_PUBLIC_DATA(int) ROUTING_STORAGE_HOST_LEVEL; diff --git a/src/kernel/EngineImpl.cpp b/src/kernel/EngineImpl.cpp index 175a18aa7a..f88b59cad8 100644 --- a/src/kernel/EngineImpl.cpp +++ b/src/kernel/EngineImpl.cpp @@ -8,21 +8,15 @@ #include "src/kernel/routing/NetZoneImpl.hpp" #include -xbt_dict_t netcards_dict; - namespace simgrid { namespace kernel { -EngineImpl::EngineImpl() -{ - netcards_dict = xbt_dict_new_homogeneous([](void* p) { - delete static_cast(p); - }); -} +EngineImpl::EngineImpl() = default; EngineImpl::~EngineImpl() { delete netRoot_; - xbt_dict_free(&netcards_dict); + for (auto kv : netcards_) + delete kv.second; } } } diff --git a/src/kernel/EngineImpl.hpp b/src/kernel/EngineImpl.hpp index 839f300ed6..d038e3bdbc 100644 --- a/src/kernel/EngineImpl.hpp +++ b/src/kernel/EngineImpl.hpp @@ -6,10 +6,13 @@ #include #include +#include + namespace simgrid { namespace kernel { namespace routing { class NetZoneImpl; +class NetCard; } class EngineImpl { @@ -19,6 +22,7 @@ public: kernel::routing::NetZoneImpl* netRoot_ = nullptr; protected: + std::unordered_map netcards_; friend simgrid::s4u::Engine; }; } diff --git a/src/kernel/routing/NetCard.cpp b/src/kernel/routing/NetCard.cpp index e45e174b41..d875e898b8 100644 --- a/src/kernel/routing/NetCard.cpp +++ b/src/kernel/routing/NetCard.cpp @@ -22,7 +22,7 @@ NetCard::NetCard(std::string name, NetCard::Type componentType, NetZoneImpl* net { if (netzone_p != nullptr) id_ = netzone_p->addComponent(this); - xbt_dict_set(netcards_dict, name.c_str(), static_cast(this), nullptr); + simgrid::s4u::Engine::instance()->netcardRegister(this); simgrid::kernel::routing::NetCard::onCreation(this); } } diff --git a/src/kernel/routing/NetCard.hpp b/src/kernel/routing/NetCard.hpp index b899b6821a..42c9ceb580 100644 --- a/src/kernel/routing/NetCard.hpp +++ b/src/kernel/routing/NetCard.hpp @@ -45,6 +45,8 @@ public: static simgrid::xbt::signal onCreation; + bool operator<(const NetCard &rhs) const { return name_ < rhs.name_; } + private: unsigned int id_; std::string name_; diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 7a8ecff949..3927a8fdb1 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -39,7 +39,7 @@ NetZoneImpl::~NetZoneImpl() for (auto& kv : bypassRoutes_) delete kv.second; - xbt_dict_remove(netcards_dict, name_); + simgrid::s4u::Engine::instance()->netcardUnregister(netcard_); } simgrid::s4u::Host* NetZoneImpl::createHost(const char* name, std::vector* speedPerPstate, int coreAmount) diff --git a/src/msg/msg_private.h b/src/msg/msg_private.h index 053679675e..4270fd8771 100644 --- a/src/msg/msg_private.h +++ b/src/msg/msg_private.h @@ -17,7 +17,6 @@ SG_BEGIN_DECL() /**************** datatypes **********************************/ /********************************* Host **************************************/ typedef struct s_msg_host_priv { - std::vector *file_descriptor_table; } s_msg_host_priv_t; /********************************* Task **************************************/ diff --git a/src/s4u/s4u_engine.cpp b/src/s4u/s4u_engine.cpp index 6e37df00eb..c98ab30d3b 100644 --- a/src/s4u/s4u_engine.cpp +++ b/src/s4u/s4u_engine.cpp @@ -15,6 +15,8 @@ #include "simgrid/simix.h" #include "src/kernel/EngineImpl.hpp" #include "src/kernel/routing/NetZoneImpl.hpp" +#include "src/kernel/routing/NetCard.hpp" + #include "src/surf/network_interface.hpp" #include "surf/surf.h" // routing_platf. FIXME:KILLME. SOON @@ -114,16 +116,29 @@ NetZone* Engine::netzoneByNameOrNull(const char* name) /** @brief Retrieve the netcard of the given name (or nullptr if not found) */ simgrid::kernel::routing::NetCard* Engine::netcardByNameOrNull(const char* name) { - return static_cast(xbt_dict_get_or_null(netcards_dict, name)); + if (pimpl->netcards_.find(name) == pimpl->netcards_.end()) + return nullptr; + return pimpl->netcards_.at(name); } +/** @brief Fill the provided vector with all existing netcards */ void Engine::netcardList(std::vector* list) { - xbt_lib_cursor_t cursor = nullptr; - char* key; - void* data; - xbt_dict_foreach (netcards_dict, cursor, key, data) { - list->push_back(static_cast(data)); - } + for (auto kv: pimpl->netcards_) + list->push_back(kv.second); +} +/** @brief Register a new netcard to the system */ +void Engine::netcardRegister(simgrid::kernel::routing::NetCard* card) +{ +// simgrid::simix::kernelImmediate([&]{ FIXME: this segfaults in set_thread + pimpl->netcards_[card->name()] = card; +// }); +} +/** @brief Unregister a given netcard */ +void Engine::netcardUnregister(simgrid::kernel::routing::NetCard* card) +{ + simgrid::simix::kernelImmediate([&]{ + pimpl->netcards_.erase(card->name()); + }); } } } diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index 1499c26d5f..72c3dfcb37 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -10,6 +10,7 @@ #include +#include "simgrid/s4u/engine.hpp" #include "simgrid/s4u/host.hpp" #include "simgrid/s4u/storage.hpp" #include "simgrid/simix.hpp" @@ -53,7 +54,7 @@ Host::~Host() delete pimpl_; if (pimpl_netcard != nullptr) // not removed yet by a children class - xbt_dict_remove(netcards_dict, name_.c_str()); + simgrid::s4u::Engine::instance()->netcardUnregister(pimpl_netcard); delete pimpl_cpu; delete mounts; } diff --git a/teshsuite/simdag/flatifier/flatifier.cpp b/teshsuite/simdag/flatifier/flatifier.cpp index f1b74a767e..710bb1acce 100644 --- a/teshsuite/simdag/flatifier/flatifier.cpp +++ b/teshsuite/simdag/flatifier/flatifier.cpp @@ -89,6 +89,10 @@ int main(int argc, char **argv) std::vector netcardList; simgrid::s4u::Engine::instance()->netcardList(&netcardList); + std::sort(netcardList.begin(), netcardList.end(), + [](simgrid::kernel::routing::NetCard* a, simgrid::kernel::routing::NetCard* b) { + return a->name() < b->name(); + }); if (timings) { XBT_INFO("Parsing time: %fs (%zu hosts, %d links)", xbt_os_timer_elapsed(parse_time), diff --git a/teshsuite/simdag/flatifier/flatifier.tesh b/teshsuite/simdag/flatifier/flatifier.tesh index 2f27faab78..1fd4bbfab0 100644 --- a/teshsuite/simdag/flatifier/flatifier.tesh +++ b/teshsuite/simdag/flatifier/flatifier.tesh @@ -373,8 +373,8 @@ $ ${bindir:=.}/flatifier$EXEEXT ../platforms/two_clusters.xml "--log=root.fmt:[% > > > -> > +> > > > @@ -399,12 +399,12 @@ $ ${bindir:=.}/flatifier$EXEEXT ../platforms/two_clusters.xml "--log=root.fmt:[% > > > -> -> -> > > > +> +> +> > > > @@ -417,12 +417,12 @@ $ ${bindir:=.}/flatifier$EXEEXT ../platforms/two_clusters.xml "--log=root.fmt:[% > > > -> -> -> > > > +> +> +> > > > @@ -435,12 +435,12 @@ $ ${bindir:=.}/flatifier$EXEEXT ../platforms/two_clusters.xml "--log=root.fmt:[% > > > -> -> -> > > > +> +> +> > > > @@ -453,36 +453,18 @@ $ ${bindir:=.}/flatifier$EXEEXT ../platforms/two_clusters.xml "--log=root.fmt:[% > > > -> -> -> > > > -> -> -> -> -> -> -> -> -> -> -> -> -> -> +> +> > -> -> +> +> > > > > -> -> -> > > > @@ -495,6 +477,24 @@ $ ${bindir:=.}/flatifier$EXEEXT ../platforms/two_clusters.xml "--log=root.fmt:[% > > > +> +> +> +> +> +> +> +> +> +> +> +> +> +> +> +> +> +> > > @@ -559,8 +559,8 @@ $ ${bindir:=.}/flatifier$EXEEXT ${srcdir:=.}/examples/platforms/bypassASroute.xm > > > -> > +> > > > @@ -582,12 +582,12 @@ $ ${bindir:=.}/flatifier$EXEEXT ${srcdir:=.}/examples/platforms/bypassASroute.xm > > > -> -> -> > > > +> +> +> > > > @@ -600,12 +600,12 @@ $ ${bindir:=.}/flatifier$EXEEXT ${srcdir:=.}/examples/platforms/bypassASroute.xm > > > -> -> -> > > > +> +> +> > > > @@ -618,39 +618,21 @@ $ ${bindir:=.}/flatifier$EXEEXT ${srcdir:=.}/examples/platforms/bypassASroute.xm > > > -> -> -> > > > +> +> +> > > > -> +> > > -> -> -> -> -> -> -> -> -> -> -> -> -> -> -> > > > -> -> -> > > > @@ -663,12 +645,30 @@ $ ${bindir:=.}/flatifier$EXEEXT ${srcdir:=.}/examples/platforms/bypassASroute.xm > > > -> -> +> +> +> +> +> +> +> +> +> +> +> +> +> +> +> +> +> > > > > +> +> +> > > > diff --git a/teshsuite/simdag/is-router/is-router.cpp b/teshsuite/simdag/is-router/is-router.cpp index 5ac0df5743..4e873ef1b0 100644 --- a/teshsuite/simdag/is-router/is-router.cpp +++ b/teshsuite/simdag/is-router/is-router.cpp @@ -20,6 +20,10 @@ int main(int argc, char **argv) std::vector netcardList; simgrid::s4u::Engine::instance()->netcardList(&netcardList); + std::sort(netcardList.begin(), netcardList.end(), + [](simgrid::kernel::routing::NetCard* a, simgrid::kernel::routing::NetCard* b) { + return a->name() < b->name(); + }); int it; sg_host_t host; diff --git a/teshsuite/simdag/is-router/is-router.tesh b/teshsuite/simdag/is-router/is-router.tesh index 2fabad2417..6039c371b3 100644 --- a/teshsuite/simdag/is-router/is-router.tesh +++ b/teshsuite/simdag/is-router/is-router.tesh @@ -1,6 +1,6 @@ #! ./tesh -$ ${bindir:=.}/is-router ../platforms/test_of_is_router.xml "--log=root.fmt:[%10.6r]%e[%i:%P@%h]%e%m%n" +$ ${bindir:=.}/is-router ${srcdir}/teshsuite/simdag/platforms/test_of_is_router.xml "--log=root.fmt:[%10.6r]%e[%i:%P@%h]%e%m%n" > [ 0.000000] [0:maestro@] Switching to the L07 model to handle parallel tasks. > Host count: 10, link number: 1 > - Seen: "host01". Type: host @@ -14,6 +14,12 @@ $ ${bindir:=.}/is-router ../platforms/test_of_is_router.xml "--log=root.fmt:[%10 > - Seen: "host09". Type: host > - Seen: "host10". Type: host > NetCards count: 21 +> - Seen: "AS". Type: netzone +> - Seen: "AS0". Type: netzone +> - Seen: "AS1". Type: netzone +> - Seen: "AS2". Type: netzone +> - Seen: "AS3". Type: netzone +> - Seen: "AS4". Type: netzone > - Seen: "host01". Type: host > - Seen: "host02". Type: host > - Seen: "host03". Type: host @@ -23,15 +29,9 @@ $ ${bindir:=.}/is-router ../platforms/test_of_is_router.xml "--log=root.fmt:[%10 > - Seen: "host07". Type: host > - Seen: "host08". Type: host > - Seen: "host09". Type: host +> - Seen: "host10". Type: host > - Seen: "router1". Type: router > - Seen: "router2". Type: router > - Seen: "router3". Type: router > - Seen: "router4". Type: router > - Seen: "router5". Type: router -> - Seen: "host10". Type: host -> - Seen: "AS0". Type: netzone -> - Seen: "AS1". Type: netzone -> - Seen: "AS2". Type: netzone -> - Seen: "AS3". Type: netzone -> - Seen: "AS4". Type: netzone -> - Seen: "AS". Type: netzone