Logo AND Algorithmique Numérique Distribuée

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