Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add function xbt_dynar_compare
[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         else
283           value = 0.0;
284       }
285       if (value > 0)
286         min = now + value;
287
288       if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION)
289           && (min == -1
290               || GENERIC_ACTION(action).start +
291               GENERIC_ACTION(action).max_duration < min))
292         min =
293             GENERIC_ACTION(action).start +
294             GENERIC_ACTION(action).max_duration;
295
296       DEBUG4("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
297              GENERIC_ACTION(action).start, now + value,
298              GENERIC_ACTION(action).max_duration);
299
300       if (action->index_heap >= 0) {
301         surf_action_cpu_Cas01_im_t heap_act =
302             xbt_heap_remove(cpu_im_action_heap, action->index_heap);
303         if (heap_act != action)
304           DIE_IMPOSSIBLE;
305       }
306       if (min != -1) {
307         xbt_heap_push(cpu_im_action_heap, action, min);
308         DEBUG2("Insert at heap action(%p) min %lf", action, min);
309       }
310     }
311     xbt_swag_remove(cpu, cpu_im_modified_cpu);
312   }
313   return xbt_heap_size(cpu_im_action_heap) >
314       0 ? xbt_heap_maxkey(cpu_im_action_heap) - now : -1;
315 }
316
317 static void cpu_im_update_actions_state(double now, double delta)
318 {
319   surf_action_cpu_Cas01_im_t action;
320
321   while ((xbt_heap_size(cpu_im_action_heap) > 0)
322          && (double_equals(xbt_heap_maxkey(cpu_im_action_heap), now))) {
323     action = xbt_heap_pop(cpu_im_action_heap);
324     DEBUG1("Action %p: finish", action);
325     GENERIC_ACTION(action).finish = surf_get_clock();
326     /* set the remains to 0 due to precision problems when updating the remaining amount */
327 #ifdef HAVE_TRACING
328     TRACE_surf_host_set_utilization(((cpu_Cas01_im_t)
329                                      (action->cpu))->generic_resource.name,
330                                     action->
331                                     generic_lmm_action.generic_action.data,
332                                     (surf_action_t) action,
333                                     lmm_variable_getvalue
334                                     (GENERIC_LMM_ACTION(action).variable),
335                                     ((cpu_Cas01_im_t)
336                                      (action->cpu))->last_update,
337                                     now -
338                                     ((cpu_Cas01_im_t)
339                                      (action->cpu))->last_update);
340 #endif
341     GENERIC_ACTION(action).remains = 0;
342     cpu_im_cpu_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
343     cpu_im_update_remains(action->cpu, surf_get_clock());
344   }
345   return;
346 }
347
348 static void cpu_im_update_resource_state(void *id,
349                                          tmgr_trace_event_t event_type,
350                                          double value, double date)
351 {
352   cpu_Cas01_im_t cpu = id;
353   if (event_type == cpu->power_event) {
354     cpu->power_scale = value;
355     lmm_update_constraint_bound(cpu_im_maxmin_system, cpu->constraint,
356                                 cpu->power_scale * cpu->power_peak);
357 #ifdef HAVE_TRACING
358     TRACE_surf_host_set_power(date, cpu->generic_resource.name,
359                               cpu->power_scale * cpu->power_peak);
360 #endif
361     xbt_swag_insert(cpu, cpu_im_modified_cpu);
362     if (tmgr_trace_event_free(event_type))
363       cpu->power_event = NULL;
364   } else if (event_type == cpu->state_event) {
365     if (value > 0)
366       cpu->state_current = SURF_RESOURCE_ON;
367     else {
368       lmm_constraint_t cnst = cpu->constraint;
369       lmm_variable_t var = NULL;
370       lmm_element_t elem = NULL;
371
372       cpu->state_current = SURF_RESOURCE_OFF;
373
374       while ((var =
375               lmm_get_var_from_cnst(cpu_im_maxmin_system, cnst, &elem))) {
376         surf_action_t action = lmm_variable_id(var);
377
378         if (surf_action_state_get(action) == SURF_ACTION_RUNNING ||
379             surf_action_state_get(action) == SURF_ACTION_READY ||
380             surf_action_state_get(action) ==
381             SURF_ACTION_NOT_IN_THE_SYSTEM) {
382           action->finish = date;
383           cpu_im_cpu_action_state_set(action, SURF_ACTION_FAILED);
384         }
385       }
386     }
387     if (tmgr_trace_event_free(event_type))
388       cpu->state_event = NULL;
389   } else {
390     CRITICAL0("Unknown event ! \n");
391     xbt_abort();
392   }
393
394   return;
395 }
396
397 static surf_action_t cpu_im_execute(void *cpu, double size)
398 {
399   surf_action_cpu_Cas01_im_t action = NULL;
400   cpu_Cas01_im_t CPU = cpu;
401
402   XBT_IN2("(%s,%g)", surf_resource_name(CPU), size);
403   action =
404       surf_action_new(sizeof(s_surf_action_cpu_Cas01_im_t), size,
405                       surf_cpu_model,
406                       CPU->state_current != SURF_RESOURCE_ON);
407
408   GENERIC_LMM_ACTION(action).suspended = 0;     /* Should be useless because of the
409                                                    calloc but it seems to help valgrind... */
410
411   GENERIC_LMM_ACTION(action).variable =
412       lmm_variable_new(cpu_im_maxmin_system, action,
413                        GENERIC_ACTION(action).priority, -1.0, 1);
414   action->index_heap = -1;
415   action->cpu = CPU;
416   xbt_swag_insert(CPU, cpu_im_modified_cpu);
417   xbt_swag_insert(action, CPU->action_set);
418   lmm_expand(cpu_im_maxmin_system, CPU->constraint,
419              GENERIC_LMM_ACTION(action).variable, 1.0);
420   XBT_OUT;
421   return (surf_action_t) action;
422 }
423
424 static surf_action_t cpu_im_action_sleep(void *cpu, double duration)
425 {
426   surf_action_cpu_Cas01_im_t action = NULL;
427
428   if (duration > 0)
429     duration = MAX(duration, MAXMIN_PRECISION);
430
431   XBT_IN2("(%s,%g)", surf_resource_name(cpu), duration);
432   action = (surf_action_cpu_Cas01_im_t) cpu_im_execute(cpu, 1.0);
433   GENERIC_ACTION(action).max_duration = duration;
434   GENERIC_LMM_ACTION(action).suspended = 2;
435   if (duration == NO_MAX_DURATION) {
436     /* Move to the *end* of the corresponding action set. This convention
437        is used to speed up update_resource_state  */
438     xbt_swag_remove(action, ((surf_action_t) action)->state_set);
439     ((surf_action_t) action)->state_set =
440         cpu_im_running_action_set_that_does_not_need_being_checked;
441     xbt_swag_insert(action, ((surf_action_t) action)->state_set);
442   }
443
444   lmm_update_variable_weight(cpu_im_maxmin_system,
445                              GENERIC_LMM_ACTION(action).variable, 0.0);
446   xbt_swag_insert(cpu, cpu_im_modified_cpu);
447   XBT_OUT;
448   return (surf_action_t) action;
449 }
450
451 static void cpu_im_action_suspend(surf_action_t action)
452 {
453   XBT_IN1("(%p)", action);
454   if (((surf_action_lmm_t) action)->suspended != 2) {
455     lmm_update_variable_weight(cpu_im_maxmin_system,
456                                ((surf_action_lmm_t) action)->variable,
457                                0.0);
458     ((surf_action_lmm_t) action)->suspended = 1;
459     xbt_heap_remove(cpu_im_action_heap,
460                     ((surf_action_cpu_Cas01_im_t) action)->index_heap);
461     xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
462   }
463   XBT_OUT;
464 }
465
466 static void cpu_im_action_resume(surf_action_t action)
467 {
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                                action->priority);
474     ((surf_action_lmm_t) action)->suspended = 0;
475     xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
476   }
477   XBT_OUT;
478 }
479
480 static int cpu_im_action_is_suspended(surf_action_t action)
481 {
482   return (((surf_action_lmm_t) action)->suspended == 1);
483 }
484
485 static void cpu_im_action_set_max_duration(surf_action_t action,
486                                            double duration)
487 {
488   XBT_IN2("(%p,%g)", action, duration);
489
490   action->max_duration = duration;
491   /* insert cpu in modified_cpu set to notice the max duration change */
492   xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
493   XBT_OUT;
494 }
495
496 static void cpu_im_action_set_priority(surf_action_t action,
497                                        double priority)
498 {
499   XBT_IN2("(%p,%g)", action, priority);
500   action->priority = priority;
501   lmm_update_variable_weight(cpu_im_maxmin_system,
502                              ((surf_action_lmm_t) action)->variable,
503                              priority);
504
505   xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
506   XBT_OUT;
507 }
508
509 static double cpu_im_action_get_remains(surf_action_t action)
510 {
511   XBT_IN1("(%p)", action);
512   /* update remains before return it */
513   cpu_im_update_remains(ACTION_GET_CPU(action), surf_get_clock());
514   return action->remains;
515   XBT_OUT;
516 }
517
518 static e_surf_resource_state_t cpu_im_get_state(void *cpu)
519 {
520   return ((cpu_Cas01_im_t) cpu)->state_current;
521 }
522
523 static double cpu_im_get_speed(void *cpu, double load)
524 {
525   return load * (((cpu_Cas01_im_t) cpu)->power_peak);
526 }
527
528 static double cpu_im_get_available_speed(void *cpu)
529 {
530   /* number between 0 and 1 */
531   return ((cpu_Cas01_im_t) cpu)->power_scale;
532 }
533
534 static void cpu_im_action_update_index_heap(void *action, int i)
535 {
536   ((surf_action_cpu_Cas01_im_t) action)->index_heap = i;
537 }
538
539 static void cpu_im_create_resource(char *name, double power_peak,
540                                    double power_scale,
541                                    tmgr_trace_t power_trace,
542                                    e_surf_resource_state_t state_initial,
543                                    tmgr_trace_t state_trace,
544                                    xbt_dict_t cpu_properties)
545 {
546   cpu_im_new(name, power_peak, power_scale, power_trace,
547              state_initial, state_trace, cpu_properties);
548 }
549
550 static void cpu_im_finalize(void)
551 {
552   void *cpu;
553   xbt_dict_cursor_t cursor;
554   char *key;
555   xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, key,
556                    cpu) {
557     cpu_Cas01_im_t CPU = cpu;
558     xbt_swag_free(CPU->action_set);
559   }
560
561   lmm_system_free(cpu_im_maxmin_system);
562   cpu_im_maxmin_system = NULL;
563
564   surf_model_exit(surf_cpu_model);
565   surf_cpu_model = NULL;
566
567   xbt_swag_free
568       (cpu_im_running_action_set_that_does_not_need_being_checked);
569   cpu_im_running_action_set_that_does_not_need_being_checked = NULL;
570   xbt_heap_free(cpu_im_action_heap);
571   xbt_swag_free(cpu_im_modified_cpu);
572 }
573
574 static void surf_cpu_im_model_init_internal(void)
575 {
576   s_surf_action_t action;
577   s_cpu_Cas01_im_t cpu;
578
579   surf_cpu_model = surf_model_init();
580
581   cpu_im_running_action_set_that_does_not_need_being_checked =
582       xbt_swag_new(xbt_swag_offset(action, state_hookup));
583
584   surf_cpu_model->name = "CPU_IM";
585
586   surf_cpu_model->action_unref = cpu_im_action_unref;
587   surf_cpu_model->action_cancel = cpu_im_action_cancel;
588   surf_cpu_model->action_state_set = cpu_im_cpu_action_state_set;
589
590   surf_cpu_model->model_private->resource_used = cpu_im_resource_used;
591   surf_cpu_model->model_private->share_resources = cpu_im_share_resources;
592   surf_cpu_model->model_private->update_actions_state =
593       cpu_im_update_actions_state;
594   surf_cpu_model->model_private->update_resource_state =
595       cpu_im_update_resource_state;
596   surf_cpu_model->model_private->finalize = cpu_im_finalize;
597
598   surf_cpu_model->suspend = cpu_im_action_suspend;
599   surf_cpu_model->resume = cpu_im_action_resume;
600   surf_cpu_model->is_suspended = cpu_im_action_is_suspended;
601   surf_cpu_model->set_max_duration = cpu_im_action_set_max_duration;
602   surf_cpu_model->set_priority = cpu_im_action_set_priority;
603   surf_cpu_model->get_remains = cpu_im_action_get_remains;
604
605   surf_cpu_model->extension.cpu.execute = cpu_im_execute;
606   surf_cpu_model->extension.cpu.sleep = cpu_im_action_sleep;
607
608   surf_cpu_model->extension.cpu.get_state = cpu_im_get_state;
609   surf_cpu_model->extension.cpu.get_speed = cpu_im_get_speed;
610   surf_cpu_model->extension.cpu.get_available_speed =
611       cpu_im_get_available_speed;
612   surf_cpu_model->extension.cpu.create_resource = cpu_im_create_resource;
613   surf_cpu_model->extension.cpu.add_traces = cpu_im_add_traces_cpu;
614
615   if (!cpu_im_maxmin_system) {
616     sg_maxmin_selective_update = 1;
617     cpu_im_maxmin_system = lmm_system_new();
618   }
619   cpu_im_action_heap = xbt_heap_new(8, NULL);
620   xbt_heap_set_update_callback(cpu_im_action_heap,
621                                cpu_im_action_update_index_heap);
622   cpu_im_modified_cpu =
623       xbt_swag_new(xbt_swag_offset(cpu, modified_cpu_hookup));
624 }
625
626 /*********************************************************************/
627 /* Basic sharing model for CPU: that is where all this started... ;) */
628 /*********************************************************************/
629 /* @InProceedings{casanova01simgrid, */
630 /*   author =       "H. Casanova", */
631 /*   booktitle =    "Proceedings of the IEEE Symposium on Cluster Computing */
632 /*                  and the Grid (CCGrid'01)", */
633 /*   publisher =    "IEEE Computer Society", */
634 /*   title =        "Simgrid: {A} Toolkit for the Simulation of Application */
635 /*                  Scheduling", */
636 /*   year =         "2001", */
637 /*   month =        may, */
638 /*   note =         "Available at */
639 /*                  \url{http://grail.sdsc.edu/papers/simgrid_ccgrid01.ps.gz}." */
640 /* } */
641 void surf_cpu_model_init_Cas01_im(const char *filename)
642 {
643   if (surf_cpu_model)
644     return;
645   surf_cpu_im_model_init_internal();
646   cpu_im_define_callbacks(filename);
647   xbt_dynar_push(model_list, &surf_cpu_model);
648 }