Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 's4u/model_list' into 'master'
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 10 Mar 2021 17:11:00 +0000 (17:11 +0000)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 10 Mar 2021 17:11:00 +0000 (17:11 +0000)
s4u Engine: expose get_all_models, get_model_list

See merge request simgrid/simgrid!53

14 files changed:
.mailmap
src/bindings/java/jxbt_utilities.cpp
src/kernel/EngineImpl.cpp
src/kernel/EngineImpl.hpp
src/kernel/activity/MutexImpl.cpp
src/mc/mc_global.cpp
src/mc/remote/Channel.cpp
src/mc/remote/RemoteSimulation.cpp
src/surf/cpu_ti.cpp
src/surf/ptask_L07.cpp
src/surf/ptask_L07.hpp
src/surf/surf_c_bindings.cpp
src/xbt/memory_map.cpp
teshsuite/mc/random-bug/random-bug.cpp

index 53da451..4ac0349 100644 (file)
--- a/.mailmap
+++ b/.mailmap
@@ -48,7 +48,7 @@ Augustin Degomme <adegomme@gmail.com> <degomme@wasabi>
 Jean-Emile Dartois <jean-emile.dartois@b-com.com>
 Jean-Emile Dartois <jean-emile.dartois@b-com.com> <jedartois@gmail.com>
 Darina Dimitrova <dimitrov@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
-Bruno Donassolo <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
+Bruno Donassolo <bruno.donassolo@inria.fr> <donassbr@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
 Yann Duplouy <yann.duplouy@inria.fr> <duplouy@crans.org>
 Pierre-François Dutot <dutot@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
 Julien Emmanuel <julien.emmanuel@inria.fr>
index d418b3f..2d61bc3 100644 (file)
@@ -9,8 +9,6 @@
 #include "xbt/string.hpp"
 #include "xbt/sysdep.h"
 
-#include <cstdlib> /* abort */
-
 jclass jxbt_get_class(JNIEnv * env, const char *name)
 {
   jclass cls = env->FindClass(name);
index c7f1443..b4f0c4f 100644 (file)
@@ -53,26 +53,27 @@ void EngineImpl::register_default(const actor::ActorCodeFactory& code)
   default_function = code;
 }
 
-void EngineImpl::add_model_ptask(resource::Model::Type type, resource::Model* model, bool is_default)
+void EngineImpl::add_model(resource::Model::Type type, std::shared_ptr<resource::Model> model, bool is_default)
 {
   if (is_default)
-    models_by_type_[type].insert(models_by_type_[type].begin(), model);
+    models_by_type_[type].insert(models_by_type_[type].begin(), model.get());
   else
-    models_by_type_[type].push_back(model);
+    models_by_type_[type].push_back(model.get());
+
+  models_.push_back(std::move(model));
 }
 
-void EngineImpl::add_model(resource::Model::Type type, std::shared_ptr<resource::Model> model, bool is_default)
+resource::Model* EngineImpl::get_default_model(resource::Model::Type type) const
 {
-  add_model_ptask(type, model.get(), is_default);
-  models_.push_back(std::move(model));
+  resource::Model* model = nullptr;
+  if (models_by_type_.find(type) != models_by_type_.end() and models_by_type_.at(type).size() > 0)
+    return models_by_type_.at(type)[0];
+  return model;
 }
 
-resource::Model* EngineImpl::get_default_model(resource::Model::Type type)
+const std::vector<resource::Model*>& EngineImpl::get_model_list(resource::Model::Type type)
 {
-  if (models_by_type_[type].size() > 0)
-    return models_by_type_[type][0];
-  else
-    return nullptr;
+  return models_by_type_[type];
 }
 
 } // namespace kernel
index f770aae..deb5664 100644 (file)
@@ -48,23 +48,14 @@ public:
    * @param is_default Is this the default model for this type of resource in this exp
    */
   void add_model(resource::Model::Type type, std::shared_ptr<resource::Model> model, bool is_default = false);
-  /**
-   * @brief Add a model (specific for ptask)
-   *
-   * Ptask is special. The CPU and NETWORK models need to be in the managed
-   * resources by surf_solve (model_by_type) but cannot be in the list of
-   * all models (old all_existing_models global variable)
-   *
-   * This methods does this job while we cannot handle ptask as the remaining models
-   */
-  void add_model_ptask(resource::Model::Type type, resource::Model* model, bool is_default);
   /** @brief Get current default model for a resource type */
-  resource::Model* get_default_model(resource::Model::Type type);
+  resource::Model* get_default_model(resource::Model::Type type) const;
 
   /** @brief Get list of models created for a resource type */
-  const std::vector<resource::Model*>& get_model_list(resource::Model::Type type) { return models_by_type_[type]; }
+  const std::vector<resource::Model*>& get_model_list(resource::Model::Type type);
+
   /** @brief Get list of all models managed by this engine */
-  const std::vector<std::shared_ptr<resource::Model>>& get_all_models() { return models_; }
+  const std::vector<std::shared_ptr<resource::Model>>& get_all_models() const { return models_; }
 
   routing::NetZoneImpl* netzone_root_ = nullptr;
   static EngineImpl* get_instance() { return simgrid::s4u::Engine::get_instance()->pimpl; }
index 2930115..c0f2a19 100644 (file)
@@ -6,8 +6,6 @@
 #include "src/kernel/activity/MutexImpl.hpp"
 #include "src/kernel/activity/SynchroRaw.hpp"
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_mutex, simix_synchro, "Mutex kernel-space implementation");
-
 #if SIMGRID_HAVE_MC
 #include "simgrid/modelchecker.h"
 #include "src/mc/mc_safety.hpp"
@@ -18,6 +16,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_mutex, simix_synchro, "Mutex kernel-space
 #define MC_CHECK_NO_DPOR() (void)0
 #endif
 
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_mutex, simix_synchro, "Mutex kernel-space implementation");
+
 namespace simgrid {
 namespace kernel {
 namespace activity {
index 1549e4e..7906df2 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <array>
 #include <boost/core/demangle.hpp>
+#include <cerrno>
+#include <cstring>
 #include <libunwind.h>
 #endif
 
@@ -61,11 +63,7 @@ FILE *dot_output = nullptr;
 void MC_init_dot_output()
 {
   dot_output = fopen(_sg_mc_dot_output_file.get().c_str(), "w");
-
-  if (dot_output == nullptr) {
-    perror("Error open dot output file");
-    xbt_abort();
-  }
+  xbt_assert(dot_output != nullptr, "Error open dot output file: %s", strerror(errno));
 
   fprintf(dot_output,
           "digraph graphname{\n fixedsize=true; rankdir=TB; ranksep=.25; edge [fontsize=12]; node [fontsize=10, shape=circle,width=.5 ]; graph [resolution=20, fontsize=10];\n");
index cfbf715..d74e53a 100644 (file)
@@ -8,9 +8,10 @@
 #include <xbt/log.h>
 
 #include <cerrno>
-#include <unistd.h>
+#include <cstring>
 #include <sys/socket.h>
 #include <sys/types.h>
+#include <unistd.h>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_Channel, mc, "MC interprocess communication");
 
@@ -28,8 +29,10 @@ int Channel::send(const void* message, size_t size) const
 {
   XBT_DEBUG("Send %s", to_c_str(*(MessageType*)message));
   while (::send(this->socket_, message, size, 0) == -1) {
-    if (errno != EINTR)
+    if (errno != EINTR) {
+      XBT_ERROR("Channel::send failure: %s", strerror(errno));
       return errno;
+    }
   }
   return 0;
 }
@@ -39,6 +42,8 @@ ssize_t Channel::receive(void* message, size_t size, bool block) const
   ssize_t res = recv(this->socket_, message, size, block ? 0 : MSG_DONTWAIT);
   if (res != -1)
     XBT_DEBUG("Receive %s", to_c_str(*(MessageType*)message));
+  else
+    XBT_ERROR("Channel::receive failure: %s", strerror(errno));
   return res;
 }
 }
index f2a3430..2d6d919 100644 (file)
@@ -16,6 +16,8 @@
 #include <sys/mman.h> // PROT_*
 
 #include <algorithm>
+#include <cerrno>
+#include <cstring>
 #include <memory>
 #include <string>
 
@@ -177,7 +179,7 @@ static ssize_t pread_whole(int fd, void* buf, size_t count, off_t offset)
     } else if (res == 0)
       return -1;
     else if (errno != EINTR) {
-      perror("pread_whole");
+      XBT_ERROR("pread_whole: %s", strerror(errno));
       return -1;
     }
   }
@@ -196,8 +198,10 @@ static ssize_t pwrite_whole(int fd, const void* buf, size_t count, off_t offset)
       offset += res;
     } else if (res == 0)
       return -1;
-    else if (errno != EINTR)
+    else if (errno != EINTR) {
+      XBT_ERROR("pwrite_whole: %s", strerror(errno));
       return -1;
+    }
   }
   return real_count;
 }
index 1316a0f..5475676 100644 (file)
@@ -139,12 +139,10 @@ double CpuTiTmgr::solve(double a, double amount) const
   }
 
   /* Sanity checks */
-  if ((a < 0.0) || (amount < 0.0)) {
-    XBT_CRITICAL("Error, invalid parameters [a = %.2f, amount = %.2f]. "
-                 "You probably have a task executing with negative computation amount. Check your code.",
-                 a, amount);
-    xbt_abort();
-  }
+  xbt_assert(a >= 0.0 && amount >= 0.0,
+             "Error, invalid parameters [a = %.2f, amount = %.2f]. "
+             "You probably have a task executing with negative computation amount. Check your code.",
+             a, amount);
 
   /* At this point, a and amount are positive */
   if (amount < EPSILON)
index 20a97a0..2eb2254 100644 (file)
@@ -34,12 +34,12 @@ HostL07Model::HostL07Model() : HostModel()
   auto* maxmin_system = new simgrid::kernel::lmm::FairBottleneck(true /* selective update */);
   set_maxmin_system(maxmin_system);
 
-  net_model_  = std::make_unique<NetworkL07Model>(this, maxmin_system);
-  auto engine = simgrid::kernel::EngineImpl::get_instance();
-  engine->add_model_ptask(simgrid::kernel::resource::Model::Type::NETWORK, net_model_.get(), true);
+  auto net_model = std::make_shared<NetworkL07Model>(this, maxmin_system);
+  auto engine    = simgrid::kernel::EngineImpl::get_instance();
+  engine->add_model(simgrid::kernel::resource::Model::Type::NETWORK, std::move(net_model), true);
 
-  cpu_model_ = std::make_unique<CpuL07Model>(this, maxmin_system);
-  engine->add_model_ptask(simgrid::kernel::resource::Model::Type::CPU_PM, cpu_model_.get(), true);
+  auto cpu_model = std::make_shared<CpuL07Model>(this, maxmin_system);
+  engine->add_model(simgrid::kernel::resource::Model::Type::CPU_PM, std::move(cpu_model), true);
 }
 
 HostL07Model::~HostL07Model() {}
index fe5fe36..a2192e1 100644 (file)
@@ -44,10 +44,6 @@ public:
   void update_actions_state(double now, double delta) override;
   kernel::resource::CpuAction* execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
                                                 const double* bytes_amount, double rate) override;
-
-private:
-  std::unique_ptr<NetworkL07Model> net_model_;
-  std::unique_ptr<CpuL07Model> cpu_model_;
 };
 
 class CpuL07Model : public kernel::resource::CpuModel {
@@ -56,6 +52,10 @@ public:
   CpuL07Model(const CpuL07Model&) = delete;
   CpuL07Model& operator=(const CpuL07Model&) = delete;
   ~CpuL07Model() override;
+  /* this action is done by HostL07Model which shares the LMM system with the CPU model
+   * Overriding to an empty function here allows us to handle the Cpu07Model as a regular
+   * method in surf_presolve */
+  void update_actions_state(double now, double delta) override{};
 
   kernel::resource::Cpu* create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate) override;
   HostL07Model* hostModel_;
@@ -71,6 +71,10 @@ public:
                                           s4u::Link::SharingPolicy policy) override;
 
   kernel::resource::Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) override;
+  /* this action is done by HostL07Model which shares the LMM system with the CPU model
+   * Overriding to an empty function here allows us to handle the Cpu07Model as a regular
+   * method in surf_presolve */
+  void update_actions_state(double now, double delta) override{};
 
   HostL07Model* hostModel_;
 };
index 097f218..c5b9139 100644 (file)
@@ -102,10 +102,11 @@ double surf_solve(double max_date)
     XBT_DEBUG("Next TRACE event: %f", next_event_date);
 
     for (auto* model : engine->get_model_list(simgrid::kernel::resource::Model::Type::NETWORK)) {
+      /* Skip all idempotent models, they were already treated above
+       * NS3 is the one to handled here */
       if (model->next_occurring_event_is_idempotent())
         continue;
 
-      // NS3, I see you
       if (next_event_date != -1.0) {
         time_delta = std::min(next_event_date - NOW, time_delta);
       } else {
index c81bcfb..98e9bff 100644 (file)
 
 #include "memory_map.hpp"
 
+// abort with a message if `expr' is false
+#define CHECK(expr)                                                                                                    \
+  if (not(expr)) {                                                                                                     \
+    fprintf(stderr, "CHECK FAILED: %s:%d: %s\n", __FILE__, __LINE__, #expr);                                           \
+    abort();                                                                                                           \
+  } else                                                                                                               \
+    ((void)0)
+
 namespace simgrid {
 namespace xbt {
 
@@ -209,21 +217,17 @@ std::vector<VmMap> get_memory_map(pid_t pid)
     char *endptr;
     memreg.start_addr = std::strtoull(tok, &endptr, 16);
     /* Make sure that the entire string was an hex number */
-    if (*endptr != '\0')
-      abort();
+    CHECK(*endptr == '\0');
 
     tok = strtok_r(nullptr, "-", &saveptr);
-    if (tok == nullptr)
-      abort();
+    CHECK(tok != nullptr);
 
     memreg.end_addr = std::strtoull(tok, &endptr, 16);
     /* Make sure that the entire string was an hex number */
-    if (*endptr != '\0')
-      abort();
+    CHECK(*endptr == '\0');
 
     /* Get the permissions flags */
-    if (std::strlen(lfields[1]) < 4)
-      abort();
+    CHECK(std::strlen(lfields[1]) >= 4);
 
     memreg.prot = 0;
     for (i = 0; i < 3; i++){
@@ -259,32 +263,26 @@ std::vector<VmMap> get_memory_map(pid_t pid)
     /* Get the offset value */
     memreg.offset = std::strtoull(lfields[2], &endptr, 16);
     /* Make sure that the entire string was an hex number */
-    if (*endptr != '\0')
-      abort();
+    CHECK(*endptr == '\0');
 
     /* Get the device major:minor bytes */
     tok = strtok_r(lfields[3], ":", &saveptr);
-    if (tok == nullptr)
-      abort();
+    CHECK(tok != nullptr);
 
     memreg.dev_major = (char) strtoul(tok, &endptr, 16);
     /* Make sure that the entire string was an hex number */
-    if (*endptr != '\0')
-      abort();
+    CHECK(*endptr == '\0');
 
     tok = strtok_r(nullptr, ":", &saveptr);
-    if (tok == nullptr)
-      abort();
+    CHECK(tok != nullptr);
 
     memreg.dev_minor = (char) std::strtoul(tok, &endptr, 16);
     /* Make sure that the entire string was an hex number */
-    if (*endptr != '\0')
-      abort();
+    CHECK(*endptr == '\0');
 
     /* Get the inode number and make sure that the entire string was a long int */
     memreg.inode = strtoul(lfields[4], &endptr, 10);
-    if (*endptr != '\0')
-      abort();
+    CHECK(*endptr == '\0');
 
     /* And finally get the pathname */
     if (lfields[5])
index 733b084..2374cae 100644 (file)
@@ -31,7 +31,7 @@ static void app()
       abort();
   } else if (behavior == Behavior::SEGV) {
 #ifndef __clang_analyzer__
-    int* A = 0;
+    int* A = nullptr;
     if (x == 3 && y == 4)
       *A = 1;
 #endif