Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
compilation errors (optimizations and model checking on) fixed in function ‘get_addr_...
[simgrid.git] / src / surf / cpu_cas01.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 #include "maxmin_private.h"
10
11 surf_model_t surf_cpu_model = NULL;
12
13 #undef GENERIC_LMM_ACTION
14 #undef GENERIC_ACTION
15 #undef ACTION_GET_CPU
16 #define GENERIC_LMM_ACTION(action) action->generic_lmm_action
17 #define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action
18 #define ACTION_GET_CPU(action) ((surf_action_cpu_Cas01_t) action)->cpu
19
20 typedef struct surf_action_cpu_cas01 {
21   s_surf_action_lmm_t generic_lmm_action;
22 } s_surf_action_cpu_Cas01_t, *surf_action_cpu_Cas01_t;
23
24 typedef struct cpu_Cas01 {
25   s_surf_resource_t generic_resource;
26   s_xbt_swag_hookup_t modified_cpu_hookup;
27   double power_peak;
28   double power_scale;
29   tmgr_trace_event_t power_event;
30   int core;
31   e_surf_resource_state_t state_current;
32   tmgr_trace_event_t state_event;
33   lmm_constraint_t constraint;
34 } s_cpu_Cas01_t, *cpu_Cas01_t;
35
36 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu, surf,
37                                 "Logging specific to the SURF CPU IMPROVED module");
38
39
40
41 static xbt_swag_t
42     cpu_running_action_set_that_does_not_need_being_checked = NULL;
43
44
45 static void *cpu_create_resource(const char *name, double power_peak,
46                                  double power_scale,
47                                  tmgr_trace_t power_trace,
48                                  int core,
49                                  e_surf_resource_state_t state_initial,
50                                  tmgr_trace_t state_trace,
51                                  xbt_dict_t cpu_properties)
52 {
53   cpu_Cas01_t cpu = NULL;
54
55   xbt_assert(!surf_cpu_resource_by_name(name),
56              "Host '%s' declared several times in the platform file",
57              name);
58   cpu = (cpu_Cas01_t) surf_resource_new(sizeof(s_cpu_Cas01_t),
59                                         surf_cpu_model, name,
60                                         cpu_properties);
61   cpu->power_peak = power_peak;
62   xbt_assert(cpu->power_peak > 0, "Power has to be >0");
63   cpu->power_scale = power_scale;
64   cpu->core = core;
65   xbt_assert(core > 0, "Invalid number of cores %d", core);
66
67   if (power_trace)
68     cpu->power_event =
69         tmgr_history_add_trace(history, power_trace, 0.0, 0, cpu);
70
71   cpu->state_current = state_initial;
72   if (state_trace)
73     cpu->state_event =
74         tmgr_history_add_trace(history, state_trace, 0.0, 0, cpu);
75
76   cpu->constraint =
77       lmm_constraint_new(surf_cpu_model->model_private->maxmin_system, cpu,
78                          cpu->core * cpu->power_scale * cpu->power_peak);
79
80   xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu);
81
82   return cpu;
83 }
84
85
86 static void parse_cpu_init(sg_platf_host_cbarg_t host)
87 {
88   cpu_create_resource(host->id,
89                       host->power_peak,
90                       host->power_scale,
91                       host->power_trace,
92                       host->core_amount,
93                       host->initial_state,
94                       host->state_trace, host->properties);
95 }
96
97 static void cpu_add_traces_cpu(void)
98 {
99   xbt_dict_cursor_t cursor = NULL;
100   char *trace_name, *elm;
101   static int called = 0;
102   if (called)
103     return;
104   called = 1;
105
106   /* connect all traces relative to hosts */
107   xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
108     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
109     cpu_Cas01_t host = surf_cpu_resource_by_name(elm);
110
111     xbt_assert(host, "Host %s undefined", elm);
112     xbt_assert(trace, "Trace %s undefined", trace_name);
113
114     host->state_event =
115         tmgr_history_add_trace(history, trace, 0.0, 0, host);
116   }
117
118   xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) {
119     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
120     cpu_Cas01_t host = surf_cpu_resource_by_name(elm);
121
122     xbt_assert(host, "Host %s undefined", elm);
123     xbt_assert(trace, "Trace %s undefined", trace_name);
124
125     host->power_event =
126         tmgr_history_add_trace(history, trace, 0.0, 0, host);
127   }
128 }
129
130 static void cpu_define_callbacks()
131 {
132   sg_platf_host_add_cb(parse_cpu_init);
133   sg_platf_postparse_add_cb(cpu_add_traces_cpu);
134 }
135
136 static int cpu_resource_used(void *resource)
137 {
138   return lmm_constraint_used(surf_cpu_model->model_private->maxmin_system,
139                              ((cpu_Cas01_t) resource)->constraint);
140 }
141
142 static void cpu_update_action_remaining_lazy(surf_action_cpu_Cas01_t action, double now)
143 {
144   double delta = 0.0;
145
146   xbt_assert(GENERIC_ACTION(action).state_set == surf_cpu_model->states.running_action_set,
147       "You're updating an action that is not running.");
148
149     /* bogus priority, skip it */
150   xbt_assert(GENERIC_ACTION(action).priority > 0,
151       "You're updating an action that seems suspended.");
152
153   delta = now - GENERIC_LMM_ACTION(action).last_update;
154   if (GENERIC_ACTION(action).remains > 0) {
155     XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", action,
156         GENERIC_ACTION(action).remains,
157         GENERIC_LMM_ACTION(action).last_update);
158     double_update(&(GENERIC_ACTION(action).remains),
159         GENERIC_LMM_ACTION(action).last_value * delta);
160
161 #ifdef HAVE_TRACING
162     if (TRACE_is_enabled()) {
163       cpu_Cas01_t cpu =
164           lmm_constraint_id(lmm_get_cnst_from_var
165               (surf_cpu_model->model_private->maxmin_system,
166                   GENERIC_LMM_ACTION(action).variable, 0));
167       TRACE_surf_host_set_utilization(cpu->generic_resource.name,
168           ((surf_action_t)action)->category,
169           GENERIC_LMM_ACTION(action).last_value,
170           GENERIC_LMM_ACTION(action).last_update,
171           now - GENERIC_LMM_ACTION(action).last_update);
172     }
173 #endif
174     XBT_DEBUG("Updating action(%p): remains is now %lf", action,
175     GENERIC_ACTION(action).remains);
176   }
177   GENERIC_LMM_ACTION(action).last_update = now;
178   GENERIC_LMM_ACTION(action).last_value = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable);
179 }
180
181 static double cpu_share_resources_lazy(double now)
182 {
183   surf_action_cpu_Cas01_t action = NULL;
184   double min = -1;
185   double value;
186
187   XBT_DEBUG
188       ("Before share resources, the size of modified actions set is %d",
189        xbt_swag_size(surf_cpu_model->model_private->modified_set));
190
191   lmm_solve(surf_cpu_model->model_private->maxmin_system);
192
193   XBT_DEBUG
194       ("After share resources, The size of modified actions set is %d",
195        xbt_swag_size(surf_cpu_model->model_private->modified_set));
196
197   while((action = xbt_swag_extract(surf_cpu_model->model_private->modified_set))) {
198     int max_dur_flag = 0;
199
200     if (GENERIC_ACTION(action).state_set !=
201         surf_cpu_model->states.running_action_set)
202       continue;
203
204     /* bogus priority, skip it */
205     if (GENERIC_ACTION(action).priority <= 0)
206       continue;
207
208     cpu_update_action_remaining_lazy(action,now);
209
210     min = -1;
211     value = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable);
212     if (value > 0) {
213       if (GENERIC_ACTION(action).remains > 0) {
214         value = GENERIC_ACTION(action).remains / value;
215         min = now + value;
216       } else {
217         value = 0.0;
218         min = now;
219       }
220     }
221
222     if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION)
223         && (min == -1
224             || GENERIC_ACTION(action).start +
225             GENERIC_ACTION(action).max_duration < min)) {
226       min = GENERIC_ACTION(action).start +
227           GENERIC_ACTION(action).max_duration;
228       max_dur_flag = 1;
229     }
230
231     XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
232         GENERIC_ACTION(action).start, now + value,
233         GENERIC_ACTION(action).max_duration);
234
235     if (min != -1) {
236       surf_action_lmm_heap_remove(surf_cpu_model->model_private->action_heap,(surf_action_lmm_t)action);
237       surf_action_lmm_heap_insert(surf_cpu_model->model_private->action_heap,(surf_action_lmm_t)action, min, max_dur_flag ? MAX_DURATION : NORMAL);
238       XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min,
239                 now);
240     } else DIE_IMPOSSIBLE;
241   }
242
243   //hereafter must have already the min value for this resource model
244   if (xbt_heap_size(surf_cpu_model->model_private->action_heap) > 0)
245     min = xbt_heap_maxkey(surf_cpu_model->model_private->action_heap) - now;
246   else
247     min = -1;
248
249   XBT_DEBUG("The minimum with the HEAP %lf", min);
250
251   return min;
252 }
253
254 static double cpu_share_resources_full(double now)
255 {
256   s_surf_action_cpu_Cas01_t action;
257   return generic_maxmin_share_resources(surf_cpu_model->states.
258                                         running_action_set,
259                                         xbt_swag_offset(action,
260                                                         generic_lmm_action.
261                                                         variable),
262                                         surf_cpu_model->model_private->maxmin_system, lmm_solve);
263 }
264
265 static void cpu_update_actions_state_lazy(double now, double delta)
266 {
267   surf_action_cpu_Cas01_t action;
268   while ((xbt_heap_size(surf_cpu_model->model_private->action_heap) > 0)
269          && (double_equals(xbt_heap_maxkey(surf_cpu_model->model_private->action_heap), now))) {
270     action = xbt_heap_pop(surf_cpu_model->model_private->action_heap);
271     XBT_DEBUG("Action %p: finish", action);
272     GENERIC_ACTION(action).finish = surf_get_clock();
273 #ifdef HAVE_TRACING
274     if (TRACE_is_enabled()) {
275       cpu_Cas01_t cpu =
276           lmm_constraint_id(lmm_get_cnst_from_var
277                             (surf_cpu_model->model_private->maxmin_system,
278                              GENERIC_LMM_ACTION(action).variable, 0));
279       TRACE_surf_host_set_utilization(cpu->generic_resource.name,
280                                       ((surf_action_t)action)->category,
281                                       lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable),
282                                       GENERIC_LMM_ACTION(action).last_update,
283                                       now - GENERIC_LMM_ACTION(action).last_update);
284     }
285 #endif
286     /* set the remains to 0 due to precision problems when updating the remaining amount */
287     GENERIC_ACTION(action).remains = 0;
288     surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
289     surf_action_lmm_heap_remove(surf_cpu_model->model_private->action_heap,(surf_action_lmm_t)action); //FIXME: strange call since action was already popped
290   }
291 #ifdef HAVE_TRACING
292   if (TRACE_is_enabled()) {
293     //defining the last timestamp that we can safely dump to trace file
294     //without losing the event ascending order (considering all CPU's)
295     double smaller = -1;
296     xbt_swag_t running_actions = surf_cpu_model->states.running_action_set;
297     xbt_swag_foreach(action, running_actions) {
298         if (smaller < 0) {
299           smaller = GENERIC_LMM_ACTION(action).last_update;
300           continue;
301         }
302         if (GENERIC_LMM_ACTION(action).last_update < smaller) {
303           smaller = GENERIC_LMM_ACTION(action).last_update;
304         }
305     }
306     if (smaller > 0) {
307       TRACE_last_timestamp_to_dump = smaller;
308     }
309   }
310 #endif
311   return;
312 }
313
314 static void cpu_update_actions_state_full(double now, double delta)
315 {
316   surf_action_cpu_Cas01_t action = NULL;
317   surf_action_cpu_Cas01_t next_action = NULL;
318   xbt_swag_t running_actions = surf_cpu_model->states.running_action_set;
319   xbt_swag_foreach_safe(action, next_action, running_actions) {
320 #ifdef HAVE_TRACING
321     if (TRACE_is_enabled()) {
322       cpu_Cas01_t x =
323           lmm_constraint_id(lmm_get_cnst_from_var
324                             (surf_cpu_model->model_private->maxmin_system,
325                              GENERIC_LMM_ACTION(action).variable, 0));
326
327       TRACE_surf_host_set_utilization(x->generic_resource.name,
328                                       ((surf_action_t)action)->category,
329                                       lmm_variable_getvalue(GENERIC_LMM_ACTION(action).
330                                        variable),
331                                       now - delta,
332                                       delta);
333       TRACE_last_timestamp_to_dump = now - delta;
334     }
335 #endif
336     double_update(&(GENERIC_ACTION(action).remains),
337                   lmm_variable_getvalue(GENERIC_LMM_ACTION(action).
338                                         variable) * delta);
339     if (GENERIC_LMM_ACTION(action).generic_action.max_duration !=
340         NO_MAX_DURATION)
341       double_update(&(GENERIC_ACTION(action).max_duration), delta);
342     if ((GENERIC_ACTION(action).remains <= 0) &&
343         (lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) >
344          0)) {
345       GENERIC_ACTION(action).finish = surf_get_clock();
346       surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
347     } else if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION) &&
348                (GENERIC_ACTION(action).max_duration <= 0)) {
349       GENERIC_ACTION(action).finish = surf_get_clock();
350       surf_action_state_set((surf_action_t) action, SURF_ACTION_DONE);
351     }
352   }
353
354   return;
355 }
356
357 static void cpu_update_resource_state(void *id,
358                                       tmgr_trace_event_t event_type,
359                                       double value, double date)
360 {
361   cpu_Cas01_t cpu = id;
362   lmm_variable_t var = NULL;
363   lmm_element_t elem = NULL;
364
365   if (event_type == cpu->power_event) {
366     cpu->power_scale = value;
367     lmm_update_constraint_bound(surf_cpu_model->model_private->maxmin_system, cpu->constraint,
368                                 cpu->core * cpu->power_scale *
369                                 cpu->power_peak);
370 #ifdef HAVE_TRACING
371     TRACE_surf_host_set_power(date, cpu->generic_resource.name,
372                               cpu->core * cpu->power_scale *
373                               cpu->power_peak);
374 #endif
375     while ((var = lmm_get_var_from_cnst
376             (surf_cpu_model->model_private->maxmin_system, cpu->constraint, &elem))) {
377       surf_action_cpu_Cas01_t action = lmm_variable_id(var);
378       lmm_update_variable_bound(surf_cpu_model->model_private->maxmin_system,
379                                 GENERIC_LMM_ACTION(action).variable,
380                                 cpu->power_scale * cpu->power_peak);
381     }
382     if (tmgr_trace_event_free(event_type))
383       cpu->power_event = NULL;
384   } else if (event_type == cpu->state_event) {
385     if (value > 0)
386       cpu->state_current = SURF_RESOURCE_ON;
387     else {
388       lmm_constraint_t cnst = cpu->constraint;
389
390       cpu->state_current = SURF_RESOURCE_OFF;
391
392       while ((var = lmm_get_var_from_cnst(surf_cpu_model->model_private->maxmin_system, cnst, &elem))) {
393         surf_action_t action = lmm_variable_id(var);
394
395         if (surf_action_state_get(action) == SURF_ACTION_RUNNING ||
396             surf_action_state_get(action) == SURF_ACTION_READY ||
397             surf_action_state_get(action) ==
398             SURF_ACTION_NOT_IN_THE_SYSTEM) {
399           action->finish = date;
400           surf_action_state_set(action, SURF_ACTION_FAILED);
401         }
402       }
403     }
404     if (tmgr_trace_event_free(event_type))
405       cpu->state_event = NULL;
406   } else {
407     XBT_CRITICAL("Unknown event ! \n");
408     xbt_abort();
409   }
410
411   return;
412 }
413
414 static surf_action_t cpu_execute(void *cpu, double size)
415 {
416   surf_action_cpu_Cas01_t action = NULL;
417   cpu_Cas01_t CPU = cpu;
418
419   XBT_IN("(%s,%g)", surf_resource_name(CPU), size);
420   action =
421       surf_action_new(sizeof(s_surf_action_cpu_Cas01_t), size,
422                       surf_cpu_model,
423                       CPU->state_current != SURF_RESOURCE_ON);
424
425   GENERIC_LMM_ACTION(action).suspended = 0;     /* Should be useless because of the
426                                                    calloc but it seems to help valgrind... */
427
428   GENERIC_LMM_ACTION(action).variable =
429       lmm_variable_new(surf_cpu_model->model_private->maxmin_system, action,
430                        GENERIC_ACTION(action).priority,
431                        CPU->power_scale * CPU->power_peak, 1);
432   if (surf_cpu_model->model_private->update_mechanism == UM_LAZY) {
433     GENERIC_LMM_ACTION(action).index_heap = -1;
434     GENERIC_LMM_ACTION(action).last_update = surf_get_clock();
435     GENERIC_LMM_ACTION(action).last_value = 0.0;
436   }
437   lmm_expand(surf_cpu_model->model_private->maxmin_system, CPU->constraint,
438              GENERIC_LMM_ACTION(action).variable, 1.0);
439   XBT_OUT();
440   return (surf_action_t) action;
441 }
442
443 static surf_action_t cpu_action_sleep(void *cpu, double duration)
444 {
445   surf_action_cpu_Cas01_t action = NULL;
446
447   if (duration > 0)
448     duration = MAX(duration, MAXMIN_PRECISION);
449
450   XBT_IN("(%s,%g)", surf_resource_name(cpu), duration);
451   action = (surf_action_cpu_Cas01_t) cpu_execute(cpu, 1.0);
452   // FIXME: sleep variables should not consume 1.0 in lmm_expand
453   GENERIC_ACTION(action).max_duration = duration;
454   GENERIC_LMM_ACTION(action).suspended = 2;
455   if (duration == NO_MAX_DURATION) {
456     /* Move to the *end* of the corresponding action set. This convention
457        is used to speed up update_resource_state  */
458     xbt_swag_remove(action, ((surf_action_t) action)->state_set);
459     ((surf_action_t) action)->state_set =
460         cpu_running_action_set_that_does_not_need_being_checked;
461     xbt_swag_insert(action, ((surf_action_t) action)->state_set);
462   }
463
464   lmm_update_variable_weight(surf_cpu_model->model_private->maxmin_system,
465                              GENERIC_LMM_ACTION(action).variable, 0.0);
466   if (surf_cpu_model->model_private->update_mechanism == UM_LAZY) {     // remove action from the heap
467     surf_action_lmm_heap_remove(surf_cpu_model->model_private->action_heap,(surf_action_lmm_t)action);
468     // this is necessary for a variable with weight 0 since such
469     // variables are ignored in lmm and we need to set its max_duration
470     // correctly at the next call to share_resources
471     xbt_swag_insert_at_head(action,surf_cpu_model->model_private->modified_set);
472   }
473
474   XBT_OUT();
475   return (surf_action_t) action;
476 }
477
478 static double cpu_action_get_remains(surf_action_t action)
479 {
480   XBT_IN("(%p)", action);
481   /* update remains before return it */
482   if (surf_cpu_model->model_private->update_mechanism == UM_LAZY)
483     cpu_update_action_remaining_lazy((surf_action_cpu_Cas01_t)action,
484         surf_get_clock());
485   XBT_OUT();
486   return action->remains;
487 }
488
489 static e_surf_resource_state_t cpu_get_state(void *cpu)
490 {
491   return ((cpu_Cas01_t) cpu)->state_current;
492 }
493
494 static double cpu_get_speed(void *cpu, double load)
495 {
496   return load * (((cpu_Cas01_t) cpu)->power_peak);
497 }
498
499 static double cpu_get_available_speed(void *cpu)
500 {
501   /* number between 0 and 1 */
502   return ((cpu_Cas01_t) cpu)->power_scale;
503 }
504
505 static void cpu_finalize(void)
506 {
507   lmm_system_free(surf_cpu_model->model_private->maxmin_system);
508   surf_cpu_model->model_private->maxmin_system = NULL;
509
510   if (surf_cpu_model->model_private->action_heap)
511     xbt_heap_free(surf_cpu_model->model_private->action_heap);
512   xbt_swag_free(surf_cpu_model->model_private->modified_set);
513
514   surf_model_exit(surf_cpu_model);
515   surf_cpu_model = NULL;
516
517   xbt_swag_free(cpu_running_action_set_that_does_not_need_being_checked);
518   cpu_running_action_set_that_does_not_need_being_checked = NULL;
519 }
520
521 static void surf_cpu_model_init_internal()
522 {
523   s_surf_action_t action;
524   s_surf_action_cpu_Cas01_t comp;
525
526   char *optim = xbt_cfg_get_string(_surf_cfg_set, "cpu/optim");
527   int select =
528       xbt_cfg_get_int(_surf_cfg_set, "cpu/maxmin_selective_update");
529
530   surf_cpu_model = surf_model_init();
531
532   if (!strcmp(optim, "Full")) {
533     surf_cpu_model->model_private->update_mechanism = UM_FULL;
534     surf_cpu_model->model_private->selective_update = select;
535   } else if (!strcmp(optim, "Lazy")) {
536     surf_cpu_model->model_private->update_mechanism = UM_LAZY;
537     surf_cpu_model->model_private->selective_update = 1;
538     xbt_assert((select == 1)
539                ||
540                (xbt_cfg_is_default_value
541                 (_surf_cfg_set, "cpu/maxmin_selective_update")),
542                "Disabling selective update while using the lazy update mechanism is dumb!");
543   } else {
544     xbt_die("Unsupported optimization (%s) for this model", optim);
545   }
546
547   cpu_running_action_set_that_does_not_need_being_checked =
548       xbt_swag_new(xbt_swag_offset(action, state_hookup));
549
550   surf_cpu_model->name = "cpu";
551
552   surf_cpu_model->action_unref = surf_action_unref;
553   surf_cpu_model->action_cancel = surf_action_cancel;
554   surf_cpu_model->action_state_set = surf_action_state_set;
555
556   surf_cpu_model->model_private->resource_used = cpu_resource_used;
557
558   if (surf_cpu_model->model_private->update_mechanism == UM_LAZY) {
559     surf_cpu_model->model_private->share_resources =
560         cpu_share_resources_lazy;
561     surf_cpu_model->model_private->update_actions_state =
562         cpu_update_actions_state_lazy;
563   } else if (surf_cpu_model->model_private->update_mechanism == UM_FULL) {
564     surf_cpu_model->model_private->share_resources =
565         cpu_share_resources_full;
566     surf_cpu_model->model_private->update_actions_state =
567         cpu_update_actions_state_full;
568   } else
569     xbt_die("Invalid cpu update mechanism!");
570
571   surf_cpu_model->model_private->update_resource_state =
572       cpu_update_resource_state;
573   surf_cpu_model->model_private->finalize = cpu_finalize;
574
575   surf_cpu_model->suspend = surf_action_suspend;
576   surf_cpu_model->resume = surf_action_resume;
577   surf_cpu_model->is_suspended = surf_action_is_suspended;
578   surf_cpu_model->set_max_duration = surf_action_set_max_duration;
579   surf_cpu_model->set_priority = surf_action_set_priority;
580 #ifdef HAVE_TRACING
581   surf_cpu_model->set_category = surf_action_set_category;
582 #endif
583   surf_cpu_model->get_remains = cpu_action_get_remains;
584
585   surf_cpu_model->extension.cpu.execute = cpu_execute;
586   surf_cpu_model->extension.cpu.sleep = cpu_action_sleep;
587
588   surf_cpu_model->extension.cpu.get_state = cpu_get_state;
589   surf_cpu_model->extension.cpu.get_speed = cpu_get_speed;
590   surf_cpu_model->extension.cpu.get_available_speed =
591       cpu_get_available_speed;
592   surf_cpu_model->extension.cpu.create_resource = cpu_create_resource;
593   surf_cpu_model->extension.cpu.add_traces = cpu_add_traces_cpu;
594
595   if (!surf_cpu_model->model_private->maxmin_system) {
596     surf_cpu_model->model_private->maxmin_system = lmm_system_new(surf_cpu_model->model_private->selective_update);
597   }
598   if (surf_cpu_model->model_private->update_mechanism == UM_LAZY) {
599     surf_cpu_model->model_private->action_heap = xbt_heap_new(8, NULL);
600     xbt_heap_set_update_callback(surf_cpu_model->model_private->action_heap,
601         surf_action_lmm_update_index_heap);
602     surf_cpu_model->model_private->modified_set =
603         xbt_swag_new(xbt_swag_offset(comp, generic_lmm_action.action_list_hookup));
604     surf_cpu_model->model_private->maxmin_system->keep_track = surf_cpu_model->model_private->modified_set;
605   }
606 }
607
608 /*********************************************************************/
609 /* Basic sharing model for CPU: that is where all this started... ;) */
610 /*********************************************************************/
611 /* @InProceedings{casanova01simgrid, */
612 /*   author =       "H. Casanova", */
613 /*   booktitle =    "Proceedings of the IEEE Symposium on Cluster Computing */
614 /*                  and the Grid (CCGrid'01)", */
615 /*   publisher =    "IEEE Computer Society", */
616 /*   title =        "Simgrid: {A} Toolkit for the Simulation of Application */
617 /*                  Scheduling", */
618 /*   year =         "2001", */
619 /*   month =        may, */
620 /*   note =         "Available at */
621 /*                  \url{http://grail.sdsc.edu/papers/simgrid_ccgrid01.ps.gz}." */
622 /* } */
623
624 void surf_cpu_model_init_Cas01()
625 {
626   char *optim = xbt_cfg_get_string(_surf_cfg_set, "cpu/optim");
627
628   if (surf_cpu_model)
629     return;
630
631   if (!strcmp(optim, "TI")) {
632     surf_cpu_model_init_ti();
633     return;
634   }
635
636   surf_cpu_model_init_internal();
637   cpu_define_callbacks();
638   xbt_dynar_push(model_list, &surf_cpu_model);
639 }