From e509955c811a80b2d03f306fa04316a6b050dbcf Mon Sep 17 00:00:00 2001 From: Bruno Donassolo Date: Thu, 1 Apr 2021 16:31:31 +0200 Subject: [PATCH] Adding seal() for Host Allow changing Host settings before seal --- include/simgrid/s4u/Host.hpp | 6 ++++++ src/kernel/routing/NetZoneImpl.cpp | 2 +- src/plugins/vm/s4u_VirtualMachine.cpp | 2 ++ src/s4u/s4u_Host.cpp | 6 ++++++ src/surf/HostImpl.cpp | 5 +++++ src/surf/HostImpl.hpp | 3 +++ src/surf/sg_platf.cpp | 2 ++ 7 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index b23efc3c63..7aba7b7d96 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -166,6 +166,12 @@ public: void route_to(const Host* dest, std::vector& links, double* latency) const; void route_to(const Host* dest, std::vector& links, double* latency) const; + /** + * @brief Seal this host + * No more configuration is allowed after the seal + */ + void seal(); + #ifndef DOXYGEN XBT_ATTRIB_DEPRECATED_v331("Please use Comm::sendto()") void sendto(Host* dest, double byte_amount); diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index ebcdc97dc8..05a9a874ae 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -162,7 +162,7 @@ s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vectorget_iface(); res->set_netpoint((new NetPoint(name, NetPoint::Type::Host))->set_englobing_zone(this)); - cpu_model_pm_->create_cpu(res, speed_per_pstate)->set_core_count(core_amount)->seal(); + cpu_model_pm_->create_cpu(res, speed_per_pstate)->set_core_count(core_amount); return res; } diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index 7450b709cd..37f6abf63c 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -52,6 +52,8 @@ VirtualMachine::VirtualMachine(const std::string& name, s4u::Host* physical_host if (physical_host->get_pstate() != 0) set_pstate(physical_host->get_pstate()); + seal(); // seal this host + // Real hosts are (only) created through NetZone::create_host(), and this where the on_creation signal is fired. // VMs are created directly, thus firing the signal here. The right solution is probably to separate Host and VM. simgrid::s4u::Host::on_creation(*this); diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 3345eca816..5dc3074d25 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -342,6 +342,12 @@ void Host::execute(double flops, double priority) const this_actor::exec_init(flops)->set_priority(1 / priority)->vetoable_start()->wait(); } +void Host::seal() +{ + kernel::actor::simcall([this]() { this->pimpl_cpu->seal(); }); + kernel::actor::simcall([this]() { this->pimpl_->seal(); }); +} + } // namespace s4u } // namespace simgrid diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index 9b8ec04df4..e5c64670ae 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -150,5 +150,10 @@ void HostImpl::remove_disk(const std::string& disk_name) position++; } } + +void HostImpl::seal() +{ + sealed_ = true; +} } // namespace surf } // namespace simgrid diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index 2429c3d91b..7fb7086d25 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -51,6 +51,7 @@ class XBT_PRIVATE HostImpl : public xbt::PropertyHolder { s4u::Host piface_; std::vector disks_; xbt::string name_{"noname"}; + bool sealed_ = false; protected: virtual ~HostImpl(); // Use destroy() instead of this destructor. @@ -83,6 +84,8 @@ public: void remove_actor(kernel::actor::ActorImpl* actor) { xbt::intrusive_erase(actor_list_, *actor); } void add_actor_at_boot(kernel::actor::ProcessArg* arg) { actors_at_boot_.emplace_back(arg); } + void seal(); + template void foreach_actor(F function) { for (auto& actor : actor_list_) diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index b7f75c96de..b4bfc7c2aa 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -78,6 +78,7 @@ void sg_platf_new_host(const simgrid::kernel::routing::HostCreationArgs* args) if (not args->coord.empty()) new simgrid::kernel::routing::vivaldi::Coords(host->get_netpoint(), args->coord); + host->seal(); simgrid::s4u::Host::on_creation(*host); // notify the signal /* When energy plugin is activated, changing the pstate requires to already have the HostEnergy extension whose @@ -426,6 +427,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); + host->seal(); simgrid::s4u::Host::on_creation(*host); // notify the signal } -- 2.20.1