2 //#include "solver.hpp"
3 #include "trace_mgr_private.h"
6 #ifndef SURF_MODEL_CPUTI_H_
7 #define SURF_MODEL_CPUTI_H_
9 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surfpp_cpu_tii, surfpp,
10 "Logging specific to the SURF CPU TRACE INTEGRATION module");
12 static xbt_swag_t cpu_ti_running_action_set_that_does_not_need_being_checked;
13 static xbt_swag_t cpu_ti_modified_cpu;
14 static xbt_heap_t cpu_ti_action_heap;
16 static CpuTiModelPtr surf_cpu_model = NULL;
18 static void cpu_ti_action_update_index_heap(void *action, int i);
24 CpuTiTrace::CpuTiTrace(tmgr_trace_t power_trace)
31 p_timePoints = (double*) xbt_malloc0(sizeof(double) *
32 (xbt_dynar_length(power_trace->s_list.event_list) + 1));
33 p_integral = (double*) xbt_malloc0(sizeof(double) *
34 (xbt_dynar_length(power_trace->s_list.event_list) + 1));
35 m_nbPoints = xbt_dynar_length(power_trace->s_list.event_list);
36 xbt_dynar_foreach(power_trace->s_list.event_list, cpt, val) {
37 p_timePoints[i] = time;
38 p_integral[i] = integral;
39 integral += val.delta * val.value;
43 p_timePoints[i] = time;
44 p_integral[i] = integral;
47 CpuTiTrace::~CpuTiTrace()
49 xbt_free(p_timePoints);
53 CpuTiTgmr::~CpuTiTgmr()
60 * \brief Integrate trace
62 * Wrapper around surf_cpu_integrate_trace_simple() to get
65 * \param trace Trace structure.
66 * \param a Begin of interval
67 * \param b End of interval
68 * \return the integrate value. -1 if an error occurs.
70 double CpuTiTgmr::integrate(double a, double b)
77 if ((a < 0.0) || (a > b)) {
79 ("Error, invalid integration interval [%.2f,%.2f]. You probably have a task executing with negative computation amount. Check your code.",
86 if (m_type == TRACE_FIXED) {
87 return ((b - a) * m_value);
90 if (ceil(a / m_lastTime) == a / m_lastTime)
91 a_index = 1 + (int) (ceil(a / m_lastTime));
93 a_index = (int) (ceil(a / m_lastTime));
95 b_index = (int) (floor(b / m_lastTime));
97 if (a_index > b_index) { /* Same chunk */
98 return p_trace->integrateSimple(a - (a_index -
105 first_chunk = p_trace->integrateSimple(a - (a_index -
109 middle_chunk = (b_index - a_index) * m_total;
110 last_chunk = p_trace->integrateSimple(0.0,
115 XBT_DEBUG("first_chunk=%.2f middle_chunk=%.2f last_chunk=%.2f\n",
116 first_chunk, middle_chunk, last_chunk);
118 return (first_chunk + middle_chunk + last_chunk);
122 * \brief Auxiliary function to calculate the integral between a and b.
123 * It simply calculates the integral at point a and b and returns the difference
125 * \param trace Trace structure
126 * \param a Initial point
127 * \param b Final point
130 double CpuTiTrace::integrateSimple(double a, double b)
132 return integrateSimplePoint(b) - integrateSimplePoint(a);
136 * \brief Auxiliary function to calculate the integral at point a.
137 * \param trace Trace structure
141 double CpuTiTrace::integrateSimplePoint(double a)
146 ind = binarySearch(p_timePoints, a, 0, m_nbPoints - 1);
147 integral += p_integral[ind];
149 ("a %lf ind %d integral %lf ind + 1 %lf ind %lf time +1 %lf time %lf",
150 a, ind, integral, p_integral[ind + 1], p_integral[ind],
151 p_timePoints[ind + 1], p_timePoints[ind]);
152 double_update(&a_aux, p_timePoints[ind]);
155 ((p_integral[ind + 1] -
156 p_integral[ind]) / (p_timePoints[ind + 1] -
157 p_timePoints[ind])) * (a - p_timePoints[ind]);
158 XBT_DEBUG("Integral a %lf = %lf", a, integral);
164 * \brief Calculate the time needed to execute "amount" on cpu.
166 * Here, amount can span multiple trace periods
168 * \param trace CPU trace structure
169 * \param a Initial time
170 * \param amount Amount to be executed
173 double CpuTiTgmr::solve(double a, double amount)
177 double reduced_amount;
181 /* Fix very small negative numbers */
182 if ((a < 0.0) && (a > -EPSILON)) {
185 if ((amount < 0.0) && (amount > -EPSILON)) {
190 if ((a < 0.0) || (amount < 0.0)) {
192 ("Error, invalid parameters [a = %.2f, amount = %.2f]. You probably have a task executing with negative computation amount. Check your code.",
197 /* At this point, a and amount are positive */
199 if (amount < EPSILON)
202 /* Is the trace fixed ? */
203 if (m_type == TRACE_FIXED) {
204 return (a + (amount / m_value));
207 XBT_DEBUG("amount %lf total %lf", amount, m_total);
208 /* Reduce the problem to one where amount <= trace_total */
209 quotient = (int) (floor(amount / m_total));
210 reduced_amount = (m_total) * ((amount / m_total) -
211 floor(amount / m_total));
212 reduced_a = a - (m_lastTime) * (int) (floor(a / m_lastTime));
214 XBT_DEBUG("Quotient: %d reduced_amount: %lf reduced_a: %lf", quotient,
215 reduced_amount, reduced_a);
217 /* Now solve for new_amount which is <= trace_total */
219 fprintf(stderr,"reduced_a = %.2f\n",reduced_a);
220 fprintf(stderr,"reduced_amount = %.2f\n",reduced_amount);
222 reduced_b = solveSomewhatSimple(reduced_a, reduced_amount);
224 /* Re-map to the original b and amount */
225 b = (m_lastTime) * (int) (floor(a / m_lastTime)) +
226 (quotient * m_lastTime) + reduced_b;
231 * \brief Auxiliary function to solve integral
233 * Here, amount is <= trace->total
234 * and a <=trace->last_time
237 double CpuTiTgmr::solveSomewhatSimple(double a, double amount)
239 double amount_till_end;
242 XBT_DEBUG("Solve integral: [%.2f, amount=%.2f]", a, amount);
243 amount_till_end = integrate(a, m_lastTime);
245 fprintf(stderr,"amount_till_end=%.2f\n",amount_till_end);
248 if (amount_till_end > amount) {
249 b = p_trace->solveSimple(a, amount);
251 b = m_lastTime + p_trace->solveSimple(0.0, amount - amount_till_end);
257 * \brief Auxiliary function to solve integral.
258 * It returns the date when the requested amount of flops is available
259 * \param trace Trace structure
260 * \param a Initial point
261 * \param amount Amount of flops
262 * \return The date when amount is available.
264 double CpuTiTrace::solveSimple(double a, double amount)
269 integral_a = integrateSimplePoint(a);
270 ind = binarySearch(p_integral, integral_a + amount, 0, m_nbPoints - 1);
271 time = p_timePoints[ind];
273 (integral_a + amount -
274 p_integral[ind]) / ((p_integral[ind + 1] -
276 (p_timePoints[ind + 1] -
283 * \brief Auxiliary function to update the CPU power scale.
285 * This function uses the trace structure to return the power scale at the determined time a.
286 * \param trace Trace structure to search the updated power scale
288 * \return CPU power scale
290 double CpuTiTgmr::getPowerScale(double a)
296 reduced_a = a - floor(a / m_lastTime) * m_lastTime;
297 point = p_trace->binarySearch(p_trace->p_timePoints, reduced_a, 0,
298 p_trace->m_nbPoints - 1);
299 xbt_dynar_get_cpy(p_powerTrace->s_list.event_list, point, &val);
304 * \brief Creates a new integration trace from a tmgr_trace_t
306 * \param power_trace CPU availability trace
307 * \param value Percentage of CPU power available (useful to fixed tracing)
308 * \param spacing Initial spacing
309 * \return Integration trace structure
311 CpuTiTgmr::CpuTiTgmr(tmgr_trace_t power_trace, double value)
313 double total_time = 0.0;
317 /* no availability file, fixed trace */
319 m_type = TRACE_FIXED;
321 XBT_DEBUG("No availabily trace. Constant value = %lf", 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 %lf, last_time %lf ",
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 %lf low %d high %d mid %d value %lf", a, low, high, mid,
373 while (low < high - 1);
382 CpuTiModel::CpuTiModel() : CpuModel("cpu_ti")
384 xbt_assert(!surf_cpu_model,"CPU model already initialized. This should not happen.");
385 surf_cpu_model = this;
386 cpu_ti_action_heap = xbt_heap_new(8, NULL);
387 xbt_heap_set_update_callback(cpu_ti_action_heap,
388 cpu_ti_action_update_index_heap);
390 /* Define callbacks */
391 //TODO sg_platf_host_add_cb(parse_cpu_ti_init);
392 //TODO sg_platf_postparse_add_cb(add_traces_cpu_ti);
394 xbt_dynar_push(model_list, &surf_cpu_model);
397 CpuTiModel::~CpuTiModel()
400 xbt_lib_cursor_t cursor;
403 xbt_lib_foreach(host_lib, cursor, key, cpu){
404 if(cpu[SURF_CPU_LEVEL])
406 CpuTiPtr CPU = (CpuTiPtr) cpu[SURF_CPU_LEVEL];
407 xbt_swag_free(CPU->p_actionSet);
408 delete CPU->p_availTrace;
412 delete surf_cpu_model;
413 surf_cpu_model = NULL;
416 (cpu_ti_running_action_set_that_does_not_need_being_checked);
417 xbt_swag_free(cpu_ti_modified_cpu);
418 cpu_ti_running_action_set_that_does_not_need_being_checked = NULL;
419 xbt_heap_free(cpu_ti_action_heap);
422 void CpuTiModel::parseInit(sg_platf_host_cbarg_t host)
424 createResource(host->id,
434 CpuTiPtr CpuTiModel::createResource(const char *name,
437 tmgr_trace_t powerTrace,
439 e_surf_resource_state_t stateInitial,
440 tmgr_trace_t stateTrace,
441 xbt_dict_t cpuProperties)
443 tmgr_trace_t empty_trace;
445 CpuTiActionPtr cpuAction;
446 xbt_assert(core==1,"Multi-core not handled with this model yet");
447 xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)),
448 "Host '%s' declared several times in the platform file",
450 CpuTiPtr cpu = new CpuTi(this, name, powerPeak, powerScale, powerTrace,
451 core, stateInitial, stateTrace, cpuProperties);
452 xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu);
453 return (CpuTiPtr) xbt_lib_get_elm_or_null(host_lib, name);
456 CpuTiActionPtr CpuTiModel::createAction(double cost, bool failed)
458 return NULL;//new CpuTiAction(this, cost, failed);
461 double CpuTiModel::shareResources(double now)
463 void *_cpu, *_cpu_next;
464 double min_action_duration = -1;
466 /* iterates over modified cpus to update share resources */
467 xbt_swag_foreach_safe(_cpu, _cpu_next, cpu_ti_modified_cpu) {
468 ((CpuTiPtr)_cpu)->updateActionFinishDate(now);
470 /* get the min next event if heap not empty */
471 if (xbt_heap_size(cpu_ti_action_heap) > 0)
472 min_action_duration = xbt_heap_maxkey(cpu_ti_action_heap) - now;
474 XBT_DEBUG("Share resources, min next event date: %lf", min_action_duration);
476 return min_action_duration;
479 void CpuTiModel::updateActionsState(double now, double delta)
481 while ((xbt_heap_size(cpu_ti_action_heap) > 0)
482 && (xbt_heap_maxkey(cpu_ti_action_heap) <= now)) {
483 CpuTiActionPtr action = (CpuTiActionPtr) xbt_heap_pop(cpu_ti_action_heap);
484 XBT_DEBUG("Action %p: finish", action);
485 action->m_finish = surf_get_clock();
486 /* set the remains to 0 due to precision problems when updating the remaining amount */
487 action->m_remains = 0;
488 action->setState(SURF_ACTION_DONE);
489 /* update remaining amout of all actions */
490 action->p_cpu->updateRemainingAmount(surf_get_clock());
498 CpuTi::CpuTi(CpuTiModelPtr model, const char *name, double powerPeak,
499 double powerScale, tmgr_trace_t powerTrace, int core,
500 e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
501 xbt_dict_t properties) :
502 Cpu(model, name, properties), m_powerPeak(powerPeak), m_powerScale(powerScale),
503 p_stateCurrent(stateInitial) {
504 tmgr_trace_t empty_trace;
506 xbt_assert(core==1,"Multi-core not handled with this model yet");
507 XBT_DEBUG("power scale %lf", powerScale);
508 p_availTrace = new CpuTiTgmr(powerTrace, powerScale);
510 p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, this);
511 if (powerTrace && xbt_dynar_length(powerTrace->s_list.event_list) > 1) {
512 // add a fake trace event if periodicity == 0
513 xbt_dynar_get_cpy(powerTrace->s_list.event_list,
514 xbt_dynar_length(powerTrace->s_list.event_list) - 1, &val);
515 if (val.delta == 0) {
516 empty_trace = tmgr_empty_trace_new();
518 tmgr_history_add_trace(history, empty_trace,
519 p_availTrace->m_lastTime, 0, this);
524 void CpuTi::updateState(tmgr_trace_event_t event_type,
525 double value, double date)
528 CpuTiActionPtr action;
530 surf_watched_hosts();
532 if (event_type == p_powerEvent) {
533 tmgr_trace_t power_trace;
537 XBT_DEBUG("Finish trace date: %lf value %lf date %lf", surf_get_clock(),
539 /* update remaining of actions and put in modified cpu swag */
540 updateRemainingAmount(date);
541 xbt_swag_insert(this, cpu_ti_modified_cpu);
543 power_trace = p_availTrace->p_powerTrace;
544 xbt_dynar_get_cpy(power_trace->s_list.event_list,
545 xbt_dynar_length(power_trace->s_list.event_list) - 1, &val);
548 m_powerScale = val.value;
550 trace = new CpuTiTgmr(TRACE_FIXED, val.value);
551 XBT_DEBUG("value %lf", val.value);
553 p_availTrace = trace;
555 if (tmgr_trace_event_free(event_type))
558 } else if (event_type == p_stateEvent) {
560 p_stateCurrent = SURF_RESOURCE_ON;
562 p_stateCurrent = SURF_RESOURCE_OFF;
564 /* put all action running on cpu to failed */
565 xbt_swag_foreach(_action, p_actionSet) {
566 action = (CpuTiActionPtr) _action;
567 if (action->getState() == SURF_ACTION_RUNNING
568 || action->getState() == SURF_ACTION_READY
569 || action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) {
570 action->m_finish = date;
571 action->setState(SURF_ACTION_FAILED);
572 if (action->m_indexHeap >= 0) {
573 CpuTiActionPtr heap_act = (CpuTiActionPtr)
574 xbt_heap_remove(cpu_ti_action_heap, action->m_indexHeap);
575 if (heap_act != action)
581 if (tmgr_trace_event_free(event_type))
584 XBT_CRITICAL("Unknown event ! \n");
591 void CpuTi::updateActionFinishDate(double now)
594 CpuTiActionPtr action;
595 double sum_priority = 0.0, total_area, min_finish = -1;
597 /* update remaning amount of actions */
598 updateRemainingAmount(now);
600 xbt_swag_foreach(_action, p_actionSet) {
601 action = (CpuTiActionPtr) _action;
602 /* action not running, skip it */
603 if (action->p_stateSet !=
604 surf_cpu_model->p_runningActionSet)
607 /* bogus priority, skip it */
608 if (action->m_priority <= 0)
611 /* action suspended, skip it */
612 if (action->m_suspended != 0)
615 sum_priority += 1.0 / action->m_priority;
617 m_sumPriority = sum_priority;
619 xbt_swag_foreach(_action, p_actionSet) {
620 action = (CpuTiActionPtr) _action;
622 /* action not running, skip it */
623 if (action->p_stateSet !=
624 surf_cpu_model->p_runningActionSet)
627 /* verify if the action is really running on cpu */
628 if (action->m_suspended == 0 && action->m_priority > 0) {
629 /* total area needed to finish the action. Used in trace integration */
631 (action->m_remains) * sum_priority *
634 total_area /= m_powerPeak;
636 action->m_finish = p_availTrace->solve(now, total_area);
637 /* verify which event will happen before (max_duration or finish time) */
638 if (action->m_maxDuration != NO_MAX_DURATION &&
639 action->m_start + action->m_maxDuration < action->m_finish)
640 min_finish = action->m_start + action->m_maxDuration;
642 min_finish = action->m_finish;
644 /* put the max duration time on heap */
645 if (action->m_maxDuration != NO_MAX_DURATION)
646 min_finish = action->m_start + action->m_maxDuration;
648 /* add in action heap */
649 XBT_DEBUG("action(%p) index %d", action, action->m_indexHeap);
650 if (action->m_indexHeap >= 0) {
651 CpuTiActionPtr heap_act = (CpuTiActionPtr)
652 xbt_heap_remove(cpu_ti_action_heap, action->m_indexHeap);
653 if (heap_act != action)
656 if (min_finish != NO_MAX_DURATION)
657 xbt_heap_push(cpu_ti_action_heap, action, min_finish);
660 ("Update finish time: Cpu(%s) Action: %p, Start Time: %lf Finish Time: %lf Max duration %lf",
661 m_name, action, action->m_start,
663 action->m_maxDuration);
665 /* remove from modified cpu */
666 xbt_swag_remove(this, cpu_ti_modified_cpu);
669 CpuTiModelPtr CpuTi::getModel()
671 return static_cast<CpuTiModelPtr>(p_model);
676 return xbt_swag_size(p_actionSet);
679 e_surf_resource_state_t CpuTi::getState()
681 return m_stateCurrent;
684 double CpuTi::getSpeed(double load)
686 return load * m_powerPeak;
689 double CpuTi::getAvailableSpeed()
691 m_powerScale = p_availTrace->getPowerScale(surf_get_clock());
692 /* number between 0 and 1 */
696 void CpuTi::addTraces()
698 xbt_dict_cursor_t cursor = NULL;
699 char *trace_name, *elm;
701 static int called = 0;
707 /* connect all traces relative to hosts */
708 xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
709 tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
710 CpuTiPtr cpu = (CpuTiPtr) surf_cpu_resource_priv(surf_cpu_resource_by_name(elm));
712 xbt_assert(cpu, "Host %s undefined", elm);
713 xbt_assert(trace, "Trace %s undefined", trace_name);
715 if (cpu->p_stateEvent) {
716 XBT_DEBUG("Trace already configured for this CPU(%s), ignoring it",
720 XBT_DEBUG("Add state trace: %s to CPU(%s)", trace_name, elm);
721 cpu->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, cpu);
724 xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
725 tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
726 CpuTiPtr cpu = (CpuTiPtr) surf_cpu_resource_priv(surf_cpu_resource_by_name(elm));
728 xbt_assert(cpu, "Host %s undefined", elm);
729 xbt_assert(trace, "Trace %s undefined", trace_name);
731 XBT_DEBUG("Add power trace: %s to CPU(%s)", trace_name, elm);
732 if (cpu->p_availTrace)
733 delete cpu->p_availTrace;
735 cpu->p_availTrace = new CpuTiTgmr(trace, cpu->m_powerScale);
737 /* add a fake trace event if periodicity == 0 */
738 if (trace && xbt_dynar_length(trace->s_list.event_list) > 1) {
740 xbt_dynar_get_cpy(trace->s_list.event_list,
741 xbt_dynar_length(trace->s_list.event_list) - 1, &val);
742 if (val.delta == 0) {
743 tmgr_trace_t empty_trace;
744 empty_trace = tmgr_empty_trace_new();
746 tmgr_history_add_trace(history, empty_trace,
747 cpu->p_availTrace->m_lastTime, 0, cpu);
754 * \brief Update the remaining amount of actions
756 * \param now Current time
758 void CpuTi::updateRemainingAmount(double now)
762 CpuTiActionPtr action;
764 /* already updated */
765 if (m_lastUpdate >= now)
768 /* calcule the surface */
769 area_total = p_availTrace->integrate(m_lastUpdate, now) * m_powerPeak;
770 XBT_DEBUG("Flops total: %lf, Last update %lf", area_total,
773 xbt_swag_foreach(_action, p_actionSet) {
774 action = (CpuTiActionPtr) _action;
775 /* action not running, skip it */
776 if (action->p_stateSet !=
777 getModel()->p_runningActionSet)
780 /* bogus priority, skip it */
781 if (action->m_priority <= 0)
784 /* action suspended, skip it */
785 if (action->m_suspended != 0)
788 /* action don't need update */
789 if (action->m_start >= now)
792 /* skip action that are finishing now */
793 if (action->m_finish >= 0
794 && action->m_finish <= now)
797 /* update remaining */
798 double_update(&(action->m_remains),
799 area_total / (m_sumPriority *
800 action->m_priority));
801 XBT_DEBUG("Update remaining action(%p) remaining %lf", action,
807 CpuActionPtr CpuTi::execute(double size)
809 XBT_IN("(%s,%g)", m_name, size);
810 CpuTiActionPtr action = new CpuTiAction(surf_cpu_model, size, p_stateCurrent != SURF_RESOURCE_ON);
812 action->p_cpu = this;
813 action->m_indexHeap = -1;
815 xbt_swag_insert(this, cpu_ti_modified_cpu);
817 xbt_swag_insert(action, p_actionSet);
819 action->m_suspended = 0; /* Should be useless because of the
820 calloc but it seems to help valgrind... */
827 CpuActionPtr CpuTi::sleep(double duration)
830 duration = MAX(duration, MAXMIN_PRECISION);
832 XBT_IN("(%s,%g)", m_name, duration);
833 CpuActionPtr action = execute(1.0);
834 action->m_maxDuration = duration;
835 action->m_suspended = 2;
836 if (duration == NO_MAX_DURATION) {
837 /* Move to the *end* of the corresponding action set. This convention
838 is used to speed up update_resource_state */
839 xbt_swag_remove(action, action->p_stateSet);
840 action->p_stateSet = cpu_ti_running_action_set_that_does_not_need_being_checked;
841 xbt_swag_insert(action, action->p_stateSet);
847 void CpuTi::printCpuTiModel()
849 std::cout << getModel()->getName() << "<<plop"<< std::endl;
855 static void cpu_ti_action_update_index_heap(void *action, int i)
857 ((CpuTiActionPtr)action)->updateIndexHeap(i);
859 void CpuTiAction::updateIndexHeap(int i)
864 void CpuTiAction::setState(e_surf_action_state_t state)
866 Action::setState(state);
867 xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
870 int CpuTiAction::unref()
874 xbt_swag_remove(this, p_stateSet);
875 /* remove from action_set */
876 xbt_swag_remove(this, ((CpuTiPtr)surf_cpu_resource_priv(p_cpu))->p_actionSet);
877 /* remove from heap */
878 xbt_heap_remove(cpu_ti_action_heap, this->m_indexHeap);
879 xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
886 void CpuTiAction::cancel()
888 this->setState(SURF_ACTION_FAILED);
889 xbt_heap_remove(cpu_ti_action_heap, this->m_indexHeap);
890 xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
894 void CpuTiAction::recycle()
899 void CpuTiAction::suspend()
901 XBT_IN("(%p)", this);
902 if (m_suspended != 2) {
904 xbt_heap_remove(cpu_ti_action_heap, m_indexHeap);
905 xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
910 void CpuTiAction::resume()
912 XBT_IN("(%p)", this);
913 if (m_suspended != 2) {
915 xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
920 bool CpuTiAction::isSuspended()
922 return m_suspended == 1;
925 void CpuTiAction::setMaxDuration(double duration)
929 XBT_IN("(%p,%g)", this, duration);
931 m_maxDuration = duration;
934 min_finish = (m_start + m_maxDuration) < m_finish ?
935 (m_start + m_maxDuration) : m_finish;
937 min_finish = m_finish;
939 /* add in action heap */
940 if (m_indexHeap >= 0) {
941 CpuTiActionPtr heap_act = (CpuTiActionPtr)
942 xbt_heap_remove(cpu_ti_action_heap, m_indexHeap);
943 if (heap_act != this)
946 xbt_heap_push(cpu_ti_action_heap, this, min_finish);
951 void CpuTiAction::setPriority(double priority)
953 XBT_IN("(%p,%g)", this, priority);
954 m_priority = priority;
955 xbt_swag_insert(surf_cpu_resource_priv(p_cpu), cpu_ti_modified_cpu);
959 double CpuTiAction::getRemains()
961 XBT_IN("(%p)", this);
962 ((CpuTiPtr)p_cpu)->updateRemainingAmount(surf_get_clock());
967 static void check() {
968 CpuTiActionPtr cupAction = new CpuTiAction(NULL, 0, true);
971 #endif /* SURF_MODEL_CPUTI_H_ */