static void host()
{
/* -Add an extra disk in a programmatic way */
- simgrid::s4u::Host::current()->create_disk()
- ->set_name("Disk3")
- ->set_read_bandwidth(9.6e7)
- ->set_write_bandwidth(6.4e7)
- ->seal();
+ simgrid::s4u::Host::current()->create_disk("Disk3", /*read bandwidth*/ 9.6e7, /*write bandwidth*/6.4e7)->seal();
/* - Display information on the disks mounted by the current host */
XBT_INFO("*** Storage info on %s ***", simgrid::s4u::Host::current()->get_cname());
profile::Event* state_event_ = nullptr;
public:
- Resource() = default;
+ Resource(const std::string& name) : name_(name){};
virtual ~Resource() = default;
/** @brief Get the Model of the current Resource */
const std::string& get_name() const { return name_; }
/** @brief Get the name of the current Resource */
const char* get_cname() const { return name_.c_str(); }
- Resource* set_name(const std::string& name);
/** @brief Get the lmm constraint associated to this Resource if it is part of a LMM component (or null if none) */
lmm::Constraint* get_constraint() const { return constraint_; }
public:
#ifndef DOXYGEN
- explicit Disk(kernel::resource::DiskImpl* pimpl) : pimpl_(pimpl) {}
+ explicit Disk(const std::string& name, kernel::resource::DiskImpl* pimpl) : pimpl_(pimpl), name_(name) {}
#endif
/** @brief Callback signal fired when a new Disk is created */
int get_pstate() const;
std::vector<Disk*> get_disks() const;
- Disk* create_disk();
+ Disk* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth);
void add_disk(const Disk* disk);
void remove_disk(const std::string& disk_name);
DiskModel& operator=(const DiskModel&) = delete;
~DiskModel() override;
- virtual DiskImpl* create_disk() = 0;
+ virtual DiskImpl* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth) = 0;
};
/************
~DiskImpl() override = default; // Disallow direct deletion. Call destroy() instead.
public:
- DiskImpl() : piface_(this){}
+ DiskImpl(const std::string& name, double read_bandwidth, double write_bandwidth)
+ : Resource(name),
+ piface_(name, this),
+ read_bw_(read_bandwidth),
+ write_bw_(write_bandwidth){}
DiskImpl(const DiskImpl&) = delete;
DiskImpl& operator=(const DiskImpl&) = delete;
namespace kernel {
namespace resource {
-Resource* Resource::set_name(const std::string& name)
-{
- name_ = name;
- return this;
-}
-
Resource* Resource::set_model(Model* model)
{
model_ = model;
public:
static double the_date;
- explicit MockedResource() { this->set_name("fake"); }
+ explicit MockedResource() : Resource("fake"){}
void apply_event(simgrid::kernel::profile::Event* event, double value) override
{
XBT_VERB("t=%.1f: Change value to %lg (idx: %u)", the_date, value, event->idx);
return kernel::actor::simcall([this] { return this->pimpl_->get_disks(); });
}
-Disk* Host::create_disk()
+Disk* Host::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth)
{
- auto pimpl = surf_disk_model->create_disk();
+ auto pimpl = surf_disk_model->create_disk(name, read_bandwidth, write_bandwidth);
pimpl->set_host(this);
return pimpl->get_iface();
}
Cpu::Cpu(Model* model, s4u::Host* host, lmm::Constraint* constraint, const std::vector<double>& speed_per_pstate,
int core)
- : core_count_(core)
+ : Resource(host->get_cname())
+ , core_count_(core)
, host_(host)
, speed_per_pstate_(speed_per_pstate)
{
- this->set_name(host->get_cname())->set_model(model)->set_constraint(constraint);
+ this->set_model(model)->set_constraint(constraint);
xbt_assert(core > 0, "Host %s must have at least one core, not 0.", host->get_cname());
all_existing_models.push_back(this);
}
-DiskImpl* DiskS19Model::create_disk()
+DiskImpl* DiskS19Model::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth)
{
- return new DiskS19();
+ return new DiskS19(name, read_bandwidth, write_bandwidth);
}
double DiskS19Model::next_occurring_event(double now)
/************
* Resource *
************/
-
DiskAction* DiskS19::io_start(sg_size_t size, s4u::Io::OpType type)
{
return new DiskS19Action(get_model(), static_cast<double>(size), not is_on(), this, type);
class DiskS19Model : public DiskModel {
public:
DiskS19Model();
- DiskImpl* create_disk() override;
+ DiskImpl* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth) override;
double next_occurring_event(double now) override;
void update_actions_state(double now, double delta) override;
};
class DiskS19 : public DiskImpl {
public:
- DiskS19() = default;
+ explicit DiskS19(const std::string& name, double read_bw, double write_bw): DiskImpl(name, read_bw, write_bw) {}
DiskAction* io_start(sg_size_t size, s4u::Io::OpType type) override;
DiskAction* read(sg_size_t size) override;
DiskAction* write(sg_size_t size) override;
************/
LinkImpl::LinkImpl(NetworkModel* model, const std::string& name, lmm::Constraint* constraint)
- : piface_(this)
+ : Resource(name), piface_(this)
{
- this->set_name(name)->set_model(model)->set_constraint(constraint);
+ this->set_model(model)->set_constraint(constraint);
if (name != "__loopback__")
xbt_assert(not s4u::Link::by_name_or_null(name), "Link '%s' declared several times in the platform.", name.c_str());
simgrid::kernel::resource::DiskImpl* sg_platf_new_disk(const simgrid::kernel::routing::DiskCreationArgs* disk)
{
- simgrid::kernel::resource::DiskImpl* pimpl = surf_disk_model->create_disk();
+ simgrid::kernel::resource::DiskImpl* pimpl = surf_disk_model->create_disk(disk->id, disk->read_bw, disk->write_bw);
- // This should be done using s4u::Disk methods and passed to the pimpl
- pimpl->set_read_bandwidth(disk->read_bw)
- ->set_write_bandwidth(disk->write_bw)
- ->set_name(disk->id);
if (disk->properties) {
pimpl->set_properties(*disk->properties);
delete disk->properties;
}
- pimpl->get_iface()->set_name(disk->id);
- // This should be done in the seal() of a Disk creation
pimpl->seal();
simgrid::s4u::Disk::on_creation(*pimpl->get_iface());
return pimpl;