Logo AND Algorithmique Numérique Distribuée

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