2 #include "trace_mgr_private.h"
5 #ifndef SURF_MODEL_CPUTI_H_
6 #define SURF_MODEL_CPUTI_H_
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_ti, surf,
10 "Logging specific to the SURF CPU TRACE INTEGRATION module");
13 static xbt_swag_t cpu_ti_running_action_set_that_does_not_need_being_checked;
14 static xbt_swag_t cpu_ti_modified_cpu;
15 static xbt_heap_t cpu_ti_action_heap;
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);
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 %lf ind %d integral %lf ind + 1 %lf ind %lf time +1 %lf time %lf",
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]);
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 %lf = %lf", 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 %lf total %lf", 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: %lf reduced_a: %lf", 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;
316 /* no availability file, fixed trace */
318 m_type = TRACE_FIXED;
320 XBT_DEBUG("No availabily trace. Constant value = %lf", value);
324 /* only one point available, fixed trace */
325 if (xbt_dynar_length(power_trace->s_list.event_list) == 1) {
326 xbt_dynar_get_cpy(power_trace->s_list.event_list, 0, &val);
327 m_type = TRACE_FIXED;
332 m_type = TRACE_DYNAMIC;
333 p_powerTrace = power_trace;
335 /* count the total time of trace file */
336 xbt_dynar_foreach(power_trace->s_list.event_list, cpt, val) {
337 total_time += val.delta;
339 p_trace = new CpuTiTrace(power_trace);
340 m_lastTime = total_time;
341 m_total = p_trace->integrateSimple(0, total_time);
343 XBT_DEBUG("Total integral %lf, last_time %lf ",
344 m_total, m_lastTime);
348 * \brief Binary search in array.
349 * It returns the first point of the interval in which "a" is.
351 * \param a Value to search
352 * \param low Low bound to search in array
353 * \param high Upper bound to search in array
354 * \return Index of point
356 int CpuTiTrace::binarySearch(double *array, double a, int low, int high)
358 xbt_assert(low < high, "Wrong parameters: low (%d) should be smaller than"
359 " high (%d)", low, high);
363 mid = low + (high - low) / 2;
364 XBT_DEBUG("a %lf low %d high %d mid %d value %lf", a, low, high, mid,
372 while (low < high - 1);
381 CpuTiModel::CpuTiModel() : CpuModel("cpu_ti")
383 xbt_assert(!surf_cpu_model,"CPU model already initialized. This should not happen.");
384 surf_cpu_model = this;
388 cpu_ti_running_action_set_that_does_not_need_being_checked =
389 xbt_swag_new(xbt_swag_offset(action, p_stateHookup));
391 cpu_ti_modified_cpu =
392 xbt_swag_new(xbt_swag_offset(cpu, p_modifiedCpuHookup));
394 cpu_ti_action_heap = xbt_heap_new(8, NULL);
395 xbt_heap_set_update_callback(cpu_ti_action_heap,
396 cpu_ti_action_update_index_heap);
397 /* Define callbacks */
398 //TODO sg_platf_host_add_cb(parse_cpu_ti_init);
399 //TODO sg_platf_postparse_add_cb(add_traces_cpu_ti);
401 xbt_dynar_push(model_list, &surf_cpu_model);
404 CpuTiModel::~CpuTiModel()
407 xbt_lib_cursor_t cursor;
410 xbt_lib_foreach(host_lib, cursor, key, cpu){
411 if(cpu[SURF_CPU_LEVEL])
413 CpuTiPtr CPU = dynamic_cast<CpuTiPtr>(static_cast<ResourcePtr>(cpu[SURF_CPU_LEVEL]));
414 xbt_swag_free(CPU->p_actionSet);
415 delete CPU->p_availTrace;
419 delete surf_cpu_model;
420 surf_cpu_model = NULL;
423 (cpu_ti_running_action_set_that_does_not_need_being_checked);
424 xbt_swag_free(cpu_ti_modified_cpu);
425 cpu_ti_running_action_set_that_does_not_need_being_checked = NULL;
426 xbt_heap_free(cpu_ti_action_heap);
429 void CpuTiModel::parseInit(sg_platf_host_cbarg_t host)
431 createResource(host->id,
441 CpuTiPtr CpuTiModel::createResource(const char *name,
444 tmgr_trace_t powerTrace,
446 e_surf_resource_state_t stateInitial,
447 tmgr_trace_t stateTrace,
448 xbt_dict_t cpuProperties)
450 tmgr_trace_t empty_trace;
452 CpuTiActionPtr cpuAction;
453 xbt_assert(core==1,"Multi-core not handled with this model yet");
454 xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)),
455 "Host '%s' declared several times in the platform file",
457 CpuTiPtr cpu = new CpuTi(this, name, powerPeak, powerScale, powerTrace,
458 core, stateInitial, stateTrace, cpuProperties);
459 xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, static_cast<ResourcePtr>(cpu));
460 return (CpuTiPtr) xbt_lib_get_elm_or_null(host_lib, name);
463 CpuTiActionPtr CpuTiModel::createAction(double cost, bool failed)
465 return NULL;//new CpuTiAction(this, cost, failed);
468 double CpuTiModel::shareResources(double now)
470 void *_cpu, *_cpu_next;
471 double min_action_duration = -1;
473 /* iterates over modified cpus to update share resources */
474 xbt_swag_foreach_safe(_cpu, _cpu_next, cpu_ti_modified_cpu) {
475 ((CpuTiPtr)_cpu)->updateActionFinishDate(now);
477 /* get the min next event if heap not empty */
478 if (xbt_heap_size(cpu_ti_action_heap) > 0)
479 min_action_duration = xbt_heap_maxkey(cpu_ti_action_heap) - now;
481 XBT_DEBUG("Share resources, min next event date: %lf", min_action_duration);
483 return min_action_duration;
486 void CpuTiModel::updateActionsState(double now, double delta)
488 while ((xbt_heap_size(cpu_ti_action_heap) > 0)
489 && (xbt_heap_maxkey(cpu_ti_action_heap) <= now)) {
490 CpuTiActionPtr action = (CpuTiActionPtr) xbt_heap_pop(cpu_ti_action_heap);
491 XBT_DEBUG("Action %p: finish", action);
492 action->m_finish = surf_get_clock();
493 /* set the remains to 0 due to precision problems when updating the remaining amount */
494 action->m_remains = 0;
495 action->setState(SURF_ACTION_DONE);
496 /* update remaining amout of all actions */
497 action->p_cpu->updateRemainingAmount(surf_get_clock());
501 void CpuTiModel::addTraces()
503 xbt_dict_cursor_t cursor = NULL;
504 char *trace_name, *elm;
506 static int called = 0;
512 /* connect all traces relative to hosts */
513 xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
514 tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
515 CpuTiPtr cpu = (CpuTiPtr) surf_cpu_resource_priv(surf_cpu_resource_by_name(elm));
517 xbt_assert(cpu, "Host %s undefined", elm);
518 xbt_assert(trace, "Trace %s undefined", trace_name);
520 if (cpu->p_stateEvent) {
521 XBT_DEBUG("Trace already configured for this CPU(%s), ignoring it",
525 XBT_DEBUG("Add state trace: %s to CPU(%s)", trace_name, elm);
526 cpu->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, cpu);
529 xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
530 tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
531 CpuTiPtr cpu = (CpuTiPtr) surf_cpu_resource_priv(surf_cpu_resource_by_name(elm));
533 xbt_assert(cpu, "Host %s undefined", elm);
534 xbt_assert(trace, "Trace %s undefined", trace_name);
536 XBT_DEBUG("Add power trace: %s to CPU(%s)", trace_name, elm);
537 if (cpu->p_availTrace)
538 delete cpu->p_availTrace;
540 cpu->p_availTrace = new CpuTiTgmr(trace, cpu->m_powerScale);
542 /* add a fake trace event if periodicity == 0 */
543 if (trace && xbt_dynar_length(trace->s_list.event_list) > 1) {
545 xbt_dynar_get_cpy(trace->s_list.event_list,
546 xbt_dynar_length(trace->s_list.event_list) - 1, &val);
547 if (val.delta == 0) {
548 tmgr_trace_t empty_trace;
549 empty_trace = tmgr_empty_trace_new();
551 tmgr_history_add_trace(history, empty_trace,
552 cpu->p_availTrace->m_lastTime, 0, cpu);
561 CpuTi::CpuTi(CpuTiModelPtr model, const char *name, double powerPeak,
562 double powerScale, tmgr_trace_t powerTrace, int core,
563 e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
564 xbt_dict_t properties) :
565 Cpu(model, name, properties), p_stateCurrent(stateInitial) {
566 m_powerPeak = powerPeak;
567 m_powerScale = powerScale;
569 tmgr_trace_t empty_trace;
571 xbt_assert(core==1,"Multi-core not handled with this model yet");
572 XBT_DEBUG("power scale %lf", powerScale);
573 p_availTrace = new CpuTiTgmr(powerTrace, powerScale);
575 p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, this);
576 if (powerTrace && xbt_dynar_length(powerTrace->s_list.event_list) > 1) {
577 // add a fake trace event if periodicity == 0
578 xbt_dynar_get_cpy(powerTrace->s_list.event_list,
579 xbt_dynar_length(powerTrace->s_list.event_list) - 1, &val);
580 if (val.delta == 0) {
581 empty_trace = tmgr_empty_trace_new();
583 tmgr_history_add_trace(history, empty_trace,
584 p_availTrace->m_lastTime, 0, this);
589 void CpuTi::updateState(tmgr_trace_event_t event_type,
590 double value, double date)
593 CpuTiActionPtr action;
595 surf_watched_hosts();
597 if (event_type == p_powerEvent) {
598 tmgr_trace_t power_trace;
602 XBT_DEBUG("Finish trace date: %lf value %lf date %lf", surf_get_clock(),
604 /* update remaining of actions and put in modified cpu swag */
605 updateRemainingAmount(date);
606 xbt_swag_insert(this, cpu_ti_modified_cpu);
608 power_trace = p_availTrace->p_powerTrace;
609 xbt_dynar_get_cpy(power_trace->s_list.event_list,
610 xbt_dynar_length(power_trace->s_list.event_list) - 1, &val);
613 m_powerScale = val.value;
615 trace = new CpuTiTgmr(TRACE_FIXED, val.value);
616 XBT_DEBUG("value %lf", val.value);
618 p_availTrace = trace;
620 if (tmgr_trace_event_free(event_type))
623 } else if (event_type == p_stateEvent) {
625 p_stateCurrent = SURF_RESOURCE_ON;
627 p_stateCurrent = SURF_RESOURCE_OFF;
629 /* put all action running on cpu to failed */
630 xbt_swag_foreach(_action, p_actionSet) {
631 action = (CpuTiActionPtr) _action;
632 if (action->getState() == SURF_ACTION_RUNNING
633 || action->getState() == SURF_ACTION_READY
634 || action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) {
635 action->m_finish = date;
636 action->setState(SURF_ACTION_FAILED);
637 if (action->m_indexHeap >= 0) {
638 CpuTiActionPtr heap_act = (CpuTiActionPtr)
639 xbt_heap_remove(cpu_ti_action_heap, action->m_indexHeap);
640 if (heap_act != action)
646 if (tmgr_trace_event_free(event_type))
649 XBT_CRITICAL("Unknown event ! \n");
656 void CpuTi::updateActionFinishDate(double now)
659 CpuTiActionPtr action;
660 double sum_priority = 0.0, total_area, min_finish = -1;
662 /* update remaning amount of actions */
663 updateRemainingAmount(now);
665 xbt_swag_foreach(_action, p_actionSet) {
666 action = (CpuTiActionPtr) _action;
667 /* action not running, skip it */
668 if (action->p_stateSet !=
669 surf_cpu_model->p_runningActionSet)
672 /* bogus priority, skip it */
673 if (action->m_priority <= 0)
676 /* action suspended, skip it */
677 if (action->m_suspended != 0)
680 sum_priority += 1.0 / action->m_priority;
682 m_sumPriority = sum_priority;
684 xbt_swag_foreach(_action, p_actionSet) {
685 action = (CpuTiActionPtr) _action;
687 /* action not running, skip it */
688 if (action->p_stateSet !=
689 surf_cpu_model->p_runningActionSet)
692 /* verify if the action is really running on cpu */
693 if (action->m_suspended == 0 && action->m_priority > 0) {
694 /* total area needed to finish the action. Used in trace integration */
696 (action->m_remains) * sum_priority *
699 total_area /= m_powerPeak;
701 action->m_finish = p_availTrace->solve(now, total_area);
702 /* verify which event will happen before (max_duration or finish time) */
703 if (action->m_maxDuration != NO_MAX_DURATION &&
704 action->m_start + action->m_maxDuration < action->m_finish)
705 min_finish = action->m_start + action->m_maxDuration;
707 min_finish = action->m_finish;
709 /* put the max duration time on heap */
710 if (action->m_maxDuration != NO_MAX_DURATION)
711 min_finish = action->m_start + action->m_maxDuration;
713 /* add in action heap */
714 XBT_DEBUG("action(%p) index %d", action, action->m_indexHeap);
715 if (action->m_indexHeap >= 0) {
716 CpuTiActionPtr heap_act = (CpuTiActionPtr)
717 xbt_heap_remove(cpu_ti_action_heap, action->m_indexHeap);
718 if (heap_act != action)
721 if (min_finish != NO_MAX_DURATION)
722 xbt_heap_push(cpu_ti_action_heap, action, min_finish);
725 ("Update finish time: Cpu(%s) Action: %p, Start Time: %lf Finish Time: %lf Max duration %lf",
726 m_name, action, action->m_start,
728 action->m_maxDuration);
730 /* remove from modified cpu */
731 xbt_swag_remove(this, cpu_ti_modified_cpu);
734 CpuTiModelPtr CpuTi::getModel()
736 return static_cast<CpuTiModelPtr>(p_model);
741 return xbt_swag_size(p_actionSet);
746 double CpuTi::getAvailableSpeed()
748 m_powerScale = 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)
761 CpuTiActionPtr action;
763 /* already updated */
764 if (m_lastUpdate >= now)
767 /* calcule the surface */
768 area_total = p_availTrace->integrate(m_lastUpdate, now) * m_powerPeak;
769 XBT_DEBUG("Flops total: %lf, Last update %lf", area_total,
772 xbt_swag_foreach(_action, p_actionSet) {
773 action = (CpuTiActionPtr) _action;
774 /* action not running, skip it */
775 if (action->p_stateSet !=
776 getModel()->p_runningActionSet)
779 /* bogus priority, skip it */
780 if (action->m_priority <= 0)
783 /* action suspended, skip it */
784 if (action->m_suspended != 0)
787 /* action don't need update */
788 if (action->m_start >= now)
791 /* skip action that are finishing now */
792 if (action->m_finish >= 0
793 && action->m_finish <= now)
796 /* update remaining */
797 double_update(&(action->m_remains),
798 area_total / (m_sumPriority *
799 action->m_priority));
800 XBT_DEBUG("Update remaining action(%p) remaining %lf", action,
806 CpuActionPtr CpuTi::execute(double size)
808 return execute(size);
811 CpuTiActionPtr CpuTi::_execute(double size)
813 XBT_IN("(%s,%g)", m_name, size);
814 CpuTiActionPtr action = new CpuTiAction((CpuTiModelPtr) p_model, size, p_stateCurrent != SURF_RESOURCE_ON);
816 action->p_cpu = this;
817 action->m_indexHeap = -1;
819 xbt_swag_insert(this, cpu_ti_modified_cpu);
821 xbt_swag_insert(action, p_actionSet);
823 action->m_suspended = 0; /* Should be useless because of the
824 calloc but it seems to help valgrind... */
831 CpuActionPtr CpuTi::sleep(double duration)
834 duration = MAX(duration, MAXMIN_PRECISION);
836 XBT_IN("(%s,%g)", m_name, duration);
837 CpuTiActionPtr action = _execute(1.0);
838 action->m_maxDuration = duration;
839 action->m_suspended = 2;
840 if (duration == NO_MAX_DURATION) {
841 /* Move to the *end* of the corresponding action set. This convention
842 is used to speed up update_resource_state */
843 xbt_swag_remove(static_cast<ActionPtr>(action), action->p_stateSet);
844 action->p_stateSet = cpu_ti_running_action_set_that_does_not_need_being_checked;
845 xbt_swag_insert(static_cast<ActionPtr>(action), action->p_stateSet);
851 void CpuTi::printCpuTiModel()
853 std::cout << getModel()->getName() << "<<plop"<< std::endl;
859 static void cpu_ti_action_update_index_heap(void *action, int i)
861 ((CpuTiActionPtr)action)->updateIndexHeap(i);
863 void CpuTiAction::updateIndexHeap(int i)
868 void CpuTiAction::setState(e_surf_action_state_t state)
870 Action::setState(state);
871 xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
874 int CpuTiAction::unref()
878 xbt_swag_remove(static_cast<ActionPtr>(this), p_stateSet);
879 /* remove from action_set */
880 xbt_swag_remove(this, ((CpuTiPtr)surf_cpu_resource_priv(p_cpu))->p_actionSet);
881 /* remove from heap */
882 xbt_heap_remove(cpu_ti_action_heap, this->m_indexHeap);
883 xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
890 void CpuTiAction::cancel()
892 this->setState(SURF_ACTION_FAILED);
893 xbt_heap_remove(cpu_ti_action_heap, this->m_indexHeap);
894 xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
898 void CpuTiAction::recycle()
903 void CpuTiAction::suspend()
905 XBT_IN("(%p)", this);
906 if (m_suspended != 2) {
908 xbt_heap_remove(cpu_ti_action_heap, m_indexHeap);
909 xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
914 void CpuTiAction::resume()
916 XBT_IN("(%p)", this);
917 if (m_suspended != 2) {
919 xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
924 bool CpuTiAction::isSuspended()
926 return m_suspended == 1;
929 void CpuTiAction::setMaxDuration(double duration)
933 XBT_IN("(%p,%g)", this, duration);
935 m_maxDuration = duration;
938 min_finish = (m_start + m_maxDuration) < m_finish ?
939 (m_start + m_maxDuration) : m_finish;
941 min_finish = m_finish;
943 /* add in action heap */
944 if (m_indexHeap >= 0) {
945 CpuTiActionPtr heap_act = (CpuTiActionPtr)
946 xbt_heap_remove(cpu_ti_action_heap, m_indexHeap);
947 if (heap_act != this)
950 xbt_heap_push(cpu_ti_action_heap, this, min_finish);
955 void CpuTiAction::setPriority(double priority)
957 XBT_IN("(%p,%g)", this, priority);
958 m_priority = priority;
959 xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
963 double CpuTiAction::getRemains()
965 XBT_IN("(%p)", this);
966 ((CpuTiPtr)p_cpu)->updateRemainingAmount(surf_get_clock());
971 static void check() {
972 CpuTiActionPtr cupAction = new CpuTiAction(NULL, 0, true);
975 #endif /* SURF_MODEL_CPUTI_H_ */