Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
change way disks are managed in the XML parsing
authorSUTER Frederic <frederic.suter@cc.in2p3.fr>
Mon, 12 Apr 2021 21:20:00 +0000 (23:20 +0200)
committerSUTER Frederic <frederic.suter@cc.in2p3.fr>
Mon, 12 Apr 2021 21:37:37 +0000 (23:37 +0200)
src/bindings/lua/lua_platf.cpp
src/kernel/resource/DiskImpl.cpp
src/s4u/s4u_Disk.cpp
src/s4u/s4u_Host.cpp
src/surf/HostImpl.cpp
src/surf/HostImpl.hpp
src/surf/sg_platf.cpp
src/surf/xml/platf_private.hpp
src/surf/xml/surfxml_sax_cb.cpp

index 865f501..d569454 100644 (file)
@@ -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;
 }
index a7ace5d..40391d1 100644 (file)
@@ -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;
 }
index 28e37b1..f8f10f8 100644 (file)
@@ -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;
 }
index 72c27ad..abf1d86 100644 (file)
@@ -319,7 +319,9 @@ std::vector<Disk*> 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;
   });
 }
 
index b2cc1cf..adfa033 100644 (file)
@@ -129,14 +129,6 @@ std::vector<s4u::Disk*> HostImpl::get_disks() const
   return disks;
 }
 
-HostImpl* HostImpl::set_disks(const std::vector<kernel::resource::DiskImpl*>& 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,
index 1601eca..6ac9e5a 100644 (file)
@@ -64,7 +64,6 @@ public:
   void destroy(); // Must be called instead of the destructor
 
   std::vector<s4u::Disk*> get_disks() const;
-  HostImpl* set_disks(const std::vector<kernel::resource::DiskImpl*>& 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);
index a0853f3..90bd01c 100644 (file)
@@ -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<std::string, std::string>& 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_map<std::string, std:
  */
 void sg_platf_new_Zone_seal()
 {
-  xbt_assert(current_routing, "Cannot seal the current Zone: zone under construction");
+  xbt_assert(current_routing, "Cannot seal the current Zone: none under construction");
   current_routing->seal();
   simgrid::s4u::NetZone::on_seal(*current_routing->get_iface());
   current_routing = current_routing->get_parent();
index 7ea69f6..66f1ef2 100644 (file)
@@ -41,8 +41,6 @@ public:
   profile::Profile* speed_trace                            = nullptr;
   profile::Profile* state_trace                            = nullptr;
   std::string coord                                        = "";
-  std::unordered_map<std::string, std::string> properties;
-  std::vector<resource::DiskImpl*> disks;
 };
 
 class HostLinkCreationArgs {
@@ -179,12 +177,17 @@ XBT_PUBLIC void sg_platf_new_Zone_set_properties(const std::unordered_map<std::s
 XBT_PUBLIC void sg_platf_new_Zone_seal();                                          // That Zone is fully described
 
 XBT_PUBLIC void
-sg_platf_new_host(const simgrid::kernel::routing::HostCreationArgs* host); // Add a host to the current Zone
+sg_platf_new_host_begin(const simgrid::kernel::routing::HostCreationArgs* host); // Add a host to the current Zone
+XBT_PUBLIC void sg_platf_new_host_set_properties(const std::unordered_map<std::string, std::string>& 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);
index a2ec81f..2582c3d 100644 (file)
@@ -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<simgrid::kernel::resource::LinkImpl*>
     parsed_link_list; /* temporary store of current link list of a route */
-std::vector<simgrid::kernel::resource::DiskImpl*> 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<std::string, std::string>());
-}
-
 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<std::string, std::string>());
   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(){