CpuAction *CpuCas01::sleep(double duration) { if (duration > 0) duration = MAX(duration, sg_surf_precision); XBT_IN("(%s,%g)", getName(), duration); CpuCas01Action *action = new CpuCas01Action(getModel(), 1.0, isOff(), speed_.scale * speed_.peak, getConstraint()); // FIXME: sleep variables should not consume 1.0 in lmm_expand action->maxDuration_ = duration; action->suspended_ = 2; if (duration == NO_MAX_DURATION) { /* Move to the *end* of the corresponding action set. This convention is used to speed up update_resource_state */ action->getStateSet()->erase(action->getStateSet()->iterator_to(*action)); action->stateSet_ = static_cast<CpuCas01Model*>(getModel())->p_cpuRunningActionSetThatDoesNotNeedBeingChecked; action->getStateSet()->push_back(*action); } lmm_update_variable_weight(getModel()->getMaxminSystem(), action->getVariable(), 0.0); if (getModel()->getUpdateMechanism() == UM_LAZY) { // remove action from the heap action->heapRemove(getModel()->getActionHeap()); // this is necessary for a variable with weight 0 since such variables are ignored in lmm and we need to set its // max_duration correctly at the next call to share_resources getModel()->getModifiedSet()->push_front(*action); } XBT_OUT(); return action; }
void StorageN11Action::suspend() { XBT_IN("(%p)", this); if (suspended_ != 2) { lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), 0.0); suspended_ = 1; } XBT_OUT(); }
static void new_model_action_suspend(surf_action_t action) { XBT_IN("(%p)", action); if (((surf_action_lmm_t) action)->suspended != 2) { lmm_update_variable_weight(new_model_maxmin_system, ((surf_action_lmm_t) action)->variable, 0.0); ((surf_action_lmm_t) action)->suspended = 1; } XBT_OUT(); }
void surf_action_set_priority(surf_action_t action, double priority) { surf_model_t model = action->model_type; XBT_IN("(%p,%g)", action, priority); action->priority = priority; lmm_update_variable_weight(model->model_private->maxmin_system, ((surf_action_lmm_t) action)->variable, priority); if (model->model_private->update_mechanism == UM_LAZY) surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action); XBT_OUT(); }
void NetworkCm02Model::updateActionsStateLazy(double now, double /*delta*/) { NetworkCm02ActionPtr action; while ((xbt_heap_size(p_actionHeap) > 0) && (double_equals(xbt_heap_maxkey(p_actionHeap), now, sg_surf_precision))) { action = (NetworkCm02ActionPtr) xbt_heap_pop(p_actionHeap); XBT_DEBUG("Something happened to action %p", action); #ifdef HAVE_TRACING if (TRACE_is_enabled()) { int n = lmm_get_number_of_cnst_from_var(p_maxminSystem, action->getVariable()); int i; for (i = 0; i < n; i++){ lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem, action->getVariable(), i); NetworkCm02LinkPtr link = static_cast<NetworkCm02LinkPtr>(lmm_constraint_id(constraint)); TRACE_surf_link_set_utilization(link->getName(), action->getCategory(), (lmm_variable_getvalue(action->getVariable())* lmm_get_cnst_weight_from_var(p_maxminSystem, action->getVariable(), i)), action->getLastUpdate(), now - action->getLastUpdate()); } } #endif // if I am wearing a latency hat if (action->getHat() == LATENCY) { XBT_DEBUG("Latency paid for action %p. Activating", action); lmm_update_variable_weight(p_maxminSystem, action->getVariable(), action->m_weight); action->heapRemove(p_actionHeap); action->refreshLastUpdate(); // if I am wearing a max_duration or normal hat } else if (action->getHat() == MAX_DURATION || action->getHat() == NORMAL) { // no need to communicate anymore // assume that flows that reached max_duration have remaining of 0 XBT_DEBUG("Action %p finished", action); action->setRemains(0); action->finish(); action->setState(SURF_ACTION_DONE); action->heapRemove(p_actionHeap); action->gapRemove(); } } return; }
void surf_action_resume(surf_action_t action) { surf_model_t model = action->model_type; XBT_IN("(%p)", action); if (((surf_action_lmm_t) action)->suspended != 2) { lmm_update_variable_weight(model->model_private->maxmin_system, ((surf_action_lmm_t) action)->variable, action->priority); ((surf_action_lmm_t) action)->suspended = 0; if (model->model_private->update_mechanism == UM_LAZY) surf_action_lmm_heap_remove(model->model_private->action_heap,(surf_action_lmm_t)action); } XBT_OUT(); }
void NetworkCm02Model::updateActionsStateFull(double now, double delta) { NetworkCm02ActionPtr action; ActionListPtr running_actions = getRunningActionSet(); for(ActionList::iterator it(running_actions->begin()), itNext=it, itend(running_actions->end()) ; it != itend ; it=itNext) { ++itNext; action = (NetworkCm02ActionPtr) &*it; XBT_DEBUG("Something happened to action %p", action); double deltap = delta; if (action->m_latency > 0) { if (action->m_latency > deltap) { double_update(&(action->m_latency), deltap, sg_surf_precision); deltap = 0.0; } else { double_update(&(deltap), action->m_latency, sg_surf_precision); action->m_latency = 0.0; } if (action->m_latency == 0.0 && !(action->isSuspended())) lmm_update_variable_weight(p_maxminSystem, action->getVariable(), action->m_weight); } #ifdef HAVE_TRACING if (TRACE_is_enabled()) { int n = lmm_get_number_of_cnst_from_var(p_maxminSystem, action->getVariable()); int i; for (i = 0; i < n; i++){ lmm_constraint_t constraint = lmm_get_cnst_from_var(p_maxminSystem, action->getVariable(), i); NetworkCm02LinkPtr link = static_cast<NetworkCm02LinkPtr>(lmm_constraint_id(constraint)); TRACE_surf_link_set_utilization(link->getName(), action->getCategory(), (lmm_variable_getvalue(action->getVariable())* lmm_get_cnst_weight_from_var(p_maxminSystem, action->getVariable(), i)), action->getLastUpdate(), now - action->getLastUpdate()); } } #endif if (!lmm_get_number_of_cnst_from_var (p_maxminSystem, action->getVariable())) { /* There is actually no link used, hence an infinite bandwidth. * This happens often when using models like vivaldi. * In such case, just make sure that the action completes immediately. */ action->updateRemains(action->getRemains()); } action->updateRemains(lmm_variable_getvalue(action->getVariable()) * delta); if (action->getMaxDuration() != NO_MAX_DURATION) action->updateMaxDuration(delta); if ((action->getRemains() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) { action->finish(); action->setState(SURF_ACTION_DONE); action->gapRemove(); } else if (((action->getMaxDuration() != NO_MAX_DURATION) && (action->getMaxDuration() <= 0))) { action->finish(); action->setState(SURF_ACTION_DONE); action->gapRemove(); } } return; }
void generic_update_actions_state_lazy(double now, double delta, surf_model_t model) { surf_action_lmm_t action; while ((xbt_heap_size(model->model_private->action_heap) > 0) && (double_equals(xbt_heap_maxkey(model->model_private->action_heap), now))) { action = xbt_heap_pop(model->model_private->action_heap); XBT_DEBUG("Something happened to action %p", action); #ifdef HAVE_TRACING if (TRACE_is_enabled()) { if(model == surf_cpu_model){ surf_resource_t cpu = lmm_constraint_id(lmm_get_cnst_from_var (model->model_private->maxmin_system, action->variable, 0)); TRACE_surf_host_set_utilization(cpu->name, ((surf_action_t)action)->category, lmm_variable_getvalue(action->variable), action->last_update, now - action->last_update); } else{ int n = lmm_get_number_of_cnst_from_var(model->model_private->maxmin_system, action->variable); unsigned int i; for (i = 0; i < n; i++){ lmm_constraint_t constraint = lmm_get_cnst_from_var(model->model_private->maxmin_system, action->variable, i); link_CM02_t link = lmm_constraint_id(constraint); TRACE_surf_link_set_utilization(link->lmm_resource.generic_resource.name, ((surf_action_t)action)->category, (lmm_variable_getvalue(action->variable)* lmm_get_cnst_weight_from_var(model->model_private->maxmin_system, action->variable, i)), action->last_update, now - action->last_update); } } } #endif if(model == surf_cpu_model){ action->generic_action.finish = surf_get_clock(); update_resource_energy(model, action); /* set the remains to 0 due to precision problems when updating the remaining amount */ action->generic_action.remains = 0; surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE); surf_action_lmm_heap_remove(model->model_private->action_heap,action); //FIXME: strange call since action was already popped } else{ // if I am wearing a latency hat if (action->hat == LATENCY) { XBT_DEBUG("Latency paid for action %p. Activating", action); lmm_update_variable_weight(model->model_private->maxmin_system, action->variable, ((surf_action_network_CM02_t)(action))->weight); surf_action_lmm_heap_remove(model->model_private->action_heap,action); action->last_update = surf_get_clock(); // if I am wearing a max_duration or normal hat } else if (action->hat == MAX_DURATION || action->hat == NORMAL) { // no need to communicate anymore // assume that flows that reached max_duration have remaining of 0 action->generic_action.finish = surf_get_clock(); XBT_DEBUG("Action %p finished", action); action->generic_action.remains = 0; ((surf_action_t)action)->finish = surf_get_clock(); model->action_state_set((surf_action_t) action, SURF_ACTION_DONE); surf_action_lmm_heap_remove(model->model_private->action_heap,action); if (model->gap_remove && model == surf_network_model) model->gap_remove(action); } } } #ifdef HAVE_TRACING if (TRACE_is_enabled() && model == surf_cpu_model) { //defining the last timestamp that we can safely dump to trace file //without losing the event ascending order (considering all CPU's) double smaller = -1; xbt_swag_t running_actions = model->states.running_action_set; xbt_swag_foreach(action, running_actions) { if (smaller < 0) { smaller = action->last_update; continue; } if (action->last_update < smaller) { smaller = action->last_update; } } if (smaller > 0) { TRACE_last_timestamp_to_dump = smaller; } }
void WorkstationL07Model::updateActionsState(double /*now*/, double delta) { double deltap = 0.0; WorkstationL07ActionPtr action; ActionListPtr actionSet = getRunningActionSet(); for(ActionList::iterator it(actionSet->begin()), itNext = it, itend(actionSet->end()) ; it != itend ; it=itNext) { ++itNext; action = static_cast<WorkstationL07ActionPtr>(&*it); deltap = delta; if (action->m_latency > 0) { if (action->m_latency > deltap) { double_update(&(action->m_latency), deltap, sg_surf_precision); deltap = 0.0; } else { double_update(&(deltap), action->m_latency, sg_surf_precision); action->m_latency = 0.0; } if ((action->m_latency == 0.0) && (action->isSuspended() == 0)) { action->updateBound(); lmm_update_variable_weight(ptask_maxmin_system, action->getVariable(), 1.0); } } XBT_DEBUG("Action (%p) : remains (%g) updated by %g.", action, action->getRemains(), lmm_variable_getvalue(action->getVariable()) * delta); action->updateRemains(lmm_variable_getvalue(action->getVariable()) * delta); if (action->getMaxDuration() != NO_MAX_DURATION) action->updateMaxDuration(delta); XBT_DEBUG("Action (%p) : remains (%g).", action, action->getRemains()); if ((action->getRemains() <= 0) && (lmm_get_variable_weight(action->getVariable()) > 0)) { action->finish(); action->setState(SURF_ACTION_DONE); } else if ((action->getMaxDuration() != NO_MAX_DURATION) && (action->getMaxDuration() <= 0)) { action->finish(); action->setState(SURF_ACTION_DONE); } else { /* Need to check that none of the model has failed */ lmm_constraint_t cnst = NULL; int i = 0; void *constraint_id = NULL; while ((cnst = lmm_get_cnst_from_var(ptask_maxmin_system, action->getVariable(), i++))) { constraint_id = lmm_constraint_id(cnst); if (static_cast<WorkstationPtr>(constraint_id)->getState() == SURF_RESOURCE_OFF) { XBT_DEBUG("Action (%p) Failed!!", action); action->finish(); action->setState(SURF_ACTION_FAILED); break; } } } } return; }