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_FULL;
14 #undef GENERIC_LMM_ACTION
17 #define GENERIC_LMM_ACTION(action) action->generic_lmm_action
18 #define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action
19 #define ACTION_GET_CPU(action) ((surf_action_cpu_Cas01_im_t) action)->cpu
21 typedef struct surf_action_cpu_cas01_im {
22 s_surf_action_lmm_t generic_lmm_action;
23 s_xbt_swag_hookup_t cpu_list_hookup;
26 } s_surf_action_cpu_Cas01_im_t, *surf_action_cpu_Cas01_im_t;
28 typedef struct cpu_Cas01_im {
29 s_surf_resource_t generic_resource;
30 s_xbt_swag_hookup_t modified_cpu_hookup;
33 tmgr_trace_event_t power_event;
35 e_surf_resource_state_t state_current;
36 tmgr_trace_event_t state_event;
37 lmm_constraint_t constraint;
38 xbt_swag_t action_set;
40 } s_cpu_Cas01_im_t, *cpu_Cas01_im_t;
42 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_im, surf,
43 "Logging specific to the SURF CPU IMPROVED module");
45 lmm_system_t cpu_im_maxmin_system = NULL;
46 static xbt_swag_t cpu_im_modified_cpu = NULL;
47 static xbt_heap_t cpu_im_action_heap = NULL;
48 extern int sg_maxmin_selective_update;
52 cpu_im_running_action_set_that_does_not_need_being_checked = NULL;
54 static void* cpu_im_create_resource(const char *name, double power_peak,
56 tmgr_trace_t power_trace,
58 e_surf_resource_state_t state_initial,
59 tmgr_trace_t state_trace,
60 xbt_dict_t cpu_properties)
62 cpu_Cas01_im_t cpu = NULL;
63 s_surf_action_cpu_Cas01_im_t action;
65 xbt_assert(!surf_cpu_resource_by_name(name),
66 "Host '%s' declared several times in the platform file",
68 cpu = (cpu_Cas01_im_t) surf_resource_new(sizeof(s_cpu_Cas01_im_t),
69 surf_cpu_model, name,cpu_properties);
70 cpu->power_peak = power_peak;
71 xbt_assert(cpu->power_peak > 0, "Power has to be >0");
72 cpu->power_scale = power_scale;
74 xbt_assert(core>0,"Invalid number of cores %d",core);
78 tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
80 cpu->state_current = state_initial;
83 tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
86 lmm_constraint_new(cpu_im_maxmin_system, cpu,
87 cpu->core * cpu->power_scale * cpu->power_peak);
89 xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu);
90 if(cpu_update_mechanism == UM_LAZY)
91 cpu->action_set = xbt_swag_new(xbt_swag_offset(action, cpu_list_hookup));
97 static void parse_cpu_im_init(sg_platf_host_cbarg_t host)
99 cpu_im_create_resource(host->id,
109 static void cpu_im_add_traces_cpu(void)
111 xbt_dict_cursor_t cursor = NULL;
112 char *trace_name, *elm;
113 static int called = 0;
118 /* connect all traces relative to hosts */
119 xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
120 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
121 cpu_Cas01_im_t host = surf_cpu_resource_by_name(elm);
123 xbt_assert(host, "Host %s undefined", elm);
124 xbt_assert(trace, "Trace %s undefined", trace_name);
127 tmgr_history_add_trace(history, trace, 0.0, 0, host);
130 xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
131 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
132 cpu_Cas01_im_t host = surf_cpu_resource_by_name(elm);
134 xbt_assert(host, "Host %s undefined", elm);
135 xbt_assert(trace, "Trace %s undefined", trace_name);
138 tmgr_history_add_trace(history, trace, 0.0, 0, host);
142 static void cpu_im_define_callbacks()
144 sg_platf_host_add_cb(parse_cpu_im_init);
145 sg_platf_postparse_add_cb(cpu_im_add_traces_cpu);
148 static int cpu_im_resource_used(void *resource)
150 return lmm_constraint_used(cpu_im_maxmin_system,
151 ((cpu_Cas01_im_t) resource)->constraint);
154 static int cpu_im_action_unref(surf_action_t action)
157 if (!action->refcount) {
158 xbt_swag_remove(action, action->state_set);
159 if (((surf_action_lmm_t) action)->variable)
160 lmm_variable_free(cpu_im_maxmin_system,
161 ((surf_action_lmm_t) action)->variable);
162 if(cpu_update_mechanism == UM_LAZY){
163 /* remove from heap */
164 xbt_heap_remove(cpu_im_action_heap,
165 ((surf_action_cpu_Cas01_im_t) action)->index_heap);
166 xbt_swag_remove(action,
167 ((cpu_Cas01_im_t) ACTION_GET_CPU(action))->action_set);
168 xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
171 xbt_free(action->category);
173 surf_action_free(&action);
179 static void cpu_im_action_cancel(surf_action_t action)
181 surf_action_state_set(action, SURF_ACTION_FAILED);
182 if(cpu_update_mechanism == UM_LAZY){
183 xbt_heap_remove(cpu_im_action_heap,
184 ((surf_action_cpu_Cas01_im_t) action)->index_heap);
185 xbt_swag_remove(action,
186 ((cpu_Cas01_im_t) ACTION_GET_CPU(action))->action_set);
191 static void cpu_im_cpu_action_state_set(surf_action_t action,
192 e_surf_action_state_t state)
194 /* if((state==SURF_ACTION_DONE) || (state==SURF_ACTION_FAILED)) */
195 /* if(((surf_action_lmm_t)action)->variable) { */
196 /* lmm_variable_disable(cpu_im_maxmin_system, ((surf_action_lmm_t)action)->variable); */
197 /* ((surf_action_lmm_t)action)->variable = NULL; */
200 surf_action_state_set(action, state);
204 static void cpu_im_update_remains(cpu_Cas01_im_t cpu, double now)
206 surf_action_cpu_Cas01_im_t action;
208 if (cpu->last_update >= now)
210 xbt_swag_foreach(action, cpu->action_set) {
211 if (GENERIC_ACTION(action).state_set !=
212 surf_cpu_model->states.running_action_set)
215 /* bogus priority, skip it */
216 if (GENERIC_ACTION(action).priority <= 0)
219 if (GENERIC_ACTION(action).remains > 0) {
220 double_update(&(GENERIC_ACTION(action).remains),
221 lmm_variable_getvalue(GENERIC_LMM_ACTION
222 (action).variable) * (now -
225 if (TRACE_is_enabled()) {
226 TRACE_surf_host_set_utilization(cpu->generic_resource.name,
228 generic_lmm_action.generic_action.
229 data, (surf_action_t) action,
230 lmm_variable_getvalue
234 now - cpu->last_update);
237 XBT_DEBUG("Update action(%p) remains %lf", action,
238 GENERIC_ACTION(action).remains);
241 cpu->last_update = now;
244 static double cpu_im_share_resources(double now)
246 surf_action_cpu_Cas01_im_t action;
249 cpu_Cas01_im_t cpu, cpu_next;
251 xbt_swag_foreach(cpu, cpu_im_modified_cpu)
252 cpu_im_update_remains(cpu, now);
254 lmm_solve(cpu_im_maxmin_system);
256 xbt_swag_foreach_safe(cpu, cpu_next, cpu_im_modified_cpu) {
257 xbt_swag_foreach(action, cpu->action_set) {
258 if (GENERIC_ACTION(action).state_set !=
259 surf_cpu_model->states.running_action_set)
262 /* bogus priority, skip it */
263 if (GENERIC_ACTION(action).priority <= 0)
267 value = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable);
269 if (GENERIC_ACTION(action).remains > 0) {
270 value = GENERIC_ACTION(action).remains / value;
278 if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION)
280 || GENERIC_ACTION(action).start +
281 GENERIC_ACTION(action).max_duration < min))
283 GENERIC_ACTION(action).start +
284 GENERIC_ACTION(action).max_duration;
286 XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
287 GENERIC_ACTION(action).start, now + value,
288 GENERIC_ACTION(action).max_duration);
290 if (action->index_heap >= 0) {
291 surf_action_cpu_Cas01_im_t heap_act =
292 xbt_heap_remove(cpu_im_action_heap, action->index_heap);
293 if (heap_act != action)
297 xbt_heap_push(cpu_im_action_heap, action, min);
298 XBT_DEBUG("Insert at heap action(%p) min %lf", action, min);
301 xbt_swag_remove(cpu, cpu_im_modified_cpu);
303 return xbt_heap_size(cpu_im_action_heap) >
304 0 ? xbt_heap_maxkey(cpu_im_action_heap) - now : -1;
307 static void cpu_im_update_actions_state(double now, double delta)
309 surf_action_cpu_Cas01_im_t action;
310 while ((xbt_heap_size(cpu_im_action_heap) > 0)
311 && (double_equals(xbt_heap_maxkey(cpu_im_action_heap), now))) {
312 action = xbt_heap_pop(cpu_im_action_heap);
313 XBT_DEBUG("Action %p: finish", action);
314 GENERIC_ACTION(action).finish = surf_get_clock();
315 /* set the remains to 0 due to precision problems when updating the remaining amount */
317 if (TRACE_is_enabled()) {
318 cpu_Cas01_im_t cpu = ((cpu_Cas01_im_t)(action->cpu));
319 TRACE_surf_host_set_utilization(cpu->generic_resource.name,
320 GENERIC_LMM_ACTION(action).generic_action.data,
321 (surf_action_t) action,
322 lmm_variable_getvalue (GENERIC_LMM_ACTION(action).variable),
324 now - cpu->last_update);
327 GENERIC_ACTION(action).remains = 0;
328 cpu_im_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
329 cpu_im_update_remains(action->cpu, surf_get_clock());
332 if (TRACE_is_enabled()) {
333 //defining the last timestamp that we can safely dump to trace file
334 //without losing the event ascending order (considering all CPU's)
337 xbt_lib_cursor_t cursor;
340 xbt_lib_foreach(host_lib, cursor, key, data){
341 if(data[SURF_CPU_LEVEL]){
342 cpu = data[SURF_CPU_LEVEL];
344 smaller = cpu->last_update;
347 if (cpu->last_update < smaller){
348 smaller = cpu->last_update;
353 TRACE_last_timestamp_to_dump = smaller;
360 static void cpu_im_update_resource_state(void *id,
361 tmgr_trace_event_t event_type,
362 double value, double date)
364 cpu_Cas01_im_t cpu = id;
365 lmm_variable_t var = NULL;
366 lmm_element_t elem = NULL;
368 if (event_type == cpu->power_event) {
369 cpu->power_scale = value;
370 lmm_update_constraint_bound(cpu_im_maxmin_system, cpu->constraint,
371 cpu->core * cpu->power_scale * cpu->power_peak);
373 TRACE_surf_host_set_power(date, cpu->generic_resource.name,
374 cpu->core * cpu->power_scale * cpu->power_peak);
376 while ((var = lmm_get_var_from_cnst
377 (cpu_im_maxmin_system, cpu->constraint, &elem))) {
378 surf_action_cpu_Cas01_im_t action = lmm_variable_id(var);
379 lmm_update_variable_bound(cpu_im_maxmin_system, GENERIC_LMM_ACTION(action).variable,
380 cpu->power_scale * cpu->power_peak);
382 if(cpu_update_mechanism == UM_LAZY)
383 xbt_swag_insert(cpu, cpu_im_modified_cpu);
384 if (tmgr_trace_event_free(event_type))
385 cpu->power_event = NULL;
386 } else if (event_type == cpu->state_event) {
388 cpu->state_current = SURF_RESOURCE_ON;
390 lmm_constraint_t cnst = cpu->constraint;
391 lmm_variable_t var = NULL;
392 lmm_element_t elem = NULL;
394 cpu->state_current = SURF_RESOURCE_OFF;
397 lmm_get_var_from_cnst(cpu_im_maxmin_system, cnst, &elem))) {
398 surf_action_t action = lmm_variable_id(var);
400 if (surf_action_state_get(action) == SURF_ACTION_RUNNING ||
401 surf_action_state_get(action) == SURF_ACTION_READY ||
402 surf_action_state_get(action) ==
403 SURF_ACTION_NOT_IN_THE_SYSTEM) {
404 action->finish = date;
405 cpu_im_cpu_action_state_set(action, SURF_ACTION_FAILED);
409 if (tmgr_trace_event_free(event_type))
410 cpu->state_event = NULL;
412 XBT_CRITICAL("Unknown event ! \n");
419 static surf_action_t cpu_im_execute(void *cpu, double size)
421 surf_action_cpu_Cas01_im_t action = NULL;
422 cpu_Cas01_im_t CPU = cpu;
424 XBT_IN("(%s,%g)", surf_resource_name(CPU), size);
426 surf_action_new(sizeof(s_surf_action_cpu_Cas01_im_t), size,
428 CPU->state_current != SURF_RESOURCE_ON);
430 GENERIC_LMM_ACTION(action).suspended = 0; /* Should be useless because of the
431 calloc but it seems to help valgrind... */
433 GENERIC_LMM_ACTION(action).variable =
434 lmm_variable_new(cpu_im_maxmin_system, action,
435 GENERIC_ACTION(action).priority, CPU->power_scale * CPU->power_peak, 1);
436 if(cpu_update_mechanism == UM_LAZY){
437 action->index_heap = -1;
439 xbt_swag_insert(CPU, cpu_im_modified_cpu);
440 xbt_swag_insert(action, CPU->action_set);
442 lmm_expand(cpu_im_maxmin_system, CPU->constraint,
443 GENERIC_LMM_ACTION(action).variable, 1.0);
445 return (surf_action_t) action;
448 static surf_action_t cpu_im_action_sleep(void *cpu, double duration)
450 surf_action_cpu_Cas01_im_t action = NULL;
453 duration = MAX(duration, MAXMIN_PRECISION);
455 XBT_IN("(%s,%g)", surf_resource_name(cpu), duration);
456 action = (surf_action_cpu_Cas01_im_t) cpu_im_execute(cpu, 1.0);
457 GENERIC_ACTION(action).max_duration = duration;
458 GENERIC_LMM_ACTION(action).suspended = 2;
459 if (duration == NO_MAX_DURATION) {
460 /* Move to the *end* of the corresponding action set. This convention
461 is used to speed up update_resource_state */
462 xbt_swag_remove(action, ((surf_action_t) action)->state_set);
463 ((surf_action_t) action)->state_set =
464 cpu_im_running_action_set_that_does_not_need_being_checked;
465 xbt_swag_insert(action, ((surf_action_t) action)->state_set);
468 lmm_update_variable_weight(cpu_im_maxmin_system,
469 GENERIC_LMM_ACTION(action).variable, 0.0);
470 if(cpu_update_mechanism == UM_LAZY)
471 xbt_swag_insert(cpu, cpu_im_modified_cpu);
473 return (surf_action_t) action;
476 static void cpu_im_action_suspend(surf_action_t action)
478 XBT_IN("(%p)", action);
479 if (((surf_action_lmm_t) action)->suspended != 2) {
480 lmm_update_variable_weight(cpu_im_maxmin_system,
481 ((surf_action_lmm_t) action)->variable,
483 ((surf_action_lmm_t) action)->suspended = 1;
484 if(cpu_update_mechanism == UM_LAZY){
485 xbt_heap_remove(cpu_im_action_heap,
486 ((surf_action_cpu_Cas01_im_t) action)->index_heap);
487 xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
493 static void cpu_im_action_resume(surf_action_t action)
496 XBT_IN("(%p)", action);
497 if (((surf_action_lmm_t) action)->suspended != 2) {
498 lmm_update_variable_weight(cpu_im_maxmin_system,
499 ((surf_action_lmm_t) action)->variable,
501 ((surf_action_lmm_t) action)->suspended = 0;
502 if(cpu_update_mechanism == UM_LAZY)
503 xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
508 static int cpu_im_action_is_suspended(surf_action_t action)
510 return (((surf_action_lmm_t) action)->suspended == 1);
513 static void cpu_im_action_set_max_duration(surf_action_t action,
516 XBT_IN("(%p,%g)", action, duration);
518 action->max_duration = duration;
519 /* insert cpu in modified_cpu set to notice the max duration change */
520 if(cpu_update_mechanism == UM_LAZY)
521 xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
525 static void cpu_im_action_set_priority(surf_action_t action,
528 XBT_IN("(%p,%g)", action, priority);
529 action->priority = priority;
530 lmm_update_variable_weight(cpu_im_maxmin_system,
531 ((surf_action_lmm_t) action)->variable,
534 if(cpu_update_mechanism == UM_LAZY)
535 xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
540 static void cpu_im_action_set_category(surf_action_t action,
541 const char *category)
543 XBT_IN("(%p,%s)", action, category);
544 action->category = xbt_strdup (category);
549 static double cpu_im_action_get_remains(surf_action_t action)
551 XBT_IN("(%p)", action);
552 /* update remains before return it */
553 if(cpu_update_mechanism == UM_LAZY)
554 cpu_im_update_remains(ACTION_GET_CPU(action), surf_get_clock());
555 return action->remains;
559 static e_surf_resource_state_t cpu_im_get_state(void *cpu)
561 return ((cpu_Cas01_im_t) cpu)->state_current;
564 static double cpu_im_get_speed(void *cpu, double load)
566 return load * (((cpu_Cas01_im_t) cpu)->power_peak);
569 static double cpu_im_get_available_speed(void *cpu)
571 /* number between 0 and 1 */
572 return ((cpu_Cas01_im_t) cpu)->power_scale;
575 static void cpu_im_action_update_index_heap(void *action, int i)
577 ((surf_action_cpu_Cas01_im_t) action)->index_heap = i;
580 static void cpu_im_finalize(void)
583 xbt_lib_cursor_t cursor;
586 xbt_lib_foreach(host_lib, cursor, key, cpu){
587 if(cpu[SURF_CPU_LEVEL])
589 cpu_Cas01_im_t CPU = cpu[SURF_CPU_LEVEL];
590 xbt_swag_free(CPU->action_set);
594 lmm_system_free(cpu_im_maxmin_system);
595 cpu_im_maxmin_system = NULL;
597 surf_model_exit(surf_cpu_model);
598 surf_cpu_model = NULL;
601 (cpu_im_running_action_set_that_does_not_need_being_checked);
602 cpu_im_running_action_set_that_does_not_need_being_checked = NULL;
603 if(cpu_im_action_heap) xbt_heap_free(cpu_im_action_heap);
604 if(cpu_im_modified_cpu) xbt_swag_free(cpu_im_modified_cpu);
607 static void surf_cpu_im_model_init_internal(const char* name)
609 s_surf_action_t action;
610 s_cpu_Cas01_im_t cpu;
612 surf_cpu_model = surf_model_init();
614 cpu_im_running_action_set_that_does_not_need_being_checked =
615 xbt_swag_new(xbt_swag_offset(action, state_hookup));
617 surf_cpu_model->name = name;
619 surf_cpu_model->action_unref = cpu_im_action_unref;
620 surf_cpu_model->action_cancel = cpu_im_action_cancel;
621 surf_cpu_model->action_state_set = cpu_im_cpu_action_state_set;
623 surf_cpu_model->model_private->resource_used = cpu_im_resource_used;
624 surf_cpu_model->model_private->share_resources = generic_share_resources;
625 surf_cpu_model->model_private->update_actions_state =
626 generic_update_actions_state;//ok
627 surf_cpu_model->model_private->update_resource_state =
628 cpu_im_update_resource_state;//ok
629 surf_cpu_model->model_private->finalize = cpu_im_finalize;
631 surf_cpu_model->suspend = cpu_im_action_suspend;
632 surf_cpu_model->resume = cpu_im_action_resume;
633 surf_cpu_model->is_suspended = cpu_im_action_is_suspended;
634 surf_cpu_model->set_max_duration = cpu_im_action_set_max_duration;
635 surf_cpu_model->set_priority = cpu_im_action_set_priority;
637 surf_cpu_model->set_category = cpu_im_action_set_category;
639 surf_cpu_model->get_remains = cpu_im_action_get_remains;
641 surf_cpu_model->extension.cpu.execute = cpu_im_execute;
642 surf_cpu_model->extension.cpu.sleep = cpu_im_action_sleep;
644 surf_cpu_model->extension.cpu.get_state = cpu_im_get_state;
645 surf_cpu_model->extension.cpu.get_speed = cpu_im_get_speed;
646 surf_cpu_model->extension.cpu.get_available_speed =
647 cpu_im_get_available_speed;
648 surf_cpu_model->extension.cpu.create_resource = cpu_im_create_resource;
649 surf_cpu_model->extension.cpu.add_traces = cpu_im_add_traces_cpu;
651 if (!cpu_im_maxmin_system) {
652 sg_maxmin_selective_update = 1;
653 cpu_im_maxmin_system = lmm_system_new();
655 if(cpu_update_mechanism == UM_LAZY){
656 cpu_im_action_heap = xbt_heap_new(8, NULL);
657 xbt_heap_set_update_callback(cpu_im_action_heap,
658 cpu_im_action_update_index_heap);
659 cpu_im_modified_cpu =
660 xbt_swag_new(xbt_swag_offset(cpu, modified_cpu_hookup));
664 /*********************************************************************/
665 /* Basic sharing model for CPU: that is where all this started... ;) */
666 /*********************************************************************/
667 /* @InProceedings{casanova01simgrid, */
668 /* author = "H. Casanova", */
669 /* booktitle = "Proceedings of the IEEE Symposium on Cluster Computing */
670 /* and the Grid (CCGrid'01)", */
671 /* publisher = "IEEE Computer Society", */
672 /* title = "Simgrid: {A} Toolkit for the Simulation of Application */
676 /* note = "Available at */
677 /* \url{http://grail.sdsc.edu/papers/simgrid_ccgrid01.ps.gz}." */
680 void surf_cpu_model_init_Cas01()
682 char *optim = xbt_cfg_get_string(_surf_cfg_set, "cpu/optim");
683 char *model = xbt_cfg_get_string(_surf_cfg_set, "cpu/model");
685 if(!strcmp(model,"Cas01_fullupdate")) {
686 XBT_WARN("[*Deprecated*. Use --cfg=cpu/model:Cas01 with option --cfg=cpu/optim:Full instead.]");
687 } else if(!strcmp(model,"CpuTI")) {
688 XBT_WARN("[*Deprecated*. Use --cfg=cpu/model:Cas01 with option --cfg=cpu/optim:TI instead.]");
691 if(!strcmp(optim,"Full")) {
692 cpu_update_mechanism = UM_FULL;
693 } else if (strcmp(optim,"Lazy")) {
694 cpu_update_mechanism = UM_LAZY;
695 } else if (strcmp(optim,"TI")) {
696 surf_cpu_model_init_ti();
699 xbt_die("Unsupported optimization (%s) for this model",optim);
704 surf_cpu_im_model_init_internal("CPU");
705 cpu_im_define_callbacks();
706 xbt_dynar_push(model_list, &surf_cpu_model);
709 double generic_share_resources(double now)
711 surf_action_cpu_Cas01_im_t action;
712 if(cpu_update_mechanism == UM_LAZY)
713 return cpu_im_share_resources(now);
714 else if (cpu_update_mechanism == UM_FULL)
716 return generic_maxmin_share_resources(surf_cpu_model->states.running_action_set,
717 xbt_swag_offset(*action, generic_lmm_action.variable),
718 cpu_im_maxmin_system, lmm_solve);
720 xbt_die("Invalide update mechanism!");
725 static void cpu_update_actions_state(double now, double delta)
727 surf_action_cpu_Cas01_im_t action = NULL;
728 surf_action_cpu_Cas01_im_t next_action = NULL;
729 xbt_swag_t running_actions = surf_cpu_model->states.running_action_set;
730 xbt_swag_foreach_safe(action, next_action, running_actions) {
732 if (TRACE_is_enabled()) {
734 lmm_constraint_id(lmm_get_cnst_from_var
735 (cpu_maxmin_system, GENERIC_LMM_ACTION(action).variable, 0));
737 TRACE_surf_host_set_utilization(x->generic_resource.name,
738 GENERIC_ACTION(action).data,
739 (surf_action_t) action,
740 lmm_variable_getvalue
741 (GENERIC_LMM_ACTION(action).variable), now - delta,
743 TRACE_last_timestamp_to_dump = now-delta;
746 double_update(&(GENERIC_ACTION(action).remains),
747 lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable) * delta);
748 if (GENERIC_LMM_ACTION(action).generic_action.max_duration != NO_MAX_DURATION)
749 double_update(&(GENERIC_ACTION(action).max_duration), delta);
750 if ((GENERIC_ACTION(action).remains <= 0) &&
751 (lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) > 0)) {
752 GENERIC_ACTION(action).finish = surf_get_clock();
753 cpu_im_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
754 } else if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION) &&
755 (GENERIC_ACTION(action).max_duration <= 0)) {
756 GENERIC_ACTION(action).finish = surf_get_clock();
757 cpu_im_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
764 void generic_update_actions_state(double now, double delta)
766 if(cpu_update_mechanism == UM_LAZY)
767 cpu_im_update_actions_state(now, delta);
768 else if(cpu_update_mechanism == UM_FULL)
770 cpu_update_actions_state(now, delta);
773 xbt_die("Not recognized surf cpu model!");