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(const char *name,
439 xbt_dynar_t speedPeak,
442 tmgr_trace_t speedTrace,
444 e_surf_resource_state_t stateInitial,
445 tmgr_trace_t stateTrace,
446 xbt_dict_t cpuProperties)
448 xbt_assert(core==1,"Multi-core not handled with this model yet");
449 sg_host_t host = sg_host_by_name(name);
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, name, speedPeak, pstate, speedScale, speedTrace,
453 core, stateInitial, stateTrace, cpuProperties);
454 sg_host_surfcpu_register(host, cpu);
458 double CpuTiModel::shareResources(double now)
460 double min_action_duration = -1;
462 /* iterates over modified cpus to update share resources */
463 for(CpuTiList::iterator it(p_modifiedCpu->begin()), itend(p_modifiedCpu->end())
467 ti->updateActionsFinishTime(now);
470 /* get the min next event if heap not empty */
471 if (xbt_heap_size(p_tiActionHeap) > 0)
472 min_action_duration = xbt_heap_maxkey(p_tiActionHeap) - now;
474 XBT_DEBUG("Share resources, min next event date: %f", min_action_duration);
476 return min_action_duration;
479 void CpuTiModel::updateActionsState(double now, double /*delta*/)
481 while ((xbt_heap_size(p_tiActionHeap) > 0)
482 && (xbt_heap_maxkey(p_tiActionHeap) <= now)) {
483 CpuTiAction *action = (CpuTiAction*) xbt_heap_pop(p_tiActionHeap);
484 XBT_DEBUG("Action %p: finish", action);
486 /* set the remains to 0 due to precision problems when updating the remaining amount */
487 action->setRemains(0);
488 action->setState(SURF_ACTION_DONE);
489 /* update remaining amount of all actions */
490 action->p_cpu->updateRemainingAmount(surf_get_clock());
494 void CpuTiModel::addTraces()
496 xbt_dict_cursor_t cursor = NULL;
497 char *trace_name, *elm;
499 static int called = 0;
505 /* connect all traces relative to hosts */
506 xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
507 tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
508 CpuTi *cpu = static_cast<CpuTi*>(sg_host_surfcpu(sg_host_by_name(elm)));
510 xbt_assert(cpu, "Host %s undefined", elm);
511 xbt_assert(trace, "Trace %s undefined", trace_name);
513 if (cpu->p_stateEvent) {
514 XBT_DEBUG("Trace already configured for this CPU(%s), ignoring it",
518 XBT_DEBUG("Add state trace: %s to CPU(%s)", trace_name, elm);
519 cpu->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, cpu);
522 xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
523 tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
524 CpuTi *cpu = static_cast<CpuTi*>(sg_host_surfcpu(sg_host_by_name(elm)));
526 xbt_assert(cpu, "Host %s undefined", elm);
527 xbt_assert(trace, "Trace %s undefined", trace_name);
529 XBT_DEBUG("Add speed trace: %s to CPU(%s)", trace_name, elm);
530 if (cpu->p_availTrace)
531 delete cpu->p_availTrace;
533 cpu->p_availTrace = new CpuTiTgmr(trace, cpu->m_speedScale);
535 /* add a fake trace event if periodicity == 0 */
536 if (trace && xbt_dynar_length(trace->s_list.event_list) > 1) {
538 xbt_dynar_get_cpy(trace->s_list.event_list,
539 xbt_dynar_length(trace->s_list.event_list) - 1, &val);
540 if (val.delta == 0) {
541 tmgr_trace_t empty_trace;
542 empty_trace = tmgr_empty_trace_new();
544 tmgr_history_add_trace(history, empty_trace,
545 cpu->p_availTrace->m_lastTime, 0, cpu);
554 CpuTi::CpuTi(CpuTiModel *model, const char *name, xbt_dynar_t speedPeak,
555 int pstate, double speedScale, tmgr_trace_t speedTrace, int core,
556 e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
557 xbt_dict_t properties)
558 : Cpu(model, name, properties, core, 0, speedScale, stateInitial)
561 m_speedScale = speedScale;
563 tmgr_trace_t empty_trace;
565 xbt_assert(core==1,"Multi-core not handled with this model yet");
566 XBT_DEBUG("speed scale %f", speedScale);
567 p_availTrace = new CpuTiTgmr(speedTrace, speedScale);
569 p_actionSet = new ActionTiList();
573 xbt_dynar_get_cpy(speedPeak, 0, &m_speedPeak);
574 XBT_DEBUG("CPU create: peak=%f", m_speedPeak);
577 p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, this);
578 if (speedTrace && xbt_dynar_length(speedTrace->s_list.event_list) > 1) {
579 // add a fake trace event if periodicity == 0
580 xbt_dynar_get_cpy(speedTrace->s_list.event_list,
581 xbt_dynar_length(speedTrace->s_list.event_list) - 1, &val);
582 if (val.delta == 0) {
583 empty_trace = tmgr_empty_trace_new();
585 tmgr_history_add_trace(history, empty_trace,
586 p_availTrace->m_lastTime, 0, this);
597 void CpuTi::updateState(tmgr_trace_event_t event_type,
598 double value, double date)
602 if (event_type == p_speedEvent) {
603 tmgr_trace_t speedTrace;
607 XBT_DEBUG("Finish trace date: %f value %f date %f", surf_get_clock(),
609 /* update remaining of actions and put in modified cpu swag */
610 updateRemainingAmount(date);
614 speedTrace = p_availTrace->p_speedTrace;
615 xbt_dynar_get_cpy(speedTrace->s_list.event_list,
616 xbt_dynar_length(speedTrace->s_list.event_list) - 1, &val);
619 m_speedScale = val.value;
621 trace = new CpuTiTgmr(TRACE_FIXED, val.value);
622 XBT_DEBUG("value %f", val.value);
624 p_availTrace = trace;
626 if (tmgr_trace_event_free(event_type))
629 } else if (event_type == p_stateEvent) {
631 if(getState() == SURF_RESOURCE_OFF)
632 xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
633 setState(SURF_RESOURCE_ON);
635 setState(SURF_RESOURCE_OFF);
637 /* put all action running on cpu to failed */
638 for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
639 ; it != itend ; ++it) {
641 if (action->getState() == SURF_ACTION_RUNNING
642 || action->getState() == SURF_ACTION_READY
643 || action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) {
644 action->setFinishTime(date);
645 action->setState(SURF_ACTION_FAILED);
646 if (action->m_indexHeap >= 0) {
647 CpuTiAction *heap_act = (CpuTiAction*)
648 xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, action->m_indexHeap);
649 if (heap_act != action)
655 if (tmgr_trace_event_free(event_type))
658 XBT_CRITICAL("Unknown event ! \n");
665 void CpuTi::updateActionsFinishTime(double now)
668 double sum_priority = 0.0, total_area, min_finish = -1;
670 /* update remaning amount of actions */
671 updateRemainingAmount(now);
673 for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
674 ; it != itend ; ++it) {
676 /* action not running, skip it */
677 if (action->getStateSet() !=
678 surf_cpu_model_pm->getRunningActionSet())
681 /* bogus priority, skip it */
682 if (action->getPriority() <= 0)
685 /* action suspended, skip it */
686 if (action->m_suspended != 0)
689 sum_priority += 1.0 / action->getPriority();
691 m_sumPriority = sum_priority;
693 for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
694 ; it != itend ; ++it) {
697 /* action not running, skip it */
698 if (action->getStateSet() !=
699 surf_cpu_model_pm->getRunningActionSet())
702 /* verify if the action is really running on cpu */
703 if (action->m_suspended == 0 && action->getPriority() > 0) {
704 /* total area needed to finish the action. Used in trace integration */
706 (action->getRemains()) * sum_priority *
707 action->getPriority();
709 total_area /= m_speedPeak;
711 action->setFinishTime(p_availTrace->solve(now, total_area));
712 /* verify which event will happen before (max_duration or finish time) */
713 if (action->getMaxDuration() != NO_MAX_DURATION &&
714 action->getStartTime() + action->getMaxDuration() < action->m_finish)
715 min_finish = action->getStartTime() + action->getMaxDuration();
717 min_finish = action->m_finish;
719 /* put the max duration time on heap */
720 if (action->getMaxDuration() != NO_MAX_DURATION)
721 min_finish = action->getStartTime() + action->getMaxDuration();
723 /* add in action heap */
724 XBT_DEBUG("action(%p) index %d", action, action->m_indexHeap);
725 if (action->m_indexHeap >= 0) {
726 CpuTiAction *heap_act = (CpuTiAction*)
727 xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, action->m_indexHeap);
728 if (heap_act != action)
731 if (min_finish != NO_MAX_DURATION)
732 xbt_heap_push(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, action, min_finish);
735 ("Update finish time: Cpu(%s) Action: %p, Start Time: %f Finish Time: %f Max duration %f",
736 getName(), action, action->getStartTime(),
738 action->getMaxDuration());
740 /* remove from modified cpu */
746 return !p_actionSet->empty();
749 double CpuTi::getAvailableSpeed()
751 m_speedScale = p_availTrace->getPowerScale(surf_get_clock());
752 return Cpu::getAvailableSpeed();
756 * \brief Update the remaining amount of actions
758 * \param now Current time
760 void CpuTi::updateRemainingAmount(double now)
765 /* already updated */
766 if (m_lastUpdate >= now)
769 /* calcule the surface */
770 area_total = p_availTrace->integrate(m_lastUpdate, now) * m_speedPeak;
771 XBT_DEBUG("Flops total: %f, Last update %f", area_total,
774 for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
775 ; it != itend ; ++it) {
777 /* action not running, skip it */
778 if (action->getStateSet() !=
779 getModel()->getRunningActionSet())
782 /* bogus priority, skip it */
783 if (action->getPriority() <= 0)
786 /* action suspended, skip it */
787 if (action->m_suspended != 0)
790 /* action don't need update */
791 if (action->getStartTime() >= now)
794 /* skip action that are finishing now */
795 if (action->m_finish >= 0
796 && action->m_finish <= now)
799 /* update remaining */
800 action->updateRemains(area_total / (m_sumPriority * action->getPriority()));
801 XBT_DEBUG("Update remaining action(%p) remaining %f", action,
807 CpuAction *CpuTi::execute(double size)
809 XBT_IN("(%s,%g)", getName(), size);
810 CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), size, getState() != SURF_RESOURCE_ON, this);
812 p_actionSet->push_back(*action);
819 CpuAction *CpuTi::sleep(double duration)
822 duration = MAX(duration, sg_surf_precision);
824 XBT_IN("(%s,%g)", getName(), duration);
825 CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), 1.0, getState() != SURF_RESOURCE_ON, this);
827 action->m_maxDuration = duration;
828 action->m_suspended = 2;
829 if (duration == NO_MAX_DURATION) {
830 /* Move to the *end* of the corresponding action set. This convention
831 is used to speed up update_resource_state */
832 action->getStateSet()->erase(action->getStateSet()->iterator_to(*action));
833 action->p_stateSet = static_cast<CpuTiModel*>(getModel())->p_runningActionSetThatDoesNotNeedBeingChecked;
834 action->getStateSet()->push_back(*action);
837 p_actionSet->push_back(*action);
843 void CpuTi::modified(bool modified){
844 CpuTiList *modifiedCpu = static_cast<CpuTiModel*>(getModel())->p_modifiedCpu;
846 if (!cpu_ti_hook.is_linked()) {
847 modifiedCpu->push_back(*this);
850 if (cpu_ti_hook.is_linked()) {
851 modifiedCpu->erase(modifiedCpu->iterator_to(*this));
860 CpuTiAction::CpuTiAction(CpuTiModel *model_, double cost, bool failed,
862 : CpuAction(model_, cost, failed)
864 m_suspended = 0; /* Should be useless because of the
865 calloc but it seems to help valgrind... */
868 p_cpu->modified(true);
871 void CpuTiAction::updateIndexHeap(int i)
876 void CpuTiAction::setState(e_surf_action_state_t state)
878 CpuAction::setState(state);
879 p_cpu->modified(true);
882 int CpuTiAction::unref()
886 if (action_hook.is_linked())
887 getStateSet()->erase(getStateSet()->iterator_to(*this));
888 /* remove from action_set */
889 if (action_ti_hook.is_linked())
890 p_cpu->p_actionSet->erase(p_cpu->p_actionSet->iterator_to(*this));
891 /* remove from heap */
892 xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, this->m_indexHeap);
893 p_cpu->modified(true);
900 void CpuTiAction::cancel()
902 this->setState(SURF_ACTION_FAILED);
903 xbt_heap_remove(getModel()->getActionHeap(), this->m_indexHeap);
904 p_cpu->modified(true);
908 void CpuTiAction::suspend()
910 XBT_IN("(%p)", this);
911 if (m_suspended != 2) {
913 xbt_heap_remove(getModel()->getActionHeap(), m_indexHeap);
914 p_cpu->modified(true);
919 void CpuTiAction::resume()
921 XBT_IN("(%p)", this);
922 if (m_suspended != 2) {
924 p_cpu->modified(true);
929 bool CpuTiAction::isSuspended()
931 return m_suspended == 1;
934 void CpuTiAction::setMaxDuration(double duration)
938 XBT_IN("(%p,%g)", this, duration);
940 m_maxDuration = duration;
943 min_finish = (getStartTime() + getMaxDuration()) < getFinishTime() ?
944 (getStartTime() + getMaxDuration()) : getFinishTime();
946 min_finish = getFinishTime();
948 /* add in action heap */
949 if (m_indexHeap >= 0) {
950 CpuTiAction *heap_act = (CpuTiAction*)
951 xbt_heap_remove(getModel()->getActionHeap(), m_indexHeap);
952 if (heap_act != this)
955 xbt_heap_push(getModel()->getActionHeap(), this, min_finish);
960 void CpuTiAction::setPriority(double priority)
962 XBT_IN("(%p,%g)", this, priority);
963 m_priority = priority;
964 p_cpu->modified(true);
968 double CpuTiAction::getRemains()
970 XBT_IN("(%p)", this);
971 p_cpu->updateRemainingAmount(surf_get_clock());
979 #endif /* SURF_MODEL_CPUTI_H_ */