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"
10 #include "src/surf/platform.hpp"
12 #ifndef SURF_MODEL_CPUTI_H_
13 #define SURF_MODEL_CPUTI_H_
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_ti, surf_cpu,
16 "Logging specific to the SURF CPU TRACE INTEGRATION module");
22 void cpu_ti_action_update_index_heap(void *action, int i)
24 ((simgrid::surf::CpuTiAction*)action)->updateIndexHeap(i);
31 CpuTiTrace::CpuTiTrace(tmgr_trace_t speedTrace)
38 p_timePoints = (double*) xbt_malloc0(sizeof(double) *
39 (xbt_dynar_length(speedTrace->s_list.event_list) + 1));
40 p_integral = (double*) xbt_malloc0(sizeof(double) *
41 (xbt_dynar_length(speedTrace->s_list.event_list) + 1));
42 m_nbPoints = xbt_dynar_length(speedTrace->s_list.event_list) + 1;
43 xbt_dynar_foreach(speedTrace->s_list.event_list, cpt, val) {
44 p_timePoints[i] = time;
45 p_integral[i] = integral;
46 integral += val.delta * val.value;
50 p_timePoints[i] = time;
51 p_integral[i] = integral;
54 CpuTiTrace::~CpuTiTrace()
56 xbt_free(p_timePoints);
60 CpuTiTgmr::~CpuTiTgmr()
67 * \brief Integrate trace
69 * Wrapper around surf_cpu_integrate_trace_simple() to get
72 * \param trace Trace structure.
73 * \param a Begin of interval
74 * \param b End of interval
75 * \return the integrate value. -1 if an error occurs.
77 double CpuTiTgmr::integrate(double a, double b)
84 if ((a < 0.0) || (a > b)) {
86 ("Error, invalid integration interval [%.2f,%.2f]. You probably have a task executing with negative computation amount. Check your code.",
93 if (m_type == TRACE_FIXED) {
94 return ((b - a) * m_value);
97 if (ceil(a / m_lastTime) == a / m_lastTime)
98 a_index = 1 + (int) (ceil(a / m_lastTime));
100 a_index = (int) (ceil(a / m_lastTime));
102 b_index = (int) (floor(b / m_lastTime));
104 if (a_index > b_index) { /* Same chunk */
105 return p_trace->integrateSimple(a - (a_index -
112 first_chunk = p_trace->integrateSimple(a - (a_index -
116 middle_chunk = (b_index - a_index) * m_total;
117 last_chunk = p_trace->integrateSimple(0.0,
122 XBT_DEBUG("first_chunk=%.2f middle_chunk=%.2f last_chunk=%.2f\n",
123 first_chunk, middle_chunk, last_chunk);
125 return (first_chunk + middle_chunk + last_chunk);
129 * \brief Auxiliary function to compute the integral between a and b.
130 * It simply computes the integrals at point a and b and returns the difference between them.
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 compute 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 Computes 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 simgrid::surf::on_postparse.connect([]() {
395 surf_cpu_model_pm->addTraces();
403 void surf_cpu_model_init_ti()
405 xbt_assert(!surf_cpu_model_pm,"CPU model already initialized. This should not happen.");
406 xbt_assert(!surf_cpu_model_vm,"CPU model already initialized. This should not happen.");
408 surf_cpu_model_pm = new simgrid::surf::CpuTiModel();
409 surf_cpu_model_vm = new simgrid::surf::CpuTiModel();
411 cpu_ti_define_callbacks();
412 simgrid::surf::Model *model_pm = static_cast<simgrid::surf::Model*>(surf_cpu_model_pm);
413 simgrid::surf::Model *model_vm = static_cast<simgrid::surf::Model*>(surf_cpu_model_vm);
414 xbt_dynar_push(all_existing_models, &model_pm);
415 xbt_dynar_push(all_existing_models, &model_vm);
421 CpuTiModel::CpuTiModel() : CpuModel()
423 p_runningActionSetThatDoesNotNeedBeingChecked = new ActionList();
425 p_modifiedCpu = new CpuTiList();
427 p_tiActionHeap = xbt_heap_new(8, NULL);
428 xbt_heap_set_update_callback(p_tiActionHeap,
429 cpu_ti_action_update_index_heap);
432 CpuTiModel::~CpuTiModel()
434 surf_cpu_model_pm = NULL;
435 delete p_runningActionSetThatDoesNotNeedBeingChecked;
436 delete p_modifiedCpu;
437 xbt_heap_free(p_tiActionHeap);
440 Cpu *CpuTiModel::createCpu(simgrid::s4u::Host *host,
441 xbt_dynar_t speedPeak,
444 tmgr_trace_t speedTrace,
447 tmgr_trace_t stateTrace)
449 xbt_assert(core==1,"Multi-core not handled with this model yet");
450 xbt_assert(xbt_dynar_getfirst_as(speedPeak, double) > 0.0,
451 "Speed has to be >0.0. Did you forget to specify the mandatory speed attribute?");
452 CpuTi *cpu = new CpuTi(this, host, speedPeak, pstate, speedScale, speedTrace,
453 core, initiallyOn, stateTrace);
457 double CpuTiModel::shareResources(double now)
459 double min_action_duration = -1;
461 /* iterates over modified cpus to update share resources */
462 for(CpuTiList::iterator it(p_modifiedCpu->begin()), itend(p_modifiedCpu->end())
466 ti->updateActionsFinishTime(now);
469 /* get the min next event if heap not empty */
470 if (xbt_heap_size(p_tiActionHeap) > 0)
471 min_action_duration = xbt_heap_maxkey(p_tiActionHeap) - now;
473 XBT_DEBUG("Share resources, min next event date: %f", min_action_duration);
475 return min_action_duration;
478 void CpuTiModel::updateActionsState(double now, double /*delta*/)
480 while ((xbt_heap_size(p_tiActionHeap) > 0)
481 && (xbt_heap_maxkey(p_tiActionHeap) <= now)) {
482 CpuTiAction *action = (CpuTiAction*) xbt_heap_pop(p_tiActionHeap);
483 XBT_DEBUG("Action %p: finish", action);
485 /* set the remains to 0 due to precision problems when updating the remaining amount */
486 action->setRemains(0);
487 action->setState(SURF_ACTION_DONE);
488 /* update remaining amount of all actions */
489 action->p_cpu->updateRemainingAmount(surf_get_clock());
493 void CpuTiModel::addTraces()
495 xbt_dict_cursor_t cursor = NULL;
496 char *trace_name, *elm;
498 static int called = 0;
504 /* connect all traces relative to hosts */
505 xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
506 tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
507 CpuTi *cpu = static_cast<CpuTi*>(sg_host_by_name(elm)->pimpl_cpu);
509 xbt_assert(cpu, "Host %s undefined", elm);
510 xbt_assert(trace, "Trace %s undefined", trace_name);
512 if (cpu->p_stateEvent) {
513 XBT_DEBUG("Trace already configured for this CPU(%s), ignoring it",
517 XBT_DEBUG("Add state trace: %s to CPU(%s)", trace_name, elm);
518 cpu->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, cpu);
521 xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
522 tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
523 CpuTi *cpu = static_cast<CpuTi*>(sg_host_by_name(elm)->pimpl_cpu);
525 xbt_assert(cpu, "Host %s undefined", elm);
526 xbt_assert(trace, "Trace %s undefined", trace_name);
528 XBT_DEBUG("Add speed trace: %s to CPU(%s)", trace_name, elm);
529 if (cpu->p_availTrace)
530 delete cpu->p_availTrace;
532 cpu->p_availTrace = new CpuTiTgmr(trace, cpu->m_speedScale);
534 /* add a fake trace event if periodicity == 0 */
535 if (trace && xbt_dynar_length(trace->s_list.event_list) > 1) {
537 xbt_dynar_get_cpy(trace->s_list.event_list,
538 xbt_dynar_length(trace->s_list.event_list) - 1, &val);
539 if (val.delta == 0) {
540 tmgr_trace_t empty_trace;
541 empty_trace = tmgr_empty_trace_new();
543 tmgr_history_add_trace(history, empty_trace,
544 cpu->p_availTrace->m_lastTime, 0, cpu);
553 CpuTi::CpuTi(CpuTiModel *model, simgrid::s4u::Host *host, xbt_dynar_t speedPeak,
554 int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
555 int initiallyOn, tmgr_trace_t stateTrace)
556 : Cpu(model, host, NULL, pstate, core, 0, speedScale, initiallyOn)
558 xbt_assert(core==1,"Multi-core not handled by this model yet");
561 m_speedScale = speedScale;
562 p_availTrace = new CpuTiTgmr(speedTrace, speedScale);
564 p_actionSet = new ActionTiList();
566 xbt_dynar_get_cpy(speedPeak, 0, &m_speedPeak);
567 XBT_DEBUG("CPU create: peak=%f", m_speedPeak);
570 p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, this);
572 if (speedTrace && xbt_dynar_length(speedTrace->s_list.event_list) > 1) {
574 // add a fake trace event if periodicity == 0
575 xbt_dynar_get_cpy(speedTrace->s_list.event_list,
576 xbt_dynar_length(speedTrace->s_list.event_list) - 1, &val);
577 if (val.delta == 0) {
578 tmgr_trace_t empty_trace = tmgr_empty_trace_new();
579 p_speedEvent = tmgr_history_add_trace(history, empty_trace, p_availTrace->m_lastTime, 0, this);
591 void CpuTi::updateState(tmgr_trace_event_t event_type,
592 double value, double date)
596 if (event_type == p_speedEvent) {
597 tmgr_trace_t speedTrace;
601 XBT_DEBUG("Finish trace date: %f value %f date %f", surf_get_clock(),
603 /* update remaining of actions and put in modified cpu swag */
604 updateRemainingAmount(date);
608 speedTrace = p_availTrace->p_speedTrace;
609 xbt_dynar_get_cpy(speedTrace->s_list.event_list,
610 xbt_dynar_length(speedTrace->s_list.event_list) - 1, &val);
613 m_speedScale = val.value;
615 trace = new CpuTiTgmr(TRACE_FIXED, val.value);
616 XBT_DEBUG("value %f", val.value);
618 p_availTrace = trace;
620 if (tmgr_trace_event_free(event_type))
623 } else if (event_type == p_stateEvent) {
626 xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
631 /* put all action running on cpu to failed */
632 for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
633 ; it != itend ; ++it) {
635 if (action->getState() == SURF_ACTION_RUNNING
636 || action->getState() == SURF_ACTION_READY
637 || action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) {
638 action->setFinishTime(date);
639 action->setState(SURF_ACTION_FAILED);
640 if (action->m_indexHeap >= 0) {
641 CpuTiAction *heap_act = (CpuTiAction*)
642 xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, action->m_indexHeap);
643 if (heap_act != action)
649 if (tmgr_trace_event_free(event_type))
652 XBT_CRITICAL("Unknown event ! \n");
659 void CpuTi::updateActionsFinishTime(double now)
662 double sum_priority = 0.0, total_area, min_finish = -1;
664 /* update remaining amount of actions */
665 updateRemainingAmount(now);
667 for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
668 ; it != itend ; ++it) {
670 /* action not running, skip it */
671 if (action->getStateSet() !=
672 surf_cpu_model_pm->getRunningActionSet())
675 /* bogus priority, skip it */
676 if (action->getPriority() <= 0)
679 /* action suspended, skip it */
680 if (action->m_suspended != 0)
683 sum_priority += 1.0 / action->getPriority();
685 m_sumPriority = sum_priority;
687 for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
688 ; it != itend ; ++it) {
691 /* action not running, skip it */
692 if (action->getStateSet() !=
693 surf_cpu_model_pm->getRunningActionSet())
696 /* verify if the action is really running on cpu */
697 if (action->m_suspended == 0 && action->getPriority() > 0) {
698 /* total area needed to finish the action. Used in trace integration */
700 (action->getRemains()) * sum_priority *
701 action->getPriority();
703 total_area /= m_speedPeak;
705 action->setFinishTime(p_availTrace->solve(now, total_area));
706 /* verify which event will happen before (max_duration or finish time) */
707 if (action->getMaxDuration() != NO_MAX_DURATION &&
708 action->getStartTime() + action->getMaxDuration() < action->m_finish)
709 min_finish = action->getStartTime() + action->getMaxDuration();
711 min_finish = action->m_finish;
713 /* put the max duration time on heap */
714 if (action->getMaxDuration() != NO_MAX_DURATION)
715 min_finish = action->getStartTime() + action->getMaxDuration();
717 /* add in action heap */
718 XBT_DEBUG("action(%p) index %d", action, action->m_indexHeap);
719 if (action->m_indexHeap >= 0) {
720 CpuTiAction *heap_act = (CpuTiAction*)
721 xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, action->m_indexHeap);
722 if (heap_act != action)
725 if (min_finish != NO_MAX_DURATION)
726 xbt_heap_push(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, action, min_finish);
729 ("Update finish time: Cpu(%s) Action: %p, Start Time: %f Finish Time: %f Max duration %f",
730 getName(), action, action->getStartTime(),
732 action->getMaxDuration());
734 /* remove from modified cpu */
740 return !p_actionSet->empty();
743 double CpuTi::getAvailableSpeed()
745 m_speedScale = p_availTrace->getPowerScale(surf_get_clock());
746 return Cpu::getAvailableSpeed();
749 /** @brief Update the remaining amount of actions */
750 void CpuTi::updateRemainingAmount(double now)
755 /* already updated */
756 if (m_lastUpdate >= now)
759 /* compute the integration area */
760 area_total = p_availTrace->integrate(m_lastUpdate, now) * m_speedPeak;
761 XBT_DEBUG("Flops total: %f, Last update %f", area_total,
764 for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
765 ; it != itend ; ++it) {
767 /* action not running, skip it */
768 if (action->getStateSet() !=
769 getModel()->getRunningActionSet())
772 /* bogus priority, skip it */
773 if (action->getPriority() <= 0)
776 /* action suspended, skip it */
777 if (action->m_suspended != 0)
780 /* action don't need update */
781 if (action->getStartTime() >= now)
784 /* skip action that are finishing now */
785 if (action->m_finish >= 0
786 && action->m_finish <= now)
789 /* update remaining */
790 action->updateRemains(area_total / (m_sumPriority * action->getPriority()));
791 XBT_DEBUG("Update remaining action(%p) remaining %f", action,
797 CpuAction *CpuTi::execute(double size)
799 XBT_IN("(%s,%g)", getName(), size);
800 CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), size, isOff(), this);
802 p_actionSet->push_back(*action);
809 CpuAction *CpuTi::sleep(double duration)
812 duration = MAX(duration, sg_surf_precision);
814 XBT_IN("(%s,%g)", getName(), duration);
815 CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), 1.0, isOff(), this);
817 action->m_maxDuration = duration;
818 action->m_suspended = 2;
819 if (duration == NO_MAX_DURATION) {
820 /* Move to the *end* of the corresponding action set. This convention
821 is used to speed up update_resource_state */
822 action->getStateSet()->erase(action->getStateSet()->iterator_to(*action));
823 action->p_stateSet = static_cast<CpuTiModel*>(getModel())->p_runningActionSetThatDoesNotNeedBeingChecked;
824 action->getStateSet()->push_back(*action);
827 p_actionSet->push_back(*action);
833 void CpuTi::modified(bool modified){
834 CpuTiList *modifiedCpu = static_cast<CpuTiModel*>(getModel())->p_modifiedCpu;
836 if (!cpu_ti_hook.is_linked()) {
837 modifiedCpu->push_back(*this);
840 if (cpu_ti_hook.is_linked()) {
841 modifiedCpu->erase(modifiedCpu->iterator_to(*this));
850 CpuTiAction::CpuTiAction(CpuTiModel *model_, double cost, bool failed,
852 : CpuAction(model_, cost, failed)
856 p_cpu->modified(true);
859 void CpuTiAction::updateIndexHeap(int i)
864 void CpuTiAction::setState(e_surf_action_state_t state)
866 CpuAction::setState(state);
867 p_cpu->modified(true);
870 int CpuTiAction::unref()
874 if (action_hook.is_linked())
875 getStateSet()->erase(getStateSet()->iterator_to(*this));
876 /* remove from action_set */
877 if (action_ti_hook.is_linked())
878 p_cpu->p_actionSet->erase(p_cpu->p_actionSet->iterator_to(*this));
879 /* remove from heap */
880 xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, this->m_indexHeap);
881 p_cpu->modified(true);
888 void CpuTiAction::cancel()
890 this->setState(SURF_ACTION_FAILED);
891 xbt_heap_remove(getModel()->getActionHeap(), this->m_indexHeap);
892 p_cpu->modified(true);
896 void CpuTiAction::suspend()
898 XBT_IN("(%p)", this);
899 if (m_suspended != 2) {
901 xbt_heap_remove(getModel()->getActionHeap(), m_indexHeap);
902 p_cpu->modified(true);
907 void CpuTiAction::resume()
909 XBT_IN("(%p)", this);
910 if (m_suspended != 2) {
912 p_cpu->modified(true);
917 void CpuTiAction::setMaxDuration(double duration)
921 XBT_IN("(%p,%g)", this, duration);
923 m_maxDuration = duration;
926 min_finish = (getStartTime() + getMaxDuration()) < getFinishTime() ?
927 (getStartTime() + getMaxDuration()) : getFinishTime();
929 min_finish = getFinishTime();
931 /* add in action heap */
932 if (m_indexHeap >= 0) {
933 CpuTiAction *heap_act = (CpuTiAction*)
934 xbt_heap_remove(getModel()->getActionHeap(), m_indexHeap);
935 if (heap_act != this)
938 xbt_heap_push(getModel()->getActionHeap(), this, min_finish);
943 void CpuTiAction::setPriority(double priority)
945 XBT_IN("(%p,%g)", this, priority);
946 m_priority = priority;
947 p_cpu->modified(true);
951 double CpuTiAction::getRemains()
953 XBT_IN("(%p)", this);
954 p_cpu->updateRemainingAmount(surf_get_clock());
962 #endif /* SURF_MODEL_CPUTI_H_ */