1 /* Copyright (c) 2009-2011. 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. */
7 #include "surf_private.h"
8 #include "surf/surf_resource.h"
10 surf_model_t surf_cpu_model = NULL;
11 lmm_system_t cpu_maxmin_system = NULL;
13 #undef GENERIC_LMM_ACTION
16 #define GENERIC_LMM_ACTION(action) action->generic_lmm_action
17 #define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action
18 #define ACTION_GET_CPU(action) ((surf_action_cpu_Cas01_im_t) action)->cpu
20 typedef struct surf_action_cpu_cas01_im {
21 s_surf_action_lmm_t generic_lmm_action;
22 s_xbt_swag_hookup_t cpu_list_hookup;
25 } s_surf_action_cpu_Cas01_im_t, *surf_action_cpu_Cas01_im_t;
27 typedef struct cpu_Cas01_im {
28 s_surf_resource_t generic_resource;
29 s_xbt_swag_hookup_t modified_cpu_hookup;
32 tmgr_trace_event_t power_event;
34 e_surf_resource_state_t state_current;
35 tmgr_trace_event_t state_event;
36 lmm_constraint_t constraint;
37 xbt_swag_t action_set;
39 } s_cpu_Cas01_im_t, *cpu_Cas01_im_t;
41 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_im, surf,
42 "Logging specific to the SURF CPU IMPROVED module");
44 lmm_system_t cpu_im_maxmin_system = NULL;
45 static xbt_swag_t cpu_im_modified_cpu = NULL;
46 static xbt_heap_t cpu_im_action_heap = NULL;
47 extern int sg_maxmin_selective_update;
51 cpu_im_running_action_set_that_does_not_need_being_checked = NULL;
53 static void* cpu_im_create_resource(const char *name, double power_peak,
55 tmgr_trace_t power_trace,
57 e_surf_resource_state_t state_initial,
58 tmgr_trace_t state_trace,
59 xbt_dict_t cpu_properties)
61 cpu_Cas01_im_t cpu = NULL;
62 s_surf_action_cpu_Cas01_im_t action;
64 xbt_assert(!surf_cpu_resource_by_name(name),
65 "Host '%s' declared several times in the platform file",
67 cpu = (cpu_Cas01_im_t) surf_resource_new(sizeof(s_cpu_Cas01_im_t),
68 surf_cpu_model, name,cpu_properties);
69 cpu->power_peak = power_peak;
70 xbt_assert(cpu->power_peak > 0, "Power has to be >0");
71 cpu->power_scale = power_scale;
73 xbt_assert(core>0,"Invalid number of cores %d",core);
77 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
79 cpu->state_current = state_initial;
82 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
85 lmm_constraint_new(cpu_im_maxmin_system, cpu,
86 cpu->core * cpu->power_scale * cpu->power_peak);
88 xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu);
89 if(!strcmp(surf_cpu_model->name,"CPU_IM"))
90 cpu->action_set = xbt_swag_new(xbt_swag_offset(action, cpu_list_hookup));
96 static void parse_cpu_im_init(sg_platf_host_cbarg_t host)
98 cpu_im_create_resource(host->id,
108 static void cpu_im_add_traces_cpu(void)
110 xbt_dict_cursor_t cursor = NULL;
111 char *trace_name, *elm;
112 static int called = 0;
117 /* connect all traces relative to hosts */
118 xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
119 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
120 cpu_Cas01_im_t host = surf_cpu_resource_by_name(elm);
122 xbt_assert(host, "Host %s undefined", elm);
123 xbt_assert(trace, "Trace %s undefined", trace_name);
126 tmgr_history_add_trace(history, trace, 0.0, 0, host);
129 xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
130 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
131 cpu_Cas01_im_t host = surf_cpu_resource_by_name(elm);
133 xbt_assert(host, "Host %s undefined", elm);
134 xbt_assert(trace, "Trace %s undefined", trace_name);
137 tmgr_history_add_trace(history, trace, 0.0, 0, host);
141 static void cpu_im_define_callbacks()
143 sg_platf_host_add_cb(parse_cpu_im_init);
144 sg_platf_postparse_add_cb(cpu_im_add_traces_cpu);
147 static int cpu_im_resource_used(void *resource)
149 return lmm_constraint_used(cpu_im_maxmin_system,
150 ((cpu_Cas01_im_t) resource)->constraint);
153 static int cpu_im_action_unref(surf_action_t action)
156 if (!action->refcount) {
157 xbt_swag_remove(action, action->state_set);
158 if (((surf_action_lmm_t) action)->variable)
159 lmm_variable_free(cpu_im_maxmin_system,
160 ((surf_action_lmm_t) action)->variable);
161 if(!strcmp(surf_cpu_model->name,"CPU_IM")){
162 /* remove from heap */
163 xbt_heap_remove(cpu_im_action_heap,
164 ((surf_action_cpu_Cas01_im_t) action)->index_heap);
165 xbt_swag_remove(action,
166 ((cpu_Cas01_im_t) ACTION_GET_CPU(action))->action_set);
167 xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
170 xbt_free(action->category);
172 surf_action_free(&action);
178 static void cpu_im_action_cancel(surf_action_t action)
180 surf_action_state_set(action, SURF_ACTION_FAILED);
181 if(!strcmp(surf_cpu_model->name,"CPU_IM")){
182 xbt_heap_remove(cpu_im_action_heap,
183 ((surf_action_cpu_Cas01_im_t) action)->index_heap);
184 xbt_swag_remove(action,
185 ((cpu_Cas01_im_t) ACTION_GET_CPU(action))->action_set);
190 static void cpu_im_cpu_action_state_set(surf_action_t action,
191 e_surf_action_state_t state)
193 /* if((state==SURF_ACTION_DONE) || (state==SURF_ACTION_FAILED)) */
194 /* if(((surf_action_lmm_t)action)->variable) { */
195 /* lmm_variable_disable(cpu_im_maxmin_system, ((surf_action_lmm_t)action)->variable); */
196 /* ((surf_action_lmm_t)action)->variable = NULL; */
199 surf_action_state_set(action, state);
203 static void cpu_im_update_remains(cpu_Cas01_im_t cpu, double now)
205 surf_action_cpu_Cas01_im_t action;
207 if (cpu->last_update >= now)
209 xbt_swag_foreach(action, cpu->action_set) {
210 if (GENERIC_ACTION(action).state_set !=
211 surf_cpu_model->states.running_action_set)
214 /* bogus priority, skip it */
215 if (GENERIC_ACTION(action).priority <= 0)
218 if (GENERIC_ACTION(action).remains > 0) {
219 double_update(&(GENERIC_ACTION(action).remains),
220 lmm_variable_getvalue(GENERIC_LMM_ACTION
221 (action).variable) * (now -
224 if (TRACE_is_enabled()) {
225 TRACE_surf_host_set_utilization(cpu->generic_resource.name,
227 generic_lmm_action.generic_action.
228 data, (surf_action_t) action,
229 lmm_variable_getvalue
233 now - cpu->last_update);
236 XBT_DEBUG("Update action(%p) remains %lf", action,
237 GENERIC_ACTION(action).remains);
240 cpu->last_update = now;
243 static double cpu_im_share_resources(double now)
245 surf_action_cpu_Cas01_im_t action;
248 cpu_Cas01_im_t cpu, cpu_next;
250 xbt_swag_foreach(cpu, cpu_im_modified_cpu)
251 cpu_im_update_remains(cpu, now);
253 lmm_solve(cpu_im_maxmin_system);
255 xbt_swag_foreach_safe(cpu, cpu_next, cpu_im_modified_cpu) {
256 xbt_swag_foreach(action, cpu->action_set) {
257 if (GENERIC_ACTION(action).state_set !=
258 surf_cpu_model->states.running_action_set)
261 /* bogus priority, skip it */
262 if (GENERIC_ACTION(action).priority <= 0)
266 value = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable);
268 if (GENERIC_ACTION(action).remains > 0) {
269 value = GENERIC_ACTION(action).remains / value;
277 if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION)
279 || GENERIC_ACTION(action).start +
280 GENERIC_ACTION(action).max_duration < min))
282 GENERIC_ACTION(action).start +
283 GENERIC_ACTION(action).max_duration;
285 XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
286 GENERIC_ACTION(action).start, now + value,
287 GENERIC_ACTION(action).max_duration);
289 if (action->index_heap >= 0) {
290 surf_action_cpu_Cas01_im_t heap_act =
291 xbt_heap_remove(cpu_im_action_heap, action->index_heap);
292 if (heap_act != action)
296 xbt_heap_push(cpu_im_action_heap, action, min);
297 XBT_DEBUG("Insert at heap action(%p) min %lf", action, min);
300 xbt_swag_remove(cpu, cpu_im_modified_cpu);
302 return xbt_heap_size(cpu_im_action_heap) >
303 0 ? xbt_heap_maxkey(cpu_im_action_heap) - now : -1;
306 static void cpu_im_update_actions_state(double now, double delta)
308 surf_action_cpu_Cas01_im_t action;
309 while ((xbt_heap_size(cpu_im_action_heap) > 0)
310 && (double_equals(xbt_heap_maxkey(cpu_im_action_heap), now))) {
311 action = xbt_heap_pop(cpu_im_action_heap);
312 XBT_DEBUG("Action %p: finish", action);
313 GENERIC_ACTION(action).finish = surf_get_clock();
314 /* set the remains to 0 due to precision problems when updating the remaining amount */
316 if (TRACE_is_enabled()) {
317 cpu_Cas01_im_t cpu = ((cpu_Cas01_im_t)(action->cpu));
318 TRACE_surf_host_set_utilization(cpu->generic_resource.name,
319 GENERIC_LMM_ACTION(action).generic_action.data,
320 (surf_action_t) action,
321 lmm_variable_getvalue (GENERIC_LMM_ACTION(action).variable),
323 now - cpu->last_update);
326 GENERIC_ACTION(action).remains = 0;
327 cpu_im_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
328 cpu_im_update_remains(action->cpu, surf_get_clock());
331 if (TRACE_is_enabled()) {
332 //defining the last timestamp that we can safely dump to trace file
333 //without losing the event ascending order (considering all CPU's)
336 xbt_lib_cursor_t cursor;
339 xbt_lib_foreach(host_lib, cursor, key, data){
340 if(data[SURF_CPU_LEVEL]){
341 cpu = data[SURF_CPU_LEVEL];
343 smaller = cpu->last_update;
346 if (cpu->last_update < smaller){
347 smaller = cpu->last_update;
352 TRACE_last_timestamp_to_dump = smaller;
359 static void cpu_im_update_resource_state(void *id,
360 tmgr_trace_event_t event_type,
361 double value, double date)
363 cpu_Cas01_im_t cpu = id;
364 lmm_variable_t var = NULL;
365 lmm_element_t elem = NULL;
367 if (event_type == cpu->power_event) {
368 cpu->power_scale = value;
369 lmm_update_constraint_bound(cpu_im_maxmin_system, cpu->constraint,
370 cpu->core * cpu->power_scale * cpu->power_peak);
372 TRACE_surf_host_set_power(date, cpu->generic_resource.name,
373 cpu->core * cpu->power_scale * cpu->power_peak);
375 while ((var = lmm_get_var_from_cnst
376 (cpu_im_maxmin_system, cpu->constraint, &elem))) {
377 surf_action_cpu_Cas01_im_t action = lmm_variable_id(var);
378 lmm_update_variable_bound(cpu_im_maxmin_system, GENERIC_LMM_ACTION(action).variable,
379 cpu->power_scale * cpu->power_peak);
381 if(!strcmp(surf_cpu_model->name,"CPU_IM"))
382 xbt_swag_insert(cpu, cpu_im_modified_cpu);
383 if (tmgr_trace_event_free(event_type))
384 cpu->power_event = NULL;
385 } else if (event_type == cpu->state_event) {
387 cpu->state_current = SURF_RESOURCE_ON;
389 lmm_constraint_t cnst = cpu->constraint;
390 lmm_variable_t var = NULL;
391 lmm_element_t elem = NULL;
393 cpu->state_current = SURF_RESOURCE_OFF;
396 lmm_get_var_from_cnst(cpu_im_maxmin_system, cnst, &elem))) {
397 surf_action_t action = lmm_variable_id(var);
399 if (surf_action_state_get(action) == SURF_ACTION_RUNNING ||
400 surf_action_state_get(action) == SURF_ACTION_READY ||
401 surf_action_state_get(action) ==
402 SURF_ACTION_NOT_IN_THE_SYSTEM) {
403 action->finish = date;
404 cpu_im_cpu_action_state_set(action, SURF_ACTION_FAILED);
408 if (tmgr_trace_event_free(event_type))
409 cpu->state_event = NULL;
411 XBT_CRITICAL("Unknown event ! \n");
418 static surf_action_t cpu_im_execute(void *cpu, double size)
420 surf_action_cpu_Cas01_im_t action = NULL;
421 cpu_Cas01_im_t CPU = cpu;
423 XBT_IN("(%s,%g)", surf_resource_name(CPU), size);
425 surf_action_new(sizeof(s_surf_action_cpu_Cas01_im_t), size,
427 CPU->state_current != SURF_RESOURCE_ON);
429 GENERIC_LMM_ACTION(action).suspended = 0; /* Should be useless because of the
430 calloc but it seems to help valgrind... */
432 GENERIC_LMM_ACTION(action).variable =
433 lmm_variable_new(cpu_im_maxmin_system, action,
434 GENERIC_ACTION(action).priority, CPU->power_scale * CPU->power_peak, 1);
435 if(!strcmp(surf_cpu_model->name,"CPU_IM")){
436 action->index_heap = -1;
438 xbt_swag_insert(CPU, cpu_im_modified_cpu);
439 xbt_swag_insert(action, CPU->action_set);
441 lmm_expand(cpu_im_maxmin_system, CPU->constraint,
442 GENERIC_LMM_ACTION(action).variable, 1.0);
444 return (surf_action_t) action;
447 static surf_action_t cpu_im_action_sleep(void *cpu, double duration)
449 surf_action_cpu_Cas01_im_t action = NULL;
452 duration = MAX(duration, MAXMIN_PRECISION);
454 XBT_IN("(%s,%g)", surf_resource_name(cpu), duration);
455 action = (surf_action_cpu_Cas01_im_t) cpu_im_execute(cpu, 1.0);
456 GENERIC_ACTION(action).max_duration = duration;
457 GENERIC_LMM_ACTION(action).suspended = 2;
458 if (duration == NO_MAX_DURATION) {
459 /* Move to the *end* of the corresponding action set. This convention
460 is used to speed up update_resource_state */
461 xbt_swag_remove(action, ((surf_action_t) action)->state_set);
462 ((surf_action_t) action)->state_set =
463 cpu_im_running_action_set_that_does_not_need_being_checked;
464 xbt_swag_insert(action, ((surf_action_t) action)->state_set);
467 lmm_update_variable_weight(cpu_im_maxmin_system,
468 GENERIC_LMM_ACTION(action).variable, 0.0);
469 if(!strcmp(surf_cpu_model->name,"CPU_IM"))
470 xbt_swag_insert(cpu, cpu_im_modified_cpu);
472 return (surf_action_t) action;
475 static void cpu_im_action_suspend(surf_action_t action)
477 XBT_IN("(%p)", action);
478 if (((surf_action_lmm_t) action)->suspended != 2) {
479 lmm_update_variable_weight(cpu_im_maxmin_system,
480 ((surf_action_lmm_t) action)->variable,
482 ((surf_action_lmm_t) action)->suspended = 1;
483 if(!strcmp(surf_cpu_model->name,"CPU_IM")){
484 xbt_heap_remove(cpu_im_action_heap,
485 ((surf_action_cpu_Cas01_im_t) action)->index_heap);
486 xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
492 static void cpu_im_action_resume(surf_action_t action)
495 XBT_IN("(%p)", action);
496 if (((surf_action_lmm_t) action)->suspended != 2) {
497 lmm_update_variable_weight(cpu_im_maxmin_system,
498 ((surf_action_lmm_t) action)->variable,
500 ((surf_action_lmm_t) action)->suspended = 0;
501 if(!strcmp(surf_cpu_model->name,"CPU_IM"))
502 xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
507 static int cpu_im_action_is_suspended(surf_action_t action)
509 return (((surf_action_lmm_t) action)->suspended == 1);
512 static void cpu_im_action_set_max_duration(surf_action_t action,
515 XBT_IN("(%p,%g)", action, duration);
517 action->max_duration = duration;
518 /* insert cpu in modified_cpu set to notice the max duration change */
519 if(!strcmp(surf_cpu_model->name,"CPU_IM"))
520 xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
524 static void cpu_im_action_set_priority(surf_action_t action,
527 XBT_IN("(%p,%g)", action, priority);
528 action->priority = priority;
529 lmm_update_variable_weight(cpu_im_maxmin_system,
530 ((surf_action_lmm_t) action)->variable,
533 if(!strcmp(surf_cpu_model->name,"CPU_IM"))
534 xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
539 static void cpu_im_action_set_category(surf_action_t action,
540 const char *category)
542 XBT_IN("(%p,%s)", action, category);
543 action->category = xbt_strdup (category);
548 static double cpu_im_action_get_remains(surf_action_t action)
550 XBT_IN("(%p)", action);
551 /* update remains before return it */
552 if(!strcmp(surf_cpu_model->name,"CPU_IM"))
553 cpu_im_update_remains(ACTION_GET_CPU(action), surf_get_clock());
554 return action->remains;
558 static e_surf_resource_state_t cpu_im_get_state(void *cpu)
560 return ((cpu_Cas01_im_t) cpu)->state_current;
563 static double cpu_im_get_speed(void *cpu, double load)
565 return load * (((cpu_Cas01_im_t) cpu)->power_peak);
568 static double cpu_im_get_available_speed(void *cpu)
570 /* number between 0 and 1 */
571 return ((cpu_Cas01_im_t) cpu)->power_scale;
574 static void cpu_im_action_update_index_heap(void *action, int i)
576 ((surf_action_cpu_Cas01_im_t) action)->index_heap = i;
579 static void cpu_im_finalize(void)
582 xbt_lib_cursor_t cursor;
585 xbt_lib_foreach(host_lib, cursor, key, cpu){
586 if(cpu[SURF_CPU_LEVEL])
588 cpu_Cas01_im_t CPU = cpu[SURF_CPU_LEVEL];
589 xbt_swag_free(CPU->action_set);
593 lmm_system_free(cpu_im_maxmin_system);
594 cpu_im_maxmin_system = NULL;
596 surf_model_exit(surf_cpu_model);
597 surf_cpu_model = NULL;
600 (cpu_im_running_action_set_that_does_not_need_being_checked);
601 cpu_im_running_action_set_that_does_not_need_being_checked = NULL;
602 if(cpu_im_action_heap) xbt_heap_free(cpu_im_action_heap);
603 if(cpu_im_modified_cpu) xbt_swag_free(cpu_im_modified_cpu);
606 static void surf_cpu_im_model_init_internal(const char* name)
608 s_surf_action_t action;
609 s_cpu_Cas01_im_t cpu;
611 surf_cpu_model = surf_model_init();
613 cpu_im_running_action_set_that_does_not_need_being_checked =
614 xbt_swag_new(xbt_swag_offset(action, state_hookup));
616 surf_cpu_model->name = name;
618 surf_cpu_model->action_unref = cpu_im_action_unref;
619 surf_cpu_model->action_cancel = cpu_im_action_cancel;
620 surf_cpu_model->action_state_set = cpu_im_cpu_action_state_set;
622 surf_cpu_model->model_private->resource_used = cpu_im_resource_used;
623 surf_cpu_model->model_private->share_resources = generic_share_resources;
624 surf_cpu_model->model_private->update_actions_state =
625 generic_update_actions_state;//ok
626 surf_cpu_model->model_private->update_resource_state =
627 cpu_im_update_resource_state;//ok
628 surf_cpu_model->model_private->finalize = cpu_im_finalize;
630 surf_cpu_model->suspend = cpu_im_action_suspend;
631 surf_cpu_model->resume = cpu_im_action_resume;
632 surf_cpu_model->is_suspended = cpu_im_action_is_suspended;
633 surf_cpu_model->set_max_duration = cpu_im_action_set_max_duration;
634 surf_cpu_model->set_priority = cpu_im_action_set_priority;
636 surf_cpu_model->set_category = cpu_im_action_set_category;
638 surf_cpu_model->get_remains = cpu_im_action_get_remains;
640 surf_cpu_model->extension.cpu.execute = cpu_im_execute;
641 surf_cpu_model->extension.cpu.sleep = cpu_im_action_sleep;
643 surf_cpu_model->extension.cpu.get_state = cpu_im_get_state;
644 surf_cpu_model->extension.cpu.get_speed = cpu_im_get_speed;
645 surf_cpu_model->extension.cpu.get_available_speed =
646 cpu_im_get_available_speed;
647 surf_cpu_model->extension.cpu.create_resource = cpu_im_create_resource;
648 surf_cpu_model->extension.cpu.add_traces = cpu_im_add_traces_cpu;
650 if (!cpu_im_maxmin_system) {
651 sg_maxmin_selective_update = 1;
652 cpu_im_maxmin_system = lmm_system_new();
654 if(!strcmp(surf_cpu_model->name,"CPU_IM")){
655 cpu_im_action_heap = xbt_heap_new(8, NULL);
656 xbt_heap_set_update_callback(cpu_im_action_heap,
657 cpu_im_action_update_index_heap);
658 cpu_im_modified_cpu =
659 xbt_swag_new(xbt_swag_offset(cpu, modified_cpu_hookup));
663 /*********************************************************************/
664 /* Basic sharing model for CPU: that is where all this started... ;) */
665 /*********************************************************************/
666 /* @InProceedings{casanova01simgrid, */
667 /* author = "H. Casanova", */
668 /* booktitle = "Proceedings of the IEEE Symposium on Cluster Computing */
669 /* and the Grid (CCGrid'01)", */
670 /* publisher = "IEEE Computer Society", */
671 /* title = "Simgrid: {A} Toolkit for the Simulation of Application */
675 /* note = "Available at */
676 /* \url{http://grail.sdsc.edu/papers/simgrid_ccgrid01.ps.gz}." */
679 void surf_cpu_model_init_Cas01_im()
682 if( strcmp(xbt_cfg_get_string(_surf_cfg_set, "cpu/model"),"Cas01"))
687 // XBT_INFO("cpu model: %s",name);
691 surf_cpu_im_model_init_internal(name);
692 cpu_im_define_callbacks();
693 xbt_dynar_push(model_list, &surf_cpu_model);
696 double generic_share_resources(double now)
698 surf_action_cpu_Cas01_im_t action;
699 if(!strcmp(surf_cpu_model->name,"CPU_IM"))
700 return cpu_im_share_resources(now);
701 else if(!strcmp(surf_cpu_model->name,"CPU"))
703 return generic_maxmin_share_resources(surf_cpu_model->states.running_action_set,
704 xbt_swag_offset(*action, generic_lmm_action.variable),
705 cpu_im_maxmin_system, lmm_solve);
707 xbt_die("Not recognized surf cpu model!");
711 static void cpu_update_actions_state(double now, double delta)
713 surf_action_cpu_Cas01_im_t action = NULL;
714 surf_action_cpu_Cas01_im_t next_action = NULL;
715 xbt_swag_t running_actions = surf_cpu_model->states.running_action_set;
716 xbt_swag_foreach_safe(action, next_action, running_actions) {
718 if (TRACE_is_enabled()) {
720 lmm_constraint_id(lmm_get_cnst_from_var
721 (cpu_maxmin_system, action->variable, 0));
723 TRACE_surf_host_set_utilization(x->generic_resource.name,
724 action->generic_action.data,
725 (surf_action_t) action,
726 lmm_variable_getvalue
727 (action->variable), now - delta,
729 TRACE_last_timestamp_to_dump = now-delta;
732 double_update(&(GENERIC_ACTION(action).remains),
733 lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable) * delta);
734 if (GENERIC_LMM_ACTION(action).generic_action.max_duration != NO_MAX_DURATION)
735 double_update(&(GENERIC_ACTION(action).max_duration), delta);
736 if ((GENERIC_ACTION(action).remains <= 0) &&
737 (lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) > 0)) {
738 GENERIC_ACTION(action).finish = surf_get_clock();
739 cpu_im_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
740 } else if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION) &&
741 (GENERIC_ACTION(action).max_duration <= 0)) {
742 GENERIC_ACTION(action).finish = surf_get_clock();
743 cpu_im_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
750 void generic_update_actions_state(double now, double delta)
752 if(!strcmp(surf_cpu_model->name,"CPU_IM"))
753 cpu_im_update_actions_state(now, delta);
754 else if(!strcmp(surf_cpu_model->name,"CPU"))
756 cpu_update_actions_state(now, delta);
759 xbt_die("Not recognized surf cpu model!");