+ void *_cpu, *_cpu_next;
+ double min_action_duration = -1;
+
+/* iterates over modified cpus to update share resources */
+ xbt_swag_foreach_safe(_cpu, _cpu_next, cpu_ti_modified_cpu) {
+ static_cast<CpuTiPtr>(_cpu)->updateActionFinishDate(now);
+ }
+/* get the min next event if heap not empty */
+ if (xbt_heap_size(cpu_ti_action_heap) > 0)
+ min_action_duration = xbt_heap_maxkey(cpu_ti_action_heap) - now;
+
+ XBT_DEBUG("Share resources, min next event date: %f", min_action_duration);
+
+ return min_action_duration;
+}
+
+void CpuTiModel::updateActionsState(double now, double /*delta*/)
+{
+ while ((xbt_heap_size(cpu_ti_action_heap) > 0)
+ && (xbt_heap_maxkey(cpu_ti_action_heap) <= now)) {
+ CpuTiActionPtr action = (CpuTiActionPtr) xbt_heap_pop(cpu_ti_action_heap);
+ XBT_DEBUG("Action %p: finish", action);
+ action->m_finish = surf_get_clock();
+ /* set the remains to 0 due to precision problems when updating the remaining amount */
+ action->m_remains = 0;
+ action->setState(SURF_ACTION_DONE);
+ /* update remaining amount of all actions */
+ action->p_cpu->updateRemainingAmount(surf_get_clock());
+ }
+}
+
+void CpuTiModel::addTraces()
+{
+ xbt_dict_cursor_t cursor = NULL;
+ char *trace_name, *elm;
+
+ static int called = 0;
+
+ if (called)
+ return;
+ called = 1;
+
+/* connect all traces relative to hosts */
+ xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
+ tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
+ CpuTiPtr cpu = static_cast<CpuTiPtr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)));
+
+ xbt_assert(cpu, "Host %s undefined", elm);
+ xbt_assert(trace, "Trace %s undefined", trace_name);
+
+ if (cpu->p_stateEvent) {
+ XBT_DEBUG("Trace already configured for this CPU(%s), ignoring it",
+ elm);
+ continue;
+ }
+ XBT_DEBUG("Add state trace: %s to CPU(%s)", trace_name, elm);
+ cpu->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(cpu));
+ }
+
+ xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
+ tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
+ CpuTiPtr cpu = dynamic_cast<CpuTiPtr>(static_cast<ResourcePtr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm))));
+
+ xbt_assert(cpu, "Host %s undefined", elm);
+ xbt_assert(trace, "Trace %s undefined", trace_name);
+
+ XBT_DEBUG("Add power trace: %s to CPU(%s)", trace_name, elm);
+ if (cpu->p_availTrace)
+ delete cpu->p_availTrace;
+
+ cpu->p_availTrace = new CpuTiTgmr(trace, cpu->m_powerScale);
+
+ /* add a fake trace event if periodicity == 0 */
+ if (trace && xbt_dynar_length(trace->s_list.event_list) > 1) {
+ s_tmgr_event_t val;
+ xbt_dynar_get_cpy(trace->s_list.event_list,
+ xbt_dynar_length(trace->s_list.event_list) - 1, &val);
+ if (val.delta == 0) {
+ tmgr_trace_t empty_trace;
+ empty_trace = tmgr_empty_trace_new();
+ cpu->p_powerEvent =
+ tmgr_history_add_trace(history, empty_trace,
+ cpu->p_availTrace->m_lastTime, 0, static_cast<ResourcePtr>(cpu));
+ }
+ }
+ }
+}