From 3eac9930d9884df93ae2beda0a1137c29b669274 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Wed, 24 Feb 2021 17:47:32 +0100 Subject: [PATCH] a bit more method chaining in the internals --- .../simgrid/kernel/routing/NetZoneImpl.hpp | 6 ++--- include/simgrid/kernel/routing/WifiZone.hpp | 3 +-- include/simgrid/s4u/Host.hpp | 6 ++--- include/simgrid/s4u/Link.hpp | 4 +++- src/kernel/routing/NetZoneImpl.cpp | 18 ++++----------- src/kernel/routing/WifiZone.cpp | 5 ++-- src/s4u/s4u_Host.cpp | 12 ++++++++-- src/s4u/s4u_Link.cpp | 15 +++++++++++- src/surf/sg_platf.cpp | 23 ++++++++----------- 9 files changed, 49 insertions(+), 43 deletions(-) diff --git a/include/simgrid/kernel/routing/NetZoneImpl.hpp b/include/simgrid/kernel/routing/NetZoneImpl.hpp index 52b88e41ff..62c25c3f91 100644 --- a/include/simgrid/kernel/routing/NetZoneImpl.hpp +++ b/include/simgrid/kernel/routing/NetZoneImpl.hpp @@ -120,12 +120,10 @@ public: int get_host_count() const; /** @brief Make a host within that NetZone */ - s4u::Host* create_host(const std::string& name, const std::vector& speed_per_pstate, int core_count, - const std::unordered_map* props); + s4u::Host* create_host(const std::string& name, const std::vector& speed_per_pstate, int core_count); /** @brief Make a link within that NetZone */ virtual s4u::Link* create_link(const std::string& name, const std::vector& bandwidths, double latency, - s4u::Link::SharingPolicy policy, - const std::unordered_map* props); + s4u::Link::SharingPolicy policy); /** @brief Creates a new route in this NetZone */ virtual void add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst, std::vector& link_list, bool symmetrical); diff --git a/include/simgrid/kernel/routing/WifiZone.hpp b/include/simgrid/kernel/routing/WifiZone.hpp index c695e6e907..f08aa1f57b 100644 --- a/include/simgrid/kernel/routing/WifiZone.hpp +++ b/include/simgrid/kernel/routing/WifiZone.hpp @@ -28,8 +28,7 @@ public: void seal() override; void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override; s4u::Link* create_link(const std::string& name, const std::vector& bandwidths, double latency, - s4u::Link::SharingPolicy policy, - const std::unordered_map* props) override; + s4u::Link::SharingPolicy policy) override; NetPoint* get_access_point() {return access_point_;} private: diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index fe1dcc4d81..6c909ecbeb 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -46,7 +46,7 @@ public: protected: virtual ~Host(); // Call destroy() instead of manually deleting it. - void set_netpoint(kernel::routing::NetPoint* netpoint) { pimpl_netpoint_ = netpoint; } + Host* set_netpoint(kernel::routing::NetPoint* netpoint); #endif public: @@ -100,9 +100,9 @@ public: bool is_on() const; const char* get_property(const std::string& key) const; - void set_property(const std::string& key, const std::string& value); + Host* set_property(const std::string& key, const std::string& value); const std::unordered_map* get_properties() const; - void set_properties(const std::unordered_map& properties); + Host* set_properties(const std::unordered_map& properties); void set_state_profile(kernel::profile::Profile* p); void set_speed_profile(kernel::profile::Profile* p); diff --git a/include/simgrid/s4u/Link.hpp b/include/simgrid/s4u/Link.hpp index d3f06f4bc1..58e26124c7 100644 --- a/include/simgrid/s4u/Link.hpp +++ b/include/simgrid/s4u/Link.hpp @@ -101,7 +101,9 @@ public: void set_latency_profile(kernel::profile::Profile* profile); const char* get_property(const std::string& key) const; - void set_property(const std::string& key, const std::string& value); + Link* set_property(const std::string& key, const std::string& value); + const std::unordered_map* get_properties() const; + Link* set_properties(const std::unordered_map& properties); /* The signals */ /** @brief Callback signal fired when a new Link is created */ diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index ec9c601c42..215fe4748b 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -66,8 +66,7 @@ int NetZoneImpl::get_host_count() const } s4u::Link* NetZoneImpl::create_link(const std::string& name, const std::vector& bandwidths, double latency, - s4u::Link::SharingPolicy policy, - const std::unordered_map* props) + s4u::Link::SharingPolicy policy) { static double last_warned_latency = sg_surf_precision; if (latency != 0.0 && latency < last_warned_latency) { @@ -79,28 +78,19 @@ s4u::Link* NetZoneImpl::create_link(const std::string& name, const std::vectorcreate_link(name, bandwidths, latency, policy); - if (props) - l->set_properties(*props); - return l->get_iface(); } + s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vector& speed_per_pstate, - int coreAmount, const std::unordered_map* props) + int coreAmount) { - auto* res = new s4u::Host(name); - if (hierarchy_ == RoutingMode::unset) hierarchy_ = RoutingMode::base; - res->set_netpoint(new NetPoint(name, NetPoint::Type::Host, this)); + auto* res = (new s4u::Host(name))->set_netpoint(new NetPoint(name, NetPoint::Type::Host, this)); surf_cpu_model_pm->create_cpu(res, speed_per_pstate, coreAmount); - if (props != nullptr) - res->set_properties(*props); - - s4u::Host::on_creation(*res); // notify the signal - return res; } diff --git a/src/kernel/routing/WifiZone.cpp b/src/kernel/routing/WifiZone.cpp index 5eae791f0e..52965610d3 100644 --- a/src/kernel/routing/WifiZone.cpp +++ b/src/kernel/routing/WifiZone.cpp @@ -56,15 +56,14 @@ void WifiZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* } } s4u::Link* WifiZone::create_link(const std::string& name, const std::vector& bandwidths, double latency, - s4u::Link::SharingPolicy policy, - const std::unordered_map* props) + s4u::Link::SharingPolicy policy) { xbt_assert(wifi_link_ == nullptr, "WIFI netzone %s contains more than one link. Please only declare one, the wifi link.", get_cname()); xbt_assert(policy == s4u::Link::SharingPolicy::WIFI, "Link %s in WIFI zone %s must follow the WIFI sharing policy.", name.c_str(), get_cname()); - auto s4u_link = NetZoneImpl::create_link(name, bandwidths, latency, policy, props); + auto s4u_link = NetZoneImpl::create_link(name, bandwidths, latency, policy); wifi_link_ = s4u_link->get_impl(); return s4u_link; } diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index becb0936d7..b87640bf49 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -37,6 +37,12 @@ Host::Host(const std::string& name) : name_(name) new surf::HostImpl(this); } +Host* Host::set_netpoint(kernel::routing::NetPoint* netpoint) +{ + pimpl_netpoint_ = netpoint; + return this; +} + Host::~Host() { delete pimpl_; @@ -192,14 +198,16 @@ const char* Host::get_property(const std::string& key) const return this->pimpl_->get_property(key); } -void Host::set_property(const std::string& key, const std::string& value) +Host* Host::set_property(const std::string& key, const std::string& value) { kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); }); + return this; } -void Host::set_properties(const std::unordered_map& properties) +Host* Host::set_properties(const std::unordered_map& properties) { kernel::actor::simcall([this, &properties] { this->pimpl_->set_properties(properties); }); + return this; } /** Specify a profile turning the host on and off according to an exhaustive list or a stochastic law. diff --git a/src/s4u/s4u_Link.cpp b/src/s4u/s4u_Link.cpp index 6d71cf2208..59cee96d9e 100644 --- a/src/s4u/s4u_Link.cpp +++ b/src/s4u/s4u_Link.cpp @@ -126,10 +126,23 @@ const char* Link::get_property(const std::string& key) const { return this->pimpl_->get_property(key); } -void Link::set_property(const std::string& key, const std::string& value) +Link* Link::set_property(const std::string& key, const std::string& value) { simgrid::kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); }); + return this; } + +const std::unordered_map* Link::get_properties() const +{ + return this->pimpl_->get_properties(); +} + +Link* Link::set_properties(const std::unordered_map& properties) +{ + kernel::actor::simcall([this, &properties] { this->pimpl_->set_properties(properties); }); + return this; +} + } // namespace s4u } // namespace simgrid diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 809225f15d..2995790d03 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -66,16 +66,13 @@ void sg_platf_exit() { /** @brief Add a host to the current AS */ void sg_platf_new_host(const simgrid::kernel::routing::HostCreationArgs* args) { - std::unordered_map props; + simgrid::s4u::Host* host = routing_get_current()->create_host(args->id, args->speed_per_pstate, args->core_amount); + if (args->properties) { - for (auto const& elm : *args->properties) - props.insert({elm.first, elm.second}); + host->set_properties(*args->properties); delete args->properties; } - simgrid::s4u::Host* host = - routing_get_current()->create_host(args->id, args->speed_per_pstate, args->core_amount, &props); - host->pimpl_->set_disks(args->disks, host); /* Change from the defaults */ @@ -87,6 +84,8 @@ void sg_platf_new_host(const simgrid::kernel::routing::HostCreationArgs* args) host->set_pstate(args->pstate); if (not args->coord.empty()) new simgrid::kernel::routing::vivaldi::Coords(host->get_netpoint(), args->coord); + + simgrid::s4u::Host::on_creation(*host); // notify the signal } /** @brief Add a "router" to the network element list */ @@ -110,13 +109,10 @@ simgrid::kernel::routing::NetPoint* sg_platf_new_router(const std::string& name, static void sg_platf_new_link(const simgrid::kernel::routing::LinkCreationArgs* args, const std::string& link_name) { - std::unordered_map props; - if (args->properties) - for (auto const& elm : *args->properties) - props.insert({elm.first, elm.second}); + simgrid::s4u::Link* link = routing_get_current()->create_link(link_name, args->bandwidths, args->latency, args->policy); - const simgrid::s4u::Link* link = - routing_get_current()->create_link(link_name, args->bandwidths, args->latency, args->policy, &props); + if (args->properties) + link->set_properties(*args->properties); simgrid::kernel::resource::LinkImpl* l = link->get_impl(); if (args->latency_trace) @@ -425,7 +421,7 @@ void sg_platf_new_peer(const simgrid::kernel::routing::PeerCreationArgs* peer) std::vector speed_per_pstate; speed_per_pstate.push_back(peer->speed); - simgrid::s4u::Host* host = as->create_host(peer->id, speed_per_pstate, 1, nullptr); + simgrid::s4u::Host* host = as->create_host(peer->id, speed_per_pstate, 1); as->set_peer_link(host->get_netpoint(), peer->bw_in, peer->bw_out, peer->coord); @@ -434,6 +430,7 @@ void sg_platf_new_peer(const simgrid::kernel::routing::PeerCreationArgs* peer) host->set_state_profile(peer->state_trace); if (peer->speed_trace) host->set_speed_profile(peer->speed_trace); + simgrid::s4u::Host::on_creation(*host); // notify the signal } /* Pick the right models for CPU, net and host, and call their model_init_preparse */ -- 2.20.1