Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
David's patch: replace != by strcmp
[simgrid.git] / src / surf / cpu_im.c
1 /* Copyright (c) 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "surf_private.h"
8
9 #undef GENERIC_LMM_ACTION
10 #undef GENERIC_ACTION
11 #undef ACTION_GET_CPU
12 #define GENERIC_LMM_ACTION(action) action->generic_lmm_action
13 #define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action
14 #define ACTION_GET_CPU(action) ((surf_action_cpu_Cas01_im_t) action)->cpu
15
16 typedef struct surf_action_cpu_cas01_im {
17   s_surf_action_lmm_t generic_lmm_action;
18   s_xbt_swag_hookup_t cpu_list_hookup;
19   int index_heap;
20   void *cpu;
21 } s_surf_action_cpu_Cas01_im_t, *surf_action_cpu_Cas01_im_t;
22
23 typedef struct cpu_Cas01_im {
24   s_surf_resource_t generic_resource;
25   s_xbt_swag_hookup_t modified_cpu_hookup;
26   double power_peak;
27   double power_scale;
28   tmgr_trace_event_t power_event;
29   int core;
30   e_surf_resource_state_t state_current;
31   tmgr_trace_event_t state_event;
32   lmm_constraint_t constraint;
33   xbt_swag_t action_set;
34   double last_update;
35 } s_cpu_Cas01_im_t, *cpu_Cas01_im_t;
36
37 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_im, surf,
38                                 "Logging specific to the SURF CPU IMPROVED module");
39
40
41 lmm_system_t cpu_im_maxmin_system = NULL;
42 static xbt_swag_t cpu_im_modified_cpu = NULL;
43 static xbt_heap_t cpu_im_action_heap = NULL;
44 extern int sg_maxmin_selective_update;
45
46
47 static xbt_swag_t
48     cpu_im_running_action_set_that_does_not_need_being_checked = NULL;
49
50 static cpu_Cas01_im_t cpu_im_new(char *name, double power_peak,
51                                  double power_scale,
52                                  tmgr_trace_t power_trace,
53                                  int core,
54                                  e_surf_resource_state_t state_initial,
55                                  tmgr_trace_t state_trace,
56                                  xbt_dict_t cpu_properties)
57 {
58   cpu_Cas01_im_t cpu = NULL;
59   s_surf_action_cpu_Cas01_im_t action;
60   cpu = xbt_new0(s_cpu_Cas01_im_t, 1);
61
62   xbt_assert1(!surf_model_resource_by_name(surf_cpu_model, name),
63               "Host '%s' declared several times in the platform file",
64               name);
65   cpu->generic_resource.model = surf_cpu_model;
66   cpu->generic_resource.name = name;
67   cpu->generic_resource.properties = cpu_properties;
68   cpu->power_peak = power_peak;
69   xbt_assert0(cpu->power_peak > 0, "Power has to be >0");
70   cpu->power_scale = power_scale;
71   if (power_trace)
72     cpu->power_event =
73         tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
74   cpu->core = core;
75   xbt_assert1(core>0,"Invalid number of cores %d",core);
76
77   cpu->state_current = state_initial;
78   if (state_trace)
79     cpu->state_event =
80         tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
81
82   cpu->constraint =
83       lmm_constraint_new(cpu_im_maxmin_system, cpu,
84                          cpu->core * cpu->power_scale * cpu->power_peak);
85
86   xbt_dict_set(surf_model_resource_set(surf_cpu_model), name, cpu,
87                surf_resource_free);
88   cpu->action_set = xbt_swag_new(xbt_swag_offset(action, cpu_list_hookup));
89
90 #ifdef HAVE_TRACING
91   TRACE_surf_host_declaration(name, core * power_scale * power_peak);
92 #endif
93
94   return cpu;
95 }
96
97
98 static void parse_cpu_im_init(void)
99 {
100   double power_peak = 0.0;
101   double power_scale = 0.0;
102   int core = 0;
103   tmgr_trace_t power_trace = NULL;
104   e_surf_resource_state_t state_initial = SURF_RESOURCE_OFF;
105   tmgr_trace_t state_trace = NULL;
106
107   power_peak = get_cpu_power(A_surfxml_host_power);
108   surf_parse_get_double(&power_scale, A_surfxml_host_availability);
109   power_trace = tmgr_trace_new(A_surfxml_host_availability_file);
110   surf_parse_get_int(&core, A_surfxml_host_core);
111
112   xbt_assert0((A_surfxml_host_state == A_surfxml_host_state_ON) ||
113               (A_surfxml_host_state == A_surfxml_host_state_OFF),
114               "Invalid state");
115   if (A_surfxml_host_state == A_surfxml_host_state_ON)
116     state_initial = SURF_RESOURCE_ON;
117   if (A_surfxml_host_state == A_surfxml_host_state_OFF)
118     state_initial = SURF_RESOURCE_OFF;
119   state_trace = tmgr_trace_new(A_surfxml_host_state_file);
120
121   current_property_set = xbt_dict_new();
122   cpu_im_new(xbt_strdup(A_surfxml_host_id), power_peak, power_scale,
123              power_trace, core, state_initial, state_trace,
124              current_property_set);
125
126 }
127
128 static void cpu_im_add_traces_cpu(void)
129 {
130   xbt_dict_cursor_t cursor = NULL;
131   char *trace_name, *elm;
132   static int called = 0;
133   if (called)
134     return;
135   called = 1;
136
137   /* connect all traces relative to hosts */
138   xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
139     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
140     cpu_Cas01_im_t host = surf_model_resource_by_name(surf_cpu_model, elm);
141
142     xbt_assert1(host, "Host %s undefined", elm);
143     xbt_assert1(trace, "Trace %s undefined", trace_name);
144
145     host->state_event =
146         tmgr_history_add_trace(history, trace, 0.0, 0, host);
147   }
148
149   xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
150     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
151     cpu_Cas01_im_t host = surf_model_resource_by_name(surf_cpu_model, elm);
152
153     xbt_assert1(host, "Host %s undefined", elm);
154     xbt_assert1(trace, "Trace %s undefined", trace_name);
155
156     host->power_event =
157         tmgr_history_add_trace(history, trace, 0.0, 0, host);
158   }
159 }
160
161 static void cpu_im_define_callbacks(const char *file)
162 {
163
164   surf_parse_reset_parser();
165   surfxml_add_callback(STag_surfxml_host_cb_list, parse_cpu_im_init);
166   surfxml_add_callback(ETag_surfxml_platform_cb_list,
167                        &cpu_im_add_traces_cpu);
168 }
169
170 static int cpu_im_resource_used(void *resource_id)
171 {
172   return lmm_constraint_used(cpu_im_maxmin_system,
173                              ((cpu_Cas01_im_t) resource_id)->constraint);
174 }
175
176 static int cpu_im_action_unref(surf_action_t action)
177 {
178   action->refcount--;
179   if (!action->refcount) {
180     xbt_swag_remove(action, action->state_set);
181     if (((surf_action_lmm_t) action)->variable)
182       lmm_variable_free(cpu_im_maxmin_system,
183                         ((surf_action_lmm_t) action)->variable);
184     /* remove from heap */
185     xbt_heap_remove(cpu_im_action_heap,
186                     ((surf_action_cpu_Cas01_im_t) action)->index_heap);
187     xbt_swag_remove(action,
188                     ((cpu_Cas01_im_t) ACTION_GET_CPU(action))->action_set);
189     xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
190 #ifdef HAVE_TRACING
191     if (action->category)
192       xbt_free(action->category);
193 #endif
194     free(action);
195     return 1;
196   }
197   return 0;
198 }
199
200 static void cpu_im_action_cancel(surf_action_t action)
201 {
202   surf_action_state_set(action, SURF_ACTION_FAILED);
203   xbt_heap_remove(cpu_im_action_heap,
204                   ((surf_action_cpu_Cas01_im_t) action)->index_heap);
205   xbt_swag_remove(action,
206                   ((cpu_Cas01_im_t) ACTION_GET_CPU(action))->action_set);
207   return;
208 }
209
210 static void cpu_im_cpu_action_state_set(surf_action_t action,
211                                         e_surf_action_state_t state)
212 {
213 /*   if((state==SURF_ACTION_DONE) || (state==SURF_ACTION_FAILED)) */
214 /*     if(((surf_action_lmm_t)action)->variable) { */
215 /*       lmm_variable_disable(cpu_im_maxmin_system, ((surf_action_lmm_t)action)->variable); */
216 /*       ((surf_action_lmm_t)action)->variable = NULL; */
217 /*     } */
218
219   surf_action_state_set(action, state);
220   return;
221 }
222
223 static void cpu_im_update_remains(cpu_Cas01_im_t cpu, double now)
224 {
225   surf_action_cpu_Cas01_im_t action;
226
227   if (cpu->last_update >= now)
228     return;
229   xbt_swag_foreach(action, cpu->action_set) {
230     if (GENERIC_ACTION(action).state_set !=
231         surf_cpu_model->states.running_action_set)
232       continue;
233
234     /* bogus priority, skip it */
235     if (GENERIC_ACTION(action).priority <= 0)
236       continue;
237
238     if (GENERIC_ACTION(action).remains > 0) {
239       double_update(&(GENERIC_ACTION(action).remains),
240                     lmm_variable_getvalue(GENERIC_LMM_ACTION
241                                           (action).variable) * (now -
242                                                                 cpu->last_update));
243 #ifdef HAVE_TRACING
244       TRACE_surf_host_set_utilization(cpu->generic_resource.name,
245                                       action->
246                                       generic_lmm_action.generic_action.
247                                       data, (surf_action_t) action,
248                                       lmm_variable_getvalue
249                                       (GENERIC_LMM_ACTION
250                                        (action).variable),
251                                       cpu->last_update,
252                                       now - cpu->last_update);
253 #endif
254       DEBUG2("Update action(%p) remains %lf", action,
255              GENERIC_ACTION(action).remains);
256     }
257   }
258   cpu->last_update = now;
259 }
260
261 static double cpu_im_share_resources(double now)
262 {
263   surf_action_cpu_Cas01_im_t action;
264   double min;
265   double value;
266   cpu_Cas01_im_t cpu, cpu_next;
267
268   xbt_swag_foreach(cpu, cpu_im_modified_cpu)
269       cpu_im_update_remains(cpu, now);
270
271   lmm_solve(cpu_im_maxmin_system);
272
273   xbt_swag_foreach_safe(cpu, cpu_next, cpu_im_modified_cpu) {
274     xbt_swag_foreach(action, cpu->action_set) {
275       if (GENERIC_ACTION(action).state_set !=
276           surf_cpu_model->states.running_action_set)
277         continue;
278
279       /* bogus priority, skip it */
280       if (GENERIC_ACTION(action).priority <= 0)
281         continue;
282
283       min = -1;
284       value = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable);
285       if (value > 0) {
286         if (GENERIC_ACTION(action).remains > 0) {
287           value = GENERIC_ACTION(action).remains / value;
288           min = now + value;
289         } else {
290           value = 0.0;
291           min = now;
292         }
293       }
294
295       if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION)
296           && (min == -1
297               || GENERIC_ACTION(action).start +
298               GENERIC_ACTION(action).max_duration < min))
299         min =
300             GENERIC_ACTION(action).start +
301             GENERIC_ACTION(action).max_duration;
302
303       DEBUG4("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
304              GENERIC_ACTION(action).start, now + value,
305              GENERIC_ACTION(action).max_duration);
306
307       if (action->index_heap >= 0) {
308         surf_action_cpu_Cas01_im_t heap_act =
309             xbt_heap_remove(cpu_im_action_heap, action->index_heap);
310         if (heap_act != action)
311           DIE_IMPOSSIBLE;
312       }
313       if (min != -1) {
314         xbt_heap_push(cpu_im_action_heap, action, min);
315         DEBUG2("Insert at heap action(%p) min %lf", action, min);
316       }
317     }
318     xbt_swag_remove(cpu, cpu_im_modified_cpu);
319   }
320   return xbt_heap_size(cpu_im_action_heap) >
321       0 ? xbt_heap_maxkey(cpu_im_action_heap) - now : -1;
322 }
323
324 static void cpu_im_update_actions_state(double now, double delta)
325 {
326   surf_action_cpu_Cas01_im_t action;
327
328   while ((xbt_heap_size(cpu_im_action_heap) > 0)
329          && (double_equals(xbt_heap_maxkey(cpu_im_action_heap), now))) {
330     action = xbt_heap_pop(cpu_im_action_heap);
331     DEBUG1("Action %p: finish", action);
332     GENERIC_ACTION(action).finish = surf_get_clock();
333     /* set the remains to 0 due to precision problems when updating the remaining amount */
334 #ifdef HAVE_TRACING
335     TRACE_surf_host_set_utilization(((cpu_Cas01_im_t)
336                                      (action->cpu))->generic_resource.name,
337                                     action->
338                                     generic_lmm_action.generic_action.data,
339                                     (surf_action_t) action,
340                                     lmm_variable_getvalue
341                                     (GENERIC_LMM_ACTION(action).variable),
342                                     ((cpu_Cas01_im_t)
343                                      (action->cpu))->last_update,
344                                     now -
345                                     ((cpu_Cas01_im_t)
346                                      (action->cpu))->last_update);
347 #endif
348     GENERIC_ACTION(action).remains = 0;
349     cpu_im_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
350     cpu_im_update_remains(action->cpu, surf_get_clock());
351   }
352   return;
353 }
354
355 static void cpu_im_update_resource_state(void *id,
356                                          tmgr_trace_event_t event_type,
357                                          double value, double date)
358 {
359   cpu_Cas01_im_t cpu = id;
360   lmm_variable_t var = NULL;
361   lmm_element_t elem = NULL;
362
363   if (event_type == cpu->power_event) {
364     cpu->power_scale = value;
365     lmm_update_constraint_bound(cpu_im_maxmin_system, cpu->constraint,
366                                 cpu->core * cpu->power_scale * cpu->power_peak);
367 #ifdef HAVE_TRACING
368     TRACE_surf_host_set_power(date, cpu->generic_resource.name,
369                               cpu->core * cpu->power_scale * cpu->power_peak);
370 #endif
371     while ((var = lmm_get_var_from_cnst
372             (cpu_im_maxmin_system, cpu->constraint, &elem))) {
373         surf_action_cpu_Cas01_im_t action = lmm_variable_id(var);
374         lmm_update_variable_bound(cpu_im_maxmin_system, action->generic_lmm_action.variable,
375                                   cpu->power_scale * cpu->power_peak);
376     }
377     xbt_swag_insert(cpu, cpu_im_modified_cpu);
378     if (tmgr_trace_event_free(event_type))
379       cpu->power_event = NULL;
380   } else if (event_type == cpu->state_event) {
381     if (value > 0)
382       cpu->state_current = SURF_RESOURCE_ON;
383     else {
384       lmm_constraint_t cnst = cpu->constraint;
385       lmm_variable_t var = NULL;
386       lmm_element_t elem = NULL;
387
388       cpu->state_current = SURF_RESOURCE_OFF;
389
390       while ((var =
391               lmm_get_var_from_cnst(cpu_im_maxmin_system, cnst, &elem))) {
392         surf_action_t action = lmm_variable_id(var);
393
394         if (surf_action_state_get(action) == SURF_ACTION_RUNNING ||
395             surf_action_state_get(action) == SURF_ACTION_READY ||
396             surf_action_state_get(action) ==
397             SURF_ACTION_NOT_IN_THE_SYSTEM) {
398           action->finish = date;
399           cpu_im_cpu_action_state_set(action, SURF_ACTION_FAILED);
400         }
401       }
402     }
403     if (tmgr_trace_event_free(event_type))
404       cpu->state_event = NULL;
405   } else {
406     CRITICAL0("Unknown event ! \n");
407     xbt_abort();
408   }
409
410   return;
411 }
412
413 static surf_action_t cpu_im_execute(void *cpu, double size)
414 {
415   surf_action_cpu_Cas01_im_t action = NULL;
416   cpu_Cas01_im_t CPU = cpu;
417
418   XBT_IN2("(%s,%g)", surf_resource_name(CPU), size);
419   action =
420       surf_action_new(sizeof(s_surf_action_cpu_Cas01_im_t), size,
421                       surf_cpu_model,
422                       CPU->state_current != SURF_RESOURCE_ON);
423
424   GENERIC_LMM_ACTION(action).suspended = 0;     /* Should be useless because of the
425                                                    calloc but it seems to help valgrind... */
426
427   GENERIC_LMM_ACTION(action).variable =
428       lmm_variable_new(cpu_im_maxmin_system, action,
429                        GENERIC_ACTION(action).priority, CPU->power_scale * CPU->power_peak, 1);
430   action->index_heap = -1;
431   action->cpu = CPU;
432   xbt_swag_insert(CPU, cpu_im_modified_cpu);
433   xbt_swag_insert(action, CPU->action_set);
434   lmm_expand(cpu_im_maxmin_system, CPU->constraint,
435              GENERIC_LMM_ACTION(action).variable, 1.0);
436   XBT_OUT;
437   return (surf_action_t) action;
438 }
439
440 static surf_action_t cpu_im_action_sleep(void *cpu, double duration)
441 {
442   surf_action_cpu_Cas01_im_t action = NULL;
443
444   if (duration > 0)
445     duration = MAX(duration, MAXMIN_PRECISION);
446
447   XBT_IN2("(%s,%g)", surf_resource_name(cpu), duration);
448   action = (surf_action_cpu_Cas01_im_t) cpu_im_execute(cpu, 1.0);
449   GENERIC_ACTION(action).max_duration = duration;
450   GENERIC_LMM_ACTION(action).suspended = 2;
451   if (duration == NO_MAX_DURATION) {
452     /* Move to the *end* of the corresponding action set. This convention
453        is used to speed up update_resource_state  */
454     xbt_swag_remove(action, ((surf_action_t) action)->state_set);
455     ((surf_action_t) action)->state_set =
456         cpu_im_running_action_set_that_does_not_need_being_checked;
457     xbt_swag_insert(action, ((surf_action_t) action)->state_set);
458   }
459
460   lmm_update_variable_weight(cpu_im_maxmin_system,
461                              GENERIC_LMM_ACTION(action).variable, 0.0);
462   xbt_swag_insert(cpu, cpu_im_modified_cpu);
463   XBT_OUT;
464   return (surf_action_t) action;
465 }
466
467 static void cpu_im_action_suspend(surf_action_t action)
468 {
469   XBT_IN1("(%p)", action);
470   if (((surf_action_lmm_t) action)->suspended != 2) {
471     lmm_update_variable_weight(cpu_im_maxmin_system,
472                                ((surf_action_lmm_t) action)->variable,
473                                0.0);
474     ((surf_action_lmm_t) action)->suspended = 1;
475     xbt_heap_remove(cpu_im_action_heap,
476                     ((surf_action_cpu_Cas01_im_t) action)->index_heap);
477     xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
478   }
479   XBT_OUT;
480 }
481
482 static void cpu_im_action_resume(surf_action_t action)
483 {
484
485   XBT_IN1("(%p)", action);
486   if (((surf_action_lmm_t) action)->suspended != 2) {
487     lmm_update_variable_weight(cpu_im_maxmin_system,
488                                ((surf_action_lmm_t) action)->variable,
489                                action->priority);
490     ((surf_action_lmm_t) action)->suspended = 0;
491     xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
492   }
493   XBT_OUT;
494 }
495
496 static int cpu_im_action_is_suspended(surf_action_t action)
497 {
498   return (((surf_action_lmm_t) action)->suspended == 1);
499 }
500
501 static void cpu_im_action_set_max_duration(surf_action_t action,
502                                            double duration)
503 {
504   XBT_IN2("(%p,%g)", action, duration);
505
506   action->max_duration = duration;
507   /* insert cpu in modified_cpu set to notice the max duration change */
508   xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
509   XBT_OUT;
510 }
511
512 static void cpu_im_action_set_priority(surf_action_t action,
513                                        double priority)
514 {
515   XBT_IN2("(%p,%g)", action, priority);
516   action->priority = priority;
517   lmm_update_variable_weight(cpu_im_maxmin_system,
518                              ((surf_action_lmm_t) action)->variable,
519                              priority);
520
521   xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
522   XBT_OUT;
523 }
524
525 #ifdef HAVE_TRACING
526 static void cpu_im_action_set_category(surf_action_t action,
527                                        const char *category)
528 {
529   XBT_IN2("(%p,%s)", action, category);
530   action->category = xbt_strdup (category);
531   XBT_OUT;
532 }
533 #endif
534
535 static double cpu_im_action_get_remains(surf_action_t action)
536 {
537   XBT_IN1("(%p)", action);
538   /* update remains before return it */
539   cpu_im_update_remains(ACTION_GET_CPU(action), surf_get_clock());
540   return action->remains;
541   XBT_OUT;
542 }
543
544 static e_surf_resource_state_t cpu_im_get_state(void *cpu)
545 {
546   return ((cpu_Cas01_im_t) cpu)->state_current;
547 }
548
549 static double cpu_im_get_speed(void *cpu, double load)
550 {
551   return load * (((cpu_Cas01_im_t) cpu)->power_peak);
552 }
553
554 static double cpu_im_get_available_speed(void *cpu)
555 {
556   /* number between 0 and 1 */
557   return ((cpu_Cas01_im_t) cpu)->power_scale;
558 }
559
560 static void cpu_im_action_update_index_heap(void *action, int i)
561 {
562   ((surf_action_cpu_Cas01_im_t) action)->index_heap = i;
563 }
564
565 static void cpu_im_create_resource(char *name, double power_peak,
566                                    double power_scale,
567                                    tmgr_trace_t power_trace,
568                                    int core,
569                                    e_surf_resource_state_t state_initial,
570                                    tmgr_trace_t state_trace,
571                                    xbt_dict_t cpu_properties)
572 {
573   cpu_im_new(name, power_peak, power_scale, power_trace, core,
574              state_initial, state_trace, cpu_properties);
575 }
576
577 static void cpu_im_finalize(void)
578 {
579   void *cpu;
580   xbt_dict_cursor_t cursor;
581   char *key;
582   xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, key,
583                    cpu) {
584     cpu_Cas01_im_t CPU = cpu;
585     xbt_swag_free(CPU->action_set);
586   }
587
588   lmm_system_free(cpu_im_maxmin_system);
589   cpu_im_maxmin_system = NULL;
590
591   surf_model_exit(surf_cpu_model);
592   surf_cpu_model = NULL;
593
594   xbt_swag_free
595       (cpu_im_running_action_set_that_does_not_need_being_checked);
596   cpu_im_running_action_set_that_does_not_need_being_checked = NULL;
597   xbt_heap_free(cpu_im_action_heap);
598   xbt_swag_free(cpu_im_modified_cpu);
599 }
600
601 static void surf_cpu_im_model_init_internal(void)
602 {
603   s_surf_action_t action;
604   s_cpu_Cas01_im_t cpu;
605
606   surf_cpu_model = surf_model_init();
607
608   cpu_im_running_action_set_that_does_not_need_being_checked =
609       xbt_swag_new(xbt_swag_offset(action, state_hookup));
610
611   surf_cpu_model->name = "CPU_IM";
612
613   surf_cpu_model->action_unref = cpu_im_action_unref;
614   surf_cpu_model->action_cancel = cpu_im_action_cancel;
615   surf_cpu_model->action_state_set = cpu_im_cpu_action_state_set;
616
617   surf_cpu_model->model_private->resource_used = cpu_im_resource_used;
618   surf_cpu_model->model_private->share_resources = cpu_im_share_resources;
619   surf_cpu_model->model_private->update_actions_state =
620       cpu_im_update_actions_state;
621   surf_cpu_model->model_private->update_resource_state =
622       cpu_im_update_resource_state;
623   surf_cpu_model->model_private->finalize = cpu_im_finalize;
624
625   surf_cpu_model->suspend = cpu_im_action_suspend;
626   surf_cpu_model->resume = cpu_im_action_resume;
627   surf_cpu_model->is_suspended = cpu_im_action_is_suspended;
628   surf_cpu_model->set_max_duration = cpu_im_action_set_max_duration;
629   surf_cpu_model->set_priority = cpu_im_action_set_priority;
630 #ifdef HAVE_TRACING
631   surf_cpu_model->set_category = cpu_im_action_set_category;
632 #endif
633   surf_cpu_model->get_remains = cpu_im_action_get_remains;
634
635   surf_cpu_model->extension.cpu.execute = cpu_im_execute;
636   surf_cpu_model->extension.cpu.sleep = cpu_im_action_sleep;
637
638   surf_cpu_model->extension.cpu.get_state = cpu_im_get_state;
639   surf_cpu_model->extension.cpu.get_speed = cpu_im_get_speed;
640   surf_cpu_model->extension.cpu.get_available_speed =
641       cpu_im_get_available_speed;
642   surf_cpu_model->extension.cpu.create_resource = cpu_im_create_resource;
643   surf_cpu_model->extension.cpu.add_traces = cpu_im_add_traces_cpu;
644
645   if (!cpu_im_maxmin_system) {
646     sg_maxmin_selective_update = 1;
647     cpu_im_maxmin_system = lmm_system_new();
648   }
649   cpu_im_action_heap = xbt_heap_new(8, NULL);
650   xbt_heap_set_update_callback(cpu_im_action_heap,
651                                cpu_im_action_update_index_heap);
652   cpu_im_modified_cpu =
653       xbt_swag_new(xbt_swag_offset(cpu, modified_cpu_hookup));
654 }
655
656 /*********************************************************************/
657 /* Basic sharing model for CPU: that is where all this started... ;) */
658 /*********************************************************************/
659 /* @InProceedings{casanova01simgrid, */
660 /*   author =       "H. Casanova", */
661 /*   booktitle =    "Proceedings of the IEEE Symposium on Cluster Computing */
662 /*                  and the Grid (CCGrid'01)", */
663 /*   publisher =    "IEEE Computer Society", */
664 /*   title =        "Simgrid: {A} Toolkit for the Simulation of Application */
665 /*                  Scheduling", */
666 /*   year =         "2001", */
667 /*   month =        may, */
668 /*   note =         "Available at */
669 /*                  \url{http://grail.sdsc.edu/papers/simgrid_ccgrid01.ps.gz}." */
670 /* } */
671 void surf_cpu_model_init_Cas01_im(const char *filename)
672 {
673   if (surf_cpu_model)
674     return;
675   surf_cpu_im_model_init_internal();
676   cpu_im_define_callbacks(filename);
677   xbt_dynar_push(model_list, &surf_cpu_model);
678 }