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_cpu,
10 "Logging specific to the SURF CPU TRACE INTEGRATION module");
13 static void cpu_ti_action_update_index_heap(void *action, int i);
19 CpuTiTrace::CpuTiTrace(tmgr_trace_t power_trace)
26 p_timePoints = (double*) xbt_malloc0(sizeof(double) *
27 (xbt_dynar_length(power_trace->s_list.event_list) + 1));
28 p_integral = (double*) xbt_malloc0(sizeof(double) *
29 (xbt_dynar_length(power_trace->s_list.event_list) + 1));
30 m_nbPoints = xbt_dynar_length(power_trace->s_list.event_list);
31 xbt_dynar_foreach(power_trace->s_list.event_list, cpt, val) {
32 p_timePoints[i] = time;
33 p_integral[i] = integral;
34 integral += val.delta * val.value;
38 p_timePoints[i] = time;
39 p_integral[i] = integral;
42 CpuTiTrace::~CpuTiTrace()
44 xbt_free(p_timePoints);
48 CpuTiTgmr::~CpuTiTgmr()
55 * \brief Integrate trace
57 * Wrapper around surf_cpu_integrate_trace_simple() to get
60 * \param trace Trace structure.
61 * \param a Begin of interval
62 * \param b End of interval
63 * \return the integrate value. -1 if an error occurs.
65 double CpuTiTgmr::integrate(double a, double b)
72 if ((a < 0.0) || (a > b)) {
74 ("Error, invalid integration interval [%.2f,%.2f]. You probably have a task executing with negative computation amount. Check your code.",
81 if (m_type == TRACE_FIXED) {
82 return ((b - a) * m_value);
85 if (ceil(a / m_lastTime) == a / m_lastTime)
86 a_index = 1 + (int) (ceil(a / m_lastTime));
88 a_index = (int) (ceil(a / m_lastTime));
90 b_index = (int) (floor(b / m_lastTime));
92 if (a_index > b_index) { /* Same chunk */
93 return p_trace->integrateSimple(a - (a_index -
100 first_chunk = p_trace->integrateSimple(a - (a_index -
104 middle_chunk = (b_index - a_index) * m_total;
105 last_chunk = p_trace->integrateSimple(0.0,
110 XBT_DEBUG("first_chunk=%.2f middle_chunk=%.2f last_chunk=%.2f\n",
111 first_chunk, middle_chunk, last_chunk);
113 return (first_chunk + middle_chunk + last_chunk);
117 * \brief Auxiliary function to calculate the integral between a and b.
118 * It simply calculates the integral at point a and b and returns the difference
120 * \param trace Trace structure
121 * \param a Initial point
122 * \param b Final point
125 double CpuTiTrace::integrateSimple(double a, double b)
127 return integrateSimplePoint(b) - integrateSimplePoint(a);
131 * \brief Auxiliary function to calculate the integral at point a.
132 * \param trace Trace structure
136 double CpuTiTrace::integrateSimplePoint(double a)
141 ind = binarySearch(p_timePoints, a, 0, m_nbPoints - 1);
142 integral += p_integral[ind];
144 ("a %f ind %d integral %f ind + 1 %f ind %f time +1 %f time %f",
145 a, ind, integral, p_integral[ind + 1], p_integral[ind],
146 p_timePoints[ind + 1], p_timePoints[ind]);
147 double_update(&a_aux, p_timePoints[ind]);
150 ((p_integral[ind + 1] -
151 p_integral[ind]) / (p_timePoints[ind + 1] -
152 p_timePoints[ind])) * (a - p_timePoints[ind]);
153 XBT_DEBUG("Integral a %f = %f", a, integral);
159 * \brief Calculate the time needed to execute "amount" on cpu.
161 * Here, amount can span multiple trace periods
163 * \param trace CPU trace structure
164 * \param a Initial time
165 * \param amount Amount to be executed
168 double CpuTiTgmr::solve(double a, double amount)
172 double reduced_amount;
176 /* Fix very small negative numbers */
177 if ((a < 0.0) && (a > -EPSILON)) {
180 if ((amount < 0.0) && (amount > -EPSILON)) {
185 if ((a < 0.0) || (amount < 0.0)) {
187 ("Error, invalid parameters [a = %.2f, amount = %.2f]. You probably have a task executing with negative computation amount. Check your code.",
192 /* At this point, a and amount are positive */
194 if (amount < EPSILON)
197 /* Is the trace fixed ? */
198 if (m_type == TRACE_FIXED) {
199 return (a + (amount / m_value));
202 XBT_DEBUG("amount %f total %f", amount, m_total);
203 /* Reduce the problem to one where amount <= trace_total */
204 quotient = (int) (floor(amount / m_total));
205 reduced_amount = (m_total) * ((amount / m_total) -
206 floor(amount / m_total));
207 reduced_a = a - (m_lastTime) * (int) (floor(a / m_lastTime));
209 XBT_DEBUG("Quotient: %d reduced_amount: %f reduced_a: %f", quotient,
210 reduced_amount, reduced_a);
212 /* Now solve for new_amount which is <= trace_total */
214 fprintf(stderr,"reduced_a = %.2f\n",reduced_a);
215 fprintf(stderr,"reduced_amount = %.2f\n",reduced_amount);
217 reduced_b = solveSomewhatSimple(reduced_a, reduced_amount);
219 /* Re-map to the original b and amount */
220 b = (m_lastTime) * (int) (floor(a / m_lastTime)) +
221 (quotient * m_lastTime) + reduced_b;
226 * \brief Auxiliary function to solve integral
228 * Here, amount is <= trace->total
229 * and a <=trace->last_time
232 double CpuTiTgmr::solveSomewhatSimple(double a, double amount)
234 double amount_till_end;
237 XBT_DEBUG("Solve integral: [%.2f, amount=%.2f]", a, amount);
238 amount_till_end = integrate(a, m_lastTime);
240 fprintf(stderr,"amount_till_end=%.2f\n",amount_till_end);
243 if (amount_till_end > amount) {
244 b = p_trace->solveSimple(a, amount);
246 b = m_lastTime + p_trace->solveSimple(0.0, amount - amount_till_end);
252 * \brief Auxiliary function to solve integral.
253 * It returns the date when the requested amount of flops is available
254 * \param trace Trace structure
255 * \param a Initial point
256 * \param amount Amount of flops
257 * \return The date when amount is available.
259 double CpuTiTrace::solveSimple(double a, double amount)
264 integral_a = integrateSimplePoint(a);
265 ind = binarySearch(p_integral, integral_a + amount, 0, m_nbPoints - 1);
266 time = p_timePoints[ind];
268 (integral_a + amount -
269 p_integral[ind]) / ((p_integral[ind + 1] -
271 (p_timePoints[ind + 1] -
278 * \brief Auxiliary function to update the CPU power scale.
280 * This function uses the trace structure to return the power scale at the determined time a.
281 * \param trace Trace structure to search the updated power scale
283 * \return CPU power scale
285 double CpuTiTgmr::getPowerScale(double a)
291 reduced_a = a - floor(a / m_lastTime) * m_lastTime;
292 point = p_trace->binarySearch(p_trace->p_timePoints, reduced_a, 0,
293 p_trace->m_nbPoints - 1);
294 xbt_dynar_get_cpy(p_powerTrace->s_list.event_list, point, &val);
299 * \brief Creates a new integration trace from a tmgr_trace_t
301 * \param power_trace CPU availability trace
302 * \param value Percentage of CPU power available (useful to fixed tracing)
303 * \param spacing Initial spacing
304 * \return Integration trace structure
306 CpuTiTgmr::CpuTiTgmr(tmgr_trace_t power_trace, double value)
308 double total_time = 0.0;
313 /* no availability file, fixed trace */
315 m_type = TRACE_FIXED;
317 XBT_DEBUG("No availability trace. Constant value = %lf", value);
321 /* only one point available, fixed trace */
322 if (xbt_dynar_length(power_trace->s_list.event_list) == 1) {
323 xbt_dynar_get_cpy(power_trace->s_list.event_list, 0, &val);
324 m_type = TRACE_FIXED;
329 m_type = TRACE_DYNAMIC;
330 p_powerTrace = power_trace;
332 /* count the total time of trace file */
333 xbt_dynar_foreach(power_trace->s_list.event_list, cpt, val) {
334 total_time += val.delta;
336 p_trace = new CpuTiTrace(power_trace);
337 m_lastTime = total_time;
338 m_total = p_trace->integrateSimple(0, total_time);
340 XBT_DEBUG("Total integral %lf, last_time %lf ",
341 m_total, m_lastTime);
345 * \brief Binary search in array.
346 * It returns the first point of the interval in which "a" is.
348 * \param a Value to search
349 * \param low Low bound to search in array
350 * \param high Upper bound to search in array
351 * \return Index of point
353 int CpuTiTrace::binarySearch(double *array, double a, int low, int high)
355 xbt_assert(low < high, "Wrong parameters: low (%d) should be smaller than"
356 " high (%d)", low, high);
360 mid = low + (high - low) / 2;
361 XBT_DEBUG("a %f low %d high %d mid %d value %f", a, low, high, mid,
369 while (low < high - 1);
378 static void parse_cpu_ti_init(sg_platf_host_cbarg_t host){
379 ((CpuTiModelPtr)surf_cpu_model_pm)->parseInit(host);
382 static void add_traces_cpu_ti(){
383 surf_cpu_model_pm->addTraces();
386 static void cpu_ti_define_callbacks()
388 sg_platf_host_add_cb(parse_cpu_ti_init);
389 sg_platf_postparse_add_cb(add_traces_cpu_ti);
396 void surf_cpu_model_init_ti()
398 xbt_assert(!surf_cpu_model_pm,"CPU model already initialized. This should not happen.");
399 xbt_assert(!surf_cpu_model_vm,"CPU model already initialized. This should not happen.");
401 surf_cpu_model_pm = new CpuTiModel();
402 surf_cpu_model_vm = new CpuTiModel();
404 cpu_ti_define_callbacks();
405 ModelPtr model_pm = static_cast<ModelPtr>(surf_cpu_model_pm);
406 ModelPtr model_vm = static_cast<ModelPtr>(surf_cpu_model_vm);
407 xbt_dynar_push(model_list, &model_pm);
408 xbt_dynar_push(model_list, &model_vm);
411 CpuTiModel::CpuTiModel() : CpuModel("cpu_ti")
413 ActionPtr action = NULL;
416 p_runningActionSetThatDoesNotNeedBeingChecked =
417 xbt_swag_new(xbt_swag_offset(*action, p_stateHookup));
420 xbt_swag_new(xbt_swag_offset(*cpu, p_modifiedCpuHookup));
422 p_tiActionHeap = xbt_heap_new(8, NULL);
423 xbt_heap_set_update_callback(p_tiActionHeap,
424 cpu_ti_action_update_index_heap);
427 CpuTiModel::~CpuTiModel()
430 xbt_lib_cursor_t cursor;
433 surf_cpu_model_pm = NULL;
435 xbt_swag_free(p_runningActionSetThatDoesNotNeedBeingChecked);
436 xbt_swag_free(p_modifiedCpu);
437 xbt_heap_free(p_tiActionHeap);
440 void CpuTiModel::parseInit(sg_platf_host_cbarg_t host)
442 createResource(host->id,
453 CpuTiPtr CpuTiModel::createResource(const char *name,
454 xbt_dynar_t powerPeak,
457 tmgr_trace_t powerTrace,
459 e_surf_resource_state_t stateInitial,
460 tmgr_trace_t stateTrace,
461 xbt_dict_t cpuProperties)
463 xbt_assert(core==1,"Multi-core not handled with this model yet");
464 xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)),
465 "Host '%s' declared several times in the platform file",
467 CpuTiPtr cpu = new CpuTi(this, name, powerPeak, pstate, powerScale, powerTrace,
468 core, stateInitial, stateTrace, cpuProperties);
469 xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, static_cast<ResourcePtr>(cpu));
473 CpuTiActionPtr CpuTiModel::createAction(double /*cost*/, bool /*failed*/)
475 return NULL;//new CpuTiAction(this, cost, failed);
478 double CpuTiModel::shareResources(double now)
480 void *_cpu, *_cpu_next;
481 double min_action_duration = -1;
483 /* iterates over modified cpus to update share resources */
484 xbt_swag_foreach_safe(_cpu, _cpu_next, p_modifiedCpu) {
485 static_cast<CpuTiPtr>(_cpu)->updateActionFinishDate(now);
487 /* get the min next event if heap not empty */
488 if (xbt_heap_size(p_tiActionHeap) > 0)
489 min_action_duration = xbt_heap_maxkey(p_tiActionHeap) - now;
491 XBT_DEBUG("Share resources, min next event date: %f", min_action_duration);
493 return min_action_duration;
496 void CpuTiModel::updateActionsState(double now, double /*delta*/)
498 while ((xbt_heap_size(p_tiActionHeap) > 0)
499 && (xbt_heap_maxkey(p_tiActionHeap) <= now)) {
500 CpuTiActionPtr action = (CpuTiActionPtr) xbt_heap_pop(p_tiActionHeap);
501 XBT_DEBUG("Action %p: finish", action);
502 action->m_finish = surf_get_clock();
503 /* set the remains to 0 due to precision problems when updating the remaining amount */
504 action->m_remains = 0;
505 action->setState(SURF_ACTION_DONE);
506 /* update remaining amount of all actions */
507 action->p_cpu->updateRemainingAmount(surf_get_clock());
511 void CpuTiModel::addTraces()
513 xbt_dict_cursor_t cursor = NULL;
514 char *trace_name, *elm;
516 static int called = 0;
522 /* connect all traces relative to hosts */
523 xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
524 tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
525 CpuTiPtr cpu = static_cast<CpuTiPtr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm)));
527 xbt_assert(cpu, "Host %s undefined", elm);
528 xbt_assert(trace, "Trace %s undefined", trace_name);
530 if (cpu->p_stateEvent) {
531 XBT_DEBUG("Trace already configured for this CPU(%s), ignoring it",
535 XBT_DEBUG("Add state trace: %s to CPU(%s)", trace_name, elm);
536 cpu->p_stateEvent = tmgr_history_add_trace(history, trace, 0.0, 0, static_cast<ResourcePtr>(cpu));
539 xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
540 tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
541 CpuTiPtr cpu = dynamic_cast<CpuTiPtr>(static_cast<ResourcePtr>(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm))));
543 xbt_assert(cpu, "Host %s undefined", elm);
544 xbt_assert(trace, "Trace %s undefined", trace_name);
546 XBT_DEBUG("Add power trace: %s to CPU(%s)", trace_name, elm);
547 if (cpu->p_availTrace)
548 delete cpu->p_availTrace;
550 cpu->p_availTrace = new CpuTiTgmr(trace, cpu->m_powerScale);
552 /* add a fake trace event if periodicity == 0 */
553 if (trace && xbt_dynar_length(trace->s_list.event_list) > 1) {
555 xbt_dynar_get_cpy(trace->s_list.event_list,
556 xbt_dynar_length(trace->s_list.event_list) - 1, &val);
557 if (val.delta == 0) {
558 tmgr_trace_t empty_trace;
559 empty_trace = tmgr_empty_trace_new();
561 tmgr_history_add_trace(history, empty_trace,
562 cpu->p_availTrace->m_lastTime, 0, static_cast<ResourcePtr>(cpu));
571 CpuTi::CpuTi(CpuTiModelPtr model, const char *name, xbt_dynar_t powerPeak,
572 int pstate, double powerScale, tmgr_trace_t powerTrace, int core,
573 e_surf_resource_state_t stateInitial, tmgr_trace_t stateTrace,
574 xbt_dict_t properties)
575 : Resource(model, name, properties)
576 , Cpu(model, name, properties, core, 0, powerScale) {
578 p_stateCurrent = stateInitial;
579 m_powerScale = powerScale;
581 tmgr_trace_t empty_trace;
583 xbt_assert(core==1,"Multi-core not handled with this model yet");
584 XBT_DEBUG("power scale %lf", powerScale);
585 p_availTrace = new CpuTiTgmr(powerTrace, powerScale);
587 CpuTiActionPtr action = NULL;
588 p_actionSet = xbt_swag_new(xbt_swag_offset(*action, p_cpuListHookup));
592 xbt_dynar_get_cpy(powerPeak, 0, &m_powerPeak);
593 xbt_dynar_free(&powerPeak); /* kill memory leak */
595 XBT_DEBUG("CPU create: peak=%f, pstate=%d", m_powerPeak, m_pstate);
597 p_modifiedCpuHookup.prev = 0;
598 p_modifiedCpuHookup.next = 0;
601 p_stateEvent = tmgr_history_add_trace(history, stateTrace, 0.0, 0, static_cast<ResourcePtr>(this));
602 if (powerTrace && xbt_dynar_length(powerTrace->s_list.event_list) > 1) {
603 // add a fake trace event if periodicity == 0
604 xbt_dynar_get_cpy(powerTrace->s_list.event_list,
605 xbt_dynar_length(powerTrace->s_list.event_list) - 1, &val);
606 if (val.delta == 0) {
607 empty_trace = tmgr_empty_trace_new();
609 tmgr_history_add_trace(history, empty_trace,
610 p_availTrace->m_lastTime, 0, static_cast<ResourcePtr>(this));
617 xbt_swag_free(p_actionSet);
620 void CpuTi::updateState(tmgr_trace_event_t event_type,
621 double value, double date)
624 CpuTiActionPtr action;
626 if (event_type == p_powerEvent) {
627 tmgr_trace_t power_trace;
631 XBT_DEBUG("Finish trace date: %f value %lf date %f", surf_get_clock(),
633 /* update remaining of actions and put in modified cpu swag */
634 updateRemainingAmount(date);
635 xbt_swag_insert(this, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
637 power_trace = p_availTrace->p_powerTrace;
638 xbt_dynar_get_cpy(power_trace->s_list.event_list,
639 xbt_dynar_length(power_trace->s_list.event_list) - 1, &val);
642 m_powerScale = val.value;
644 trace = new CpuTiTgmr(TRACE_FIXED, val.value);
645 XBT_DEBUG("value %f", val.value);
647 p_availTrace = trace;
649 if (tmgr_trace_event_free(event_type))
652 } else if (event_type == p_stateEvent) {
654 if(p_stateCurrent == SURF_RESOURCE_OFF)
655 xbt_dynar_push_as(host_that_restart, char*, (char *)m_name);
656 p_stateCurrent = SURF_RESOURCE_ON;
658 p_stateCurrent = SURF_RESOURCE_OFF;
660 /* put all action running on cpu to failed */
661 xbt_swag_foreach(_action, p_actionSet) {
662 action = static_cast<CpuTiActionPtr>(_action);
663 if (action->getState() == SURF_ACTION_RUNNING
664 || action->getState() == SURF_ACTION_READY
665 || action->getState() == SURF_ACTION_NOT_IN_THE_SYSTEM) {
666 action->m_finish = date;
667 action->setState(SURF_ACTION_FAILED);
668 if (action->m_indexHeap >= 0) {
669 CpuTiActionPtr heap_act = (CpuTiActionPtr)
670 xbt_heap_remove(reinterpret_cast<CpuTiModelPtr>(p_model)->p_tiActionHeap, action->m_indexHeap);
671 if (heap_act != action)
677 if (tmgr_trace_event_free(event_type))
680 XBT_CRITICAL("Unknown event ! \n");
687 void CpuTi::updateActionFinishDate(double now)
690 CpuTiActionPtr action;
691 double sum_priority = 0.0, total_area, min_finish = -1;
693 /* update remaning amount of actions */
694 updateRemainingAmount(now);
696 xbt_swag_foreach(_action, p_actionSet) {
697 action = static_cast<CpuTiActionPtr>(_action);
698 /* action not running, skip it */
699 if (action->p_stateSet !=
700 surf_cpu_model_pm->p_runningActionSet)
703 /* bogus priority, skip it */
704 if (action->m_priority <= 0)
707 /* action suspended, skip it */
708 if (action->m_suspended != 0)
711 sum_priority += 1.0 / action->m_priority;
713 m_sumPriority = sum_priority;
715 xbt_swag_foreach(_action, p_actionSet) {
716 action = static_cast<CpuTiActionPtr>(_action);
718 /* action not running, skip it */
719 if (action->p_stateSet !=
720 surf_cpu_model_pm->p_runningActionSet)
723 /* verify if the action is really running on cpu */
724 if (action->m_suspended == 0 && action->m_priority > 0) {
725 /* total area needed to finish the action. Used in trace integration */
727 (action->m_remains) * sum_priority *
730 total_area /= m_powerPeak;
732 action->m_finish = p_availTrace->solve(now, total_area);
733 /* verify which event will happen before (max_duration or finish time) */
734 if (action->m_maxDuration != NO_MAX_DURATION &&
735 action->m_start + action->m_maxDuration < action->m_finish)
736 min_finish = action->m_start + action->m_maxDuration;
738 min_finish = action->m_finish;
740 /* put the max duration time on heap */
741 if (action->m_maxDuration != NO_MAX_DURATION)
742 min_finish = action->m_start + action->m_maxDuration;
744 /* add in action heap */
745 XBT_DEBUG("action(%p) index %d", action, action->m_indexHeap);
746 if (action->m_indexHeap >= 0) {
747 CpuTiActionPtr heap_act = (CpuTiActionPtr)
748 xbt_heap_remove(reinterpret_cast<CpuTiModelPtr>(p_model)->p_tiActionHeap, action->m_indexHeap);
749 if (heap_act != action)
752 if (min_finish != NO_MAX_DURATION)
753 xbt_heap_push(reinterpret_cast<CpuTiModelPtr>(p_model)->p_tiActionHeap, action, min_finish);
756 ("Update finish time: Cpu(%s) Action: %p, Start Time: %f Finish Time: %f Max duration %f",
757 m_name, action, action->m_start,
759 action->m_maxDuration);
761 /* remove from modified cpu */
762 xbt_swag_remove(this, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
767 return xbt_swag_size(p_actionSet);
772 double CpuTi::getAvailableSpeed()
774 m_powerScale = p_availTrace->getPowerScale(surf_get_clock());
775 return Cpu::getAvailableSpeed();
779 * \brief Update the remaining amount of actions
781 * \param now Current time
783 void CpuTi::updateRemainingAmount(double now)
787 CpuTiActionPtr action;
789 /* already updated */
790 if (m_lastUpdate >= now)
793 /* calcule the surface */
794 area_total = p_availTrace->integrate(m_lastUpdate, now) * m_powerPeak;
795 XBT_DEBUG("Flops total: %f, Last update %f", area_total,
798 xbt_swag_foreach(_action, p_actionSet) {
799 action = static_cast<CpuTiActionPtr>(_action);
800 /* action not running, skip it */
801 if (action->p_stateSet !=
802 getModel()->p_runningActionSet)
805 /* bogus priority, skip it */
806 if (action->m_priority <= 0)
809 /* action suspended, skip it */
810 if (action->m_suspended != 0)
813 /* action don't need update */
814 if (action->m_start >= now)
817 /* skip action that are finishing now */
818 if (action->m_finish >= 0
819 && action->m_finish <= now)
822 /* update remaining */
823 double_update(&(action->m_remains),
824 area_total / (m_sumPriority *
825 action->m_priority));
826 XBT_DEBUG("Update remaining action(%p) remaining %f", action,
832 CpuActionPtr CpuTi::execute(double size)
834 return _execute(size);
837 CpuTiActionPtr CpuTi::_execute(double size)
839 XBT_IN("(%s,%g)", m_name, size);
840 CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(p_model), size, p_stateCurrent != SURF_RESOURCE_ON);
842 action->p_cpu = this;
843 action->m_indexHeap = -1;
845 xbt_swag_insert(this, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
847 xbt_swag_insert(action, p_actionSet);
849 action->m_suspended = 0; /* Should be useless because of the
850 ยป calloc but it seems to help valgrind... */
857 CpuActionPtr CpuTi::sleep(double duration)
860 duration = MAX(duration, MAXMIN_PRECISION);
862 XBT_IN("(%s,%g)", m_name, duration);
863 CpuTiActionPtr action = _execute(1.0);
864 action->m_maxDuration = duration;
865 action->m_suspended = 2;
866 if (duration == NO_MAX_DURATION) {
867 /* Move to the *end* of the corresponding action set. This convention
868 is used to speed up update_resource_state */
869 xbt_swag_remove(static_cast<ActionPtr>(action), action->p_stateSet);
870 action->p_stateSet = reinterpret_cast<CpuTiModelPtr>(p_model)->p_runningActionSetThatDoesNotNeedBeingChecked;
871 xbt_swag_insert(static_cast<ActionPtr>(action), action->p_stateSet);
877 void CpuTi::printCpuTiModel()
879 std::cout << getModel()->getName() << "<<plop"<< std::endl;
885 static void cpu_ti_action_update_index_heap(void *action, int i)
887 ((CpuTiActionPtr)action)->updateIndexHeap(i);
889 void CpuTiAction::updateIndexHeap(int i)
894 void CpuTiAction::setState(e_surf_action_state_t state)
896 Action::setState(state);
897 xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
900 int CpuTiAction::unref()
904 xbt_swag_remove(static_cast<ActionPtr>(this), p_stateSet);
905 /* remove from action_set */
906 xbt_swag_remove(this, p_cpu->p_actionSet);
907 /* remove from heap */
908 xbt_heap_remove(reinterpret_cast<CpuTiModelPtr>(p_model)->p_tiActionHeap, this->m_indexHeap);
909 xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
916 void CpuTiAction::cancel()
918 this->setState(SURF_ACTION_FAILED);
919 xbt_heap_remove(p_model->p_actionHeap, this->m_indexHeap);
920 xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
924 void CpuTiAction::recycle()
929 void CpuTiAction::suspend()
931 XBT_IN("(%p)", this);
932 if (m_suspended != 2) {
934 xbt_heap_remove(p_model->p_actionHeap, m_indexHeap);
935 xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
940 void CpuTiAction::resume()
942 XBT_IN("(%p)", this);
943 if (m_suspended != 2) {
945 xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
950 bool CpuTiAction::isSuspended()
952 return m_suspended == 1;
955 void CpuTiAction::setMaxDuration(double duration)
959 XBT_IN("(%p,%g)", this, duration);
961 m_maxDuration = duration;
964 min_finish = (m_start + m_maxDuration) < m_finish ?
965 (m_start + m_maxDuration) : m_finish;
967 min_finish = m_finish;
969 /* add in action heap */
970 if (m_indexHeap >= 0) {
971 CpuTiActionPtr heap_act = (CpuTiActionPtr)
972 xbt_heap_remove(p_model->p_actionHeap, m_indexHeap);
973 if (heap_act != this)
976 xbt_heap_push(p_model->p_actionHeap, this, min_finish);
981 void CpuTiAction::setPriority(double priority)
983 XBT_IN("(%p,%g)", this, priority);
984 m_priority = priority;
985 xbt_swag_insert(p_cpu, reinterpret_cast<CpuTiModelPtr>(p_model)->p_modifiedCpu);
989 double CpuTiAction::getRemains()
991 XBT_IN("(%p)", this);
992 p_cpu->updateRemainingAmount(surf_get_clock());
997 #endif /* SURF_MODEL_CPUTI_H_ */