Logo AND Algorithmique Numérique Distribuée

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