From acc023ef628e5c9efdd290c09a8b492eb97db699 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Fri, 3 Nov 2017 10:50:20 +0100 Subject: [PATCH] more protected->private fields --- src/instr/instr_paje_events.cpp | 29 +++++++++++++++-------------- src/instr/instr_paje_events.hpp | 10 ++++++---- src/surf/cpu_cas01.cpp | 6 +++--- src/surf/cpu_ti.cpp | 26 +++++++++++++------------- src/surf/network_cm02.cpp | 12 ++++++------ src/surf/surf_interface.cpp | 2 +- src/surf/surf_interface.hpp | 10 ++++++---- 7 files changed, 50 insertions(+), 45 deletions(-) diff --git a/src/instr/instr_paje_events.cpp b/src/instr/instr_paje_events.cpp index ec50dda2c5..067fb8b5d5 100644 --- a/src/instr/instr_paje_events.cpp +++ b/src/instr/instr_paje_events.cpp @@ -73,10 +73,10 @@ void NewEvent::print() return; if (timestamp_ < 1e-12) - stream << eventType_ << " " << 0 << " " << type->getId() << " " << container->getId(); + stream << eventType_ << " " << 0 << " "; else - stream << eventType_ << " " << timestamp_ << " " << type->getId() << " " << container->getId(); - stream << " " << val->getId(); + stream << eventType_ << " " << timestamp_ << " "; + stream << getType()->getId() << " " << getContainer()->getId() << " " << val->getId(); XBT_DEBUG("Dump %s", stream.str().c_str()); fprintf(tracing_file, "%s\n", stream.str().c_str()); } @@ -89,11 +89,11 @@ void LinkEvent::print() if (instr_fmt_type != instr_fmt_paje) return; if (timestamp_ < 1e-12) - stream << eventType_ << " " << 0 << " " << type->getId() << " " << container->getId() << " " << value_; + stream << eventType_ << " " << 0 << " " << getType()->getId() << " " << getContainer()->getId(); else - stream << eventType_ << " " << timestamp_ << " " << type->getId() << " " << container->getId() << " " << value_; + stream << eventType_ << " " << timestamp_ << " " << getType()->getId() << " " << getContainer()->getId(); - stream << " " << endpoint_->getId() << " " << key_; + stream << " " << value_ << " " << endpoint_->getId() << " " << key_; if (TRACE_display_sizes()) { stream << " " << size_; @@ -111,9 +111,10 @@ void VariableEvent::print() return; if (timestamp_ < 1e-12) - stream << eventType_ << " " << 0 << " " << type->getId() << " " << container->getId() << " " << value; + stream << eventType_ << " " << 0 << " "; else - stream << eventType_ << " " << timestamp_ << " " << type->getId() << " " << container->getId() << " " << value; + stream << eventType_ << " " << timestamp_ << " "; + stream << getType()->getId() << " " << getContainer()->getId() << " " << value; XBT_DEBUG("Dump %s", stream.str().c_str()); fprintf(tracing_file, "%s\n", stream.str().c_str()); } @@ -125,9 +126,9 @@ void StateEvent::print() XBT_DEBUG("%s: event_type=%u, timestamp=%.*f", __FUNCTION__, eventType_, TRACE_precision(), timestamp_); if (instr_fmt_type == instr_fmt_paje) { if (timestamp_ < 1e-12) - stream << eventType_ << " " << 0 << " " << type->getId() << " " << container->getId(); + stream << eventType_ << " " << 0 << " " << getType()->getId() << " " << getContainer()->getId(); else - stream << eventType_ << " " << timestamp_ << " " << type->getId() << " " << container->getId(); + stream << eventType_ << " " << timestamp_ << " " << getType()->getId() << " " << getContainer()->getId(); if (value != nullptr) // PAJE_PopState Event does not need to have a value stream << " " << value->getId(); @@ -161,12 +162,12 @@ void StateEvent::print() instr_extra_data extra = (instr_extra_data)extra_; // FIXME: dirty extract "rank-" from the name, as we want the bare process id here - if (container->getName().find("rank-") != 0) - stream << container->getName() << " "; + if (getContainer()->getName().find("rank-") != 0) + stream << getContainer()->getName() << " "; else - stream << container->getName().erase(0, 5) << " "; + stream << getContainer()->getName().erase(0, 5) << " "; - FILE* trace_file = tracing_files.at(container); + FILE* trace_file = tracing_files.at(getContainer()); switch (extra->type) { case TRACING_INIT: diff --git a/src/instr/instr_paje_events.hpp b/src/instr/instr_paje_events.hpp index 768ac591ae..6f0b3bb4e6 100644 --- a/src/instr/instr_paje_events.hpp +++ b/src/instr/instr_paje_events.hpp @@ -35,15 +35,17 @@ enum e_event_type : unsigned int { }; class PajeEvent { -protected: - Container* container; - Type* type; + Container* container_; + Type* type_; +protected: + Type* getType() { return type_; } + Container* getContainer() { return container_; } public: double timestamp_; e_event_type eventType_; PajeEvent(Container* container, Type* type, double timestamp, e_event_type eventType) - : container(container), type(type), timestamp_(timestamp), eventType_(eventType){}; + : container_(container), type_(type), timestamp_(timestamp), eventType_(eventType){}; virtual ~PajeEvent() = default; virtual void print() = 0; void insertIntoBuffer(); diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index e269ce6093..446d217b22 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -41,10 +41,10 @@ CpuCas01Model::CpuCas01Model() : simgrid::surf::CpuModel() bool select = xbt_cfg_get_boolean("cpu/maxmin-selective-update"); if (not strcmp(optim, "Full")) { - updateMechanism_ = UM_FULL; + setUpdateMechanism(UM_FULL); selectiveUpdate_ = select; } else if (not strcmp(optim, "Lazy")) { - updateMechanism_ = UM_LAZY; + setUpdateMechanism(UM_LAZY); selectiveUpdate_ = true; xbt_assert(select || (xbt_cfg_is_default_value("cpu/maxmin-selective-update")), "Disabling selective update while using the lazy update mechanism is dumb!"); @@ -214,7 +214,7 @@ CpuCas01Action::CpuCas01Action(Model* model, double cost, bool failed, double sp , requestedCore_(requestedCore) { if (model->getUpdateMechanism() == UM_LAZY) { - indexHeap_ = -1; + updateIndexHeap(-1); refreshLastUpdate(); setLastValue(0.0); } diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 01496568dc..991cf38c9b 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -468,9 +468,9 @@ void CpuTi::apply_event(tmgr_trace_event_t event, double value) || action->getState() == Action::State::not_in_the_system) { action->setFinishTime(date); action->setState(Action::State::failed); - if (action->indexHeap_ >= 0) { + if (action->getIndexHeap() >= 0) { CpuTiAction* heap_act = static_cast( - xbt_heap_remove(static_cast(model())->tiActionHeap_, action->indexHeap_)); + xbt_heap_remove(static_cast(model())->tiActionHeap_, action->getIndexHeap())); if (heap_act != action) DIE_IMPOSSIBLE; } @@ -538,10 +538,10 @@ void CpuTi::updateActionsFinishTime(double now) min_finish = action->getStartTime() + action->getMaxDuration(); } /* add in action heap */ - XBT_DEBUG("action(%p) index %d", action, action->indexHeap_); - if (action->indexHeap_ >= 0) { + XBT_DEBUG("action(%p) index %d", action, action->getIndexHeap()); + if (action->getIndexHeap() >= 0) { CpuTiAction* heap_act = static_cast( - xbt_heap_remove(static_cast(model())->tiActionHeap_, action->indexHeap_)); + xbt_heap_remove(static_cast(model())->tiActionHeap_, action->getIndexHeap())); if (heap_act != action) DIE_IMPOSSIBLE; } @@ -664,13 +664,13 @@ CpuTiAction::CpuTiAction(CpuTiModel *model_, double cost, bool failed, CpuTi *cp : CpuAction(model_, cost, failed) , cpu_(cpu) { - indexHeap_ = -1; + updateIndexHeap(-1); cpu_->modified(true); } void CpuTiAction::updateIndexHeap(int i) { - indexHeap_ = i; + Action::updateIndexHeap(i); } void CpuTiAction::setState(Action::State state) @@ -689,7 +689,7 @@ int CpuTiAction::unref() if (action_ti_hook.is_linked()) cpu_->actionSet_->erase(cpu_->actionSet_->iterator_to(*this)); /* remove from heap */ - xbt_heap_remove(static_cast(getModel())->tiActionHeap_, this->indexHeap_); + xbt_heap_remove(static_cast(getModel())->tiActionHeap_, getIndexHeap()); cpu_->modified(true); delete this; return 1; @@ -700,7 +700,7 @@ int CpuTiAction::unref() void CpuTiAction::cancel() { this->setState(Action::State::failed); - xbt_heap_remove(getModel()->getActionHeap(), this->indexHeap_); + xbt_heap_remove(getModel()->getActionHeap(), getIndexHeap()); cpu_->modified(true); } @@ -709,7 +709,7 @@ void CpuTiAction::suspend() XBT_IN("(%p)", this); if (suspended_ != 2) { suspended_ = 1; - xbt_heap_remove(getModel()->getActionHeap(), indexHeap_); + xbt_heap_remove(getModel()->getActionHeap(), getIndexHeap()); cpu_->modified(true); } XBT_OUT(); @@ -740,8 +740,8 @@ void CpuTiAction::setMaxDuration(double duration) min_finish = getFinishTime(); /* add in action heap */ - if (indexHeap_ >= 0) { - CpuTiAction *heap_act = static_cast(xbt_heap_remove(getModel()->getActionHeap(), indexHeap_)); + if (getIndexHeap() >= 0) { + CpuTiAction* heap_act = static_cast(xbt_heap_remove(getModel()->getActionHeap(), getIndexHeap())); if (heap_act != this) DIE_IMPOSSIBLE; } @@ -753,7 +753,7 @@ void CpuTiAction::setMaxDuration(double duration) void CpuTiAction::setSharingWeight(double priority) { XBT_IN("(%p,%g)", this, priority); - sharingWeight_ = priority; + setSharingWeightNoUpdate(priority); cpu_->modified(true); XBT_OUT(); } diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index b55b754f5f..fe1a8dcedb 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -138,10 +138,10 @@ NetworkCm02Model::NetworkCm02Model() bool select = xbt_cfg_get_boolean("network/maxmin-selective-update"); if (not strcmp(optim, "Full")) { - updateMechanism_ = UM_FULL; + setUpdateMechanism(UM_FULL); selectiveUpdate_ = select; } else if (not strcmp(optim, "Lazy")) { - updateMechanism_ = UM_LAZY; + setUpdateMechanism(UM_LAZY); selectiveUpdate_ = true; xbt_assert(select || (xbt_cfg_is_default_value("network/maxmin-selective-update")), "You cannot disable selective update when using the lazy update mechanism"); @@ -152,7 +152,7 @@ NetworkCm02Model::NetworkCm02Model() maxminSystem_ = lmm_system_new(selectiveUpdate_); loopback_ = createLink("__loopback__", 498000000, 0.000015, SURF_LINK_FATPIPE); - if (updateMechanism_ == UM_LAZY) { + if (getUpdateMechanism() == UM_LAZY) { actionHeap_ = xbt_heap_new(8, nullptr); xbt_heap_set_update_callback(actionHeap_, surf_action_lmm_update_index_heap); modifiedSet_ = new ActionLmmList(); @@ -293,8 +293,8 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz action->weight_ = latency; action->latency_ = latency; action->rate_ = rate; - if (updateMechanism_ == UM_LAZY) { - action->indexHeap_ = -1; + if (getUpdateMechanism() == UM_LAZY) { + action->updateIndexHeap(-1); action->refreshLastUpdate(); } @@ -318,7 +318,7 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz if (action->latency_ > 0) { action->setVariable(lmm_variable_new(maxminSystem_, action, 0.0, -1.0, constraints_per_variable)); - if (updateMechanism_ == UM_LAZY) { + if (getUpdateMechanism() == UM_LAZY) { // add to the heap the event when the latency is payed XBT_DEBUG("Added action (%p) one latency event at date %f", action, action->latency_ + action->getLastUpdate()); action->heapInsert(actionHeap_, action->latency_ + action->getLastUpdate(), route->empty() ? NORMAL : LATENCY); diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 837bf97e61..77bc7caba0 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -790,7 +790,7 @@ void Action::resume() { XBT_IN("(%p)", this); if (suspended_ != 2) { - lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), sharingWeight_); + lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), getPriority()); suspended_ = 0; if (getModel()->getUpdateMechanism() == UM_LAZY) heapRemove(getModel()->getActionHeap()); diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index dc6ddd3262..32e6ec3a80 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -201,6 +201,7 @@ public: double getPriority() { return sharingWeight_; }; /** @brief Set the priority of the current Action */ virtual void setSharingWeight(double priority); + void setSharingWeightNoUpdate(double weight) { sharingWeight_ = weight; } /** @brief Get the state set in which the action is */ ActionList* getStateSet() {return stateSet_;}; @@ -211,10 +212,10 @@ public: protected: ActionList* stateSet_; - double sharingWeight_ = 1.0; /**< priority (1.0 by default) */ int refcount_ = 1; private: + double sharingWeight_ = 1.0; /**< priority (1.0 by default) */ double maxDuration_ = NO_MAX_DURATION; /*< max_duration (may fluctuate until the task is completed) */ double remains_; /**< How much of that cost remains to be done in the currently running task */ double start_; /**< start time */ @@ -231,6 +232,7 @@ private: double lastValue_ = 0; lmm_variable_t variable_ = nullptr; enum heap_action_type hat_ = NOTSET; + int indexHeap_; public: virtual void updateRemainingLazy(double now) { THROW_IMPOSSIBLE; }; @@ -246,10 +248,9 @@ public: void setLastValue(double val) { lastValue_ = val; } enum heap_action_type getHat() { return hat_; } bool is_linked() {return action_lmm_hook.is_linked();} - + int getIndexHeap() { return indexHeap_; } protected: int suspended_ = 0; - int indexHeap_; }; typedef Action::ActionList ActionList; @@ -295,6 +296,7 @@ public: * @see e_UM_t */ e_UM_t getUpdateMechanism() {return updateMechanism_;} + void setUpdateMechanism(e_UM_t mechanism) { updateMechanism_ = mechanism; } /** @brief Get Action heap */ xbt_heap_t getActionHeap() {return actionHeap_;} @@ -329,11 +331,11 @@ public: protected: ActionLmmListPtr modifiedSet_; lmm_system_t maxminSystem_ = nullptr; - e_UM_t updateMechanism_ = UM_UNDEFINED; bool selectiveUpdate_; xbt_heap_t actionHeap_; private: + e_UM_t updateMechanism_ = UM_UNDEFINED; ActionList* readyActionSet_; /**< Actions in state SURF_ACTION_READY */ ActionList* runningActionSet_; /**< Actions in state SURF_ACTION_RUNNING */ ActionList* failedActionSet_; /**< Actions in state SURF_ACTION_FAILED */ -- 2.20.1