1 /* Copyright (c) 2013-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "trace_mgr_private.h"
11 #ifndef SURF_MODEL_CPUTI_H_
12 #define SURF_MODEL_CPUTI_H_
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_ti, surf_cpu,
15 "Logging specific to the SURF CPU TRACE INTEGRATION module");
21 void cpu_ti_action_update_index_heap(void *action, int i)
23 ((simgrid::surf::CpuTiAction*)action)->updateIndexHeap(i);
30 CpuTiTrace::CpuTiTrace(tmgr_trace_t speedTrace)
37 p_timePoints = (double*) xbt_malloc0(sizeof(double) *
38 (xbt_dynar_length(speedTrace->s_list.event_list) + 1));
39 p_integral = (double*) xbt_malloc0(sizeof(double) *
40 (xbt_dynar_length(speedTrace->s_list.event_list) + 1));
41 m_nbPoints = xbt_dynar_length(speedTrace->s_list.event_list) + 1;
42 xbt_dynar_foreach(speedTrace->s_list.event_list, cpt, val) {
43 p_timePoints[i] = time;
44 p_integral[i] = integral;
45 integral += val.delta * val.value;
49 p_timePoints[i] = time;
50 p_integral[i] = integral;
53 CpuTiTrace::~CpuTiTrace()
55 xbt_free(p_timePoints);
59 CpuTiTgmr::~CpuTiTgmr()
66 * \brief Integrate trace
68 * Wrapper around surf_cpu_integrate_trace_simple() to get
71 * \param trace Trace structure.
72 * \param a Begin of interval
73 * \param b End of interval
74 * \return the integrate value. -1 if an error occurs.
76 double CpuTiTgmr::integrate(double a, double b)
83 if ((a < 0.0) || (a > b)) {
85 ("Error, invalid integration interval [%.2f,%.2f]. You probably have a task executing with negative computation amount. Check your code.",
92 if (m_type == TRACE_FIXED) {
93 return ((b - a) * m_value);
96 if (ceil(a / m_lastTime) == a / m_lastTime)
97 a_index = 1 + (int) (ceil(a / m_lastTime));
99 a_index = (int) (ceil(a / m_lastTime));
101 b_index = (int) (floor(b / m_lastTime));
103 if (a_index > b_index) { /* Same chunk */
104 return p_trace->integrateSimple(a - (a_index -
111 first_chunk = p_trace->integrateSimple(a - (a_index -
115 middle_chunk = (b_index - a_index) * m_total;
116 last_chunk = p_trace->integrateSimple(0.0,
121 XBT_DEBUG("first_chunk=%.2f middle_chunk=%.2f last_chunk=%.2f\n",
122 first_chunk, middle_chunk, last_chunk);
124 return (first_chunk + middle_chunk + last_chunk);
128 * \brief Auxiliary function to calculate the integral between a and b.
129 * It simply calculates the integral at point a and b and returns the difference
131 * \param trace Trace structure
132 * \param a Initial point
133 * \param b Final point
136 double CpuTiTrace::integrateSimple(double a, double b)
138 return integrateSimplePoint(b) - integrateSimplePoint(a);
142 * \brief Auxiliary function to calculate the integral at point a.
143 * \param trace Trace structure
147 double CpuTiTrace::integrateSimplePoint(double a)
152 ind = binarySearch(p_timePoints, a, 0, m_nbPoints - 1);
153 integral += p_integral[ind];
155 ("a %f ind %d integral %f ind + 1 %f ind %f time +1 %f time %f",
156 a, ind, integral, p_integral[ind + 1], p_integral[ind],
157 p_timePoints[ind + 1], p_timePoints[ind]);
158 double_update(&a_aux, p_timePoints[ind], sg_maxmin_precision*sg_surf_precision);
161 ((p_integral[ind + 1] -
162 p_integral[ind]) / (p_timePoints[ind + 1] -
163 p_timePoints[ind])) * (a - p_timePoints[ind]);
164 XBT_DEBUG("Integral a %f = %f", a, integral);
170 * \brief Calculate the time needed to execute "amount" on cpu.
172 * Here, amount can span multiple trace periods
174 * \param trace CPU trace structure
175 * \param a Initial time
176 * \param amount Amount to be executed
179 double CpuTiTgmr::solve(double a, double amount)
183 double reduced_amount;
187 /* Fix very small negative numbers */
188 if ((a < 0.0) && (a > -EPSILON)) {
191 if ((amount < 0.0) && (amount > -EPSILON)) {
196 if ((a < 0.0) || (amount < 0.0)) {
198 ("Error, invalid parameters [a = %.2f, amount = %.2f]. You probably have a task executing with negative computation amount. Check your code.",
203 /* At this point, a and amount are positive */
205 if (amount < EPSILON)
208 /* Is the trace fixed ? */
209 if (m_type == TRACE_FIXED) {
210 return (a + (amount / m_value));
213 XBT_DEBUG("amount %f total %f", amount, m_total);
214 /* Reduce the problem to one where amount <= trace_total */
215 quotient = (int) (floor(amount / m_total));
216 reduced_amount = (m_total) * ((amount / m_total) -
217 floor(amount / m_total));
218 reduced_a = a - (m_lastTime) * (int) (floor(a / m_lastTime));
220 XBT_DEBUG("Quotient: %d reduced_amount: %f reduced_a: %f", quotient,
221 reduced_amount, reduced_a);
223 /* Now solve for new_amount which is <= trace_total */
225 fprintf(stderr,"reduced_a = %.2f\n",reduced_a);
226 fprintf(stderr,"reduced_amount = %.2f\n",reduced_amount);
228 reduced_b = solveSomewhatSimple(reduced_a, reduced_amount);
230 /* Re-map to the original b and amount */
231 b = (m_lastTime) * (int) (floor(a / m_lastTime)) +
232 (quotient * m_lastTime) + reduced_b;
237 * \brief Auxiliary function to solve integral
239 * Here, amount is <= trace->total
240 * and a <=trace->last_time
243 double CpuTiTgmr::solveSomewhatSimple(double a, double amount)
245 double amount_till_end;
248 XBT_DEBUG("Solve integral: [%.2f, amount=%.2f]", a, amount);
249 amount_till_end = integrate(a, m_lastTime);
251 fprintf(stderr,"amount_till_end=%.2f\n",amount_till_end);
254 if (amount_till_end > amount) {
255 b = p_trace->solveSimple(a, amount);
257 b = m_lastTime + p_trace->solveSimple(0.0, amount - amount_till_end);
263 * \brief Auxiliary function to solve integral.
264 * It returns the date when the requested amount of flops is available
265 * \param trace Trace structure
266 * \param a Initial point
267 * \param amount Amount of flops
268 * \return The date when amount is available.
270 double CpuTiTrace::solveSimple(double a, double amount)
275 integral_a = integrateSimplePoint(a);
276 ind = binarySearch(p_integral, integral_a + amount, 0, m_nbPoints - 1);
277 time = p_timePoints[ind];
279 (integral_a + amount -
280 p_integral[ind]) / ((p_integral[ind + 1] -
282 (p_timePoints[ind + 1] -
289 * \brief Auxiliary function to update the CPU speed scale.
291 * This function uses the trace structure to return the speed scale at the determined time a.
292 * \param trace Trace structure to search the updated speed scale
294 * \return CPU speed scale
296 double CpuTiTgmr::getPowerScale(double a)
302 reduced_a = a - floor(a / m_lastTime) * m_lastTime;
303 point = p_trace->binarySearch(p_trace->p_timePoints, reduced_a, 0,
304 p_trace->m_nbPoints - 1);
305 xbt_dynar_get_cpy(p_speedTrace->s_list.event_list, point, &val);
310 * \brief Creates a new integration trace from a tmgr_trace_t
312 * \param speedTrace CPU availability trace
313 * \param value Percentage of CPU speed available (useful to fixed tracing)
314 * \param spacing Initial spacing
315 * \return Integration trace structure
317 CpuTiTgmr::CpuTiTgmr(tmgr_trace_t speedTrace, double value)
319 double total_time = 0.0;
324 /* no availability file, fixed trace */
326 m_type = TRACE_FIXED;
328 XBT_DEBUG("No availability trace. Constant value = %f", value);
332 /* only one point available, fixed trace */
333 if (xbt_dynar_length(speedTrace->s_list.event_list) == 1) {
334 xbt_dynar_get_cpy(speedTrace->s_list.event_list, 0, &val);
335 m_type = TRACE_FIXED;
340 m_type = TRACE_DYNAMIC;
341 p_speedTrace = speedTrace;
343 /* count the total time of trace file */
344 xbt_dynar_foreach(speedTrace->s_list.event_list, cpt, val) {
345 total_time += val.delta;
347 p_trace = new CpuTiTrace(speedTrace);
348 m_lastTime = total_time;
349 m_total = p_trace->integrateSimple(0, total_time);
351 XBT_DEBUG("Total integral %f, last_time %f ",
352 m_total, m_lastTime);
356 * \brief Binary search in array.
357 * It returns the first point of the interval in which "a" is.
359 * \param a Value to search
360 * \param low Low bound to search in array
361 * \param high Upper bound to search in array
362 * \return Index of point
364 int CpuTiTrace::binarySearch(double *array, double a, int low, int high)
366 xbt_assert(low < high, "Wrong parameters: low (%d) should be smaller than"
367 " high (%d)", low, high);
371 mid = low + (high - low) / 2;
372 XBT_DEBUG("a %f low %d high %d mid %d value %f", a, low, high, mid,
380 while (low < high - 1);
392 static void cpu_ti_define_callbacks()
394 sg_platf_postparse_add_cb(simgrid::surf::cpu_add_traces);
401 void surf_cpu_model_init_ti()
403 xbt_assert(!surf_cpu_model_pm,"CPU model already initialized. This should not happen.");
404 xbt_assert(!surf_cpu_model_vm,"CPU model already initialized. This should not happen.");
406 surf_cpu_model_pm = new simgrid::surf::CpuTiModel();
407 surf_cpu_model_vm = new simgrid::surf::CpuTiModel();
409 cpu_ti_define_callbacks();
410 simgrid::surf::Model *model_pm = static_cast<simgrid::surf::Model*>(surf_cpu_model_pm);
411 simgrid::surf::Model *model_vm = static_cast<simgrid::surf::Model*>(surf_cpu_model_vm);
412 xbt_dynar_push(all_existing_models, &model_pm);
413 xbt_dynar_push(all_existing_models, &model_vm);
419 CpuTiModel::CpuTiModel() : CpuModel()
421 p_runningActionSetThatDoesNotNeedBeingChecked = new ActionList();
423 p_modifiedCpu = new CpuTiList();
425 p_tiActionHeap = xbt_heap_new(8, NULL);
426 xbt_heap_set_update_callback(p_tiActionHeap,
427 cpu_ti_action_update_index_heap);
430 CpuTiModel::~CpuTiModel()
432 surf_cpu_model_pm = NULL;
433 delete p_runningActionSetThatDoesNotNeedBeingChecked;
434 delete p_modifiedCpu;
435 xbt_heap_free(p_tiActionHeap);
438 Cpu *CpuTiModel::createCpu(simgrid::Host *host,
439 xbt_dynar_t speedPeak,
442 tmgr_trace_t speedTrace,
444 e_surf_resource_state_t stateInitial,
445 tmgr_trace_t stateTrace)
447 xbt_assert(core==1,"Multi-core not handled with this model yet");
448 xbt_assert(xbt_dynar_getfirst_as(speedPeak, double) > 0.0,
449 "Speed has to be >0.0. Did you forget to specify the mandatory speed attribute?");
450 CpuTi *cpu = new CpuTi(this, host, speedPeak, pstate, speedScale, speedTrace,
451 core, stateInitial, stateTrace);
455 double CpuTiModel::shareResources(double now)
457 double min_action_duration = -1;
459 /* iterates over modified cpus to update share resources */
460 for(CpuTiList::iterator it(p_modifiedCpu->begin()), itend(p_modifiedCpu->end())
464 ti->updateActionsFinishTime(now);
467 /* get the min next event if heap not empty */
468 if (xbt_heap_size(p_tiActionHeap) > 0)
469 min_action_duration = xbt_heap_maxkey(p_tiActionHeap) - now;
471 XBT_DEBUG("Share resources, min next event date: %f", min_action_duration);
473 return min_action_duration;
476 void CpuTiModel::updateActionsState(double now, double /*delta*/)
478 while ((xbt_heap_size(p_tiActionHeap) > 0)
479 && (xbt_heap_maxkey(p_tiActionHeap) <= now)) {
480 CpuTiAction *action = (CpuTiAction*) xbt_heap_pop(p_tiActionHeap);
481 XBT_DEBUG("Action %p: finish", action);
483 /* set the remains to 0 due to precision problems when updating the remaining amount */
484 action->setRemains(0);
485 action->setState(SURF_ACTION_DONE);
486 /* update remaining amount of all actions */
487 action->p_cpu->updateRemainingAmount(surf_get_clock());
491 void CpuTiModel::addTraces()
493 xbt_dict_cursor_t cursor = NULL;
494 char *trace_name, *elm;
496 static int called = 0;
502 /* connect all traces relative to hosts */
503 xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
504 tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
505 CpuTi *cpu = static_cast<CpuTi*>(sg_host_surfcpu(sg_host_by_name(elm)));
507 xbt_assert(cpu, "Host %s undefined", elm);
508 xbt_assert(trace, "Trace %s undefined", trace_name);
510 if (cpu->p_stateEvent) {
511 XBT_DEBUG("Trace already configured for this CPU(%s), ignoring it",
515 XBT_DEBUG("Add state trace: %s to CPU(%s)", trace_name, elm);
516 cpu->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, cpu);
519 xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
520 tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
521 CpuTi *cpu = static_cast<CpuTi*>(sg_host_surfcpu(sg_host_by_name(elm)));
523 xbt_assert(cpu, "Host %s undefined", elm);
524 xbt_assert(trace, "Trace %s undefined", trace_name);
526 XBT_DEBUG("Add speed trace: %s to CPU(%s)", trace_name, elm);
527 if (cpu->p_availTrace)
528 delete cpu->p_availTrace;
530 cpu->p_availTrace = new CpuTiTgmr(trace, cpu->m_speedScale);
532 /* add a fake trace event if periodicity == 0 */
533 if (trace && xbt_dynar_length(trace->s_list.event_list) > 1) {
535 xbt_dynar_get_cpy(trace->s_list.event_list,
536 xbt_dynar_length(trace->s_list.event_list) - 1, &val);
537 if (val.delta == 0) {
538 tmgr_trace_t empty_trace;
539 empty_trace = tmgr_empty_trace_new();
541 tmgr_history_add_trace(history, empty_trace,
542 cpu->p_availTrace->m_lastTime, 0, cpu);
551 CpuTi::CpuTi(CpuTiModel *model, simgrid::Host *host, xbt_dynar_t speedPeak,
552 int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
553 e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace)
554 : Cpu(model, host, NULL, pstate, core, 0, speedScale, stateInitial)
557 m_speedScale = speedScale;
559 tmgr_trace_t empty_trace;
561 xbt_assert(core==1,"Multi-core not handled with this model yet");
562 XBT_DEBUG("speed scale %f", speedScale);
563 p_availTrace = new CpuTiTgmr(speedTrace, speedScale);
565 p_actionSet = new ActionTiList();
569 xbt_dynar_get_cpy(speedPeak, 0, &m_speedPeak);
570 XBT_DEBUG("CPU create: peak=%f", m_speedPeak);
573 p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, this);
574 if (speedTrace && xbt_dynar_length(speedTrace->s_list.event_list) > 1) {
575 // add a fake trace event if periodicity == 0
576 xbt_dynar_get_cpy(speedTrace->s_list.event_list,
577 xbt_dynar_length(speedTrace->s_list.event_list) - 1, &val);
578 if (val.delta == 0) {
579 empty_trace = tmgr_empty_trace_new();
581 tmgr_history_add_trace(history, empty_trace,
582 p_availTrace->m_lastTime, 0, this);
594 void CpuTi::updateState(tmgr_trace_event_t event_type,
595 double value, double date)
599 if (event_type == p_speedEvent) {
600 tmgr_trace_t speedTrace;
604 XBT_DEBUG("Finish trace date: %f value %f date %f", surf_get_clock(),
606 /* update remaining of actions and put in modified cpu swag */
607 updateRemainingAmount(date);
611 speedTrace = p_availTrace->p_speedTrace;
612 xbt_dynar_get_cpy(speedTrace->s_list.event_list,
613 xbt_dynar_length(speedTrace->s_list.event_list) - 1, &val);
616 m_speedScale = val.value;
618 trace = new CpuTiTgmr(TRACE_FIXED, val.value);
619 XBT_DEBUG("value %f", val.value);
621 p_availTrace = trace;
623 if (tmgr_trace_event_free(event_type))
626 } else if (event_type == p_stateEvent) {
628 if(getState() == SURF_RESOURCE_OFF)
629 xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
630 setState(SURF_RESOURCE_ON);
632 setState(SURF_RESOURCE_OFF);
634 /* put all action running on cpu to failed */
635 for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
636 ; it != itend ; ++it) {
638 if (action->getState() == SURF_ACTION_RUNNING
639 || action->getState() == SURF_ACTION_READY
640 || action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) {
641 action->setFinishTime(date);
642 action->setState(SURF_ACTION_FAILED);
643 if (action->m_indexHeap >= 0) {
644 CpuTiAction *heap_act = (CpuTiAction*)
645 xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, action->m_indexHeap);
646 if (heap_act != action)
652 if (tmgr_trace_event_free(event_type))
655 XBT_CRITICAL("Unknown event ! \n");
662 void CpuTi::updateActionsFinishTime(double now)
665 double sum_priority = 0.0, total_area, min_finish = -1;
667 /* update remaning amount of actions */
668 updateRemainingAmount(now);
670 for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
671 ; it != itend ; ++it) {
673 /* action not running, skip it */
674 if (action->getStateSet() !=
675 surf_cpu_model_pm->getRunningActionSet())
678 /* bogus priority, skip it */
679 if (action->getPriority() <= 0)
682 /* action suspended, skip it */
683 if (action->m_suspended != 0)
686 sum_priority += 1.0 / action->getPriority();
688 m_sumPriority = sum_priority;
690 for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
691 ; it != itend ; ++it) {
694 /* action not running, skip it */
695 if (action->getStateSet() !=
696 surf_cpu_model_pm->getRunningActionSet())
699 /* verify if the action is really running on cpu */
700 if (action->m_suspended == 0 && action->getPriority() > 0) {
701 /* total area needed to finish the action. Used in trace integration */
703 (action->getRemains()) * sum_priority *
704 action->getPriority();
706 total_area /= m_speedPeak;
708 action->setFinishTime(p_availTrace->solve(now, total_area));
709 /* verify which event will happen before (max_duration or finish time) */
710 if (action->getMaxDuration() != NO_MAX_DURATION &&
711 action->getStartTime() + action->getMaxDuration() < action->m_finish)
712 min_finish = action->getStartTime() + action->getMaxDuration();
714 min_finish = action->m_finish;
716 /* put the max duration time on heap */
717 if (action->getMaxDuration() != NO_MAX_DURATION)
718 min_finish = action->getStartTime() + action->getMaxDuration();
720 /* add in action heap */
721 XBT_DEBUG("action(%p) index %d", action, action->m_indexHeap);
722 if (action->m_indexHeap >= 0) {
723 CpuTiAction *heap_act = (CpuTiAction*)
724 xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, action->m_indexHeap);
725 if (heap_act != action)
728 if (min_finish != NO_MAX_DURATION)
729 xbt_heap_push(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, action, min_finish);
732 ("Update finish time: Cpu(%s) Action: %p, Start Time: %f Finish Time: %f Max duration %f",
733 getName(), action, action->getStartTime(),
735 action->getMaxDuration());
737 /* remove from modified cpu */
743 return !p_actionSet->empty();
746 double CpuTi::getAvailableSpeed()
748 m_speedScale = p_availTrace->getPowerScale(surf_get_clock());
749 return Cpu::getAvailableSpeed();
753 * \brief Update the remaining amount of actions
755 * \param now Current time
757 void CpuTi::updateRemainingAmount(double now)
762 /* already updated */
763 if (m_lastUpdate >= now)
766 /* calcule the surface */
767 area_total = p_availTrace->integrate(m_lastUpdate, now) * m_speedPeak;
768 XBT_DEBUG("Flops total: %f, Last update %f", area_total,
771 for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
772 ; it != itend ; ++it) {
774 /* action not running, skip it */
775 if (action->getStateSet() !=
776 getModel()->getRunningActionSet())
779 /* bogus priority, skip it */
780 if (action->getPriority() <= 0)
783 /* action suspended, skip it */
784 if (action->m_suspended != 0)
787 /* action don't need update */
788 if (action->getStartTime() >= now)
791 /* skip action that are finishing now */
792 if (action->m_finish >= 0
793 && action->m_finish <= now)
796 /* update remaining */
797 action->updateRemains(area_total / (m_sumPriority * action->getPriority()));
798 XBT_DEBUG("Update remaining action(%p) remaining %f", action,
804 CpuAction *CpuTi::execute(double size)
806 XBT_IN("(%s,%g)", getName(), size);
807 CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), size, getState() != SURF_RESOURCE_ON, this);
809 p_actionSet->push_back(*action);
816 CpuAction *CpuTi::sleep(double duration)
819 duration = MAX(duration, sg_surf_precision);
821 XBT_IN("(%s,%g)", getName(), duration);
822 CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), 1.0, getState() != SURF_RESOURCE_ON, this);
824 action->m_maxDuration = duration;
825 action->m_suspended = 2;
826 if (duration == NO_MAX_DURATION) {
827 /* Move to the *end* of the corresponding action set. This convention
828 is used to speed up update_resource_state */
829 action->getStateSet()->erase(action->getStateSet()->iterator_to(*action));
830 action->p_stateSet = static_cast<CpuTiModel*>(getModel())->p_runningActionSetThatDoesNotNeedBeingChecked;
831 action->getStateSet()->push_back(*action);
834 p_actionSet->push_back(*action);
840 void CpuTi::modified(bool modified){
841 CpuTiList *modifiedCpu = static_cast<CpuTiModel*>(getModel())->p_modifiedCpu;
843 if (!cpu_ti_hook.is_linked()) {
844 modifiedCpu->push_back(*this);
847 if (cpu_ti_hook.is_linked()) {
848 modifiedCpu->erase(modifiedCpu->iterator_to(*this));
857 CpuTiAction::CpuTiAction(CpuTiModel *model_, double cost, bool failed,
859 : CpuAction(model_, cost, failed)
861 m_suspended = 0; /* Should be useless because of the
862 calloc but it seems to help valgrind... */
865 p_cpu->modified(true);
868 void CpuTiAction::updateIndexHeap(int i)
873 void CpuTiAction::setState(e_surf_action_state_t state)
875 CpuAction::setState(state);
876 p_cpu->modified(true);
879 int CpuTiAction::unref()
883 if (action_hook.is_linked())
884 getStateSet()->erase(getStateSet()->iterator_to(*this));
885 /* remove from action_set */
886 if (action_ti_hook.is_linked())
887 p_cpu->p_actionSet->erase(p_cpu->p_actionSet->iterator_to(*this));
888 /* remove from heap */
889 xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, this->m_indexHeap);
890 p_cpu->modified(true);
897 void CpuTiAction::cancel()
899 this->setState(SURF_ACTION_FAILED);
900 xbt_heap_remove(getModel()->getActionHeap(), this->m_indexHeap);
901 p_cpu->modified(true);
905 void CpuTiAction::suspend()
907 XBT_IN("(%p)", this);
908 if (m_suspended != 2) {
910 xbt_heap_remove(getModel()->getActionHeap(), m_indexHeap);
911 p_cpu->modified(true);
916 void CpuTiAction::resume()
918 XBT_IN("(%p)", this);
919 if (m_suspended != 2) {
921 p_cpu->modified(true);
926 bool CpuTiAction::isSuspended()
928 return m_suspended == 1;
931 void CpuTiAction::setMaxDuration(double duration)
935 XBT_IN("(%p,%g)", this, duration);
937 m_maxDuration = duration;
940 min_finish = (getStartTime() + getMaxDuration()) < getFinishTime() ?
941 (getStartTime() + getMaxDuration()) : getFinishTime();
943 min_finish = getFinishTime();
945 /* add in action heap */
946 if (m_indexHeap >= 0) {
947 CpuTiAction *heap_act = (CpuTiAction*)
948 xbt_heap_remove(getModel()->getActionHeap(), m_indexHeap);
949 if (heap_act != this)
952 xbt_heap_push(getModel()->getActionHeap(), this, min_finish);
957 void CpuTiAction::setPriority(double priority)
959 XBT_IN("(%p,%g)", this, priority);
960 m_priority = priority;
961 p_cpu->modified(true);
965 double CpuTiAction::getRemains()
967 XBT_IN("(%p)", this);
968 p_cpu->updateRemainingAmount(surf_get_clock());
976 #endif /* SURF_MODEL_CPUTI_H_ */