Implements variability in disk operations.
Similarly to network factors, the effective amount of bytes read/written
in disk operations is scaled by a factor defined by the user.
Users can define a different callback for each disk. The callback is
called when SimGrid updates the remaining amount of bytes in disk
operations.
*/
Disk* set_sharing_policy(Operation op, SharingPolicy policy, const s4u::NonLinearResourceCb& cb = {});
SharingPolicy get_sharing_policy(Operation op) const;
+ /**
+ * @brief Callback to set IO factors
+ *
+ * This callback offers a flexible way to create variability in I/O operations
+ *
+ * @param size I/O operation size in bytes
+ * @param op I/O operation type: read or write
+ * @return Multiply factor
+ */
+ using IoFactorCb = double(sg_size_t size, Io::OpType op);
+ /** @brief Configure the factor callback */
+ Disk* set_factor_cb(const std::function<IoFactorCb>& cb);
Disk* seal();
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());
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 *
**********/
{s4u::Disk::Operation::WRITE, s4u::Disk::SharingPolicy::LINEAR},
{s4u::Disk::Operation::READWRITE, s4u::Disk::SharingPolicy::LINEAR}};
std::unordered_map<s4u::Disk::Operation, s4u::NonLinearResourceCb> sharing_policy_cb_ = {};
+ std::function<s4u::Disk::IoFactorCb> factor_cb_ = {};
void apply_sharing_policy_cfg();
void set_sharing_policy(s4u::Disk::Operation op, s4u::Disk::SharingPolicy policy, const s4u::NonLinearResourceCb& cb);
s4u::Disk::SharingPolicy get_sharing_policy(s4u::Disk::Operation op) const;
+ void set_factor_cb(const std::function<s4u::Disk::IoFactorCb>& cb);
+ const std::function<s4u::Disk::IoFactorCb>& get_factor_cb() const { return factor_cb_; }
+
/** @brief Check if the Disk is used (if an action currently uses its resources) */
bool is_used() const override;
void turn_on() override;
return this->pimpl_->get_sharing_policy(op);
}
+Disk* Disk::set_factor_cb(const std::function<IoFactorCb>& cb)
+{
+ kernel::actor::simcall([this, &cb] { pimpl_->set_factor_cb(cb); });
+ return this;
+}
+
Disk* Disk::seal()
{
kernel::actor::simcall([this]{ pimpl_->seal(); });