Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] ptrace the model-checker application
[simgrid.git] / src / simix / smx_global.c
1 /* Copyright (c) 2007-2015. 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 <stdlib.h>
8 #include <sys/ptrace.h>
9
10 #include "smx_private.h"
11 #include "xbt/heap.h"
12 #include "xbt/sysdep.h"
13 #include "xbt/log.h"
14 #include "xbt/str.h"
15 #include "xbt/ex.h"             /* ex_backtrace_display */
16 #include "mc/mc.h"
17 #include "src/mc/mc_replay.h"
18 #include "simgrid/sg_config.h"
19
20 #ifdef HAVE_MC
21 #include "src/mc/mc_private.h"
22 #include "src/mc/mc_protocol.h"
23 #include "src/mc/mc_client.h"
24 #endif
25
26 #ifdef HAVE_MC
27 #include <stdlib.h>
28 #include "src/mc/mc_protocol.h"
29 #endif 
30
31 #include "src/mc/mc_record.h"
32
33 #ifdef HAVE_SMPI
34 #include "src/smpi/private.h"
35 #endif
36
37 XBT_LOG_NEW_CATEGORY(simix, "All SIMIX categories");
38 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_kernel, simix,
39                                 "Logging specific to SIMIX (kernel)");
40
41 smx_global_t simix_global = NULL;
42 static xbt_heap_t simix_timers = NULL;
43
44 static void* SIMIX_synchro_mallocator_new_f(void);
45 static void SIMIX_synchro_mallocator_free_f(void* synchro);
46 static void SIMIX_synchro_mallocator_reset_f(void* synchro);
47
48 /* FIXME: Yeah, I'll do it in a portable maner one day [Mt] */
49 #include <signal.h>
50
51 int _sg_do_verbose_exit = 1;
52 static void _XBT_CALL inthandler(int ignored)
53 {
54   if ( _sg_do_verbose_exit ) {
55      XBT_INFO("CTRL-C pressed. The current status will be displayed before exit (disable that behavior with option 'verbose-exit').");
56      SIMIX_display_process_status();
57   }
58   else {
59      XBT_INFO("CTRL-C pressed, exiting. Hiding the current process status since 'verbose-exit' is set to false.");
60   }
61   exit(1);
62 }
63
64 #ifndef WIN32
65 static void _XBT_CALL segvhandler(int signum, siginfo_t *siginfo, void *context)
66 {
67   if (siginfo->si_signo == SIGSEGV && siginfo->si_code == SEGV_ACCERR) {
68     fprintf(stderr,
69             "Access violation detected.\n"
70             "This can result from a programming error in your code or, although less likely,\n"
71             "from a bug in SimGrid itself.  This can also be the sign of a bug in the OS or\n"
72             "in third-party libraries.  Failing hardware can sometimes generate such errors\n"
73             "too.\n"
74             "Finally, if nothing of the above applies, this can result from a stack overflow.\n"
75             "Try to increase stack size with --cfg=contexts/stack_size (current size is %d KiB).\n",
76             smx_context_stack_size / 1024);
77     if (XBT_LOG_ISENABLED(simix_kernel, xbt_log_priority_debug)) {
78       fprintf(stderr,
79               "siginfo = {si_signo = %d, si_errno = %d, si_code = %d, si_addr = %p}\n",
80               siginfo->si_signo, siginfo->si_errno, siginfo->si_code, siginfo->si_addr);
81     }
82   } else  if (siginfo->si_signo == SIGSEGV) {
83     fprintf(stderr, "Segmentation fault.\n");
84 #ifdef HAVE_SMPI
85     if (smpi_enabled() && !smpi_privatize_global_variables) {
86       fprintf(stderr,
87         "Try to enable SMPI variable privatization with --cfg=smpi/privatize_global_variables:yes.\n");
88     }
89 #endif
90   }
91 #ifdef HAVE_MC
92   if (MC_is_active()) {
93     if (mc_stack) {
94       MC_dump_stack_safety(mc_stack);
95     }
96     MC_print_statistics(mc_stats);
97   }
98 #endif
99   raise(signum);
100 }
101
102 char sigsegv_stack[SIGSTKSZ];   /* alternate stack for SIGSEGV handler */
103
104 /**
105  * Install signal handler for SIGSEGV.  Check that nobody has already installed
106  * its own handler.  For example, the Java VM does this.
107  */
108 static void install_segvhandler(void)
109 {
110   stack_t stack, old_stack;
111   stack.ss_sp = sigsegv_stack;
112   stack.ss_size = sizeof sigsegv_stack;
113   stack.ss_flags = 0;
114
115   if (sigaltstack(&stack, &old_stack) == -1) {
116     XBT_WARN("Failed to register alternate signal stack: %s",
117              strerror(errno));
118     return;
119   }
120   if (!(old_stack.ss_flags & SS_DISABLE)) {
121     XBT_DEBUG("An alternate stack was already installed (sp=%p, size=%zd, flags=%x). Restore it.",
122               old_stack.ss_sp, old_stack.ss_size, old_stack.ss_flags);
123     sigaltstack(&old_stack, NULL);
124   }
125
126   struct sigaction action, old_action;
127   action.sa_sigaction = segvhandler;
128   action.sa_flags = SA_ONSTACK | SA_RESETHAND | SA_SIGINFO;
129   sigemptyset(&action.sa_mask);
130
131   if (sigaction(SIGSEGV, &action, &old_action) == -1) {
132     XBT_WARN("Failed to register signal handler for SIGSEGV: %s",
133              strerror(errno));
134     return;
135   }
136   if ((old_action.sa_flags & SA_SIGINFO) || old_action.sa_handler != SIG_DFL) {
137     XBT_DEBUG("A signal handler was already installed for SIGSEGV (%p). Restore it.",
138              (old_action.sa_flags & SA_SIGINFO) ?
139              (void*)old_action.sa_sigaction : (void*)old_action.sa_handler);
140     sigaction(SIGSEGV, &old_action, NULL);
141   }
142 }
143
144 #endif
145 /********************************* SIMIX **************************************/
146
147 XBT_INLINE double SIMIX_timer_next(void)
148 {
149   return xbt_heap_size(simix_timers) > 0 ? xbt_heap_maxkey(simix_timers) : -1.0;
150 }
151
152 /**
153  * \ingroup SIMIX_API
154  * \brief Initialize SIMIX internal data.
155  *
156  * \param argc Argc
157  * \param argv Argv
158  */
159 void SIMIX_global_init(int *argc, char **argv)
160 {
161 #ifdef HAVE_MC
162   _sg_do_model_check = getenv(MC_ENV_VARIABLE) != NULL;
163 #endif
164
165   s_smx_process_t proc;
166
167   if (!simix_global) {
168     simix_global = xbt_new0(s_smx_global_t, 1);
169
170 #ifdef TIME_BENCH_AMDAHL
171     simix_global->timer_seq = xbt_os_timer_new();
172     simix_global->timer_par = xbt_os_timer_new();
173     xbt_os_cputimer_start(simix_global->timer_seq);
174 #endif
175     simix_global->process_to_run = xbt_dynar_new(sizeof(smx_process_t), NULL);
176     simix_global->process_that_ran = xbt_dynar_new(sizeof(smx_process_t), NULL);
177     simix_global->process_list =
178         xbt_swag_new(xbt_swag_offset(proc, process_hookup));
179     simix_global->process_to_destroy =
180         xbt_swag_new(xbt_swag_offset(proc, destroy_hookup));
181
182     simix_global->maestro_process = NULL;
183     simix_global->registered_functions = xbt_dict_new_homogeneous(NULL);
184
185     simix_global->create_process_function = SIMIX_process_create;
186     simix_global->kill_process_function = SIMIX_process_kill;
187     simix_global->cleanup_process_function = SIMIX_process_cleanup;
188     simix_global->synchro_mallocator = xbt_mallocator_new(65536,
189         SIMIX_synchro_mallocator_new_f, SIMIX_synchro_mallocator_free_f,
190         SIMIX_synchro_mallocator_reset_f);
191     simix_global->autorestart = SIMIX_host_restart_processes;
192     simix_global->mutex = xbt_os_mutex_init();
193
194     surf_init(argc, argv);      /* Initialize SURF structures */
195     SIMIX_context_mod_init();
196     SIMIX_create_maestro_process();
197
198     /* context exception handlers */
199     __xbt_running_ctx_fetch = SIMIX_process_get_running_context;
200     __xbt_ex_terminate = SIMIX_process_exception_terminate;
201
202     SIMIX_network_init();
203
204     /* Prepare to display some more info when dying on Ctrl-C pressing */
205     signal(SIGINT, inthandler);
206
207 #ifndef WIN32
208     /* Install SEGV handler */
209     install_segvhandler();
210 #endif
211     /* register a function to be called by SURF after the environment creation */
212     sg_platf_init();
213     sg_platf_postparse_add_cb(SIMIX_post_create_environment);
214
215   }
216   if (!simix_timers) {
217     simix_timers = xbt_heap_new(8, &free);
218   }
219
220   SIMIX_STORAGE_LEVEL = xbt_lib_add_level(storage_lib, SIMIX_storage_destroy);
221
222   if (sg_cfg_get_boolean("clean_atexit"))
223     atexit(SIMIX_clean);
224
225 #ifdef HAVE_MC
226   // The communication initialization is done ASAP.
227   // We need to communicate  initialization of the different layers to the model-checker.
228   if (mc_mode == MC_MODE_NONE) {
229     if (getenv(MC_ENV_SOCKET_FD)) {
230
231       mc_mode = MC_MODE_CLIENT;
232       MC_client_init();
233
234       // Waiting for the model-checker:
235       if (ptrace(PTRACE_TRACEME, 0, NULL, NULL) == -1 || raise(SIGSTOP) != 0)
236         xbt_die("Could not wait for the model-checker");
237
238       MC_client_handle_messages();
239     }
240   }
241 #endif
242
243   if (_sg_cfg_exit_asap)
244     exit(0);
245 }
246
247 int smx_cleaned = 0;
248 /**
249  * \ingroup SIMIX_API
250  * \brief Clean the SIMIX simulation
251  *
252  * This functions remove the memory used by SIMIX
253  */
254 void SIMIX_clean(void)
255 {
256 #ifdef TIME_BENCH_PER_SR
257   smx_ctx_raw_new_sr();
258 #endif
259   if (smx_cleaned) return; // to avoid double cleaning by java and C
260   smx_cleaned = 1;
261   XBT_DEBUG("SIMIX_clean called. Simulation's over.");
262   if (!xbt_dynar_is_empty(simix_global->process_to_run) && SIMIX_get_clock() == 0.0) {
263           XBT_CRITICAL("   ");
264           XBT_CRITICAL("The time is still 0, and you still have processes ready to run.");
265           XBT_CRITICAL("It seems that you forgot to run the simulation that you setup.");
266           xbt_die("Bailing out to avoid that stop-before-start madness. Please fix your code.");
267   }
268   /* Kill all processes (but maestro) */
269   SIMIX_process_killall(simix_global->maestro_process, 1);
270
271   /* Exit the SIMIX network module */
272   SIMIX_network_exit();
273
274   xbt_heap_free(simix_timers);
275   simix_timers = NULL;
276   /* Free the remaining data structures */
277   xbt_dynar_free(&simix_global->process_to_run);
278   xbt_dynar_free(&simix_global->process_that_ran);
279   xbt_swag_free(simix_global->process_to_destroy);
280   xbt_swag_free(simix_global->process_list);
281   simix_global->process_list = NULL;
282   simix_global->process_to_destroy = NULL;
283   xbt_dict_free(&(simix_global->registered_functions));
284
285   xbt_os_mutex_destroy(simix_global->mutex);
286   simix_global->mutex = NULL;
287
288   /* Let's free maestro now */
289   SIMIX_context_free(simix_global->maestro_process->context);
290   xbt_free(simix_global->maestro_process->running_ctx);
291   xbt_free(simix_global->maestro_process);
292   simix_global->maestro_process = NULL;
293
294   /* Restore the default exception setup */
295   __xbt_running_ctx_fetch = &__xbt_ex_ctx_default;
296   __xbt_ex_terminate = &__xbt_ex_terminate_default;
297
298   /* Finish context module and SURF */
299   SIMIX_context_mod_exit();
300
301   surf_exit();
302
303 #ifdef TIME_BENCH_AMDAHL
304   xbt_os_cputimer_stop(simix_global->timer_seq);
305   XBT_INFO("Amdahl timing informations. Sequential time: %f; Parallel time: %f",
306            xbt_os_timer_elapsed(simix_global->timer_seq),
307            xbt_os_timer_elapsed(simix_global->timer_par));
308   xbt_os_timer_free(simix_global->timer_seq);
309   xbt_os_timer_free(simix_global->timer_par);
310 #endif
311
312   xbt_mallocator_free(simix_global->synchro_mallocator);
313   xbt_free(simix_global);
314   simix_global = NULL;
315
316   return;
317 }
318
319
320 /**
321  * \ingroup SIMIX_API
322  * \brief A clock (in second).
323  *
324  * \return Return the clock.
325  */
326 XBT_INLINE double SIMIX_get_clock(void)
327 {
328   if(MC_is_active() || MC_record_replay_is_active()){
329     return MC_process_clock_get(SIMIX_process_self());
330   }else{
331     return surf_get_clock();
332   }
333 }
334
335 static int process_syscall_color(void *p)
336 {
337   switch ((*(smx_process_t *)p)->simcall.call) {
338   case SIMCALL_NONE:
339   case SIMCALL_PROCESS_KILL:
340     return 2;
341   case SIMCALL_PROCESS_RESUME:
342     return 1;
343   default:
344     return 0;
345   }
346 }
347
348 /**
349  * \ingroup SIMIX_API
350  * \brief Run the main simulation loop.
351  */
352 void SIMIX_run(void)
353 {
354   if(MC_record_path) {
355     MC_record_replay_init();
356     MC_record_replay_from_string(MC_record_path);
357     return;
358   }
359
360   double time = 0;
361   smx_process_t process;
362   surf_action_t action;
363   smx_timer_t timer;
364   surf_model_t model;
365   unsigned int iter;
366
367   do {
368     XBT_DEBUG("New Schedule Round; size(queue)=%lu",
369         xbt_dynar_length(simix_global->process_to_run));
370 #ifdef TIME_BENCH_PER_SR
371     smx_ctx_raw_new_sr();
372 #endif
373     while (!xbt_dynar_is_empty(simix_global->process_to_run)) {
374       XBT_DEBUG("New Sub-Schedule Round; size(queue)=%lu",
375               xbt_dynar_length(simix_global->process_to_run));
376
377       /* Run all processes that are ready to run, possibly in parallel */
378 #ifdef TIME_BENCH_AMDAHL
379       xbt_os_cputimer_stop(simix_global->timer_seq);
380       xbt_os_cputimer_resume(simix_global->timer_par);
381 #endif
382       SIMIX_process_runall();
383 #ifdef TIME_BENCH_AMDAHL
384       xbt_os_cputimer_stop(simix_global->timer_par);
385       xbt_os_cputimer_resume(simix_global->timer_seq);
386 #endif
387
388       /* Move all killer processes to the end of the list, because killing a process that have an ongoing simcall is a bad idea */
389       xbt_dynar_three_way_partition(simix_global->process_that_ran, process_syscall_color);
390
391       /* answer sequentially and in a fixed arbitrary order all the simcalls that were issued during that sub-round */
392
393       /* WARNING, the order *must* be fixed or you'll jeopardize the simulation reproducibility (see RR-7653) */
394
395       /* Here, the order is ok because:
396        *
397        *   Short proof: only maestro adds stuff to the process_to_run array, so the execution order of user contexts do not impact its order.
398        *
399        *   Long proof: processes remain sorted through an arbitrary (implicit, complex but fixed) order in all cases.
400        *
401        *   - if there is no kill during the simulation, processes remain sorted according by their PID.
402        *     rational: This can be proved inductively.
403        *        Assume that process_to_run is sorted at a beginning of one round (it is at round 0: the deployment file is parsed linearly).
404        *        Let's show that it is still so at the end of this round.
405        *        - if a process is added when being created, that's from maestro. It can be either at startup
406        *          time (and then in PID order), or in response to a process_create simcall. Since simcalls are handled
407        *          in arbitrary order (inductive hypothesis), we are fine.
408        *        - If a process is added because it's getting killed, its subsequent actions shouldn't matter
409        *        - If a process gets added to process_to_run because one of their blocking action constituting the meat
410        *          of a simcall terminates, we're still good. Proof:
411        *          - You are added from SIMIX_simcall_answer() only. When this function is called depends on the resource
412        *            kind (network, cpu, disk, whatever), but the same arguments hold. Let's take communications as an example.
413        *          - For communications, this function is called from SIMIX_comm_finish().
414        *            This function itself don't mess with the order since simcalls are handled in FIFO order.
415        *            The function is called:
416        *            - before the comm starts (invalid parameters, or resource already dead or whatever).
417        *              The order then trivial holds since maestro didn't interrupt its handling of the simcall yet
418        *            - because the communication failed or were canceled after startup. In this case, it's called from the function
419        *              we are in, by the chunk:
420        *                       set = model->states.failed_action_set;
421        *                       while ((synchro = xbt_swag_extract(set)))
422        *                          SIMIX_simcall_post((smx_synchro_t) synchro->data);
423        *              This order is also fixed because it depends of the order in which the surf actions were
424        *              added to the system, and only maestro can add stuff this way, through simcalls.
425        *              We thus use the inductive hypothesis once again to conclude that the order in which synchros are
426        *              poped out of the swag does not depend on the user code's execution order.
427        *            - because the communication terminated. In this case, synchros are served in the order given by
428        *                       set = model->states.done_action_set;
429        *                       while ((synchro = xbt_swag_extract(set)))
430        *                          SIMIX_simcall_post((smx_synchro_t) synchro->data);
431        *              and the argument is very similar to the previous one.
432        *            So, in any case, the orders of calls to SIMIX_comm_finish() do not depend on the order in which user processes are executed.
433        *          So, in any cases, the orders of processes within process_to_run do not depend on the order in which user processes were executed previously.
434        *     So, if there is no killing in the simulation, the simulation reproducibility is not jeopardized.
435        *   - If there is some process killings, the order is changed by this decision that comes from user-land
436        *     But this decision may not have been motivated by a situation that were different because the simulation is not reproducible.
437        *     So, even the order change induced by the process killing is perfectly reproducible.
438        *
439        *   So science works, bitches [http://xkcd.com/54/].
440        *
441        *   We could sort the process_that_ran array completely so that we can describe the order in which simcalls are handled
442        *   (like "according to the PID of issuer"), but it's not mandatory (order is fixed already even if unfriendly).
443        *   That would thus be a pure waste of time.
444        */
445
446       xbt_dynar_foreach(simix_global->process_that_ran, iter, process) {
447         if (process->simcall.call != SIMCALL_NONE) {
448           SIMIX_simcall_handle(&process->simcall, 0);
449         }
450       }
451       /* Wake up all processes waiting for a Surf action to finish */
452       xbt_dynar_foreach(model_list, iter, model) {
453         XBT_DEBUG("Handling process whose action failed");
454         while ((action = surf_model_extract_failed_action_set(model))) {
455           XBT_DEBUG("   Handling Action %p",action);
456           SIMIX_simcall_exit((smx_synchro_t) surf_action_get_data(action));
457         }
458         XBT_DEBUG("Handling process whose action terminated normally");
459         while ((action = surf_model_extract_done_action_set(model))) {
460           XBT_DEBUG("   Handling Action %p",action);
461           if (surf_action_get_data(action) == NULL)
462             XBT_DEBUG("probably vcpu's action %p, skip", action);
463           else
464             SIMIX_simcall_exit((smx_synchro_t) surf_action_get_data(action));
465         }
466       }
467     }
468
469     time = SIMIX_timer_next();
470     if (time != -1.0 || xbt_swag_size(simix_global->process_list) != 0) {
471       XBT_DEBUG("Calling surf_solve");
472       time = surf_solve(time);
473       XBT_DEBUG("Moving time ahead : %g", time);
474     }
475     /* Notify all the hosts that have failed */
476     /* FIXME: iterate through the list of failed host and mark each of them */
477     /* as failed. On each host, signal all the running processes with host_fail */
478
479     /* Handle any pending timer */
480     while (xbt_heap_size(simix_timers) > 0 && SIMIX_get_clock() >= SIMIX_timer_next()) {
481        //FIXME: make the timers being real callbacks
482        // (i.e. provide dispatchers that read and expand the args)
483        timer = xbt_heap_pop(simix_timers);
484        if (timer->func)
485          ((void (*)(void*))timer->func)(timer->args);
486        xbt_free(timer);
487     }
488
489     /* Wake up all processes waiting for a Surf action to finish */
490     xbt_dynar_foreach(model_list, iter, model) {
491       XBT_DEBUG("Handling process whose action failed");
492       while ((action = surf_model_extract_failed_action_set(model))) {
493         XBT_DEBUG("   Handling Action %p",action);
494         SIMIX_simcall_exit((smx_synchro_t) surf_action_get_data(action));
495       }
496       XBT_DEBUG("Handling process whose action terminated normally");
497       while ((action = surf_model_extract_done_action_set(model))) {
498         XBT_DEBUG("   Handling Action %p",action);
499         if (surf_action_get_data(action) == NULL)
500           XBT_DEBUG("probably vcpu's action %p, skip", action);
501         else
502           SIMIX_simcall_exit((smx_synchro_t) surf_action_get_data(action));
503       }
504     }
505
506     /* Autorestart all process */
507     if(host_that_restart) {
508       char *hostname = NULL;
509       xbt_dynar_foreach(host_that_restart,iter,hostname) {
510         XBT_INFO("Restart processes on host: %s",hostname);
511         SIMIX_host_autorestart(sg_host_by_name(hostname));
512       }
513       xbt_dynar_reset(host_that_restart);
514     }
515
516     /* Clean processes to destroy */
517     SIMIX_process_empty_trash();
518
519
520     XBT_DEBUG("### time %f, empty %d", time, xbt_dynar_is_empty(simix_global->process_to_run));
521
522   } while (time != -1.0 || !xbt_dynar_is_empty(simix_global->process_to_run));
523
524   if (xbt_swag_size(simix_global->process_list) != 0) {
525
526         TRACE_end();
527
528     XBT_CRITICAL("Oops ! Deadlock or code not perfectly clean.");
529     SIMIX_display_process_status();
530     xbt_abort();
531   }
532 }
533
534 /**
535  *   \brief Set the date to execute a function
536  *
537  * Set the date to execute the function on the surf.
538  *   \param date Date to execute function
539  *   \param function Function to be executed
540  *   \param arg Parameters of the function
541  *
542  */
543 XBT_INLINE smx_timer_t SIMIX_timer_set(double date, void *function, void *arg)
544 {
545   smx_timer_t timer = xbt_new0(s_smx_timer_t, 1);
546
547   timer->date = date;
548   timer->func = function;
549   timer->args = arg;
550   xbt_heap_push(simix_timers, timer, date);
551   return timer;
552 }
553 /** @brief cancels a timer that was added earlier */
554 XBT_INLINE void SIMIX_timer_remove(smx_timer_t timer) {
555         xbt_heap_rm_elm(simix_timers, timer, timer->date);
556 }
557
558 /** @brief Returns the date at which the timer will trigger (or 0 if NULL timer) */
559 XBT_INLINE double SIMIX_timer_get_date(smx_timer_t timer) {
560         return timer?timer->date:0;
561 }
562
563 /**
564  * \brief Registers a function to create a process.
565  *
566  * This function registers a function to be called
567  * when a new process is created. The function has
568  * to call SIMIX_process_create().
569  * \param function create process function
570  */
571 XBT_INLINE void SIMIX_function_register_process_create(smx_creation_func_t
572                                                        function)
573 {
574   simix_global->create_process_function = function;
575 }
576
577 /**
578  * \brief Registers a function to kill a process.
579  *
580  * This function registers a function to be called when a
581  * process is killed. The function has to call the SIMIX_process_kill().
582  *
583  * \param function Kill process function
584  */
585 XBT_INLINE void SIMIX_function_register_process_kill(void_pfn_smxprocess_t_smxprocess_t
586                                                      function)
587 {
588   simix_global->kill_process_function = function;
589 }
590
591 /**
592  * \brief Registers a function to cleanup a process.
593  *
594  * This function registers a user function to be called when
595  * a process ends properly.
596  *
597  * \param function cleanup process function
598  */
599 XBT_INLINE void SIMIX_function_register_process_cleanup(void_pfn_smxprocess_t
600                                                         function)
601 {
602   simix_global->cleanup_process_function = function;
603 }
604
605
606 void SIMIX_display_process_status(void)
607 {
608   if (simix_global->process_list == NULL) {
609     return;
610   }
611
612   smx_process_t process = NULL;
613   int nbprocess = xbt_swag_size(simix_global->process_list);
614
615   XBT_INFO("%d processes are still running, waiting for something.", nbprocess);
616   /*  List the process and their state */
617   XBT_INFO
618     ("Legend of the following listing: \"Process <pid> (<name>@<host>): <status>\"");
619   xbt_swag_foreach(process, simix_global->process_list) {
620
621     if (process->waiting_synchro) {
622
623       const char* synchro_description = "unknown";
624       switch (process->waiting_synchro->type) {
625
626       case SIMIX_SYNC_EXECUTE:
627         synchro_description = "execution";
628         break;
629
630       case SIMIX_SYNC_PARALLEL_EXECUTE:
631         synchro_description = "parallel execution";
632         break;
633
634       case SIMIX_SYNC_COMMUNICATE:
635         synchro_description = "communication";
636         break;
637
638       case SIMIX_SYNC_SLEEP:
639         synchro_description = "sleeping";
640         break;
641
642       case SIMIX_SYNC_JOIN:
643         synchro_description = "joining";
644         break;
645
646       case SIMIX_SYNC_SYNCHRO:
647         synchro_description = "synchronization";
648         break;
649
650       case SIMIX_SYNC_IO:
651         synchro_description = "I/O";
652         break;
653       }
654       XBT_INFO("Process %lu (%s@%s): waiting for %s synchro %p (%s) in state %d to finish",
655           process->pid, process->name, sg_host_name(process->host),
656           synchro_description, process->waiting_synchro,
657           process->waiting_synchro->name, (int)process->waiting_synchro->state);
658     }
659     else {
660       XBT_INFO("Process %lu (%s@%s)", process->pid, process->name, sg_host_name(process->host));
661     }
662   }
663 }
664
665 static void* SIMIX_synchro_mallocator_new_f(void) {
666   smx_synchro_t synchro = xbt_new(s_smx_synchro_t, 1);
667   synchro->simcalls = xbt_fifo_new();
668   return synchro;
669 }
670
671 static void SIMIX_synchro_mallocator_free_f(void* synchro) {
672   xbt_fifo_free(((smx_synchro_t) synchro)->simcalls);
673   xbt_free(synchro);
674 }
675
676 static void SIMIX_synchro_mallocator_reset_f(void* synchro) {
677
678   // we also recycle the simcall list
679   xbt_fifo_t fifo = ((smx_synchro_t) synchro)->simcalls;
680   xbt_fifo_reset(fifo);
681   memset(synchro, 0, sizeof(s_smx_synchro_t));
682   ((smx_synchro_t) synchro)->simcalls = fifo;
683 }
684
685 xbt_dict_t simcall_HANDLER_asr_get_properties(smx_simcall_t simcall, const char *name){
686   return SIMIX_asr_get_properties(name);
687 }
688 xbt_dict_t SIMIX_asr_get_properties(const char *name)
689 {
690   return xbt_lib_get_or_null(as_router_lib, name, ROUTING_PROP_ASR_LEVEL);
691 }