2 #include "trace_mgr_private.h"
5 #ifndef SURF_MODEL_CPUTI_H_
6 #define SURF_MODEL_CPUTI_H_
8 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_ti, surf_cpu,
9 "Logging specific to the SURF CPU TRACE INTEGRATION module");
11 static void cpu_ti_action_update_index_heap(void *action, int i);
17 CpuTiTrace::CpuTiTrace(tmgr_trace_t power_trace)
24 p_timePoints = (double*) xbt_malloc0(sizeof(double) *
25 (xbt_dynar_length(power_trace->s_list.event_list) + 1));
26 p_integral = (double*) xbt_malloc0(sizeof(double) *
27 (xbt_dynar_length(power_trace->s_list.event_list) + 1));
28 m_nbPoints = xbt_dynar_length(power_trace->s_list.event_list);
29 xbt_dynar_foreach(power_trace->s_list.event_list, cpt, val) {
30 p_timePoints[i] = time;
31 p_integral[i] = integral;
32 integral += val.delta * val.value;
36 p_timePoints[i] = time;
37 p_integral[i] = integral;
40 CpuTiTrace::~CpuTiTrace()
42 xbt_free(p_timePoints);
46 CpuTiTgmr::~CpuTiTgmr()
53 * \brief Integrate trace
55 * Wrapper around surf_cpu_integrate_trace_simple() to get
58 * \param trace Trace structure.
59 * \param a Begin of interval
60 * \param b End of interval
61 * \return the integrate value. -1 if an error occurs.
63 double CpuTiTgmr::integrate(double a, double b)
70 if ((a < 0.0) || (a > b)) {
72 ("Error, invalid integration interval [%.2f,%.2f]. You probably have a task executing with negative computation amount. Check your code.",
79 if (m_type == TRACE_FIXED) {
80 return ((b - a) * m_value);
83 if (ceil(a / m_lastTime) == a / m_lastTime)
84 a_index = 1 + (int) (ceil(a / m_lastTime));
86 a_index = (int) (ceil(a / m_lastTime));
88 b_index = (int) (floor(b / m_lastTime));
90 if (a_index > b_index) { /* Same chunk */
91 return p_trace->integrateSimple(a - (a_index -
98 first_chunk = p_trace->integrateSimple(a - (a_index -
102 middle_chunk = (b_index - a_index) * m_total;
103 last_chunk = p_trace->integrateSimple(0.0,
108 XBT_DEBUG("first_chunk=%.2f middle_chunk=%.2f last_chunk=%.2f\n",
109 first_chunk, middle_chunk, last_chunk);
111 return (first_chunk + middle_chunk + last_chunk);
115 * \brief Auxiliary function to calculate the integral between a and b.
116 * It simply calculates the integral at point a and b and returns the difference
118 * \param trace Trace structure
119 * \param a Initial point
120 * \param b Final point
123 double CpuTiTrace::integrateSimple(double a, double b)
125 return integrateSimplePoint(b) - integrateSimplePoint(a);
129 * \brief Auxiliary function to calculate the integral at point a.
130 * \param trace Trace structure
134 double CpuTiTrace::integrateSimplePoint(double a)
139 ind = binarySearch(p_timePoints, a, 0, m_nbPoints - 1);
140 integral += p_integral[ind];
142 ("a %f ind %d integral %f ind + 1 %f ind %f time +1 %f time %f",
143 a, ind, integral, p_integral[ind + 1], p_integral[ind],
144 p_timePoints[ind + 1], p_timePoints[ind]);
145 double_update(&a_aux, p_timePoints[ind]);
148 ((p_integral[ind + 1] -
149 p_integral[ind]) / (p_timePoints[ind + 1] -
150 p_timePoints[ind])) * (a - p_timePoints[ind]);
151 XBT_DEBUG("Integral a %f = %f", a, integral);
157 * \brief Calculate the time needed to execute "amount" on cpu.
159 * Here, amount can span multiple trace periods
161 * \param trace CPU trace structure
162 * \param a Initial time
163 * \param amount Amount to be executed
166 double CpuTiTgmr::solve(double a, double amount)
170 double reduced_amount;
174 /* Fix very small negative numbers */
175 if ((a < 0.0) && (a > -EPSILON)) {
178 if ((amount < 0.0) && (amount > -EPSILON)) {
183 if ((a < 0.0) || (amount < 0.0)) {
185 ("Error, invalid parameters [a = %.2f, amount = %.2f]. You probably have a task executing with negative computation amount. Check your code.",
190 /* At this point, a and amount are positive */
192 if (amount < EPSILON)
195 /* Is the trace fixed ? */
196 if (m_type == TRACE_FIXED) {
197 return (a + (amount / m_value));
200 XBT_DEBUG("amount %f total %f", amount, m_total);
201 /* Reduce the problem to one where amount <= trace_total */
202 quotient = (int) (floor(amount / m_total));
203 reduced_amount = (m_total) * ((amount / m_total) -
204 floor(amount / m_total));
205 reduced_a = a - (m_lastTime) * (int) (floor(a / m_lastTime));
207 XBT_DEBUG("Quotient: %d reduced_amount: %f reduced_a: %f", quotient,
208 reduced_amount, reduced_a);
210 /* Now solve for new_amount which is <= trace_total */
212 fprintf(stderr,"reduced_a = %.2f\n",reduced_a);
213 fprintf(stderr,"reduced_amount = %.2f\n",reduced_amount);
215 reduced_b = solveSomewhatSimple(reduced_a, reduced_amount);
217 /* Re-map to the original b and amount */
218 b = (m_lastTime) * (int) (floor(a / m_lastTime)) +
219 (quotient * m_lastTime) + reduced_b;
224 * \brief Auxiliary function to solve integral
226 * Here, amount is <= trace->total
227 * and a <=trace->last_time
230 double CpuTiTgmr::solveSomewhatSimple(double a, double amount)
232 double amount_till_end;
235 XBT_DEBUG("Solve integral: [%.2f, amount=%.2f]", a, amount);
236 amount_till_end = integrate(a, m_lastTime);
238 fprintf(stderr,"amount_till_end=%.2f\n",amount_till_end);
241 if (amount_till_end > amount) {
242 b = p_trace->solveSimple(a, amount);
244 b = m_lastTime + p_trace->solveSimple(0.0, amount - amount_till_end);
250 * \brief Auxiliary function to solve integral.
251 * It returns the date when the requested amount of flops is available
252 * \param trace Trace structure
253 * \param a Initial point
254 * \param amount Amount of flops
255 * \return The date when amount is available.
257 double CpuTiTrace::solveSimple(double a, double amount)
262 integral_a = integrateSimplePoint(a);
263 ind = binarySearch(p_integral, integral_a + amount, 0, m_nbPoints - 1);
264 time = p_timePoints[ind];
266 (integral_a + amount -
267 p_integral[ind]) / ((p_integral[ind + 1] -
269 (p_timePoints[ind + 1] -
276 * \brief Auxiliary function to update the CPU power scale.
278 * This function uses the trace structure to return the power scale at the determined time a.
279 * \param trace Trace structure to search the updated power scale
281 * \return CPU power scale
283 double CpuTiTgmr::getPowerScale(double a)
289 reduced_a = a - floor(a / m_lastTime) * m_lastTime;
290 point = p_trace->binarySearch(p_trace->p_timePoints, reduced_a, 0,
291 p_trace->m_nbPoints - 1);
292 xbt_dynar_get_cpy(p_powerTrace->s_list.event_list, point, &val);
297 * \brief Creates a new integration trace from a tmgr_trace_t
299 * \param power_trace CPU availability trace
300 * \param value Percentage of CPU power available (useful to fixed tracing)
301 * \param spacing Initial spacing
302 * \return Integration trace structure
304 CpuTiTgmr::CpuTiTgmr(tmgr_trace_t power_trace, double value)
306 double total_time = 0.0;
311 /* no availability file, fixed trace */
313 m_type = TRACE_FIXED;
315 XBT_DEBUG("No availability trace. Constant value = %lf", value);
319 /* only one point available, fixed trace */
320 if (xbt_dynar_length(power_trace->s_list.event_list) == 1) {
321 xbt_dynar_get_cpy(power_trace->s_list.event_list, 0, &val);
322 m_type = TRACE_FIXED;
327 m_type = TRACE_DYNAMIC;
328 p_powerTrace = power_trace;
330 /* count the total time of trace file */
331 xbt_dynar_foreach(power_trace->s_list.event_list, cpt, val) {
332 total_time += val.delta;
334 p_trace = new CpuTiTrace(power_trace);
335 m_lastTime = total_time;
336 m_total = p_trace->integrateSimple(0, total_time);
338 XBT_DEBUG("Total integral %lf, last_time %lf ",
339 m_total, m_lastTime);
343 * \brief Binary search in array.
344 * It returns the first point of the interval in which "a" is.
346 * \param a Value to search
347 * \param low Low bound to search in array
348 * \param high Upper bound to search in array
349 * \return Index of point
351 int CpuTiTrace::binarySearch(double *array, double a, int low, int high)
353 xbt_assert(low < high, "Wrong parameters: low (%d) should be smaller than"
354 " high (%d)", low, high);
358 mid = low + (high - low) / 2;
359 XBT_DEBUG("a %f low %d high %d mid %d value %f", a, low, high, mid,
367 while (low < high - 1);
376 static void parse_cpu_ti_init(sg_platf_host_cbarg_t host){
377 ((CpuTiModelPtr)surf_cpu_model_pm)->parseInit(host);
380 static void add_traces_cpu_ti(){
381 surf_cpu_model_pm->addTraces();
384 static void cpu_ti_define_callbacks()
386 sg_platf_host_add_cb(parse_cpu_ti_init);
387 sg_platf_postparse_add_cb(add_traces_cpu_ti);
394 void surf_cpu_model_init_ti()
396 xbt_assert(!surf_cpu_model_pm,"CPU model already initialized. This should not happen.");
397 xbt_assert(!surf_cpu_model_vm,"CPU model already initialized. This should not happen.");
399 surf_cpu_model_pm = new CpuTiModel();
400 surf_cpu_model_vm = new CpuTiModel();
402 cpu_ti_define_callbacks();
403 ModelPtr model_pm = static_cast<ModelPtr>(surf_cpu_model_pm);
404 ModelPtr model_vm = static_cast<ModelPtr>(surf_cpu_model_vm);
405 xbt_dynar_push(model_list, &model_pm);
406 xbt_dynar_push(model_list, &model_vm);
409 CpuTiModel::CpuTiModel() : CpuModel("cpu_ti")
413 p_runningActionSetThatDoesNotNeedBeingChecked = new ActionList();
416 xbt_swag_new(xbt_swag_offset(*cpu, p_modifiedCpuHookup));
418 p_tiActionHeap = xbt_heap_new(8, NULL);
419 xbt_heap_set_update_callback(p_tiActionHeap,
420 cpu_ti_action_update_index_heap);
423 CpuTiModel::~CpuTiModel()
425 surf_cpu_model_pm = NULL;
427 delete p_runningActionSetThatDoesNotNeedBeingChecked;
428 xbt_swag_free(p_modifiedCpu);
429 xbt_heap_free(p_tiActionHeap);
432 void CpuTiModel::parseInit(sg_platf_host_cbarg_t host)
434 createResource(host->id,
445 CpuTiPtr CpuTiModel::createResource(const char *name,
446 xbt_dynar_t powerPeak,
449 tmgr_trace_t powerTrace,
451 e_surf_resource_state_t stateInitial,
452 tmgr_trace_t stateTrace,
453 xbt_dict_t cpuProperties)
455 xbt_assert(core==1,"Multi-core not handled with this model yet");
456 xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)),
457 "Host '%s' declared several times in the platform file",
459 CpuTiPtr cpu = new CpuTi(this, name, powerPeak, pstate, powerScale, powerTrace,
460 core, stateInitial, stateTrace, cpuProperties);
461 xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, static_cast<ResourcePtr>(cpu));
465 CpuTiActionPtr CpuTiModel::createAction(double /*cost*/, bool /*failed*/)
467 return NULL;//new CpuTiAction(this, cost, failed);
470 double CpuTiModel::shareResources(double now)
472 void *_cpu, *_cpu_next;
473 double min_action_duration = -1;
475 /* iterates over modified cpus to update share resources */
476 xbt_swag_foreach_safe(_cpu, _cpu_next, p_modifiedCpu) {
477 static_cast<CpuTiPtr>(_cpu)->updateActionsFinishTime(now);
479 /* get the min next event if heap not empty */
480 if (xbt_heap_size(p_tiActionHeap) > 0)
481 min_action_duration = xbt_heap_maxkey(p_tiActionHeap) - now;
483 XBT_DEBUG("Share resources, min next event date: %f", min_action_duration);
485 return min_action_duration;
488 void CpuTiModel::updateActionsState(double now, double /*delta*/)
490 while ((xbt_heap_size(p_tiActionHeap) > 0)
491 && (xbt_heap_maxkey(p_tiActionHeap) <= now)) {
492 CpuTiActionPtr action = (CpuTiActionPtr) xbt_heap_pop(p_tiActionHeap);
493 XBT_DEBUG("Action %p: finish", action);
495 /* set the remains to 0 due to precision problems when updating the remaining amount */
496 action->setRemains(0);
497 action->setState(SURF_ACTION_DONE);
498 /* update remaining amount of all actions */
499 action->p_cpu->updateRemainingAmount(surf_get_clock());
503 void CpuTiModel::addTraces()
505 xbt_dict_cursor_t cursor = NULL;
506 char *trace_name, *elm;
508 static int called = 0;
514 /* connect all traces relative to hosts */
515 xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
516 tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
517 CpuTiPtr cpu = static_cast<CpuTiPtr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)));
519 xbt_assert(cpu, "Host %s undefined", elm);
520 xbt_assert(trace, "Trace %s undefined", trace_name);
522 if (cpu->p_stateEvent) {
523 XBT_DEBUG("Trace already configured for this CPU(%s), ignoring it",
527 XBT_DEBUG("Add state trace: %s to CPU(%s)", trace_name, elm);
528 cpu->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(cpu));
531 xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
532 tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
533 CpuTiPtr cpu = static_cast<CpuTiPtr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)));
535 xbt_assert(cpu, "Host %s undefined", elm);
536 xbt_assert(trace, "Trace %s undefined", trace_name);
538 XBT_DEBUG("Add power trace: %s to CPU(%s)", trace_name, elm);
539 if (cpu->p_availTrace)
540 delete cpu->p_availTrace;
542 cpu->p_availTrace = new CpuTiTgmr(trace, cpu->m_powerScale);
544 /* add a fake trace event if periodicity == 0 */
545 if (trace && xbt_dynar_length(trace->s_list.event_list) > 1) {
547 xbt_dynar_get_cpy(trace->s_list.event_list,
548 xbt_dynar_length(trace->s_list.event_list) - 1, &val);
549 if (val.delta == 0) {
550 tmgr_trace_t empty_trace;
551 empty_trace = tmgr_empty_trace_new();
553 tmgr_history_add_trace(history, empty_trace,
554 cpu->p_availTrace->m_lastTime, 0, static_cast<ResourcePtr>(cpu));
563 CpuTi::CpuTi(CpuTiModelPtr model, const char *name, xbt_dynar_t powerPeak,
564 int pstate, double powerScale, tmgr_trace_t powerTrace, int core,
565 e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
566 xbt_dict_t properties)
567 : Cpu(model, name, properties, core, 0, powerScale)
570 setState(stateInitial);
571 m_powerScale = powerScale;
573 tmgr_trace_t empty_trace;
575 xbt_assert(core==1,"Multi-core not handled with this model yet");
576 XBT_DEBUG("power scale %lf", powerScale);
577 p_availTrace = new CpuTiTgmr(powerTrace, powerScale);
579 CpuTiActionPtr action = NULL;
580 p_actionSet = xbt_swag_new(xbt_swag_offset(*action, p_cpuListHookup));
584 xbt_dynar_get_cpy(powerPeak, 0, &m_powerPeak);
585 xbt_dynar_free(&powerPeak); /* kill memory leak */
587 XBT_DEBUG("CPU create: peak=%f, pstate=%d", m_powerPeak, m_pstate);
589 p_modifiedCpuHookup.prev = 0;
590 p_modifiedCpuHookup.next = 0;
593 p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, static_cast<ResourcePtr>(this));
594 if (powerTrace && xbt_dynar_length(powerTrace->s_list.event_list) > 1) {
595 // add a fake trace event if periodicity == 0
596 xbt_dynar_get_cpy(powerTrace->s_list.event_list,
597 xbt_dynar_length(powerTrace->s_list.event_list) - 1, &val);
598 if (val.delta == 0) {
599 empty_trace = tmgr_empty_trace_new();
601 tmgr_history_add_trace(history, empty_trace,
602 p_availTrace->m_lastTime, 0, static_cast<ResourcePtr>(this));
609 xbt_swag_free(p_actionSet);
612 void CpuTi::updateState(tmgr_trace_event_t event_type,
613 double value, double date)
616 CpuTiActionPtr action;
618 if (event_type == p_powerEvent) {
619 tmgr_trace_t power_trace;
623 XBT_DEBUG("Finish trace date: %f value %lf date %f", surf_get_clock(),
625 /* update remaining of actions and put in modified cpu swag */
626 updateRemainingAmount(date);
627 xbt_swag_insert(this, reinterpret_cast<CpuTiModelPtr>(getModel())->p_modifiedCpu);
629 power_trace = p_availTrace->p_powerTrace;
630 xbt_dynar_get_cpy(power_trace->s_list.event_list,
631 xbt_dynar_length(power_trace->s_list.event_list) - 1, &val);
634 m_powerScale = val.value;
636 trace = new CpuTiTgmr(TRACE_FIXED, val.value);
637 XBT_DEBUG("value %f", val.value);
639 p_availTrace = trace;
641 if (tmgr_trace_event_free(event_type))
644 } else if (event_type == p_stateEvent) {
646 if(getState() == SURF_RESOURCE_OFF)
647 xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
648 setState(SURF_RESOURCE_ON);
650 setState(SURF_RESOURCE_OFF);
652 /* put all action running on cpu to failed */
653 xbt_swag_foreach(_action, p_actionSet) {
654 action = static_cast<CpuTiActionPtr>(_action);
655 if (action->getState() == SURF_ACTION_RUNNING
656 || action->getState() == SURF_ACTION_READY
657 || action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) {
658 action->setFinishTime(date);
659 action->setState(SURF_ACTION_FAILED);
660 if (action->m_indexHeap >= 0) {
661 CpuTiActionPtr heap_act = (CpuTiActionPtr)
662 xbt_heap_remove(reinterpret_cast<CpuTiModelPtr>(getModel())->p_tiActionHeap, action->m_indexHeap);
663 if (heap_act != action)
669 if (tmgr_trace_event_free(event_type))
672 XBT_CRITICAL("Unknown event ! \n");
679 void CpuTi::updateActionsFinishTime(double now)
682 CpuTiActionPtr action;
683 double sum_priority = 0.0, total_area, min_finish = -1;
685 /* update remaning amount of actions */
686 updateRemainingAmount(now);
688 xbt_swag_foreach(_action, p_actionSet) {
689 action = static_cast<CpuTiActionPtr>(_action);
690 /* action not running, skip it */
691 if (action->getStateSet() !=
692 surf_cpu_model_pm->getRunningActionSet())
695 /* bogus priority, skip it */
696 if (action->getPriority() <= 0)
699 /* action suspended, skip it */
700 if (action->m_suspended != 0)
703 sum_priority += 1.0 / action->getPriority();
705 m_sumPriority = sum_priority;
707 xbt_swag_foreach(_action, p_actionSet) {
708 action = static_cast<CpuTiActionPtr>(_action);
710 /* action not running, skip it */
711 if (action->getStateSet() !=
712 surf_cpu_model_pm->getRunningActionSet())
715 /* verify if the action is really running on cpu */
716 if (action->m_suspended == 0 && action->getPriority() > 0) {
717 /* total area needed to finish the action. Used in trace integration */
719 (action->getRemains()) * sum_priority *
720 action->getPriority();
722 total_area /= m_powerPeak;
724 action->setFinishTime(p_availTrace->solve(now, total_area));
725 /* verify which event will happen before (max_duration or finish time) */
726 if (action->getMaxDuration() != NO_MAX_DURATION &&
727 action->getStartTime() + action->getMaxDuration() < action->m_finish)
728 min_finish = action->getStartTime() + action->getMaxDuration();
730 min_finish = action->m_finish;
732 /* put the max duration time on heap */
733 if (action->getMaxDuration() != NO_MAX_DURATION)
734 min_finish = action->getStartTime() + action->getMaxDuration();
736 /* add in action heap */
737 XBT_DEBUG("action(%p) index %d", action, action->m_indexHeap);
738 if (action->m_indexHeap >= 0) {
739 CpuTiActionPtr heap_act = (CpuTiActionPtr)
740 xbt_heap_remove(reinterpret_cast<CpuTiModelPtr>(getModel())->p_tiActionHeap, action->m_indexHeap);
741 if (heap_act != action)
744 if (min_finish != NO_MAX_DURATION)
745 xbt_heap_push(reinterpret_cast<CpuTiModelPtr>(getModel())->p_tiActionHeap, action, min_finish);
748 ("Update finish time: Cpu(%s) Action: %p, Start Time: %f Finish Time: %f Max duration %f",
749 getName(), action, action->getStartTime(),
751 action->getMaxDuration());
753 /* remove from modified cpu */
754 xbt_swag_remove(this, reinterpret_cast<CpuTiModelPtr>(getModel())->p_modifiedCpu);
759 return xbt_swag_size(p_actionSet);
764 double CpuTi::getAvailableSpeed()
766 m_powerScale = p_availTrace->getPowerScale(surf_get_clock());
767 return Cpu::getAvailableSpeed();
771 * \brief Update the remaining amount of actions
773 * \param now Current time
775 void CpuTi::updateRemainingAmount(double now)
779 CpuTiActionPtr action;
781 /* already updated */
782 if (m_lastUpdate >= now)
785 /* calcule the surface */
786 area_total = p_availTrace->integrate(m_lastUpdate, now) * m_powerPeak;
787 XBT_DEBUG("Flops total: %f, Last update %f", area_total,
790 xbt_swag_foreach(_action, p_actionSet) {
791 action = static_cast<CpuTiActionPtr>(_action);
792 /* action not running, skip it */
793 if (action->getStateSet() !=
794 getModel()->getRunningActionSet())
797 /* bogus priority, skip it */
798 if (action->getPriority() <= 0)
801 /* action suspended, skip it */
802 if (action->m_suspended != 0)
805 /* action don't need update */
806 if (action->getStartTime() >= now)
809 /* skip action that are finishing now */
810 if (action->m_finish >= 0
811 && action->m_finish <= now)
814 /* update remaining */
815 action->updateRemains(area_total / (m_sumPriority * action->getPriority()));
816 XBT_DEBUG("Update remaining action(%p) remaining %f", action,
822 CpuActionPtr CpuTi::execute(double size)
824 XBT_IN("(%s,%g)", getName(), size);
825 CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(getModel()), size, getState() != SURF_RESOURCE_ON, this);
827 xbt_swag_insert(action, p_actionSet);
834 CpuActionPtr CpuTi::sleep(double duration)
837 duration = MAX(duration, MAXMIN_PRECISION);
839 XBT_IN("(%s,%g)", getName(), duration);
840 CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(getModel()), 1.0, getState() != SURF_RESOURCE_ON, this);
842 action->m_maxDuration = duration;
843 action->m_suspended = 2;
844 if (duration == NO_MAX_DURATION) {
845 /* Move to the *end* of the corresponding action set. This convention
846 is used to speed up update_resource_state */
847 action->getStateSet()->erase(action->getStateSet()->iterator_to(*action));
848 action->p_stateSet = reinterpret_cast<CpuTiModelPtr>(getModel())->p_runningActionSetThatDoesNotNeedBeingChecked;
849 action->getStateSet()->push_back(*static_cast<ActionPtr>(action));
852 xbt_swag_insert(action, p_actionSet);
862 static void cpu_ti_action_update_index_heap(void *action, int i)
864 ((CpuTiActionPtr)action)->updateIndexHeap(i);
867 CpuTiAction::CpuTiAction(CpuTiModelPtr model_, double cost, bool failed,
869 : CpuAction(model_, cost, failed)
871 p_cpuListHookup.next = 0;
872 p_cpuListHookup.prev = 0;
874 m_suspended = 0; /* Should be useless because of the
875 calloc but it seems to help valgrind... */
878 xbt_swag_insert(cpu, reinterpret_cast<CpuTiModelPtr>(getModel())->p_modifiedCpu);
881 void CpuTiAction::updateIndexHeap(int i)
886 void CpuTiAction::setState(e_surf_action_state_t state)
888 Action::setState(state);
889 xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(getModel())->p_modifiedCpu);
892 int CpuTiAction::unref()
896 if (actionHook::is_linked())
897 getStateSet()->erase(getStateSet()->iterator_to(*this));
898 /* remove from action_set */
899 xbt_swag_remove(this, p_cpu->p_actionSet);
900 /* remove from heap */
901 xbt_heap_remove(reinterpret_cast<CpuTiModelPtr>(getModel())->p_tiActionHeap, this->m_indexHeap);
902 xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(getModel())->p_modifiedCpu);
909 void CpuTiAction::cancel()
911 this->setState(SURF_ACTION_FAILED);
912 xbt_heap_remove(getModel()->getActionHeap(), this->m_indexHeap);
913 xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(getModel())->p_modifiedCpu);
917 void CpuTiAction::recycle()
922 void CpuTiAction::suspend()
924 XBT_IN("(%p)", this);
925 if (m_suspended != 2) {
927 xbt_heap_remove(getModel()->getActionHeap(), m_indexHeap);
928 xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(getModel())->p_modifiedCpu);
933 void CpuTiAction::resume()
935 XBT_IN("(%p)", this);
936 if (m_suspended != 2) {
938 xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(getModel())->p_modifiedCpu);
943 bool CpuTiAction::isSuspended()
945 return m_suspended == 1;
948 void CpuTiAction::setMaxDuration(double duration)
952 XBT_IN("(%p,%g)", this, duration);
954 m_maxDuration = duration;
957 min_finish = (getStartTime() + getMaxDuration()) < getFinishTime() ?
958 (getStartTime() + getMaxDuration()) : getFinishTime();
960 min_finish = getFinishTime();
962 /* add in action heap */
963 if (m_indexHeap >= 0) {
964 CpuTiActionPtr heap_act = (CpuTiActionPtr)
965 xbt_heap_remove(getModel()->getActionHeap(), m_indexHeap);
966 if (heap_act != this)
969 xbt_heap_push(getModel()->getActionHeap(), this, min_finish);
974 void CpuTiAction::setPriority(double priority)
976 XBT_IN("(%p,%g)", this, priority);
977 m_priority = priority;
978 xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(getModel())->p_modifiedCpu);
982 double CpuTiAction::getRemains()
984 XBT_IN("(%p)", this);
985 p_cpu->updateRemainingAmount(surf_get_clock());
990 #endif /* SURF_MODEL_CPUTI_H_ */