Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
CPU factors: dynamic factors for CPU
authorBruno Donassolo <bruno.donassolo@inria.fr>
Mon, 9 Aug 2021 13:46:24 +0000 (15:46 +0200)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Mon, 9 Aug 2021 13:50:19 +0000 (15:50 +0200)
- Allows the use of user's callback to change the speed at the
update_remaining.
- Add a simple example.
- Minor improv. for disk
- Update changelog
- Available only for Cas01 (not ptask or TI)

13 files changed:
ChangeLog
MANIFEST.in
examples/cpp/CMakeLists.txt
examples/cpp/exec-cpu-factors/s4u-exec-cpu-factors.cpp [new file with mode: 0644]
examples/cpp/exec-cpu-factors/s4u-exec-cpu-factors.tesh [new file with mode: 0644]
examples/cpp/exec-cpu-nonlinear/s4u-exec-cpu-nonlinear.cpp
include/simgrid/s4u/Host.hpp
src/kernel/activity/IoImpl.cpp
src/s4u/s4u_Host.cpp
src/surf/cpu_cas01.cpp
src/surf/cpu_cas01.hpp
src/surf/cpu_interface.hpp
src/surf/disk_s19.cpp

index 17aa1df..b490262 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,6 +17,10 @@ New features:
      - Disk: examples/cpp/io-degradation
         - Link: examples/cpp/network-nonlinear
         - CPU: examples/cpp/exec-cpu-nonlinear
+ - Dynamic factors for CPU and disk: similarly to dynamic network factors,
+ allows the user to set a callback which can affect the progress of activities
+ (multiplicative factor applied when updating the amount of work remaining).
+   - Example: examples/cpp/exec-cpu-factors
 
 S4U:
  - New: s4u::Disk::set_sharing_policy() and s4u::Host::set_sharing_policy().
@@ -25,6 +29,8 @@ S4U:
 
 Documentation:
   * New section "Release Notes" documenting recent and current developments.
+  * New section "Modeling I/O: the realistic way" presenting how to properly
+  model disks in SimGrid.
 
 ----------------------------------------------------------------------------
 
index fb0bf5c..e2dda2b 100644 (file)
@@ -234,6 +234,8 @@ include examples/cpp/exec-async/s4u-exec-async.cpp
 include examples/cpp/exec-async/s4u-exec-async.tesh
 include examples/cpp/exec-basic/s4u-exec-basic.cpp
 include examples/cpp/exec-basic/s4u-exec-basic.tesh
+include examples/cpp/exec-cpu-factors/s4u-exec-cpu-factors.cpp
+include examples/cpp/exec-cpu-factors/s4u-exec-cpu-factors.tesh
 include examples/cpp/exec-cpu-nonlinear/s4u-exec-cpu-nonlinear.cpp
 include examples/cpp/exec-cpu-nonlinear/s4u-exec-cpu-nonlinear.tesh
 include examples/cpp/exec-dependent/s4u-exec-dependent.cpp
@@ -1692,6 +1694,8 @@ include teshsuite/smpi/pt2pt-pingpong/TI_output.tesh
 include teshsuite/smpi/pt2pt-pingpong/broken_hostfiles.tesh
 include teshsuite/smpi/pt2pt-pingpong/pt2pt-pingpong.c
 include teshsuite/smpi/pt2pt-pingpong/pt2pt-pingpong.tesh
+include teshsuite/smpi/replay-ti-colls/replay-ti-colls.c
+include teshsuite/smpi/replay-ti-colls/replay-ti-colls.tesh
 include teshsuite/smpi/timers/timers.c
 include teshsuite/smpi/timers/timers.tesh
 include teshsuite/smpi/topo-cart-sub/topo-cart-sub.c
index ac25009..960123b 100644 (file)
@@ -70,7 +70,7 @@ foreach (example actor-create actor-daemon actor-exiting actor-join actor-kill
                  energy-exec energy-boot energy-link energy-vm energy-exec-ptask energy-wifi
                  engine-filtering
                  exec-async exec-basic exec-dvfs exec-remote exec-waitany exec-waitfor exec-dependent exec-unassigned
-                 exec-ptask-multicore exec-cpu-nonlinear
+                 exec-ptask-multicore exec-cpu-nonlinear exec-cpu-factors
                  maestro-set
                  mc-bugged1 mc-bugged2 mc-electric-fence mc-failing-assert
                                 network-wifi
diff --git a/examples/cpp/exec-cpu-factors/s4u-exec-cpu-factors.cpp b/examples/cpp/exec-cpu-factors/s4u-exec-cpu-factors.cpp
new file mode 100644 (file)
index 0000000..820614b
--- /dev/null
@@ -0,0 +1,67 @@
+/* Copyright (c) 2010-2021. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+/* This example shows how to simulate variability for CPUs, using multiplicative factors
+ */
+
+#include <simgrid/s4u.hpp>
+
+namespace sg4 = simgrid::s4u;
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+
+/*************************************************************************************************/
+static void runner()
+{
+  double computation_amount = sg4::this_actor::get_host()->get_speed();
+
+  XBT_INFO("Executing 1 tasks of %g flops, should take 1 second.", computation_amount);
+  sg4::this_actor::execute(computation_amount);
+  XBT_INFO("Executing 1 tasks of %g flops, it would take .001s without factor. It'll take .002s",
+           computation_amount / 10);
+  sg4::this_actor::execute(computation_amount / 1000);
+
+  XBT_INFO("Finished executing. Goodbye now!");
+}
+/*************************************************************************************************/
+/** @brief Variability for CPU */
+static double cpu_variability(const sg4::Host* host, double flops)
+{
+  /* creates variability for tasks smaller than 1% of CPU power.
+   * unrealistic, for learning purposes */
+  double factor = 1.0;
+  double speed  = host->get_speed();
+  if (flops < speed / 100) {
+    factor = 0.5;
+  }
+  XBT_INFO("Host %s, task with %lf flops, new factor %lf", host->get_cname(), flops, factor);
+  return factor;
+}
+
+/** @brief Create a simple 1-host platform */
+static void load_platform()
+{
+  auto* zone        = sg4::create_empty_zone("Zone1");
+  auto* runner_host = zone->create_host("runner", 1e6);
+  runner_host->set_factor_cb(std::bind(&cpu_variability, runner_host, std::placeholders::_1))->seal();
+  zone->seal();
+
+  /* create actor runner */
+  sg4::Actor::create("runner", runner_host, runner);
+}
+
+/*************************************************************************************************/
+int main(int argc, char* argv[])
+{
+  sg4::Engine e(&argc, argv);
+
+  /* create platform */
+  load_platform();
+
+  /* runs the simulation */
+  e.run();
+
+  return 0;
+}
diff --git a/examples/cpp/exec-cpu-factors/s4u-exec-cpu-factors.tesh b/examples/cpp/exec-cpu-factors/s4u-exec-cpu-factors.tesh
new file mode 100644 (file)
index 0000000..9fa8d57
--- /dev/null
@@ -0,0 +1,6 @@
+$ ${bindir:=.}/s4u-exec-cpu-factors "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n"
+> [  0.000000] (1:runner@runner) Executing 1 tasks of 1e+06 flops, should take 1 second.
+> [  0.000000] (0:maestro@) Host runner, task with 1000000.000000 flops, new factor 1.000000
+> [  1.000000] (1:runner@runner) Executing 1 tasks of 100000 flops, it would take .001s without factor. It'll take .002s
+> [  1.000000] (0:maestro@) Host runner, task with 1000.000000 flops, new factor 0.500000
+> [  1.002000] (1:runner@runner) Finished executing. Goodbye now!
index 8c5280d..9e980cd 100644 (file)
@@ -11,7 +11,7 @@
 
 namespace sg4 = simgrid::s4u;
 
-XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_network_nonlinear, "Messages specific for this s4u example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
 
 /*************************************************************************************************/
 static void runner()
@@ -36,7 +36,7 @@ static void runner()
 /** @brief Non-linear resource sharing for CPU */
 static double cpu_nonlinear(const sg4::Host* host, double capacity, int n)
 {
-  /* emulates a degradation in link according to the number of flows
+  /* emulates a degradation in CPU according to the number of tasks
    * totally unrealistic but for learning purposes */
   capacity = n > 1 ? capacity / 2 : capacity;
   XBT_INFO("Host %s, %d concurrent tasks, new capacity %lf", host->get_cname(), n, capacity);
index 4280793..901b4f8 100644 (file)
@@ -89,6 +89,19 @@ public:
   Host* set_cpu(kernel::resource::CpuImpl* cpu);
   kernel::resource::CpuImpl* get_cpu() const { return pimpl_cpu_; }
   kernel::routing::NetPoint* get_netpoint() const { return pimpl_netpoint_; }
+  /**
+   * @brief Callback to set CPU factor
+   *
+   * This callback offers a flexible way to create variability in CPU executions
+   *
+   * @param flops Execution size in flops
+   * @return Multiply factor
+   */
+  using CpuFactorCb = double(sg_size_t flops);
+  /**
+   * @brief Configure the factor callback to the CPU associated to this host
+   */
+  Host* set_factor_cb(const std::function<CpuFactorCb>& cb);
 
   size_t get_actor_count() const;
   std::vector<ActorPtr> get_all_actors() const;
index bdef78f..4f692b2 100644 (file)
@@ -59,10 +59,6 @@ IoImpl* IoImpl::start()
   surf_action_ =
       disk_->get_host()->get_netpoint()->get_englobing_zone()->get_disk_model()->io_start(disk_, size_, type_);
   surf_action_->set_activity(this);
-  const auto& factor_cb = disk_->get_factor_cb();
-  if (factor_cb) { // handling disk variability
-    surf_action_->set_rate_factor(factor_cb(size_, type_));
-  }
 
   XBT_DEBUG("Create IO synchro %p %s", this, get_cname());
 
index 575dfad..fb079bf 100644 (file)
@@ -326,6 +326,12 @@ int Host::get_pstate() const
   return this->pimpl_cpu_->get_pstate();
 }
 
+Host* Host::set_factor_cb(const std::function<CpuFactorCb>& cb)
+{
+  kernel::actor::simcall([this, &cb] { pimpl_cpu_->set_factor_cb(cb); });
+  return this;
+}
+
 Host* Host::set_coordinates(const std::string& coords)
 {
   if (not coords.empty())
index 88aab66..b3b215b 100644 (file)
@@ -154,6 +154,9 @@ CpuAction* CpuCas01::execution_start(double size, int requested_cores, double us
   if (user_bound > 0 && user_bound < action->get_bound()) {
     get_model()->get_maxmin_system()->update_variable_bound(action->get_variable(), user_bound);
   }
+  if (factor_cb_) {
+    action->set_rate_factor(factor_cb_(size));
+  }
 
   return action;
 }
@@ -184,6 +187,12 @@ CpuAction* CpuCas01::sleep(double duration)
   return action;
 }
 
+void CpuCas01::set_factor_cb(const std::function<s4u::Host::CpuFactorCb>& cb)
+{
+  xbt_assert(not is_sealed(), "Cannot set CPU factor callback in an already sealed CPU(%s)", get_cname());
+  factor_cb_ = cb;
+}
+
 /**********
  * Action *
  **********/
index 61b588b..ed193cb 100644 (file)
@@ -47,11 +47,15 @@ public:
   CpuAction* execution_start(double size, double user_bound) override;
   CpuAction* execution_start(double size, int requested_cores, double user_bound) override;
   CpuAction* sleep(double duration) override;
+  void set_factor_cb(const std::function<s4u::Host::CpuFactorCb>& cb) override;
 
   bool is_used() const override;
 
 protected:
   void on_speed_change() override;
+
+private:
+  std::function<s4u::Host::CpuFactorCb> factor_cb_ = {};
 };
 
 /**********
index 10c1d03..a8b3440 100644 (file)
@@ -119,6 +119,12 @@ public:
   void set_sharing_policy(s4u::Host::SharingPolicy policy, const s4u::NonLinearResourceCb& cb);
   s4u::Host::SharingPolicy get_sharing_policy() const;
 
+  /**
+   * @brief Sets factor callback
+   * Implemented only for cas01
+   */
+  virtual void set_factor_cb(const std::function<s4u::Host::CpuFactorCb>& cb) { THROW_UNIMPLEMENTED; }
+
   /**
    * @brief Execute some quantity of computation
    *
index 86028da..1686085 100644 (file)
@@ -65,6 +65,10 @@ DiskAction* DiskS19Model::io_start(const DiskImpl* disk, sg_size_t size, s4u::Io
     default:
       THROW_UNIMPLEMENTED;
   }
+  const auto& factor_cb = disk->get_factor_cb();
+  if (factor_cb) { // handling disk variability
+    action->set_rate_factor(factor_cb(size, type));
+  }
   return action;
 }