* @details This is the ancestor class of every resources in SimGrid, such as links, CPU or disk
*/
class XBT_PUBLIC Resource {
- std::string name_;
- Model* model_;
- bool is_on_ = true;
+ std::string name_ = "unnamed";
+ Model* model_ = nullptr;
+ bool is_on_ = true;
- lmm::Constraint* const constraint_;
+ lmm::Constraint* constraint_ = nullptr;
protected:
struct Metric {
profile::Event* state_event_ = nullptr;
public:
- /**
- * @brief Constructor of LMM Resources
- *
- * @param model Model associated to this Resource
- * @param name The name of the Resource
- * @param constraint The lmm constraint associated to this Resource if it is part of a LMM component
- */
- Resource(Model* model, const std::string& name, lmm::Constraint* constraint)
- : name_(name), model_(model), constraint_(constraint)
- {
- }
-
+ Resource() = default;
virtual ~Resource() = default;
/** @brief Get the Model of the current Resource */
Model* get_model() const { return model_; }
+ Resource* set_model(Model* model);
/** @brief Get the name 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_; }
+ Resource* set_constraint(lmm::Constraint* constraint);
bool operator==(const Resource& other) const { return name_ == other.name_; }
/** @brief setup the profile file with states events (ON or OFF). The profile must contain boolean values. */
virtual void set_state_profile(profile::Profile* profile);
- /** @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_; }
};
} // namespace resource
} // namespace kernel
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)
+ : piface_(name, this)
, read_bw_(read_bw)
, write_bw_(write_bw)
{
+ this->set_name(name)->set_model(model)->set_constraint(maxminSystem->constraint_new(this, std::max(read_bw, write_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);
namespace kernel {
namespace resource {
+Resource* Resource::set_name(const std::string& name)
+{
+ name_ = name;
+ return this;
+}
+
+Resource* Resource::set_model(Model* model)
+{
+ model_ = model;
+ return this;
+}
+
+Resource* Resource::set_constraint(lmm::Constraint* constraint)
+{
+ constraint_ = constraint;
+ return this;
+}
+
double Resource::get_load() const
{
return constraint_->get_usage();
public:
static double the_date;
- explicit MockedResource() : simgrid::kernel::resource::Resource(nullptr, "fake", nullptr) {}
+ explicit MockedResource() { this->set_name("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);
Cpu::Cpu(Model* model, s4u::Host* host, lmm::Constraint* constraint, const std::vector<double>& speed_per_pstate,
int core)
- : Resource(model, host->get_cname(), constraint)
- , core_count_(core)
+ : core_count_(core)
, host_(host)
, speed_per_pstate_(speed_per_pstate)
{
+ this->set_name(host->get_cname())->set_model(model)->set_constraint(constraint);
+
xbt_assert(core > 0, "Host %s must have at least one core, not 0.", host->get_cname());
speed_.peak = speed_per_pstate_.front();
************/
LinkImpl::LinkImpl(NetworkModel* model, const std::string& name, lmm::Constraint* constraint)
- : Resource(model, name, constraint), piface_(this)
+ : piface_(this)
{
+ this->set_name(name)->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());