From 10d527068096e98e4f574a89434d8f25b6641b28 Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Mon, 12 Apr 2021 23:20:00 +0200 Subject: [PATCH] change way disks are managed in the XML parsing --- src/bindings/lua/lua_platf.cpp | 3 +- src/kernel/resource/DiskImpl.cpp | 1 + src/s4u/s4u_Disk.cpp | 1 - src/s4u/s4u_Host.cpp | 4 +- src/surf/HostImpl.cpp | 8 ---- src/surf/HostImpl.hpp | 1 - src/surf/sg_platf.cpp | 64 ++++++++++++++++++-------------- src/surf/xml/platf_private.hpp | 11 +++--- src/surf/xml/surfxml_sax_cb.cpp | 32 ++++++++-------- 9 files changed, 64 insertions(+), 61 deletions(-) diff --git a/src/bindings/lua/lua_platf.cpp b/src/bindings/lua/lua_platf.cpp index 865f501a61..d569454e88 100644 --- a/src/bindings/lua/lua_platf.cpp +++ b/src/bindings/lua/lua_platf.cpp @@ -210,7 +210,8 @@ int console_add_host(lua_State *L) { host.state_trace = simgrid::kernel::profile::Profile::from_file(filename); lua_pop(L, 1); - sg_platf_new_host(&host); + sg_platf_new_host_begin(&host); + sg_platf_new_host_seal(0); return 0; } diff --git a/src/kernel/resource/DiskImpl.cpp b/src/kernel/resource/DiskImpl.cpp index a7ace5d5d4..40391d1caf 100644 --- a/src/kernel/resource/DiskImpl.cpp +++ b/src/kernel/resource/DiskImpl.cpp @@ -29,6 +29,7 @@ DiskModel::DiskModel(const std::string& name) : Model(name) ************/ DiskImpl* DiskImpl::set_host(s4u::Host* host) { + xbt_assert(host, "Cannot set host, none given"); host_ = host; return this; } diff --git a/src/s4u/s4u_Disk.cpp b/src/s4u/s4u_Disk.cpp index 28e37b15c5..f8f10f81f2 100644 --- a/src/s4u/s4u_Disk.cpp +++ b/src/s4u/s4u_Disk.cpp @@ -109,7 +109,6 @@ sg_size_t Disk::write(sg_size_t size) const Disk* Disk::seal() { kernel::actor::simcall([this]{ pimpl_->seal(); }); - get_host()->add_disk(this); Disk::on_creation(*this); return this; } diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 72c27ad7ca..abf1d86547 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -319,7 +319,9 @@ std::vector Host::get_disks() const Disk* Host::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth) { return kernel::actor::simcall([this, &name, read_bandwidth, write_bandwidth] { - return this->pimpl_->create_disk(name, read_bandwidth, write_bandwidth); + auto* disk = pimpl_->create_disk(name, read_bandwidth, write_bandwidth); + pimpl_->add_disk(disk); + return disk; }); } diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index b2cc1cfeb7..adfa0336aa 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -129,14 +129,6 @@ std::vector HostImpl::get_disks() const return disks; } -HostImpl* HostImpl::set_disks(const std::vector& disks) -{ - disks_ = disks; - for (auto d : disks_) - d->set_host(&piface_); - return this; -} - s4u::Disk* HostImpl::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth) { auto disk = piface_.get_netpoint()->get_englobing_zone()->get_disk_model()->create_disk(name, read_bandwidth, diff --git a/src/surf/HostImpl.hpp b/src/surf/HostImpl.hpp index 1601eca115..6ac9e5af0f 100644 --- a/src/surf/HostImpl.hpp +++ b/src/surf/HostImpl.hpp @@ -64,7 +64,6 @@ public: void destroy(); // Must be called instead of the destructor std::vector get_disks() const; - HostImpl* set_disks(const std::vector& disks); s4u::Disk* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth); void add_disk(const s4u::Disk* disk); void remove_disk(const std::string& disk_name); diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index a0853f368e..90bd01c367 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -44,6 +44,7 @@ static simgrid::kernel::routing::NetZoneImpl* routing_get_current() { return current_routing; } +static simgrid::s4u::Host* current_host = nullptr; /** Module management function: creates all internal data structures */ void sg_platf_init() @@ -61,25 +62,35 @@ void sg_platf_exit() } /** @brief Add a host to the current NetZone */ -void sg_platf_new_host(const simgrid::kernel::routing::HostCreationArgs* args) +void sg_platf_new_host_begin(const simgrid::kernel::routing::HostCreationArgs* args) { - simgrid::s4u::Host* host = routing_get_current() - ->create_host(args->id, args->speed_per_pstate) - ->set_coordinates(args->coord) - ->set_properties(args->properties); - - host->get_impl()->set_disks(args->disks); + current_host = routing_get_current() + ->create_host(args->id, args->speed_per_pstate) + ->set_coordinates(args->coord) + ->set_core_count(args->core_amount) + ->set_state_profile(args->state_trace) + ->set_speed_profile(args->speed_trace); + // host->get_impl()->set_disks(args->disks); +} - host->pimpl_cpu->set_core_count(args->core_amount) - ->set_state_profile(args->state_trace) - ->set_speed_profile(args->speed_trace); +void sg_platf_new_host_set_properties(const std::unordered_map& props) +{ + xbt_assert(current_host, "Cannot set properties of the current host: none under construction"); + current_host->set_properties(props); +} - host->seal(); +void sg_platf_new_host_seal(int pstate) +{ + xbt_assert(current_host, "Cannot seal the current Host: none under construction"); + current_host->seal(); /* When energy plugin is activated, changing the pstate requires to already have the HostEnergy extension whose - * allocation is triggered by the on_creation signal. Then set_pstate must be called after the signal emition */ - if (args->pstate != 0) - host->set_pstate(args->pstate); + * allocation is triggered by the on_creation signal. Then set_pstate must be called after the signal emission */ + + if (pstate != 0) + current_host->set_pstate(pstate); + + current_host = nullptr; } /** @brief Add a "router" to the network element list */ @@ -122,6 +133,17 @@ void sg_platf_new_link(const simgrid::kernel::routing::LinkCreationArgs* link) } } +void sg_platf_new_disk(const simgrid::kernel::routing::DiskCreationArgs* disk) +{ + simgrid::s4u::Disk* new_disk = routing_get_current() + ->create_disk(disk->id, disk->read_bw, disk->write_bw) + ->set_host(current_host) + ->set_properties(disk->properties) + ->seal(); + + current_host->add_disk(new_disk); +} + void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* cluster) { using simgrid::kernel::routing::ClusterZone; @@ -269,18 +291,6 @@ void sg_platf_new_cabinet(const simgrid::kernel::routing::CabinetCreationArgs* c } } -simgrid::kernel::resource::DiskImpl* sg_platf_new_disk(const simgrid::kernel::routing::DiskCreationArgs* disk) -{ - simgrid::kernel::resource::DiskImpl* pimpl = routing_get_current() - ->create_disk(disk->id, disk->read_bw, disk->write_bw) - ->set_properties(disk->properties) - ->get_impl(); - - pimpl->seal(); - simgrid::s4u::Disk::on_creation(*pimpl->get_iface()); - return pimpl; -} - void sg_platf_new_route(simgrid::kernel::routing::RouteCreationArgs* route) { routing_get_current()->add_route(route->src, route->dst, route->gw_src, route->gw_dst, route->link_list, @@ -462,7 +472,7 @@ void sg_platf_new_Zone_set_properties(const std::unordered_mapseal(); simgrid::s4u::NetZone::on_seal(*current_routing->get_iface()); current_routing = current_routing->get_parent(); diff --git a/src/surf/xml/platf_private.hpp b/src/surf/xml/platf_private.hpp index 7ea69f684f..66f1ef2c3a 100644 --- a/src/surf/xml/platf_private.hpp +++ b/src/surf/xml/platf_private.hpp @@ -41,8 +41,6 @@ public: profile::Profile* speed_trace = nullptr; profile::Profile* state_trace = nullptr; std::string coord = ""; - std::unordered_map properties; - std::vector disks; }; class HostLinkCreationArgs { @@ -179,12 +177,17 @@ XBT_PUBLIC void sg_platf_new_Zone_set_properties(const std::unordered_map& props); +XBT_PUBLIC void sg_platf_new_host_seal(int pstate); // That Host is fully described + XBT_PUBLIC void sg_platf_new_hostlink(const simgrid::kernel::routing::HostLinkCreationArgs* h); // Add a host_link to the current Zone XBT_PUBLIC void sg_platf_new_link(const simgrid::kernel::routing::LinkCreationArgs* link); // Add a link to the current Zone XBT_PUBLIC void +sg_platf_new_disk(const simgrid::kernel::routing::DiskCreationArgs* disk); // Add a disk to the current host +XBT_PUBLIC void sg_platf_new_peer(const simgrid::kernel::routing::PeerCreationArgs* peer); // Add a peer to the current Zone XBT_PUBLIC void sg_platf_new_cluster(simgrid::kernel::routing::ClusterCreationArgs* clust); // Add a cluster to the current Zone XBT_PUBLIC void @@ -197,8 +200,6 @@ XBT_PUBLIC void sg_platf_new_bypassRoute(simgrid::kernel::routing::RouteCreation XBT_PUBLIC void sg_platf_new_trace(simgrid::kernel::routing::ProfileCreationArgs* trace); -XBT_PUBLIC simgrid::kernel::resource::DiskImpl* -sg_platf_new_disk(const simgrid::kernel::routing::DiskCreationArgs* disk); // Add a disk to the current host XBT_PUBLIC void sg_platf_new_actor(simgrid::kernel::routing::ActorCreationArgs* actor); XBT_PRIVATE void sg_platf_trace_connect(simgrid::kernel::routing::TraceConnectCreationArgs* trace_connect); diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index a2ec81fd41..2582c3d5b5 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -30,10 +30,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF std::string surf_parsed_filename; // Currently parsed file (for the error messages) std::vector parsed_link_list; /* temporary store of current link list of a route */ -std::vector parsed_disk_list; /* temporary store of current disk list of a host */ -/* - * Helping functions - */ + +/* Helping functions */ void surf_parse_assert(bool cond, const std::string& msg) { if (not cond) @@ -226,10 +224,6 @@ void ETag_surfxml_platform(){ simgrid::s4u::Engine::on_platform_created(); } -void STag_surfxml_host(){ - property_sets.push_back(std::unordered_map()); -} - void STag_surfxml_prop() { property_sets.back().insert({A_surfxml_prop_id, A_surfxml_prop_value}); @@ -237,12 +231,10 @@ void STag_surfxml_prop() &(property_sets.back())); } -void ETag_surfxml_host() { +void STag_surfxml_host() +{ simgrid::kernel::routing::HostCreationArgs host; - - host.properties = property_sets.back(); - property_sets.pop_back(); - + property_sets.push_back(std::unordered_map()); host.id = A_surfxml_host_id; host.speed_per_pstate = @@ -260,11 +252,17 @@ void ETag_surfxml_host() { host.state_trace = A_surfxml_host_state___file[0] ? simgrid::kernel::profile::Profile::from_file(A_surfxml_host_state___file) : nullptr; - host.pstate = surf_parse_get_int(A_surfxml_host_pstate); host.coord = A_surfxml_host_coordinates; - host.disks.swap(parsed_disk_list); - sg_platf_new_host(&host); + sg_platf_new_host_begin(&host); +} + +void ETag_surfxml_host() +{ + sg_platf_new_host_set_properties(property_sets.back()); + property_sets.pop_back(); + + sg_platf_new_host_seal(surf_parse_get_int(A_surfxml_host_pstate)); } void STag_surfxml_disk() { @@ -282,7 +280,7 @@ void ETag_surfxml_disk() { disk.write_bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_disk_write___bw, "write_bw of disk ", disk.id); - parsed_disk_list.push_back(sg_platf_new_disk(&disk)); + sg_platf_new_disk(&disk); } void STag_surfxml_host___link(){ -- 2.20.1