Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into disk
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 16 Sep 2019 09:28:01 +0000 (11:28 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 16 Sep 2019 09:28:01 +0000 (11:28 +0200)
1  2 
include/simgrid/s4u/Engine.hpp
include/simgrid/s4u/Host.hpp
src/s4u/s4u_Engine.cpp
src/s4u/s4u_Host.cpp
src/surf/sg_platf.cpp
src/surf/surf_c_bindings.cpp
src/surf/surf_interface.cpp
src/surf/xml/surfxml_sax_cb.cpp

@@@ -87,7 -87,6 +87,7 @@@ protected
  #ifndef DOXYGEN
    friend Host;
    friend Link;
 +  friend Disk;
    friend Storage;
    friend kernel::routing::NetPoint;
    friend kernel::routing::NetZoneImpl;
@@@ -155,27 -154,27 +155,27 @@@ public
     */
    void set_config(const std::string& str);
  
- private:
-   kernel::EngineImpl* const pimpl;
-   static Engine* instance_;
- };
+   /** Callback fired when the platform is created (ie, the xml file parsed),
+    * right before the actual simulation starts. */
+   static xbt::signal<void()> on_platform_created;
  
- /** Callback fired when the platform is created (ie, the xml file parsed),
-  * right before the actual simulation starts. */
extern XBT_PUBLIC xbt::signal<void()> on_platform_created;
+   /** Callback fired when the platform is about to be created
+    * (ie, after any configuration change and just before the resource creation) */
  static xbt::signal<void()> on_platform_creation;
  
- /** Callback fired when the platform is about to be created
-  * (ie, after any configuration change and just before the resource creation) */
- extern XBT_PUBLIC xbt::signal<void()> on_platform_creation;
+   /** Callback fired when the main simulation loop ends, just before the end of Engine::run() */
+   static xbt::signal<void()> on_simulation_end;
  
/** Callback fired when the main simulation loop ends, just before the end of Engine::run() */
extern XBT_PUBLIC xbt::signal<void()> on_simulation_end;
  /** Callback fired when the time jumps into the future */
  static xbt::signal<void(double)> on_time_advance;
  
/** Callback fired when the time jumps into the future */
extern XBT_PUBLIC xbt::signal<void(double)> on_time_advance;
  /** Callback fired when the time cannot advance because of inter-actors deadlock */
  static xbt::signal<void(void)> on_deadlock;
  
- /** Callback fired when the time cannot advance because of inter-actors deadlock */
- extern XBT_PUBLIC xbt::signal<void(void)> on_deadlock;
+ private:
+   kernel::EngineImpl* const pimpl;
+   static Engine* instance_;
+ };
  
  #ifndef DOXYGEN /* Internal use only, no need to expose it */
  template <class T> XBT_PRIVATE void get_filtered_netzones_recursive(s4u::NetZone* current, std::vector<T*>* whereto)
@@@ -115,10 -115,6 +115,10 @@@ public
    void set_pstate(int pstate_index);
    int get_pstate() const;
  
 +  std::vector<Disk*> get_disks() const;
 +  void add_disk(Disk* disk);
 +  void remove_disk(std::string disk_name);
 +
    std::vector<const char*> get_attached_storages() const;
  
    /** Get an associative list [mount point]->[Storage] of all local mount points.
@@@ -161,6 -157,4 +161,4 @@@ public
  } // namespace s4u
  } // namespace simgrid
  
- extern int USER_HOST_LEVEL;
  #endif /* SIMGRID_S4U_HOST_HPP */
diff --combined src/s4u/s4u_Engine.cpp
@@@ -8,7 -8,6 +8,7 @@@
  #include "mc/mc.h"
  #include "simgrid/kernel/routing/NetPoint.hpp"
  #include "simgrid/kernel/routing/NetZoneImpl.hpp"
 +#include "simgrid/s4u/Disk.hpp"
  #include "simgrid/s4u/Engine.hpp"
  #include "simgrid/s4u/Host.hpp"
  #include "simgrid/s4u/Mailbox.hpp"
@@@ -29,11 -28,11 +29,11 @@@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_eng
  
  namespace simgrid {
  namespace s4u {
- xbt::signal<void()> on_platform_creation;
- xbt::signal<void()> on_platform_created;
- xbt::signal<void()> on_simulation_end;
- xbt::signal<void(double)> on_time_advance;
- xbt::signal<void(void)> on_deadlock;
+ xbt::signal<void()> Engine::on_platform_creation;
+ xbt::signal<void()> Engine::on_platform_created;
+ xbt::signal<void()> Engine::on_simulation_end;
+ xbt::signal<void(double)> Engine::on_time_advance;
+ xbt::signal<void(void)> Engine::on_deadlock;
  
  Engine* Engine::instance_ = nullptr; /* That singleton is awful, but I don't see no other solution right now. */
  
diff --combined src/s4u/s4u_Host.cpp
@@@ -18,8 -18,6 +18,6 @@@
  XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_host, s4u, "Logging specific to the S4U hosts");
  XBT_LOG_EXTERNAL_CATEGORY(surf_route);
  
- int USER_HOST_LEVEL = -1;
  namespace simgrid {
  namespace xbt {
  template class Extendable<s4u::Host>;
@@@ -284,19 -282,6 +282,19 @@@ int Host::get_pstate() cons
    return this->pimpl_cpu->get_pstate();
  }
  
 +std::vector<Disk*> Host::get_disks() const
 +{
 +  return kernel::actor::simcall([this] { return this->pimpl_->get_disks(); });
 +}
 +
 +void Host::add_disk(Disk* disk)
 +{
 +  kernel::actor::simcall([this, disk] { this->pimpl_->add_disk(disk); });
 +}
 +void Host::remove_disk(std::string disk_name)
 +{
 +  kernel::actor::simcall([this, disk_name] { this->pimpl_->remove_disk(disk_name); });
 +}
  /**
   * @ingroup simix_storage_management
   * @brief Returns the list of storages attached to a host.
@@@ -400,17 -385,25 +398,25 @@@ xbt_dynar_t sg_hosts_as_dynar(
  // ========= Layering madness ==============*
  
  // ========== User data Layer ==========
- void* sg_host_user(sg_host_t host)
+ void* sg_host_data(sg_host_t host)
+ {
+   return host->get_data();
+ }
+ void sg_host_data_set(sg_host_t host, void* userdata)
+ {
+   host->set_data(userdata);
+ }
+ void* sg_host_user(sg_host_t host) // deprecated
  {
-   return host->extension(USER_HOST_LEVEL);
+   return host->get_data();
  }
- void sg_host_user_set(sg_host_t host, void* userdata)
+ void sg_host_user_set(sg_host_t host, void* userdata) // deprecated
  {
-   host->extension_set(USER_HOST_LEVEL, userdata);
+   host->set_data(userdata);
  }
- void sg_host_user_destroy(sg_host_t host)
+ void sg_host_user_destroy(sg_host_t host) // deprecated
  {
-   host->extension_set(USER_HOST_LEVEL, nullptr);
+   host->set_data(nullptr);
  }
  
  // ========= storage related functions ============
diff --combined src/surf/sg_platf.cpp
@@@ -19,7 -19,6 +19,7 @@@
  #include "src/include/simgrid/sg_config.hpp"
  #include "src/include/surf/surf.hpp"
  #include "src/kernel/EngineImpl.hpp"
 +#include "src/kernel/resource/DiskImpl.hpp"
  #include "src/kernel/resource/profile/Profile.hpp"
  #include "src/simix/smx_private.hpp"
  #include "src/surf/HostImpl.hpp"
@@@ -52,13 -51,13 +52,13 @@@ static simgrid::kernel::routing::NetZon
  /** Module management function: creates all internal data structures */
  void sg_platf_init()
  {
-   simgrid::s4u::on_platform_created.connect(check_disk_attachment);
+   simgrid::s4u::Engine::on_platform_created.connect(check_disk_attachment);
  }
  
  /** Module management function: frees all internal data structures */
  void sg_platf_exit() {
    simgrid::surf::on_cluster.disconnect_slots();
-   simgrid::s4u::on_platform_created.disconnect_slots();
+   simgrid::s4u::Engine::on_platform_created.disconnect_slots();
  
    /* make sure that we will reinit the models while loading the platf once reinited */
    surf_parse_models_setup_already_called = 0;
@@@ -81,10 -80,6 +81,10 @@@ void sg_platf_new_host(simgrid::kernel:
    host->pimpl_->storage_ = mount_list;
    mount_list.clear();
  
 +  host->pimpl_->disks_ = std::move(args->disks);
 +  for (auto d : host->pimpl_->disks_)
 +    d->set_host(host);
 +
    /* Change from the defaults */
    if (args->state_trace)
      host->pimpl_cpu->set_state_profile(args->state_trace);
@@@ -336,17 -331,6 +336,17 @@@ void sg_platf_new_cabinet(simgrid::kern
    delete cabinet->radicals;
  }
  
 +simgrid::kernel::resource::DiskImpl* sg_platf_new_disk(simgrid::kernel::routing::DiskCreationArgs* disk)
 +{
 +  simgrid::kernel::resource::DiskImpl* d = surf_disk_model->createDisk(disk->id, disk->read_bw, disk->write_bw);
 +  if (disk->properties) {
 +    d->set_properties(*disk->properties);
 +    delete disk->properties;
 +  }
 +  simgrid::s4u::Disk::on_creation(*d->get_iface());
 +  return d;
 +}
 +
  void sg_platf_new_storage(simgrid::kernel::routing::StorageCreationArgs* storage)
  {
    xbt_assert(std::find(known_storages.begin(), known_storages.end(), storage->id) == known_storages.end(),
@@@ -518,7 -502,6 +518,7 @@@ static void surf_config_models_setup(
    std::string host_model_name    = simgrid::config::get_value<std::string>("host/model");
    std::string network_model_name = simgrid::config::get_value<std::string>("network/model");
    std::string cpu_model_name     = simgrid::config::get_value<std::string>("cpu/model");
 +  std::string disk_model_name    = simgrid::config::get_value<std::string>("disk/model");
    std::string storage_model_name = simgrid::config::get_value<std::string>("storage/model");
  
    /* The compound host model is needed when using non-default net/cpu models */
    XBT_DEBUG("Call vm_model_init");
    surf_vm_model_init_HL13();
  
 +  XBT_DEBUG("Call disk_model_init");
 +  int disk_id = find_model_description(surf_disk_model_description, disk_model_name);
 +  surf_disk_model_description[disk_id].model_init_preparse();
 +
    XBT_DEBUG("Call storage_model_init");
    int storage_id = find_model_description(surf_storage_model_description, storage_model_name);
    surf_storage_model_description[storage_id].model_init_preparse();
  simgrid::kernel::routing::NetZoneImpl* sg_platf_new_Zone_begin(simgrid::kernel::routing::ZoneCreationArgs* zone)
  {
    if (not surf_parse_models_setup_already_called) {
-     simgrid::s4u::on_platform_creation();
+     simgrid::s4u::Engine::on_platform_creation();
  
      /* Initialize the surf models. That must be done after we got all config, and before we need the models.
       * That is, after the last <config> tag, if any, and before the first of cluster|peer|zone|trace|trace_connect
@@@ -6,7 -6,6 +6,7 @@@
  #include "simgrid/s4u/Engine.hpp"
  #include "src/include/surf/surf.hpp"
  #include "src/instr/instr_private.hpp"
 +#include "src/kernel/resource/DiskImpl.hpp"
  #include "src/kernel/resource/profile/FutureEvtSet.hpp"
  #include "src/plugins/vm/VirtualMachineImpl.hpp"
  
@@@ -72,7 -71,7 +72,7 @@@ double surf_solve(double max_date
  
    for (auto const& model : all_existing_models) {
      if (model != surf_host_model && model != surf_vm_model && model != surf_network_model &&
 -        model != surf_storage_model) {
 +        model != surf_storage_model && model != surf_disk_model) {
        double next_event_model = model->next_occuring_event(NOW);
        if ((time_delta < 0.0 || next_event_model < time_delta) && next_event_model >= 0.0)
          time_delta = next_event_model;
    for (auto const& model : all_existing_models)
      model->update_actions_state(NOW, time_delta);
  
-   simgrid::s4u::on_time_advance(time_delta);
+   simgrid::s4u::Engine::on_time_advance(time_delta);
  
    TRACE_paje_dump_buffer(false);
  
@@@ -12,6 -12,7 +12,7 @@@
  #include "src/simgrid/version.h"
  #include "src/surf/HostImpl.hpp"
  #include "src/surf/xml/platf.hpp"
+ #include "src/xbt_modinter.h" /* whether initialization was already done */
  #include "surf/surf.hpp"
  #include "xbt/module.h"
  
@@@ -111,10 -112,6 +112,10 @@@ const std::vector<surf_model_descriptio
      {"Full", "Full update of remaining and variables. Slow but may be useful when debugging.", nullptr},
  };
  
 +const std::vector<surf_model_description_t> surf_disk_model_description = {
 +    {"default", "Simplistic disk model.", &surf_disk_model_init_default},
 +};
 +
  const std::vector<surf_model_description_t> surf_storage_model_description = {
      {"default", "Simplistic storage model.", &surf_storage_model_init_default},
  };
@@@ -291,12 -288,9 +292,9 @@@ void sg_version(
  
  void surf_init(int *argc, char **argv)
  {
-   if (USER_HOST_LEVEL != -1) // Already initialized
+   if (xbt_initialized > 0)
      return;
  
-   XBT_DEBUG("Create all Libs");
-   USER_HOST_LEVEL = simgrid::s4u::Host::extension_create(nullptr);
    xbt_init(argc, argv);
  
    sg_config_init(argc, argv);
@@@ -28,8 -28,8 +28,8 @@@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_pa
  
  static 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 list link of a route */
 -
 +    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
   */
@@@ -409,7 -409,7 +409,7 @@@ void STag_surfxml_platform() 
               surf_parsed_filename.c_str(), version);
  }
  void ETag_surfxml_platform(){
-   simgrid::s4u::on_platform_created();
+   simgrid::s4u::Engine::on_platform_created();
  }
  
  void STag_surfxml_host(){
@@@ -458,27 -458,14 +458,27 @@@ void ETag_surfxml_host()    
                           : 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);
  }
  
  void STag_surfxml_disk() {
 -  THROW_UNIMPLEMENTED;
 +  ZONE_TAG = 0;
 +  xbt_assert(current_property_set == nullptr,
 +             "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
  }
 +
  void ETag_surfxml_disk() {
 +  simgrid::kernel::routing::DiskCreationArgs disk;
 +  disk.properties      = current_property_set;
 +  current_property_set = nullptr;
 +
 +  disk.id       = A_surfxml_disk_id;
 +  disk.read_bw  = surf_parse_get_bandwidth(A_surfxml_disk_read___bw, "read_bw of disk ", disk.id);
 +  disk.write_bw = surf_parse_get_bandwidth(A_surfxml_disk_write___bw, "write_bw of disk ", disk.id);
 +
 +  parsed_disk_list.push_back(sg_platf_new_disk(&disk));
  }
  
  void STag_surfxml_host___link(){