Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'dev-get-hostname-faster' into 'master'
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 30 Jun 2022 08:15:45 +0000 (08:15 +0000)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 30 Jun 2022 08:15:45 +0000 (08:15 +0000)
Make host_by_name faster

See merge request simgrid/simgrid!112

ChangeLog
examples/c/cloud-migration/cloud-migration.c
include/simgrid/host.h
include/simgrid/s4u/Host.hpp
src/kernel/routing/NetZoneImpl.cpp
src/s4u/s4u_Host.cpp

index 3dc42c3..3738be9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -36,6 +36,12 @@ Platform description & visualization:
     demonstrates how we can generate a nice graphical representation of the
        platform.
 
+General: 
+  - Modified the host_by_name functions:
+    - Now, they return only hosts, not VMs, and in a much more efficient way.
+       - If one wants to find a VM by name, he now needs to know the host on
+       which it runs and call vm_by_name (or manually iterate over the list of hosts)
+
 Tools:
   - Enhancements to the graphicator tool:
        - Allow to dump the platform topology as a CSV file representing the edges
index 3ffb504..5319ebb 100644 (file)
@@ -33,7 +33,8 @@ static void migration_worker_main(int argc, char* argv[])
   const char* vm_name     = argv[1];
   const char* dst_pm_name = argv[2];
 
-  sg_vm_t vm       = (sg_vm_t)sg_host_by_name(vm_name);
+  sg_host_t src_pm = sg_host_self();
+  sg_vm_t vm       = (sg_vm_t)sg_vm_by_name(src_pm,vm_name);
   sg_host_t dst_pm = sg_host_by_name(dst_pm_name);
 
   vm_migrate(vm, dst_pm);
index 8d70956..37efe41 100644 (file)
@@ -27,6 +27,7 @@ XBT_PUBLIC void* sg_host_extension_get(const_sg_host_t host, size_t rank);
 
 /** Finds a host from its name */
 XBT_PUBLIC sg_host_t sg_host_by_name(const char* name);
+XBT_PUBLIC sg_vm_t sg_vm_by_name(sg_host_t host, const char* name);
 
 /** @brief Return the name of the sg_host_t. */
 XBT_PUBLIC const char* sg_host_get_name(const_sg_host_t host);
index 6208ff0..8fbe494 100644 (file)
@@ -227,6 +227,8 @@ public:
 
   VirtualMachine* create_vm(const std::string& name, int core_amount);
   VirtualMachine* create_vm(const std::string& name, int core_amount, size_t ramsize);
+  /** Retrieve a VM running on this host from its name, or return nullptr */
+  VirtualMachine* vm_by_name_or_null(const std::string& name);
 
   void route_to(const Host* dest, std::vector<Link*>& links, double* latency) const;
   void route_to(const Host* dest, std::vector<kernel::resource::StandardLinkImpl*>& links, double* latency) const;
index b1e3416..885e4e5 100644 (file)
@@ -343,15 +343,9 @@ resource::SplitDuplexLinkImpl* NetZoneImpl::get_split_duplex_link_by_name_or_nul
 
 resource::HostImpl* NetZoneImpl::get_host_by_name_or_null(const std::string& name) const
 {
-  for (auto const& [_, host] : hosts_) {
-    if (host->get_name() == name)
-      return host;
-    /* keep old behavior where host and VMs were saved together on EngineImpl::hosts_
-     * get hosts returns VMs too */
-    auto* vm = host->get_vm_by_name_or_null(name);
-    if (vm)
-      return vm;
-  }
+  auto host_it = hosts_.find(name);
+  if(host_it != hosts_.end())
+        return host_it->second;
 
   for (const auto* child : children_) {
     auto* host = child->get_host_by_name_or_null(name);
index 742cd13..237a129 100644 (file)
@@ -373,6 +373,11 @@ VirtualMachine* Host::create_vm(const std::string& name, int core_amount, size_t
       [this, &name, core_amount, ramsize] { return this->pimpl_->create_vm(name, core_amount, ramsize); });
 }
 
+VirtualMachine* Host::vm_by_name_or_null(const std::string& name) {
+    simgrid::kernel::resource::VirtualMachineImpl* vm=this->pimpl_->get_vm_by_name_or_null(name);
+  return vm ? vm->get_iface() : nullptr;
+}
+
 ExecPtr Host::exec_init(double flops) const
 {
   return this_actor::exec_init(flops);
@@ -442,6 +447,12 @@ sg_host_t sg_host_by_name(const char* name)
   return simgrid::s4u::Host::by_name_or_null(name);
 }
 
+/** @brief Retrieve a VM running on a given host from its name, or return NULL if no VM matches*/
+sg_vm_t sg_vm_by_name(sg_host_t host, const char* name)
+{
+  return host->vm_by_name_or_null(name);
+}
+
 // ========= Layering madness ==============*
 
 // ========== User data Layer ==========