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;
12 e_UM_t cpu_update_mechanism = UM_UNDEFINED;
13 static xbt_swag_t cpu_modified_cpu = NULL;
14 static xbt_heap_t cpu_action_heap = NULL;
15 extern int sg_maxmin_selective_update;
17 #undef GENERIC_LMM_ACTION
20 #define GENERIC_LMM_ACTION(action) action->generic_lmm_action
21 #define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action
22 #define ACTION_GET_CPU(action) ((surf_action_cpu_Cas01_t) action)->cpu
24 typedef struct surf_action_cpu_cas01 {
25 s_surf_action_lmm_t generic_lmm_action;
26 s_xbt_swag_hookup_t cpu_list_hookup;
29 } s_surf_action_cpu_Cas01_t, *surf_action_cpu_Cas01_t;
31 typedef struct cpu_Cas01 {
32 s_surf_resource_t generic_resource;
33 s_xbt_swag_hookup_t modified_cpu_hookup;
36 tmgr_trace_event_t power_event;
38 e_surf_resource_state_t state_current;
39 tmgr_trace_event_t state_event;
40 lmm_constraint_t constraint;
41 xbt_swag_t action_set;
43 } s_cpu_Cas01_t, *cpu_Cas01_t;
45 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu, surf,
46 "Logging specific to the SURF CPU IMPROVED module");
51 cpu_running_action_set_that_does_not_need_being_checked = NULL;
53 static void* cpu_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_t cpu = NULL;
62 s_surf_action_cpu_Cas01_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_t) surf_resource_new(sizeof(s_cpu_Cas01_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_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(cpu_update_mechanism == UM_LAZY)
90 cpu->action_set = xbt_swag_new(xbt_swag_offset(action, cpu_list_hookup));
96 static void parse_cpu_init(sg_platf_host_cbarg_t host)
98 cpu_create_resource(host->id,
108 static void cpu_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_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_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_define_callbacks()
143 sg_platf_host_add_cb(parse_cpu_init);
144 sg_platf_postparse_add_cb(cpu_add_traces_cpu);
147 static int cpu_resource_used(void *resource)
149 return lmm_constraint_used(cpu_maxmin_system,
150 ((cpu_Cas01_t) resource)->constraint);
153 static int cpu_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_maxmin_system,
160 ((surf_action_lmm_t) action)->variable);
161 if(cpu_update_mechanism == UM_LAZY){
162 /* remove from heap */
163 xbt_heap_remove(cpu_action_heap,
164 ((surf_action_cpu_Cas01_t) action)->index_heap);
165 xbt_swag_remove(action,
166 ((cpu_Cas01_t) ACTION_GET_CPU(action))->action_set);
167 xbt_swag_insert(ACTION_GET_CPU(action), cpu_modified_cpu);
170 xbt_free(action->category);
172 surf_action_free(&action);
178 static void cpu_action_cancel(surf_action_t action)
180 surf_action_state_set(action, SURF_ACTION_FAILED);
181 if(cpu_update_mechanism == UM_LAZY){
182 xbt_heap_remove(cpu_action_heap,
183 ((surf_action_cpu_Cas01_t) action)->index_heap);
184 xbt_swag_remove(action,
185 ((cpu_Cas01_t) ACTION_GET_CPU(action))->action_set);
190 static void cpu_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_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_update_remains(cpu_Cas01_t cpu, double now)
205 surf_action_cpu_Cas01_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_share_resources_lazy(double now)
245 surf_action_cpu_Cas01_t action;
248 cpu_Cas01_t cpu, cpu_next;
250 xbt_swag_foreach(cpu, cpu_modified_cpu)
251 cpu_update_remains(cpu, now);
253 lmm_solve(cpu_maxmin_system);
255 xbt_swag_foreach_safe(cpu, cpu_next, cpu_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_t heap_act =
291 xbt_heap_remove(cpu_action_heap, action->index_heap);
292 if (heap_act != action)
296 xbt_heap_push(cpu_action_heap, action, min);
297 XBT_DEBUG("Insert at heap action(%p) min %lf", action, min);
300 xbt_swag_remove(cpu, cpu_modified_cpu);
302 return xbt_heap_size(cpu_action_heap) >
303 0 ? xbt_heap_maxkey(cpu_action_heap) - now : -1;
306 static void cpu_update_actions_state_lazy(double now, double delta)
308 surf_action_cpu_Cas01_t action;
309 while ((xbt_heap_size(cpu_action_heap) > 0)
310 && (double_equals(xbt_heap_maxkey(cpu_action_heap), now))) {
311 action = xbt_heap_pop(cpu_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_t cpu = ((cpu_Cas01_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_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
328 cpu_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_update_resource_state(void *id,
360 tmgr_trace_event_t event_type,
361 double value, double date)
363 cpu_Cas01_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_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_maxmin_system, cpu->constraint, &elem))) {
377 surf_action_cpu_Cas01_t action = lmm_variable_id(var);
378 lmm_update_variable_bound(cpu_maxmin_system, GENERIC_LMM_ACTION(action).variable,
379 cpu->power_scale * cpu->power_peak);
381 if(cpu_update_mechanism == UM_LAZY)
382 xbt_swag_insert(cpu, cpu_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_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_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_execute(void *cpu, double size)
420 surf_action_cpu_Cas01_t action = NULL;
421 cpu_Cas01_t CPU = cpu;
423 XBT_IN("(%s,%g)", surf_resource_name(CPU), size);
425 surf_action_new(sizeof(s_surf_action_cpu_Cas01_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_maxmin_system, action,
434 GENERIC_ACTION(action).priority, CPU->power_scale * CPU->power_peak, 1);
435 if(cpu_update_mechanism == UM_LAZY){
436 action->index_heap = -1;
438 xbt_swag_insert(CPU, cpu_modified_cpu);
439 xbt_swag_insert(action, CPU->action_set);
441 lmm_expand(cpu_maxmin_system, CPU->constraint,
442 GENERIC_LMM_ACTION(action).variable, 1.0);
444 return (surf_action_t) action;
447 static surf_action_t cpu_action_sleep(void *cpu, double duration)
449 surf_action_cpu_Cas01_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_t) cpu_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_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_maxmin_system,
468 GENERIC_LMM_ACTION(action).variable, 0.0);
469 if(cpu_update_mechanism == UM_LAZY)
470 xbt_swag_insert(cpu, cpu_modified_cpu);
472 return (surf_action_t) action;
475 static void cpu_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_maxmin_system,
480 ((surf_action_lmm_t) action)->variable,
482 ((surf_action_lmm_t) action)->suspended = 1;
483 if(cpu_update_mechanism == UM_LAZY){
484 xbt_heap_remove(cpu_action_heap,
485 ((surf_action_cpu_Cas01_t) action)->index_heap);
486 xbt_swag_insert(ACTION_GET_CPU(action), cpu_modified_cpu);
492 static void cpu_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_maxmin_system,
498 ((surf_action_lmm_t) action)->variable,
500 ((surf_action_lmm_t) action)->suspended = 0;
501 if(cpu_update_mechanism == UM_LAZY)
502 xbt_swag_insert(ACTION_GET_CPU(action), cpu_modified_cpu);
507 static int cpu_action_is_suspended(surf_action_t action)
509 return (((surf_action_lmm_t) action)->suspended == 1);
512 static void cpu_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(cpu_update_mechanism == UM_LAZY)
520 xbt_swag_insert(ACTION_GET_CPU(action), cpu_modified_cpu);
524 static void cpu_action_set_priority(surf_action_t action,
527 XBT_IN("(%p,%g)", action, priority);
528 action->priority = priority;
529 lmm_update_variable_weight(cpu_maxmin_system,
530 ((surf_action_lmm_t) action)->variable,
533 if(cpu_update_mechanism == UM_LAZY)
534 xbt_swag_insert(ACTION_GET_CPU(action), cpu_modified_cpu);
539 static void cpu_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_action_get_remains(surf_action_t action)
550 XBT_IN("(%p)", action);
551 /* update remains before return it */
552 if(cpu_update_mechanism == UM_LAZY)
553 cpu_update_remains(ACTION_GET_CPU(action), surf_get_clock());
554 return action->remains;
558 static e_surf_resource_state_t cpu_get_state(void *cpu)
560 return ((cpu_Cas01_t) cpu)->state_current;
563 static double cpu_get_speed(void *cpu, double load)
565 return load * (((cpu_Cas01_t) cpu)->power_peak);
568 static double cpu_get_available_speed(void *cpu)
570 /* number between 0 and 1 */
571 return ((cpu_Cas01_t) cpu)->power_scale;
574 static void cpu_action_update_index_heap(void *action, int i)
576 ((surf_action_cpu_Cas01_t) action)->index_heap = i;
579 static void cpu_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_t CPU = cpu[SURF_CPU_LEVEL];
589 xbt_swag_free(CPU->action_set);
593 lmm_system_free(cpu_maxmin_system);
594 cpu_maxmin_system = NULL;
596 surf_model_exit(surf_cpu_model);
597 surf_cpu_model = NULL;
600 (cpu_running_action_set_that_does_not_need_being_checked);
601 cpu_running_action_set_that_does_not_need_being_checked = NULL;
602 if(cpu_action_heap) xbt_heap_free(cpu_action_heap);
603 if(cpu_modified_cpu) xbt_swag_free(cpu_modified_cpu);
606 static void surf_cpu_model_init_internal(const char* name)
608 s_surf_action_t action;
611 surf_cpu_model = surf_model_init();
613 cpu_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_action_unref;
619 surf_cpu_model->action_cancel = cpu_action_cancel;
620 surf_cpu_model->action_state_set = cpu_cpu_action_state_set;
622 surf_cpu_model->model_private->resource_used = cpu_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;
626 surf_cpu_model->model_private->update_resource_state =
627 cpu_update_resource_state;
628 surf_cpu_model->model_private->finalize = cpu_finalize;
630 surf_cpu_model->suspend = cpu_action_suspend;
631 surf_cpu_model->resume = cpu_action_resume;
632 surf_cpu_model->is_suspended = cpu_action_is_suspended;
633 surf_cpu_model->set_max_duration = cpu_action_set_max_duration;
634 surf_cpu_model->set_priority = cpu_action_set_priority;
636 surf_cpu_model->set_category = cpu_action_set_category;
638 surf_cpu_model->get_remains = cpu_action_get_remains;
640 surf_cpu_model->extension.cpu.execute = cpu_execute;
641 surf_cpu_model->extension.cpu.sleep = cpu_action_sleep;
643 surf_cpu_model->extension.cpu.get_state = cpu_get_state;
644 surf_cpu_model->extension.cpu.get_speed = cpu_get_speed;
645 surf_cpu_model->extension.cpu.get_available_speed =
646 cpu_get_available_speed;
647 surf_cpu_model->extension.cpu.create_resource = cpu_create_resource;
648 surf_cpu_model->extension.cpu.add_traces = cpu_add_traces_cpu;
650 if (!cpu_maxmin_system) {
651 sg_maxmin_selective_update = 1;
652 cpu_maxmin_system = lmm_system_new();
654 if(cpu_update_mechanism == UM_LAZY){
655 cpu_action_heap = xbt_heap_new(8, NULL);
656 xbt_heap_set_update_callback(cpu_action_heap,
657 cpu_action_update_index_heap);
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()
681 char *optim = xbt_cfg_get_string(_surf_cfg_set, "cpu/optim");
682 char *model = xbt_cfg_get_string(_surf_cfg_set, "cpu/model");
684 if(!strcmp(model,"Cas01_fullupdate")) {
685 XBT_WARN("[*Deprecated*. Use --cfg=cpu/model:Cas01 with option --cfg=cpu/optim:Full instead.]");
686 } else if(!strcmp(model,"CpuTI")) {
687 XBT_WARN("[*Deprecated*. Use --cfg=cpu/model:Cas01 with option --cfg=cpu/optim:TI instead.]");
690 if(!strcmp(optim,"Full")) {
691 cpu_update_mechanism = UM_FULL;
692 } else if (strcmp(optim,"Lazy")) {
693 cpu_update_mechanism = UM_LAZY;
694 } else if (strcmp(optim,"TI")) {
695 surf_cpu_model_init_ti();
698 xbt_die("Unsupported optimization (%s) for this model",optim);
703 surf_cpu_model_init_internal("CPU");
704 cpu_define_callbacks();
705 xbt_dynar_push(model_list, &surf_cpu_model);
708 double generic_share_resources(double now)
710 surf_action_cpu_Cas01_t action;
711 if(cpu_update_mechanism == UM_LAZY)
712 return cpu_share_resources_lazy(now);
713 else if (cpu_update_mechanism == UM_FULL)
714 return generic_maxmin_share_resources(surf_cpu_model->states.running_action_set,
715 xbt_swag_offset(*action, generic_lmm_action.variable),
716 cpu_maxmin_system, lmm_solve);
718 xbt_die("Invalide update mechanism!");
723 static void cpu_update_actions_state_full(double now, double delta)
725 surf_action_cpu_Cas01_t action = NULL;
726 surf_action_cpu_Cas01_t next_action = NULL;
727 xbt_swag_t running_actions = surf_cpu_model->states.running_action_set;
728 xbt_swag_foreach_safe(action, next_action, running_actions) {
730 if (TRACE_is_enabled()) {
732 lmm_constraint_id(lmm_get_cnst_from_var
733 (cpu_maxmin_system, GENERIC_LMM_ACTION(action).variable, 0));
735 TRACE_surf_host_set_utilization(x->generic_resource.name,
736 GENERIC_ACTION(action).data,
737 (surf_action_t) action,
738 lmm_variable_getvalue
739 (GENERIC_LMM_ACTION(action).variable), now - delta,
741 TRACE_last_timestamp_to_dump = now-delta;
744 double_update(&(GENERIC_ACTION(action).remains),
745 lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable) * delta);
746 if (GENERIC_LMM_ACTION(action).generic_action.max_duration != NO_MAX_DURATION)
747 double_update(&(GENERIC_ACTION(action).max_duration), delta);
748 if ((GENERIC_ACTION(action).remains <= 0) &&
749 (lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) > 0)) {
750 GENERIC_ACTION(action).finish = surf_get_clock();
751 cpu_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
752 } else if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION) &&
753 (GENERIC_ACTION(action).max_duration <= 0)) {
754 GENERIC_ACTION(action).finish = surf_get_clock();
755 cpu_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
762 void generic_update_actions_state(double now, double delta)
764 if(cpu_update_mechanism == UM_LAZY)
765 cpu_update_actions_state_lazy(now, delta);
766 else if(cpu_update_mechanism == UM_FULL)
767 cpu_update_actions_state_full(now, delta);
769 xbt_die("Not recognized surf cpu model!");