-/* Copyright (c) 2019-2020. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2019-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. */
#include "src/kernel/EngineImpl.hpp"
#include "src/kernel/lmm/maxmin.hpp"
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(disk_kernel, surf, "Logging specific to the disk kernel resource");
-
-simgrid::kernel::resource::DiskModel* surf_disk_model = nullptr;
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_disk, ker_resource, "Disk resources, fuelling I/O activities");
namespace simgrid {
namespace kernel {
* Model *
*********/
-DiskModel::DiskModel() : Model(Model::UpdateAlgo::FULL)
+DiskModel::DiskModel(const std::string& name) : Model(name)
{
- set_maxmin_system(new simgrid::kernel::lmm::System(true /* selective update */));
-}
-
-DiskModel::~DiskModel()
-{
- surf_disk_model = nullptr;
+ set_maxmin_system(new lmm::System(true /* selective update */));
}
/************
* Resource *
************/
+DiskImpl* DiskImpl::set_host(s4u::Host* host)
+{
+ host_ = host;
+ return this;
+}
-DiskImpl::DiskImpl(kernel::resource::Model* model, const std::string& name, kernel::lmm::System* maxminSystem,
- double read_bw, double write_bw)
- : Resource(model, name, maxminSystem->constraint_new(this, std::max(read_bw, write_bw)))
- , piface_(name, this)
- , read_bw_(read_bw)
- , write_bw_(write_bw)
+DiskImpl* DiskImpl::set_read_bandwidth(double read_bw)
{
- DiskImpl::turn_on();
- XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw_, write_bw_);
- constraint_read_ = maxminSystem->constraint_new(this, read_bw);
- constraint_write_ = maxminSystem->constraint_new(this, write_bw);
+ read_bw_ = read_bw;
+ return this;
}
-DiskImpl::~DiskImpl()
+DiskImpl* DiskImpl::set_write_bandwidth(double write_bw)
{
- xbt_assert(currently_destroying_, "Don't delete Disks directly. Call destroy() instead.");
+ write_bw_ = write_bw;
+ return this;
+}
+
+DiskImpl* DiskImpl::set_read_constraint(lmm::Constraint* constraint_read)
+{
+ constraint_read_ = constraint_read;
+ return this;
+}
+
+DiskImpl* DiskImpl::set_write_constraint(lmm::Constraint* constraint_write)
+{
+ constraint_write_ = constraint_write;
+ return this;
}
/** @brief Fire the required callbacks and destroy the object
*/
void DiskImpl::destroy()
{
- if (not currently_destroying_) {
- currently_destroying_ = true;
- s4u::Disk::on_destruction(this->piface_);
- delete this;
- }
+ s4u::Disk::on_destruction(this->piface_);
+ delete this;
}
-bool DiskImpl::is_used()
+bool DiskImpl::is_used() const
{
THROW_UNIMPLEMENTED;
}
}
}
+void DiskImpl::seal()
+{
+ xbt_assert(this->get_model(), "Cannot seal Disk (%s) without setting the model first", this->get_cname());
+ lmm::System* maxmin_system = get_model()->get_maxmin_system();
+ this->set_read_constraint(maxmin_system->constraint_new(this, read_bw_))
+ ->set_write_constraint(maxmin_system->constraint_new(this, write_bw_))
+ ->set_constraint(maxmin_system->constraint_new(this, std::max(read_bw_, write_bw_)));
+ XBT_DEBUG("Create resource with read_bw '%f' write_bw '%f'", read_bw_, write_bw_);
+ Resource::seal();
+ turn_on();
+}
xbt::signal<void(DiskAction const&, Action::State, Action::State)> DiskAction::on_state_change;
/**********