+ m_powerScale = p_availTrace->getPowerScale(surf_get_clock());
+ return Cpu::getAvailableSpeed();
+}
+
+/**
+* \brief Update the remaining amount of actions
+*
+* \param now Current time
+*/
+void CpuTi::updateRemainingAmount(double now)
+{
+ double area_total;
+ CpuTiAction *action;
+
+ /* already updated */
+ if (m_lastUpdate >= now)
+ return;
+
+/* calcule the surface */
+ area_total = p_availTrace->integrate(m_lastUpdate, now) * m_powerPeak;
+ XBT_DEBUG("Flops total: %f, Last update %f", area_total,
+ m_lastUpdate);
+
+ for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
+ ; it != itend ; ++it) {
+ action = &*it;
+ /* action not running, skip it */
+ if (action->getStateSet() !=
+ getModel()->getRunningActionSet())
+ continue;
+
+ /* bogus priority, skip it */
+ if (action->getPriority() <= 0)
+ continue;
+
+ /* action suspended, skip it */
+ if (action->m_suspended != 0)
+ continue;
+
+ /* action don't need update */
+ if (action->getStartTime() >= now)
+ continue;
+
+ /* skip action that are finishing now */
+ if (action->m_finish >= 0
+ && action->m_finish <= now)
+ continue;
+
+ /* update remaining */
+ action->updateRemains(area_total / (m_sumPriority * action->getPriority()));
+ XBT_DEBUG("Update remaining action(%p) remaining %f", action,
+ action->m_remains);
+ }
+ m_lastUpdate = now;
+}
+
+CpuAction *CpuTi::execute(double size)
+{
+ XBT_IN("(%s,%g)", getName(), size);
+ CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), size, getState() != SURF_RESOURCE_ON, this);
+
+ p_actionSet->push_back(*action);
+
+ XBT_OUT();
+ return action;
+}
+
+
+CpuAction *CpuTi::sleep(double duration)
+{
+ if (duration > 0)
+ duration = MAX(duration, sg_surf_precision);
+
+ XBT_IN("(%s,%g)", getName(), duration);
+ CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), 1.0, getState() != SURF_RESOURCE_ON, this);
+
+ action->m_maxDuration = duration;
+ action->m_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->p_stateSet = static_cast<CpuTiModel*>(getModel())->p_runningActionSetThatDoesNotNeedBeingChecked;
+ action->getStateSet()->push_back(*action);
+ }
+
+ p_actionSet->push_back(*action);
+
+ XBT_OUT();
+ return action;
+}
+
+void CpuTi::modified(bool modified){
+ CpuTiList *modifiedCpu = static_cast<CpuTiModel*>(getModel())->p_modifiedCpu;
+ if (modified) {
+ if (!cpu_ti_hook.is_linked()) {
+ modifiedCpu->push_back(*this);
+ }
+ } else {
+ if (cpu_ti_hook.is_linked()) {
+ modifiedCpu->erase(modifiedCpu->iterator_to(*this));
+ }
+ }