Logo AND Algorithmique Numérique Distribuée

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