Logo AND Algorithmique Numérique Distribuée

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