]> AND Public Git Repository - simgrid.git/blobdiff - src/kernel/resource/DiskImpl.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
De-obfuscation.
[simgrid.git] / src / kernel / resource / DiskImpl.cpp
index acd3ff3d0f194f468b1a551ce3e3ad2580197932..8a45da63199d031bc5f71c06dda005416f91dffb 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2019-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2019-2022. 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. */
@@ -6,11 +6,18 @@
 #include "DiskImpl.hpp"
 
 #include "simgrid/s4u/Engine.hpp"
+#include "simgrid/sg_config.hpp"
 #include "src/kernel/EngineImpl.hpp"
 #include "src/kernel/lmm/maxmin.hpp"
 #include "src/kernel/resource/profile/Profile.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_disk, ker_resource, "Disk resources, that fuel I/O activities");
+/***********
+ * Options *
+ ***********/
+static simgrid::config::Flag<std::string> cfg_disk_solver("disk/solver",
+                                                          "Set linear equations solver used by disk model", "maxmin",
+                                                          &simgrid::kernel::lmm::System::validate_solver);
 
 namespace simgrid {
 namespace kernel {
@@ -24,7 +31,7 @@ xbt::signal<void(DiskAction const&, Action::State, Action::State)> DiskAction::o
 
 DiskModel::DiskModel(const std::string& name) : Model(name)
 {
-  set_maxmin_system(new lmm::System(true /* selective update */));
+  set_maxmin_system(lmm::System::build(cfg_disk_solver, true /* selective update */));
 }
 
 /************
@@ -68,11 +75,6 @@ void DiskImpl::destroy()
   delete this;
 }
 
-bool DiskImpl::is_used() const
-{
-  return get_model()->get_maxmin_system()->constraint_used(get_constraint());
-}
-
 void DiskImpl::turn_on()
 {
   if (not is_on()) {
@@ -113,9 +115,13 @@ void DiskImpl::seal()
 
   xbt_assert(this->get_model(), "Cannot seal Disk (%s) without setting the model first", get_cname());
   lmm::System* maxmin_system = get_model()->get_maxmin_system();
+  /* set readwrite constraint if not configured by user */
+  if (readwrite_bw_ == -1) {
+    readwrite_bw_ = std::max(read_bw_.peak, write_bw_.peak);
+  }
   this->set_read_constraint(maxmin_system->constraint_new(this, read_bw_.peak * read_bw_.scale))
       ->set_write_constraint(maxmin_system->constraint_new(this, write_bw_.peak * write_bw_.scale))
-      ->set_constraint(maxmin_system->constraint_new(this, std::max(read_bw_.peak, write_bw_.peak)));
+      ->set_constraint(maxmin_system->constraint_new(this, readwrite_bw_));
   apply_sharing_policy_cfg();
   XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw_.peak, write_bw_.peak);
   Resource::seal();
@@ -124,12 +130,10 @@ void DiskImpl::seal()
 
 constexpr kernel::lmm::Constraint::SharingPolicy to_maxmin_policy(s4u::Disk::SharingPolicy policy)
 {
-  switch (policy) {
-    case s4u::Disk::SharingPolicy::NONLINEAR:
-      return kernel::lmm::Constraint::SharingPolicy::NONLINEAR;
-    default:
-      return kernel::lmm::Constraint::SharingPolicy::SHARED;
-  }
+  kernel::lmm::Constraint::SharingPolicy lmm_policy = kernel::lmm::Constraint::SharingPolicy::SHARED;
+  if (policy == s4u::Disk::SharingPolicy::NONLINEAR)
+    lmm_policy = kernel::lmm::Constraint::SharingPolicy::NONLINEAR;
+  return lmm_policy;
 }
 
 void DiskImpl::set_sharing_policy(s4u::Disk::Operation op, s4u::Disk::SharingPolicy policy,
@@ -158,6 +162,12 @@ void DiskImpl::apply_sharing_policy_cfg()
                                           sharing_policy_cb_[s4u::Disk::Operation::WRITE]);
 }
 
+void DiskImpl::set_factor_cb(const std::function<s4u::Disk::IoFactorCb>& cb)
+{
+  xbt_assert(not is_sealed(), "Cannot set I/O factor callback in an already sealed disk(%s)", get_cname());
+  factor_cb_ = cb;
+}
+
 /**********
  * Action *
  **********/