From 745de4b9b7e938a60ebc8a57286f795bd7ca112d Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 12 Jan 2017 17:53:02 +0100 Subject: [PATCH] add the properties as argument to NetZoneImpl->createHost This allows to incorporate the onHostCreation to that function instead of having each host creator specifying that they just created an host This was mandatory because the plugin energy needs the properties to be setup when the signal is called. --- src/kernel/routing/NetZoneImpl.cpp | 9 ++++++++- src/kernel/routing/NetZoneImpl.hpp | 3 ++- src/s4u/s4u_host.cpp | 1 + src/surf/sg_platf.cpp | 21 ++++++++++----------- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index b48032b06c..d4637b302e 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -42,7 +42,8 @@ NetZoneImpl::~NetZoneImpl() simgrid::s4u::Engine::instance()->netcardUnregister(netcard_); } -simgrid::s4u::Host* NetZoneImpl::createHost(const char* name, std::vector* speedPerPstate, int coreAmount) +simgrid::s4u::Host* NetZoneImpl::createHost(const char* name, std::vector* speedPerPstate, int coreAmount, + std::unordered_map* props) { simgrid::s4u::Host* res = new simgrid::s4u::Host(name); @@ -53,6 +54,12 @@ simgrid::s4u::Host* NetZoneImpl::createHost(const char* name, std::vectorcreateCpu(res, speedPerPstate, coreAmount); + if (props != nullptr) + for (auto kv : *props) + res->setProperty(kv.first.c_str(), kv.second.c_str()); + + simgrid::s4u::Host::onCreation(*res); + return res; } diff --git a/src/kernel/routing/NetZoneImpl.hpp b/src/kernel/routing/NetZoneImpl.hpp index ef725ab4f7..bac785d56f 100644 --- a/src/kernel/routing/NetZoneImpl.hpp +++ b/src/kernel/routing/NetZoneImpl.hpp @@ -58,7 +58,8 @@ protected: public: /** @brief Make an host within that NetZone */ - simgrid::s4u::Host* createHost(const char* name, std::vector* speedPerPstate, int coreAmount); + simgrid::s4u::Host* createHost(const char* name, std::vector* speedPerPstate, int coreAmount, + std::unordered_map* props); /** @brief Creates a new route in this NetZone */ void addBypassRoute(sg_platf_route_cbarg_t e_route) override; diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index e58eead5f5..bffb0714c6 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -46,6 +46,7 @@ Host::Host(const char* name) { xbt_assert(Host::by_name_or_null(name) == nullptr, "Refusing to create a second host named '%s'.", name); host_list[name_] = this; + new simgrid::surf::HostImpl(this, nullptr); } Host::~Host() diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 49897a1f8e..3271fc0be0 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -65,20 +65,22 @@ void sg_platf_exit() { /** @brief Add an host to the current AS */ void sg_platf_new_host(sg_platf_host_cbarg_t args) { - simgrid::s4u::Host* host = routing_get_current()->createHost(args->id, &args->speed_per_pstate, args->core_amount); - - new simgrid::surf::HostImpl(host, mount_list); - xbt_lib_set(storage_lib, args->id, ROUTING_STORAGE_HOST_LEVEL, static_cast(mount_list)); - mount_list = nullptr; - + std::unordered_map props; if (args->properties) { xbt_dict_cursor_t cursor=nullptr; char *key,*data; xbt_dict_foreach (args->properties, cursor, key, data) - host->setProperty(key, data); + props[key] = data; xbt_dict_free(&args->properties); } + simgrid::s4u::Host* host = + routing_get_current()->createHost(args->id, &args->speed_per_pstate, args->core_amount, &props); + + host->pimpl_->storage_ = mount_list; + xbt_lib_set(storage_lib, args->id, ROUTING_STORAGE_HOST_LEVEL, static_cast(mount_list)); + mount_list = nullptr; + /* Change from the defaults */ if (args->state_trace) host->pimpl_cpu->setStateTrace(args->state_trace); @@ -89,8 +91,6 @@ void sg_platf_new_host(sg_platf_host_cbarg_t args) if (args->coord && strcmp(args->coord, "")) new simgrid::kernel::routing::vivaldi::Coords(host->pimpl_netcard, args->coord); - simgrid::s4u::Host::onCreation(*host); - if (TRACE_is_enabled() && TRACE_needs_platform()) sg_instr_new_host(*host); } @@ -555,10 +555,9 @@ void sg_platf_new_peer(sg_platf_peer_cbarg_t peer) std::vector speedPerPstate; speedPerPstate.push_back(peer->speed); - simgrid::s4u::Host* host = as->createHost(peer->id, &speedPerPstate, 1); + simgrid::s4u::Host* host = as->createHost(peer->id, &speedPerPstate, 1, nullptr); as->setPeerLink(host->pimpl_netcard, peer->bw_in, peer->bw_out, peer->coord); - simgrid::s4u::Host::onCreation(*host); /* Change from the defaults */ if (peer->state_trace) -- 2.20.1