From: Frederic Suter Date: Thu, 2 Nov 2017 11:21:20 +0000 (+0100) Subject: use (existing) accessors to make protected fields private X-Git-Tag: v3.18~319 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/33f7f52135858a7e673099cd70f31bc28e04edbe use (existing) accessors to make protected fields private --- diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index ca7cae6f4e..e269ce6093 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -183,7 +183,7 @@ CpuAction *CpuCas01::sleep(double duration) CpuCas01Action* action = new CpuCas01Action(model(), 1.0, isOff(), speed_.scale * speed_.peak, constraint()); // FIXME: sleep variables should not consume 1.0 in lmm_expand - action->maxDuration_ = duration; + action->setMaxDuration(duration); action->suspended_ = 2; if (duration < 0) { // NO_MAX_DURATION /* Move to the *end* of the corresponding action set. This convention is used to speed up update_resource_state */ @@ -215,8 +215,8 @@ CpuCas01Action::CpuCas01Action(Model* model, double cost, bool failed, double sp { if (model->getUpdateMechanism() == UM_LAZY) { indexHeap_ = -1; - lastUpdate_ = surf_get_clock(); - lastValue_ = 0.0; + refreshLastUpdate(); + setLastValue(0.0); } lmm_expand(model->getMaxminSystem(), constraint, getVariable(), 1.0); } diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index acb282b05b..044d58fca3 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -191,21 +191,23 @@ void CpuAction::updateRemainingLazy(double now) xbt_assert(getStateSet() == getModel()->getRunningActionSet(), "You're updating an action that is not running."); xbt_assert(getPriority() > 0, "You're updating an action that seems suspended."); - double delta = now - lastUpdate_; + double delta = now - getLastUpdate(); - if (remains_ > 0) { - XBT_CDEBUG(surf_kernel, "Updating action(%p): remains was %f, last_update was: %f", this, remains_, lastUpdate_); - double_update(&(remains_), lastValue_ * delta, sg_maxmin_precision*sg_surf_precision); + if (getRemainsNoUpdate() > 0) { + XBT_CDEBUG(surf_kernel, "Updating action(%p): remains was %f, last_update was: %f", this, getRemainsNoUpdate(), + getLastUpdate()); + updateRemains(getLastValue() * delta); if (TRACE_is_enabled()) { Cpu *cpu = static_cast(lmm_constraint_id(lmm_get_cnst_from_var(getModel()->getMaxminSystem(), getVariable(), 0))); - TRACE_surf_host_set_utilization(cpu->getCname(), getCategory(), lastValue_, lastUpdate_, now - lastUpdate_); + TRACE_surf_host_set_utilization(cpu->getCname(), getCategory(), getLastValue(), getLastUpdate(), + now - getLastUpdate()); } - XBT_CDEBUG(surf_kernel, "Updating action(%p): remains is now %f", this, remains_); + XBT_CDEBUG(surf_kernel, "Updating action(%p): remains is now %f", this, getRemainsNoUpdate()); } - lastUpdate_ = now; - lastValue_ = lmm_variable_getvalue(getVariable()); + refreshLastUpdate(); + setLastValue(lmm_variable_getvalue(getVariable())); } simgrid::xbt::signal CpuAction::onStateChange; diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index eea488f589..de1be6eb81 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -528,10 +528,10 @@ void CpuTi::updateActionsFinishTime(double now) action->setFinishTime(speedIntegratedTrace_->solve(now, total_area)); /* verify which event will happen before (max_duration or finish time) */ if (action->getMaxDuration() > NO_MAX_DURATION && - action->getStartTime() + action->getMaxDuration() < action->finishTime_) + action->getStartTime() + action->getMaxDuration() < action->getFinishTime()) min_finish = action->getStartTime() + action->getMaxDuration(); else - min_finish = action->finishTime_; + min_finish = action->getFinishTime(); } else { /* put the max duration time on heap */ if (action->getMaxDuration() > NO_MAX_DURATION) @@ -549,7 +549,7 @@ void CpuTi::updateActionsFinishTime(double now) xbt_heap_push(static_cast(model())->tiActionHeap_, action, min_finish); XBT_DEBUG("Update finish time: Cpu(%s) Action: %p, Start Time: %f Finish Time: %f Max duration %f", getCname(), - action, action->getStartTime(), action->finishTime_, action->getMaxDuration()); + action, action->getStartTime(), action->getFinishTime(), action->getMaxDuration()); } /* remove from modified cpu */ modified(false); @@ -597,12 +597,12 @@ void CpuTi::updateRemainingAmount(double now) continue; /* skip action that are finishing now */ - if (action->finishTime_ >= 0 && action->finishTime_ <= now) + if (action->getFinishTime() >= 0 && action->getFinishTime() <= now) continue; /* update remaining */ action->updateRemains(area_total / (sumPriority_ * action->getPriority())); - XBT_DEBUG("Update remaining action(%p) remaining %f", action, action->remains_); + XBT_DEBUG("Update remaining action(%p) remaining %f", action, action->getRemainsNoUpdate()); } lastUpdate_ = now; } @@ -627,7 +627,7 @@ CpuAction *CpuTi::sleep(double duration) XBT_IN("(%s,%g)", getCname(), duration); CpuTiAction* action = new CpuTiAction(static_cast(model()), 1.0, isOff(), this); - action->maxDuration_ = duration; + action->setMaxDuration(duration); action->suspended_ = 2; if (duration == NO_MAX_DURATION) { /* Move to the *end* of the corresponding action set. This convention @@ -731,7 +731,7 @@ void CpuTiAction::setMaxDuration(double duration) XBT_IN("(%p,%g)", this, duration); - maxDuration_ = duration; + setMaxDuration(duration); if (duration >= 0) min_finish = (getStartTime() + getMaxDuration()) < getFinishTime() ? @@ -763,7 +763,7 @@ double CpuTiAction::getRemains() XBT_IN("(%p)", this); cpu_->updateRemainingAmount(surf_get_clock()); XBT_OUT(); - return remains_; + return getRemainsNoUpdate(); } } diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 9bd196ab18..b55b754f5f 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -295,7 +295,7 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz action->rate_ = rate; if (updateMechanism_ == UM_LAZY) { action->indexHeap_ = -1; - action->lastUpdate_ = surf_get_clock(); + action->refreshLastUpdate(); } double bandwidth_bound = -1.0; @@ -317,14 +317,14 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz constraints_per_variable += back_route->size(); if (action->latency_ > 0) { - action->variable_ = lmm_variable_new(maxminSystem_, action, 0.0, -1.0, constraints_per_variable); + action->setVariable(lmm_variable_new(maxminSystem_, action, 0.0, -1.0, constraints_per_variable)); if (updateMechanism_ == 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->lastUpdate_); - action->heapInsert(actionHeap_, action->latency_ + action->lastUpdate_, route->empty() ? NORMAL : LATENCY); + 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); } } else - action->variable_ = lmm_variable_new(maxminSystem_, action, 1.0, -1.0, constraints_per_variable); + action->setVariable(lmm_variable_new(maxminSystem_, action, 1.0, -1.0, constraints_per_variable)); if (action->rate_ < 0) { lmm_update_variable_bound(maxminSystem_, action->getVariable(), (action->latCurrent_ > 0) ? sg_tcp_gamma / (2.0 * action->latCurrent_) : -1.0); @@ -476,26 +476,29 @@ void NetworkCm02Action::updateRemainingLazy(double now) if (suspended_ != 0) return; - double delta = now - lastUpdate_; + double delta = now - getLastUpdate(); + double max_duration = getMaxDuration(); - if (remains_ > 0) { - XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", this, remains_, lastUpdate_); - double_update(&(remains_), lastValue_ * delta, sg_maxmin_precision*sg_surf_precision); + if (getRemainsNoUpdate() > 0) { + XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", this, getRemainsNoUpdate(), getLastUpdate()); + updateRemains(getLastValue() * delta); - XBT_DEBUG("Updating action(%p): remains is now %f", this, remains_); + XBT_DEBUG("Updating action(%p): remains is now %f", this, getRemainsNoUpdate()); } - if (maxDuration_ > NO_MAX_DURATION) - double_update(&maxDuration_, delta, sg_surf_precision); + if (max_duration > NO_MAX_DURATION) { + double_update(&max_duration, delta, sg_surf_precision); + setMaxDuration(max_duration); + } - if ((remains_ <= 0 && (lmm_get_variable_weight(getVariable()) > 0)) || - ((maxDuration_ > NO_MAX_DURATION) && (maxDuration_ <= 0))) { + if ((getRemainsNoUpdate() <= 0 && (lmm_get_variable_weight(getVariable()) > 0)) || + ((max_duration > NO_MAX_DURATION) && (max_duration <= 0))) { finish(Action::State::done); heapRemove(getModel()->getActionHeap()); } - lastUpdate_ = now; - lastValue_ = lmm_variable_getvalue(getVariable()); + refreshLastUpdate(); + setLastValue(lmm_variable_getvalue(getVariable())); } } diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index 0b5a2bbddd..a7803a93fe 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -196,7 +196,7 @@ namespace simgrid { { std::list retlist; lmm_system_t sys = getModel()->getMaxminSystem(); - int llen = lmm_get_number_of_cnst_from_var(sys, variable_); + int llen = lmm_get_number_of_cnst_from_var(sys, getVariable()); for (int i = 0; i < llen; i++) { /* Beware of composite actions: ptasks put links and cpus together */ diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index f11d8dff39..17f312cf66 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -195,17 +195,15 @@ L07Action::L07Action(Model *model, int host_nb, sg_host_t *host_list, } XBT_DEBUG("Creating a parallel task (%p) with %d hosts and %d unique links.", this, host_nb, nb_link); - this->latency_ = latency; + latency_ = latency; - this->variable_ = lmm_variable_new(model->getMaxminSystem(), this, 1.0, - (rate > 0 ? rate : -1.0), - host_nb + nb_link); + setVariable(lmm_variable_new(model->getMaxminSystem(), this, 1.0, (rate > 0 ? rate : -1.0), host_nb + nb_link)); - if (this->latency_ > 0) - lmm_update_variable_weight(model->getMaxminSystem(), this->getVariable(), 0.0); + if (latency_ > 0) + lmm_update_variable_weight(model->getMaxminSystem(), getVariable(), 0.0); for (int i = 0; i < host_nb; i++) - lmm_expand(model->getMaxminSystem(), host_list[i]->pimpl_cpu->constraint(), this->getVariable(), flops_amount[i]); + lmm_expand(model->getMaxminSystem(), host_list[i]->pimpl_cpu->constraint(), getVariable(), flops_amount[i]); if(bytes_amount != nullptr) { for (int i = 0; i < host_nb; i++) { @@ -292,7 +290,7 @@ Action *CpuL07::execution_start(double size) Action *CpuL07::sleep(double duration) { L07Action *action = static_cast(execution_start(1.0)); - action->maxDuration_ = duration; + action->setMaxDuration(duration); action->suspended_ = 2; lmm_update_variable_weight(model()->getMaxminSystem(), action->getVariable(), 0.0); diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index c8fae21557..837bf97e61 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -705,8 +705,7 @@ double Action::getStartTime() double Action::getFinishTime() { - /* keep the function behavior, some models (cpu_ti) change the finish time before the action end */ - return remains_ <= 0 ? finishTime_ : -1; + return finishTime_; } void Action::setData(void* data) diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 85d23ef9f9..dc6ddd3262 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -213,19 +213,25 @@ protected: ActionList* stateSet_; double sharingWeight_ = 1.0; /**< priority (1.0 by default) */ int refcount_ = 1; - double remains_; /**< How much of that cost remains to be done in the currently running task */ - double maxDuration_ = NO_MAX_DURATION; /*< max_duration (may fluctuate until the task is completed) */ - double finishTime_ = -1; /**< finish time : this is modified during the run and fluctuates until the task is completed */ private: + 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 */ char *category_ = nullptr; /**< tracing category for categorized resource utilization monitoring */ + double finishTime_ = + -1; /**< finish time : this is modified during the run and fluctuates until the task is completed */ double cost_; simgrid::surf::Model *model_; void *data_ = nullptr; /**< for your convenience */ /* LMM */ + double lastUpdate_ = 0; + double lastValue_ = 0; + lmm_variable_t variable_ = nullptr; + enum heap_action_type hat_ = NOTSET; + public: virtual void updateRemainingLazy(double now) { THROW_IMPOSSIBLE; }; void heapInsert(xbt_heap_t heap, double key, enum heap_action_type hat); @@ -233,20 +239,17 @@ public: void heapUpdate(xbt_heap_t heap, double key, enum heap_action_type hat); virtual void updateIndexHeap(int i); lmm_variable_t getVariable() {return variable_;} + void setVariable(lmm_variable_t var) { variable_ = var; } double getLastUpdate() {return lastUpdate_;} void refreshLastUpdate() {lastUpdate_ = surf_get_clock();} - enum heap_action_type getHat() {return hat_;} + double getLastValue() { return lastValue_; } + void setLastValue(double val) { lastValue_ = val; } + enum heap_action_type getHat() { return hat_; } bool is_linked() {return action_lmm_hook.is_linked();} protected: - lmm_variable_t variable_ = nullptr; - double lastValue_ = 0; - double lastUpdate_ = 0; int suspended_ = 0; int indexHeap_; - -private: - enum heap_action_type hat_ = NOTSET; }; typedef Action::ActionList ActionList;