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");
17 static void cpu_ti_action_update_index_heap(void *action, int i);
23 CpuTiTrace::CpuTiTrace(tmgr_trace_t power_trace)
30 p_timePoints = (double*) xbt_malloc0(sizeof(double) *
31 (xbt_dynar_length(power_trace->s_list.event_list) + 1));
32 p_integral = (double*) xbt_malloc0(sizeof(double) *
33 (xbt_dynar_length(power_trace->s_list.event_list) + 1));
34 m_nbPoints = xbt_dynar_length(power_trace->s_list.event_list) + 1;
35 xbt_dynar_foreach(power_trace->s_list.event_list, cpt, val) {
36 p_timePoints[i] = time;
37 p_integral[i] = integral;
38 integral += val.delta * val.value;
42 p_timePoints[i] = time;
43 p_integral[i] = integral;
46 CpuTiTrace::~CpuTiTrace()
48 xbt_free(p_timePoints);
52 CpuTiTgmr::~CpuTiTgmr()
59 * \brief Integrate trace
61 * Wrapper around surf_cpu_integrate_trace_simple() to get
64 * \param trace Trace structure.
65 * \param a Begin of interval
66 * \param b End of interval
67 * \return the integrate value. -1 if an error occurs.
69 double CpuTiTgmr::integrate(double a, double b)
76 if ((a < 0.0) || (a > b)) {
78 ("Error, invalid integration interval [%.2f,%.2f]. You probably have a task executing with negative computation amount. Check your code.",
85 if (m_type == TRACE_FIXED) {
86 return ((b - a) * m_value);
89 if (ceil(a / m_lastTime) == a / m_lastTime)
90 a_index = 1 + (int) (ceil(a / m_lastTime));
92 a_index = (int) (ceil(a / m_lastTime));
94 b_index = (int) (floor(b / m_lastTime));
96 if (a_index > b_index) { /* Same chunk */
97 return p_trace->integrateSimple(a - (a_index -
104 first_chunk = p_trace->integrateSimple(a - (a_index -
108 middle_chunk = (b_index - a_index) * m_total;
109 last_chunk = p_trace->integrateSimple(0.0,
114 XBT_DEBUG("first_chunk=%.2f middle_chunk=%.2f last_chunk=%.2f\n",
115 first_chunk, middle_chunk, last_chunk);
117 return (first_chunk + middle_chunk + last_chunk);
121 * \brief Auxiliary function to calculate the integral between a and b.
122 * It simply calculates the integral at point a and b and returns the difference
124 * \param trace Trace structure
125 * \param a Initial point
126 * \param b Final point
129 double CpuTiTrace::integrateSimple(double a, double b)
131 return integrateSimplePoint(b) - integrateSimplePoint(a);
135 * \brief Auxiliary function to calculate the integral at point a.
136 * \param trace Trace structure
140 double CpuTiTrace::integrateSimplePoint(double a)
145 ind = binarySearch(p_timePoints, a, 0, m_nbPoints - 1);
146 integral += p_integral[ind];
148 ("a %f ind %d integral %f ind + 1 %f ind %f time +1 %f time %f",
149 a, ind, integral, p_integral[ind + 1], p_integral[ind],
150 p_timePoints[ind + 1], p_timePoints[ind]);
151 double_update(&a_aux, p_timePoints[ind], sg_maxmin_precision*sg_surf_precision);
154 ((p_integral[ind + 1] -
155 p_integral[ind]) / (p_timePoints[ind + 1] -
156 p_timePoints[ind])) * (a - p_timePoints[ind]);
157 XBT_DEBUG("Integral a %f = %f", a, integral);
163 * \brief Calculate the time needed to execute "amount" on cpu.
165 * Here, amount can span multiple trace periods
167 * \param trace CPU trace structure
168 * \param a Initial time
169 * \param amount Amount to be executed
172 double CpuTiTgmr::solve(double a, double amount)
176 double reduced_amount;
180 /* Fix very small negative numbers */
181 if ((a < 0.0) && (a > -EPSILON)) {
184 if ((amount < 0.0) && (amount > -EPSILON)) {
189 if ((a < 0.0) || (amount < 0.0)) {
191 ("Error, invalid parameters [a = %.2f, amount = %.2f]. You probably have a task executing with negative computation amount. Check your code.",
196 /* At this point, a and amount are positive */
198 if (amount < EPSILON)
201 /* Is the trace fixed ? */
202 if (m_type == TRACE_FIXED) {
203 return (a + (amount / m_value));
206 XBT_DEBUG("amount %f total %f", amount, m_total);
207 /* Reduce the problem to one where amount <= trace_total */
208 quotient = (int) (floor(amount / m_total));
209 reduced_amount = (m_total) * ((amount / m_total) -
210 floor(amount / m_total));
211 reduced_a = a - (m_lastTime) * (int) (floor(a / m_lastTime));
213 XBT_DEBUG("Quotient: %d reduced_amount: %f reduced_a: %f", quotient,
214 reduced_amount, reduced_a);
216 /* Now solve for new_amount which is <= trace_total */
218 fprintf(stderr,"reduced_a = %.2f\n",reduced_a);
219 fprintf(stderr,"reduced_amount = %.2f\n",reduced_amount);
221 reduced_b = solveSomewhatSimple(reduced_a, reduced_amount);
223 /* Re-map to the original b and amount */
224 b = (m_lastTime) * (int) (floor(a / m_lastTime)) +
225 (quotient * m_lastTime) + reduced_b;
230 * \brief Auxiliary function to solve integral
232 * Here, amount is <= trace->total
233 * and a <=trace->last_time
236 double CpuTiTgmr::solveSomewhatSimple(double a, double amount)
238 double amount_till_end;
241 XBT_DEBUG("Solve integral: [%.2f, amount=%.2f]", a, amount);
242 amount_till_end = integrate(a, m_lastTime);
244 fprintf(stderr,"amount_till_end=%.2f\n",amount_till_end);
247 if (amount_till_end > amount) {
248 b = p_trace->solveSimple(a, amount);
250 b = m_lastTime + p_trace->solveSimple(0.0, amount - amount_till_end);
256 * \brief Auxiliary function to solve integral.
257 * It returns the date when the requested amount of flops is available
258 * \param trace Trace structure
259 * \param a Initial point
260 * \param amount Amount of flops
261 * \return The date when amount is available.
263 double CpuTiTrace::solveSimple(double a, double amount)
268 integral_a = integrateSimplePoint(a);
269 ind = binarySearch(p_integral, integral_a + amount, 0, m_nbPoints - 1);
270 time = p_timePoints[ind];
272 (integral_a + amount -
273 p_integral[ind]) / ((p_integral[ind + 1] -
275 (p_timePoints[ind + 1] -
282 * \brief Auxiliary function to update the CPU power scale.
284 * This function uses the trace structure to return the power scale at the determined time a.
285 * \param trace Trace structure to search the updated power scale
287 * \return CPU power scale
289 double CpuTiTgmr::getPowerScale(double a)
295 reduced_a = a - floor(a / m_lastTime) * m_lastTime;
296 point = p_trace->binarySearch(p_trace->p_timePoints, reduced_a, 0,
297 p_trace->m_nbPoints - 1);
298 xbt_dynar_get_cpy(p_powerTrace->s_list.event_list, point, &val);
303 * \brief Creates a new integration trace from a tmgr_trace_t
305 * \param power_trace CPU availability trace
306 * \param value Percentage of CPU power available (useful to fixed tracing)
307 * \param spacing Initial spacing
308 * \return Integration trace structure
310 CpuTiTgmr::CpuTiTgmr(tmgr_trace_t power_trace, double value)
312 double total_time = 0.0;
317 /* no availability file, fixed trace */
319 m_type = TRACE_FIXED;
321 XBT_DEBUG("No availability trace. Constant value = %f", value);
325 /* only one point available, fixed trace */
326 if (xbt_dynar_length(power_trace->s_list.event_list) == 1) {
327 xbt_dynar_get_cpy(power_trace->s_list.event_list, 0, &val);
328 m_type = TRACE_FIXED;
333 m_type = TRACE_DYNAMIC;
334 p_powerTrace = power_trace;
336 /* count the total time of trace file */
337 xbt_dynar_foreach(power_trace->s_list.event_list, cpt, val) {
338 total_time += val.delta;
340 p_trace = new CpuTiTrace(power_trace);
341 m_lastTime = total_time;
342 m_total = p_trace->integrateSimple(0, total_time);
344 XBT_DEBUG("Total integral %f, last_time %f ",
345 m_total, m_lastTime);
349 * \brief Binary search in array.
350 * It returns the first point of the interval in which "a" is.
352 * \param a Value to search
353 * \param low Low bound to search in array
354 * \param high Upper bound to search in array
355 * \return Index of point
357 int CpuTiTrace::binarySearch(double *array, double a, int low, int high)
359 xbt_assert(low < high, "Wrong parameters: low (%d) should be smaller than"
360 " high (%d)", low, high);
364 mid = low + (high - low) / 2;
365 XBT_DEBUG("a %f low %d high %d mid %d value %f", a, low, high, mid,
373 while (low < high - 1);
382 static void cpu_ti_define_callbacks()
384 sg_platf_host_add_cb(cpu_parse_init);
385 sg_platf_postparse_add_cb(cpu_add_traces);
392 void surf_cpu_model_init_ti()
394 xbt_assert(!surf_cpu_model_pm,"CPU model already initialized. This should not happen.");
395 xbt_assert(!surf_cpu_model_vm,"CPU model already initialized. This should not happen.");
397 surf_cpu_model_pm = new CpuTiModel();
398 surf_cpu_model_vm = new CpuTiModel();
400 cpu_ti_define_callbacks();
401 Model *model_pm = static_cast<Model*>(surf_cpu_model_pm);
402 Model *model_vm = static_cast<Model*>(surf_cpu_model_vm);
403 xbt_dynar_push(model_list, &model_pm);
404 xbt_dynar_push(model_list, &model_vm);
407 CpuTiModel::CpuTiModel() : CpuModel()
409 p_runningActionSetThatDoesNotNeedBeingChecked = new ActionList();
411 p_modifiedCpu = new CpuTiList();
413 p_tiActionHeap = xbt_heap_new(8, NULL);
414 xbt_heap_set_update_callback(p_tiActionHeap,
415 cpu_ti_action_update_index_heap);
418 CpuTiModel::~CpuTiModel()
420 surf_cpu_model_pm = NULL;
421 delete p_runningActionSetThatDoesNotNeedBeingChecked;
422 delete p_modifiedCpu;
423 xbt_heap_free(p_tiActionHeap);
426 Cpu *CpuTiModel::createCpu(const char *name,
427 xbt_dynar_t powerPeak,
430 tmgr_trace_t powerTrace,
432 e_surf_resource_state_t stateInitial,
433 tmgr_trace_t stateTrace,
434 xbt_dict_t cpuProperties)
436 xbt_assert(core==1,"Multi-core not handled with this model yet");
437 sg_host_t host = sg_host_by_name(name);
438 xbt_assert(!sg_host_surfcpu(host),
439 "Host '%s' declared several times in the platform file",
441 xbt_assert(xbt_dynar_getfirst_as(powerPeak, double) > 0.0,
442 "Power has to be >0.0. Did you forget to specify the mandatory power attribute?");
443 CpuTi *cpu = new CpuTi(this, name, powerPeak, pstate, powerScale, powerTrace,
444 core, stateInitial, stateTrace, cpuProperties);
445 sg_host_surfcpu_set(host, cpu);
449 double CpuTiModel::shareResources(double now)
451 double min_action_duration = -1;
453 /* iterates over modified cpus to update share resources */
454 for(CpuTiList::iterator it(p_modifiedCpu->begin()), itend(p_modifiedCpu->end())
458 ti->updateActionsFinishTime(now);
461 /* get the min next event if heap not empty */
462 if (xbt_heap_size(p_tiActionHeap) > 0)
463 min_action_duration = xbt_heap_maxkey(p_tiActionHeap) - now;
465 XBT_DEBUG("Share resources, min next event date: %f", min_action_duration);
467 return min_action_duration;
470 void CpuTiModel::updateActionsState(double now, double /*delta*/)
472 while ((xbt_heap_size(p_tiActionHeap) > 0)
473 && (xbt_heap_maxkey(p_tiActionHeap) <= now)) {
474 CpuTiAction *action = (CpuTiAction*) xbt_heap_pop(p_tiActionHeap);
475 XBT_DEBUG("Action %p: finish", action);
477 /* set the remains to 0 due to precision problems when updating the remaining amount */
478 action->setRemains(0);
479 action->setState(SURF_ACTION_DONE);
480 /* update remaining amount of all actions */
481 action->p_cpu->updateRemainingAmount(surf_get_clock());
485 void CpuTiModel::addTraces()
487 xbt_dict_cursor_t cursor = NULL;
488 char *trace_name, *elm;
490 static int called = 0;
496 /* connect all traces relative to hosts */
497 xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
498 tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
499 CpuTi *cpu = static_cast<CpuTi*>(sg_host_surfcpu(sg_host_by_name(elm)));
501 xbt_assert(cpu, "Host %s undefined", elm);
502 xbt_assert(trace, "Trace %s undefined", trace_name);
504 if (cpu->p_stateEvent) {
505 XBT_DEBUG("Trace already configured for this CPU(%s), ignoring it",
509 XBT_DEBUG("Add state trace: %s to CPU(%s)", trace_name, elm);
510 cpu->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, cpu);
513 xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
514 tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
515 CpuTi *cpu = static_cast<CpuTi*>(sg_host_surfcpu(sg_host_by_name(elm)));
517 xbt_assert(cpu, "Host %s undefined", elm);
518 xbt_assert(trace, "Trace %s undefined", trace_name);
520 XBT_DEBUG("Add power trace: %s to CPU(%s)", trace_name, elm);
521 if (cpu->p_availTrace)
522 delete cpu->p_availTrace;
524 cpu->p_availTrace = new CpuTiTgmr(trace, cpu->m_powerScale);
526 /* add a fake trace event if periodicity == 0 */
527 if (trace && xbt_dynar_length(trace->s_list.event_list) > 1) {
529 xbt_dynar_get_cpy(trace->s_list.event_list,
530 xbt_dynar_length(trace->s_list.event_list) - 1, &val);
531 if (val.delta == 0) {
532 tmgr_trace_t empty_trace;
533 empty_trace = tmgr_empty_trace_new();
535 tmgr_history_add_trace(history, empty_trace,
536 cpu->p_availTrace->m_lastTime, 0, cpu);
545 CpuTi::CpuTi(CpuTiModel *model, const char *name, xbt_dynar_t powerPeak,
546 int pstate, double powerScale, tmgr_trace_t powerTrace, int core,
547 e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
548 xbt_dict_t properties)
549 : Cpu(model, name, properties, core, 0, powerScale)
552 setState(stateInitial);
553 m_powerScale = powerScale;
555 tmgr_trace_t empty_trace;
557 xbt_assert(core==1,"Multi-core not handled with this model yet");
558 XBT_DEBUG("power scale %f", powerScale);
559 p_availTrace = new CpuTiTgmr(powerTrace, powerScale);
561 p_actionSet = new ActionTiList();
565 xbt_dynar_get_cpy(powerPeak, 0, &m_powerPeak);
566 xbt_dynar_free(&powerPeak); /* kill memory leak */
567 XBT_DEBUG("CPU create: peak=%f", m_powerPeak);
570 p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, this);
571 if (powerTrace && xbt_dynar_length(powerTrace->s_list.event_list) > 1) {
572 // add a fake trace event if periodicity == 0
573 xbt_dynar_get_cpy(powerTrace->s_list.event_list,
574 xbt_dynar_length(powerTrace->s_list.event_list) - 1, &val);
575 if (val.delta == 0) {
576 empty_trace = tmgr_empty_trace_new();
578 tmgr_history_add_trace(history, empty_trace,
579 p_availTrace->m_lastTime, 0, this);
590 void CpuTi::updateState(tmgr_trace_event_t event_type,
591 double value, double date)
595 if (event_type == p_powerEvent) {
596 tmgr_trace_t power_trace;
600 XBT_DEBUG("Finish trace date: %f value %f date %f", surf_get_clock(),
602 /* update remaining of actions and put in modified cpu swag */
603 updateRemainingAmount(date);
607 power_trace = p_availTrace->p_powerTrace;
608 xbt_dynar_get_cpy(power_trace->s_list.event_list,
609 xbt_dynar_length(power_trace->s_list.event_list) - 1, &val);
612 m_powerScale = val.value;
614 trace = new CpuTiTgmr(TRACE_FIXED, val.value);
615 XBT_DEBUG("value %f", val.value);
617 p_availTrace = trace;
619 if (tmgr_trace_event_free(event_type))
622 } else if (event_type == p_stateEvent) {
624 if(getState() == SURF_RESOURCE_OFF)
625 xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
626 setState(SURF_RESOURCE_ON);
628 setState(SURF_RESOURCE_OFF);
630 /* put all action running on cpu to failed */
631 for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
632 ; it != itend ; ++it) {
634 if (action->getState() == SURF_ACTION_RUNNING
635 || action->getState() == SURF_ACTION_READY
636 || action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) {
637 action->setFinishTime(date);
638 action->setState(SURF_ACTION_FAILED);
639 if (action->m_indexHeap >= 0) {
640 CpuTiAction *heap_act = (CpuTiAction*)
641 xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, action->m_indexHeap);
642 if (heap_act != action)
648 if (tmgr_trace_event_free(event_type))
651 XBT_CRITICAL("Unknown event ! \n");
658 void CpuTi::updateActionsFinishTime(double now)
661 double sum_priority = 0.0, total_area, min_finish = -1;
663 /* update remaning amount of actions */
664 updateRemainingAmount(now);
666 for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
667 ; it != itend ; ++it) {
669 /* action not running, skip it */
670 if (action->getStateSet() !=
671 surf_cpu_model_pm->getRunningActionSet())
674 /* bogus priority, skip it */
675 if (action->getPriority() <= 0)
678 /* action suspended, skip it */
679 if (action->m_suspended != 0)
682 sum_priority += 1.0 / action->getPriority();
684 m_sumPriority = sum_priority;
686 for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
687 ; it != itend ; ++it) {
690 /* action not running, skip it */
691 if (action->getStateSet() !=
692 surf_cpu_model_pm->getRunningActionSet())
695 /* verify if the action is really running on cpu */
696 if (action->m_suspended == 0 && action->getPriority() > 0) {
697 /* total area needed to finish the action. Used in trace integration */
699 (action->getRemains()) * sum_priority *
700 action->getPriority();
702 total_area /= m_powerPeak;
704 action->setFinishTime(p_availTrace->solve(now, total_area));
705 /* verify which event will happen before (max_duration or finish time) */
706 if (action->getMaxDuration() != NO_MAX_DURATION &&
707 action->getStartTime() + action->getMaxDuration() < action->m_finish)
708 min_finish = action->getStartTime() + action->getMaxDuration();
710 min_finish = action->m_finish;
712 /* put the max duration time on heap */
713 if (action->getMaxDuration() != NO_MAX_DURATION)
714 min_finish = action->getStartTime() + action->getMaxDuration();
716 /* add in action heap */
717 XBT_DEBUG("action(%p) index %d", action, action->m_indexHeap);
718 if (action->m_indexHeap >= 0) {
719 CpuTiAction *heap_act = (CpuTiAction*)
720 xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, action->m_indexHeap);
721 if (heap_act != action)
724 if (min_finish != NO_MAX_DURATION)
725 xbt_heap_push(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, action, min_finish);
728 ("Update finish time: Cpu(%s) Action: %p, Start Time: %f Finish Time: %f Max duration %f",
729 getName(), action, action->getStartTime(),
731 action->getMaxDuration());
733 /* remove from modified cpu */
739 return !p_actionSet->empty();
742 double CpuTi::getAvailableSpeed()
744 m_powerScale = p_availTrace->getPowerScale(surf_get_clock());
745 return Cpu::getAvailableSpeed();
749 * \brief Update the remaining amount of actions
751 * \param now Current time
753 void CpuTi::updateRemainingAmount(double now)
758 /* already updated */
759 if (m_lastUpdate >= now)
762 /* calcule the surface */
763 area_total = p_availTrace->integrate(m_lastUpdate, now) * m_powerPeak;
764 XBT_DEBUG("Flops total: %f, Last update %f", area_total,
767 for(ActionTiList::iterator it(p_actionSet->begin()), itend(p_actionSet->end())
768 ; it != itend ; ++it) {
770 /* action not running, skip it */
771 if (action->getStateSet() !=
772 getModel()->getRunningActionSet())
775 /* bogus priority, skip it */
776 if (action->getPriority() <= 0)
779 /* action suspended, skip it */
780 if (action->m_suspended != 0)
783 /* action don't need update */
784 if (action->getStartTime() >= now)
787 /* skip action that are finishing now */
788 if (action->m_finish >= 0
789 && action->m_finish <= now)
792 /* update remaining */
793 action->updateRemains(area_total / (m_sumPriority * action->getPriority()));
794 XBT_DEBUG("Update remaining action(%p) remaining %f", action,
800 CpuAction *CpuTi::execute(double size)
802 XBT_IN("(%s,%g)", getName(), size);
803 CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), size, getState() != SURF_RESOURCE_ON, this);
805 p_actionSet->push_back(*action);
812 CpuAction *CpuTi::sleep(double duration)
815 duration = MAX(duration, sg_surf_precision);
817 XBT_IN("(%s,%g)", getName(), duration);
818 CpuTiAction *action = new CpuTiAction(static_cast<CpuTiModel*>(getModel()), 1.0, getState() != SURF_RESOURCE_ON, this);
820 action->m_maxDuration = duration;
821 action->m_suspended = 2;
822 if (duration == NO_MAX_DURATION) {
823 /* Move to the *end* of the corresponding action set. This convention
824 is used to speed up update_resource_state */
825 action->getStateSet()->erase(action->getStateSet()->iterator_to(*action));
826 action->p_stateSet = static_cast<CpuTiModel*>(getModel())->p_runningActionSetThatDoesNotNeedBeingChecked;
827 action->getStateSet()->push_back(*action);
830 p_actionSet->push_back(*action);
836 void CpuTi::modified(bool modified){
837 CpuTiList *modifiedCpu = static_cast<CpuTiModel*>(getModel())->p_modifiedCpu;
840 modifiedCpu->push_back(*this);
844 modifiedCpu->erase(modifiedCpu->iterator_to(*this));
853 static void cpu_ti_action_update_index_heap(void *action, int i)
855 ((CpuTiAction*)action)->updateIndexHeap(i);
858 CpuTiAction::CpuTiAction(CpuTiModel *model_, double cost, bool failed,
860 : CpuAction(model_, cost, failed)
862 m_suspended = 0; /* Should be useless because of the
863 calloc but it seems to help valgrind... */
866 p_cpu->modified(true);
869 void CpuTiAction::updateIndexHeap(int i)
874 void CpuTiAction::setState(e_surf_action_state_t state)
876 CpuAction::setState(state);
877 p_cpu->modified(true);
880 int CpuTiAction::unref()
884 if (actionHook::is_linked())
885 getStateSet()->erase(getStateSet()->iterator_to(*this));
886 /* remove from action_set */
887 if (actionTiHook::is_linked())
888 p_cpu->p_actionSet->erase(p_cpu->p_actionSet->iterator_to(*this));
889 /* remove from heap */
890 xbt_heap_remove(static_cast<CpuTiModel*>(getModel())->p_tiActionHeap, this->m_indexHeap);
891 p_cpu->modified(true);
898 void CpuTiAction::cancel()
900 this->setState(SURF_ACTION_FAILED);
901 xbt_heap_remove(getModel()->getActionHeap(), this->m_indexHeap);
902 p_cpu->modified(true);
906 void CpuTiAction::suspend()
908 XBT_IN("(%p)", this);
909 if (m_suspended != 2) {
911 xbt_heap_remove(getModel()->getActionHeap(), m_indexHeap);
912 p_cpu->modified(true);
917 void CpuTiAction::resume()
919 XBT_IN("(%p)", this);
920 if (m_suspended != 2) {
922 p_cpu->modified(true);
927 bool CpuTiAction::isSuspended()
929 return m_suspended == 1;
932 void CpuTiAction::setMaxDuration(double duration)
936 XBT_IN("(%p,%g)", this, duration);
938 m_maxDuration = duration;
941 min_finish = (getStartTime() + getMaxDuration()) < getFinishTime() ?
942 (getStartTime() + getMaxDuration()) : getFinishTime();
944 min_finish = getFinishTime();
946 /* add in action heap */
947 if (m_indexHeap >= 0) {
948 CpuTiAction *heap_act = (CpuTiAction*)
949 xbt_heap_remove(getModel()->getActionHeap(), m_indexHeap);
950 if (heap_act != this)
953 xbt_heap_push(getModel()->getActionHeap(), this, min_finish);
958 void CpuTiAction::setPriority(double priority)
960 XBT_IN("(%p,%g)", this, priority);
961 m_priority = priority;
962 p_cpu->modified(true);
966 double CpuTiAction::getRemains()
968 XBT_IN("(%p)", this);
969 p_cpu->updateRemainingAmount(surf_get_clock());
974 #endif /* SURF_MODEL_CPUTI_H_ */