+ if (event == p_speed.event) {
+ tmgr_trace_t speedTrace;
+ CpuTiTgmr *trace;
+ s_tmgr_event_t val;
+
+ XBT_DEBUG("Finish trace date: value %f", value);
+ /* update remaining of actions and put in modified cpu swag */
+ updateRemainingAmount(surf_get_clock());
+
+ modified(true);
+
+ speedTrace = availTrace_->speedTrace_;
+ xbt_dynar_get_cpy(speedTrace->event_list, xbt_dynar_length(speedTrace->event_list) - 1, &val);
+ delete availTrace_;
+ p_speed.scale = val.value;
+
+ trace = new CpuTiTgmr(TRACE_FIXED, val.value);
+ XBT_DEBUG("value %f", val.value);
+
+ availTrace_ = trace;
+
+ tmgr_trace_event_unref(&p_speed.event);
+
+ } else if (event == p_stateEvent) {
+ if (value > 0) {
+ if(isOff())
+ xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
+ turnOn();
+ } else {
+ turnOff();
+ double date = surf_get_clock();
+
+ /* put all action running on cpu to failed */
+ for(ActionTiList::iterator it(actionSet_->begin()), itend(actionSet_->end())
+ ; it != itend ; ++it) {
+
+ CpuTiAction *action = &*it;
+ if (action->getState() == SURF_ACTION_RUNNING
+ || action->getState() == SURF_ACTION_READY
+ || action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) {
+ action->setFinishTime(date);
+ action->setState(SURF_ACTION_FAILED);
+ if (action->indexHeap_ >= 0) {
+ CpuTiAction *heap_act = (CpuTiAction*)
+ xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->tiActionHeap_, action->indexHeap_);
+ if (heap_act != action)
+ DIE_IMPOSSIBLE;
+ }
+ }
+ }
+ }
+ tmgr_trace_event_unref(&p_stateEvent);
+
+ } else {
+ xbt_die("Unknown event!\n");
+ }
+}
+
+void CpuTi::updateActionsFinishTime(double now)
+{
+ CpuTiAction *action;
+ double sum_priority = 0.0, total_area, min_finish = -1;
+
+ /* update remaining amount of actions */
+ updateRemainingAmount(now);
+
+ for(ActionTiList::iterator it(actionSet_->begin()), itend(actionSet_->end()) ; it != itend ; ++it) {
+ action = &*it;
+ /* action not running, skip it */
+ if (action->getStateSet() != surf_cpu_model_pm->getRunningActionSet())
+ continue;
+
+ /* bogus priority, skip it */
+ if (action->getPriority() <= 0)
+ continue;
+
+ /* action suspended, skip it */
+ if (action->suspended_ != 0)
+ continue;
+
+ sum_priority += 1.0 / action->getPriority();
+ }
+ sumPriority_ = sum_priority;
+
+ for(ActionTiList::iterator it(actionSet_->begin()), itend(actionSet_->end()) ; it != itend ; ++it) {
+ action = &*it;
+ min_finish = -1;
+ /* action not running, skip it */
+ if (action->getStateSet() !=
+ surf_cpu_model_pm->getRunningActionSet())
+ continue;
+
+ /* verify if the action is really running on cpu */
+ if (action->suspended_ == 0 && action->getPriority() > 0) {
+ /* total area needed to finish the action. Used in trace integration */
+ total_area =
+ (action->getRemains()) * sum_priority *
+ action->getPriority();
+
+ total_area /= p_speed.peak;
+
+ action->setFinishTime(availTrace_->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->m_finish)
+ min_finish = action->getStartTime() + action->getMaxDuration();
+ else
+ min_finish = action->m_finish;
+ } else {
+ /* put the max duration time on heap */
+ if (action->getMaxDuration() != NO_MAX_DURATION)
+ min_finish = action->getStartTime() + action->getMaxDuration();
+ }
+ /* add in action heap */
+ XBT_DEBUG("action(%p) index %d", action, action->indexHeap_);
+ if (action->indexHeap_ >= 0) {
+ CpuTiAction *heap_act = (CpuTiAction*)
+ xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->tiActionHeap_, action->indexHeap_);
+ if (heap_act != action)
+ DIE_IMPOSSIBLE;
+ }
+ if (min_finish != NO_MAX_DURATION)
+ xbt_heap_push(static_cast<CpuTiModel*>(getModel())->tiActionHeap_, action, min_finish);
+
+ XBT_DEBUG
+ ("Update finish time: Cpu(%s) Action: %p, Start Time: %f Finish Time: %f Max duration %f",
+ getName(), action, action->getStartTime(),
+ action->m_finish,
+ action->getMaxDuration());
+ }
+ /* remove from modified cpu */
+ modified(false);
+}
+
+bool CpuTi::isUsed()
+{
+ return !actionSet_->empty();