Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill an unused simcall: comm_get_state
[simgrid.git] / src / simix / libsmx.cpp
1 /* libsmx.c - public interface to simix                                       */
2 /* --------                                                                   */
3 /* These functions are the only ones that are visible from the higher levels  */
4 /* (most of them simply add some documentation to the generated simcall body) */
5 /*                                                                            */
6 /* This is somehow the "libc" of SimGrid                                      */
7
8 /* Copyright (c) 2010-2015. The SimGrid Team.
9  * All rights reserved.                                                     */
10
11 /* This program is free software; you can redistribute it and/or modify it
12  * under the terms of the license (GNU LGPL) which comes with this package. */
13
14 #include <cmath>         /* std::isfinite() */
15
16 #include <functional>
17
18 #include "src/mc/mc_replay.h"
19 #include "smx_private.h"
20 #include "src/mc/mc_forward.hpp"
21 #include "xbt/ex.h"
22 #include "mc/mc.h"
23 #include "src/simix/smx_host_private.h"
24 #include "src/simix/smx_private.hpp"
25
26 #include <simgrid/simix.hpp>
27
28 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
29
30 #include "popping_bodies.cpp"
31
32 void simcall_call(smx_process_t process)
33 {
34   if (process != simix_global->maestro_process) {
35     XBT_DEBUG("Yield process '%s' on simcall %s (%d)", process->name,
36               SIMIX_simcall_name(process->simcall.call), (int)process->simcall.call);
37     SIMIX_process_yield(process);
38   } else {
39     SIMIX_simcall_handle(&process->simcall, 0);
40   }
41 }
42
43 // ***** AS simcalls
44
45 /**
46  * \ingroup simix_host_management
47  * \brief Returns a dict of the properties assigned to a router or AS.
48  *
49  * \param name The name of the router or AS
50  * \return The properties
51  */
52 xbt_dict_t simcall_asr_get_properties(const char *name)
53 {
54   return simcall_BODY_asr_get_properties(name);
55 }
56
57 /**
58  * \ingroup simix_process_management
59  * \brief Creates a synchro that executes some computation of an host.
60  *
61  * This function creates a SURF action and allocates the data necessary
62  * to create the SIMIX synchro. It can raise a host_error exception if the host crashed.
63  *
64  * \param name Name of the execution synchro to create
65  * \param flops_amount amount Computation amount (in flops)
66  * \param priority computation priority
67  * \param bound
68  * \param affinity_mask
69  * \return A new SIMIX execution synchronization
70  */
71 smx_synchro_t simcall_execution_start(const char *name,
72                                     double flops_amount,
73                                     double priority, double bound, unsigned long affinity_mask)
74 {
75   /* checking for infinite values */
76   xbt_assert(std::isfinite(flops_amount), "flops_amount is not finite!");
77   xbt_assert(std::isfinite(priority), "priority is not finite!");
78
79   return simcall_BODY_execution_start(name, flops_amount, priority, bound, affinity_mask);
80 }
81
82 /**
83  * \ingroup simix_process_management
84  * \brief Creates a synchro that may involve parallel computation on
85  * several hosts and communication between them.
86  *
87  * \param name Name of the execution synchro to create
88  * \param host_nb Number of hosts where the synchro will be executed
89  * \param host_list Array (of size host_nb) of hosts where the synchro will be executed
90  * \param flops_amount Array (of size host_nb) of computation amount of hosts (in bytes)
91  * \param bytes_amount Array (of size host_nb * host_nb) representing the communication
92  * amount between each pair of hosts
93  * \param amount the SURF action amount
94  * \param rate the SURF action rate
95  * \return A new SIMIX execution synchronization
96  */
97 smx_synchro_t simcall_execution_parallel_start(const char *name,
98                                          int host_nb,
99                                          sg_host_t *host_list,
100                                          double *flops_amount,
101                                          double *bytes_amount,
102                                          double amount,
103                                          double rate)
104 {
105   int i,j;
106   /* checking for infinite values */
107   for (i = 0 ; i < host_nb ; ++i) {
108     xbt_assert(std::isfinite(flops_amount[i]), "flops_amount[%d] is not finite!", i);
109     if (bytes_amount != NULL) {
110       for (j = 0 ; j < host_nb ; ++j) {
111         xbt_assert(std::isfinite(bytes_amount[i + host_nb * j]),
112                    "bytes_amount[%d+%d*%d] is not finite!", i, host_nb, j);
113       }
114     }
115   }
116
117   xbt_assert(std::isfinite(amount), "amount is not finite!");
118   xbt_assert(std::isfinite(rate), "rate is not finite!");
119
120   return simcall_BODY_execution_parallel_start(name, host_nb, host_list,
121                                             flops_amount,
122                                             bytes_amount,
123                                             amount, rate);
124
125 }
126
127 /**
128  * \ingroup simix_process_management
129  * \brief Destroys an execution synchro.
130  *
131  * Destroys a synchro, freeing its memory. This function cannot be called if there are a conditional waiting for it.
132  * \param execution The execution synchro to destroy
133  */
134 void simcall_execution_destroy(smx_synchro_t execution)
135 {
136   simcall_BODY_execution_destroy(execution);
137 }
138
139 /**
140  * \ingroup simix_process_management
141  * \brief Cancels an execution synchro.
142  *
143  * This functions stops the execution. It calls a surf function.
144  * \param execution The execution synchro to cancel
145  */
146 void simcall_execution_cancel(smx_synchro_t execution)
147 {
148   simcall_BODY_execution_cancel(execution);
149 }
150
151 /**
152  * \ingroup simix_process_management
153  * \brief Returns how much of an execution synchro remains to be done.
154  *
155  * \param execution The execution synchro
156  * \return The remaining amount
157  */
158 double simcall_execution_get_remains(smx_synchro_t execution)
159 {
160   return simcall_BODY_execution_get_remains(execution);
161 }
162
163 /**
164  * \ingroup simix_process_management
165  * \brief Returns the state of an execution synchro.
166  *
167  * \param execution The execution synchro
168  * \return The state
169  */
170 e_smx_state_t simcall_execution_get_state(smx_synchro_t execution)
171 {
172   return simcall_BODY_execution_get_state(execution);
173 }
174
175 /**
176  * \ingroup simix_process_management
177  * \brief Changes the priority of an execution synchro.
178  *
179  * This functions changes the priority only. It calls a surf function.
180  * \param execution The execution synchro
181  * \param priority The new priority
182  */
183 void simcall_execution_set_priority(smx_synchro_t execution, double priority)
184 {
185   /* checking for infinite values */
186   xbt_assert(std::isfinite(priority), "priority is not finite!");
187
188   simcall_BODY_execution_set_priority(execution, priority);
189 }
190
191 /**
192  * \ingroup simix_process_management
193  * \brief Changes the capping (the maximum CPU utilization) of an execution synchro.
194  *
195  * This functions changes the capping only. It calls a surf function.
196  * \param execution The execution synchro
197  * \param bound The new bound
198  */
199 void simcall_execution_set_bound(smx_synchro_t execution, double bound)
200 {
201   simcall_BODY_execution_set_bound(execution, bound);
202 }
203
204 /**
205  * \ingroup simix_process_management
206  * \brief Changes the CPU affinity of an execution synchro.
207  *
208  * This functions changes the CPU affinity of an execution synchro. See taskset(1) on Linux.
209  * \param execution The execution synchro
210  * \param host Host
211  * \param mask Affinity mask
212  */
213 void simcall_execution_set_affinity(smx_synchro_t execution, sg_host_t host, unsigned long mask)
214 {
215   simcall_BODY_execution_set_affinity(execution, host, mask);
216 }
217
218 /**
219  * \ingroup simix_host_management
220  * \brief Waits for the completion of an execution synchro and destroy it.
221  *
222  * \param execution The execution synchro
223  */
224 e_smx_state_t simcall_execution_wait(smx_synchro_t execution)
225 {
226   return (e_smx_state_t) simcall_BODY_execution_wait(execution);
227 }
228
229
230 /**
231  * \ingroup simix_vm_management
232  * \brief Create a VM on the given physical host.
233  *
234  * \param name VM name
235  * \param host Physical host
236  *
237  * \return The host object of the VM
238  */
239 void* simcall_vm_create(const char *name, sg_host_t phys_host)
240 {
241   return simgrid::simix::kernel(std::bind(SIMIX_vm_create, name, phys_host));
242 }
243
244 /**
245  * \ingroup simix_vm_management
246  * \brief Start the given VM to the given physical host
247  *
248  * \param vm VM
249  */
250 void simcall_vm_start(sg_host_t vm)
251 {
252   return simgrid::simix::kernel(std::bind(SIMIX_vm_start, vm));
253 }
254
255 /**
256  * \ingroup simix_vm_management
257  * \brief Get the state of the given VM
258  *
259  * \param vm VM
260  * \return The state of the VM
261  */
262 int simcall_vm_get_state(sg_host_t vm)
263 {
264   return simgrid::simix::kernel(std::bind(SIMIX_vm_get_state, vm));
265 }
266
267 /**
268  * \ingroup simix_vm_management
269  * \brief Get the name of the physical host on which the given VM runs.
270  *
271  * \param vm VM
272  * \return The name of the physical host
273  */
274 void *simcall_vm_get_pm(sg_host_t vm)
275 {
276   return simgrid::simix::kernel(std::bind(SIMIX_vm_get_pm, vm));
277 }
278
279 void simcall_vm_set_bound(sg_host_t vm, double bound)
280 {
281   simgrid::simix::kernel(std::bind(SIMIX_vm_set_bound, vm, bound));
282 }
283
284 void simcall_vm_set_affinity(sg_host_t vm, sg_host_t pm, unsigned long mask)
285 {
286   simgrid::simix::kernel(std::bind(SIMIX_vm_set_affinity, vm, pm, mask));
287 }
288
289 /**
290  * \ingroup simix_vm_management
291  * \brief Migrate the given VM to the given physical host
292  *
293  * \param vm VM
294  * \param host Destination physical host
295  */
296 void simcall_vm_migrate(sg_host_t vm, sg_host_t host)
297 {
298   return simgrid::simix::kernel(std::bind(SIMIX_vm_migrate, vm, host));
299 }
300
301 /**
302  * \ingroup simix_vm_management
303  * \brief Suspend the given VM
304  *
305  * \param vm VM
306  */
307 void simcall_vm_suspend(sg_host_t vm)
308 {
309   simcall_BODY_vm_suspend(vm);
310 }
311
312 /**
313  * \ingroup simix_vm_management
314  * \brief Resume the given VM
315  *
316  * \param vm VM
317  */
318 void simcall_vm_resume(sg_host_t vm)
319 {
320   simcall_BODY_vm_resume(vm);
321 }
322
323 /**
324  * \ingroup simix_vm_management
325  * \brief Save the given VM
326  *
327  * \param vm VM
328  */
329 void simcall_vm_save(sg_host_t vm)
330 {
331   simcall_BODY_vm_save(vm);
332 }
333
334 /**
335  * \ingroup simix_vm_management
336  * \brief Restore the given VM
337  *
338  * \param vm VM
339  */
340 void simcall_vm_restore(sg_host_t vm)
341 {
342   simcall_BODY_vm_restore(vm);
343 }
344
345 /**
346  * \ingroup simix_vm_management
347  * \brief Shutdown the given VM
348  *
349  * \param vm VM
350  */
351 void simcall_vm_shutdown(sg_host_t vm)
352 {
353   simcall_BODY_vm_shutdown(vm);
354 }
355
356 /**
357  * \ingroup simix_vm_management
358  * \brief Destroy the given VM
359  *
360  * \param vm VM
361  */
362 void simcall_vm_destroy(sg_host_t vm)
363 {
364   simgrid::simix::kernel(std::bind(SIMIX_vm_destroy, vm));
365 }
366
367 /**
368  * \ingroup simix_vm_management
369  * \brief Encompassing simcall to prevent the removal of the src or the dst node at the end of a VM migration
370  *  The simcall actually invokes the following calls: 
371  *     simcall_vm_set_affinity(vm, src_pm, 0); 
372  *     simcall_vm_migrate(vm, dst_pm); 
373  *     simcall_vm_resume(vm);
374  *
375  * It is called at the end of the migration_rx_fun function from msg/msg_vm.c
376  *
377  * \param vm VM to migrate
378  * \param src_pm  Source physical host
379  * \param dst_pmt Destination physical host
380  */
381 void simcall_vm_migratefrom_resumeto(sg_host_t vm, sg_host_t src_pm, sg_host_t dst_pm)
382 {
383   simgrid::simix::kernel(std::bind(
384     SIMIX_vm_migratefrom_resumeto, vm, src_pm, dst_pm));
385 }
386
387 /**
388  * \ingroup simix_process_management
389  * \brief Creates and runs a new SIMIX process.
390  *
391  * The structure and the corresponding thread are created and put in the list of ready processes.
392  *
393  * \param name a name for the process. It is for user-level information and can be NULL.
394  * \param code the main function of the process
395  * \param data a pointer to any data one may want to attach to the new object. It is for user-level information and can be NULL.
396  * It can be retrieved with the function \ref simcall_process_get_data.
397  * \param hostname name of the host where the new agent is executed.
398  * \param kill_time time when the process is killed
399  * \param argc first argument passed to \a code
400  * \param argv second argument passed to \a code
401  * \param properties the properties of the process
402  * \param auto_restart either it is autorestarting or not.
403  */
404 smx_process_t simcall_process_create(const char *name,
405                               xbt_main_func_t code,
406                               void *data,
407                               const char *hostname,
408                               double kill_time,
409                               int argc, char **argv,
410                               xbt_dict_t properties,
411                               int auto_restart)
412 {
413   return (smx_process_t) simcall_BODY_process_create(name, code, data, hostname,
414                               kill_time, argc, argv, properties,
415                               auto_restart);
416 }
417
418 /**
419  * \ingroup simix_process_management
420  * \brief Kills a SIMIX process.
421  *
422  * This function simply kills a  process.
423  *
424  * \param process poor victim
425  */
426 void simcall_process_kill(smx_process_t process)
427 {
428   simcall_BODY_process_kill(process);
429 }
430
431 /**
432  * \ingroup simix_process_management
433  * \brief Kills all SIMIX processes.
434  */
435 void simcall_process_killall(int reset_pid)
436 {
437   simcall_BODY_process_killall(reset_pid);
438 }
439
440 /**
441  * \ingroup simix_process_management
442  * \brief Cleans up a SIMIX process.
443  * \param process poor victim (must have already been killed)
444  */
445 void simcall_process_cleanup(smx_process_t process)
446 {
447   simcall_BODY_process_cleanup(process);
448 }
449
450 /**
451  * \ingroup simix_process_management
452  * \brief Migrates an agent to another location.
453  *
454  * This function changes the value of the host on which \a process is running.
455  *
456  * \param process the process to migrate
457  * \param dest name of the new host
458  */
459 void simcall_process_set_host(smx_process_t process, sg_host_t dest)
460 {
461   simcall_BODY_process_set_host(process, dest);
462 }
463
464 void simcall_process_join(smx_process_t process, double timeout)
465 {
466   simcall_BODY_process_join(process, timeout);
467 }
468
469 /**
470  * \ingroup simix_process_management
471  * \brief Suspends a process.
472  *
473  * This function suspends the process by suspending the synchro
474  * it was waiting for completion.
475  *
476  * \param process a SIMIX process
477  */
478 void simcall_process_suspend(smx_process_t process)
479 {
480   xbt_assert(process, "Invalid parameters");
481
482   simcall_BODY_process_suspend(process);
483 }
484
485 /**
486  * \ingroup simix_process_management
487  * \brief Resumes a suspended process.
488  *
489  * This function resumes a suspended process by resuming the synchro
490  * it was waiting for completion.
491  *
492  * \param process a SIMIX process
493  */
494 void simcall_process_resume(smx_process_t process)
495 {
496   simcall_BODY_process_resume(process);
497 }
498
499 /**
500  * \ingroup simix_process_management
501  * \brief Returns the amount of SIMIX processes in the system
502  *
503  * Maestro internal process is not counted, only user code processes are
504  */
505 int simcall_process_count(void)
506 {
507   return simgrid::simix::kernel(SIMIX_process_count);
508 }
509
510 /**
511  * \ingroup simix_process_management
512  * \brief Return the PID of a #smx_process_t.
513  * \param process a SIMIX process
514  * \return the PID of this process
515  */
516 int simcall_process_get_PID(smx_process_t process)
517 {
518   return SIMIX_process_get_PID(process);
519 }
520
521 /**
522  * \ingroup simix_process_management
523  * \brief Return the parent PID of a #smx_process_t.
524  * \param process a SIMIX process
525  * \return the PID of this process parenrt
526  */
527 int simcall_process_get_PPID(smx_process_t process)
528 {
529   return SIMIX_process_get_PPID(process);
530 }
531
532 /**
533  * \ingroup simix_process_management
534  * \brief Return the user data of a #smx_process_t.
535  * \param process a SIMIX process
536  * \return the user data of this process
537  */
538 void* simcall_process_get_data(smx_process_t process)
539 {
540   return SIMIX_process_get_data(process);
541 }
542
543 /**
544  * \ingroup simix_process_management
545  * \brief Set the user data of a #smx_process_t.
546  *
547  * This functions sets the user data associated to \a process.
548  * \param process SIMIX process
549  * \param data User data
550  */
551 void simcall_process_set_data(smx_process_t process, void *data)
552 {
553   simgrid::simix::kernel(std::bind(SIMIX_process_set_data, process, data));
554 }
555
556 static void kill_process_from_timer(void* arg)
557 {
558   smx_process_t process = (smx_process_t) arg;
559   simix_global->kill_process_function(process);
560   process->kill_timer=NULL;
561 }
562
563 /**
564  * \ingroup simix_process_management
565  * \brief Set the kill time of a process.
566  */
567 void simcall_process_set_kill_time(smx_process_t process, double kill_time)
568 {
569
570   if (kill_time > SIMIX_get_clock()) {
571     if (simix_global->kill_process_function) {
572       XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name,
573           sg_host_get_name(process->host));
574       process->kill_timer = SIMIX_timer_set(kill_time, kill_process_from_timer, process);
575     }
576   }
577 }
578 /**
579  * \ingroup simix_process_management
580  * \brief Get the kill time of a process (or 0 if unset).
581  */
582 double simcall_process_get_kill_time(smx_process_t process) {
583   return SIMIX_timer_get_date(process->kill_timer);
584 }
585
586 /**
587  * \ingroup simix_process_management
588  * \brief Return the location on which an agent is running.
589  *
590  * This functions returns the sg_host_t corresponding to the location on which
591  * \a process is running.
592  * \param process SIMIX process
593  * \return SIMIX host
594  */
595 sg_host_t simcall_process_get_host(smx_process_t process)
596 {
597   return SIMIX_process_get_host(process);
598 }
599
600 /**
601  * \ingroup simix_process_management
602  * \brief Return the name of an agent.
603  *
604  * This functions checks whether \a process is a valid pointer or not and return its name.
605  * \param process SIMIX process
606  * \return The process name
607  */
608 const char* simcall_process_get_name(smx_process_t process)
609 {
610   return SIMIX_process_get_name(process);
611 }
612
613 /**
614  * \ingroup simix_process_management
615  * \brief Returns true if the process is suspended .
616  *
617  * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
618  * \param process SIMIX process
619  * \return 1, if the process is suspended, else 0.
620  */
621 int simcall_process_is_suspended(smx_process_t process)
622 {
623   return simcall_BODY_process_is_suspended(process);
624 }
625
626 /**
627  * \ingroup simix_process_management
628  * \brief Return the properties
629  *
630  * This functions returns the properties associated with this process
631  */
632 xbt_dict_t simcall_process_get_properties(smx_process_t process)
633 {
634   return SIMIX_process_get_properties(process);
635 }
636 /**
637  * \ingroup simix_process_management
638  * \brief Add an on_exit function
639  * Add an on_exit function which will be executed when the process exits/is killed.
640  */
641 XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_pvoid_t fun, void *data)
642 {
643   simcall_BODY_process_on_exit(process, fun, data);
644 }
645 /**
646  * \ingroup simix_process_management
647  * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up.
648  * Will restart the process when the host comes back up if auto_restart is set to 1.
649  */
650
651 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart)
652 {
653   simcall_BODY_process_auto_restart_set(process, auto_restart);
654 }
655
656 /**
657  * \ingroup simix_process_management
658  * \brief Restarts the process, killing it and starting it again from scratch.
659  */
660 XBT_PUBLIC(smx_process_t) simcall_process_restart(smx_process_t process)
661 {
662   return (smx_process_t) simcall_BODY_process_restart(process);
663 }
664 /**
665  * \ingroup simix_process_management
666  * \brief Creates a new sleep SIMIX synchro.
667  *
668  * This function creates a SURF action and allocates the data necessary
669  * to create the SIMIX synchro. It can raise a host_error exception if the
670  * host crashed. The default SIMIX name of the synchro is "sleep".
671  *
672  *   \param duration Time duration of the sleep.
673  *   \return A result telling whether the sleep was successful
674  */
675 e_smx_state_t simcall_process_sleep(double duration)
676 {
677   /* checking for infinite values */
678   xbt_assert(std::isfinite(duration), "duration is not finite!");
679   return (e_smx_state_t) simcall_BODY_process_sleep(duration);
680 }
681
682 /**
683  *  \ingroup simix_mbox_management
684  *  \brief Creates a new rendez-vous point
685  *  \param name The name of the rendez-vous point
686  *  \return The created rendez-vous point
687  */
688 smx_mailbox_t simcall_mbox_create(const char *name)
689 {
690   return simcall_BODY_mbox_create(name);
691 }
692
693 /**
694  *  \ingroup simix_mbox_management
695  *  \brief Returns a rendez-vous point knowing its name
696  */
697 smx_mailbox_t simcall_mbox_get_by_name(const char *name)
698 {
699   /* FIXME: this is a horrible loss of performance, so we hack it out by
700    * skipping the simcall (for now). It works in parallel, it won't work on
701    * distributed but probably we will change MSG for that. */
702
703   return SIMIX_mbox_get_by_name(name);
704 }
705
706 /**
707  *  \ingroup simix_mbox_management
708  *  \brief returns the communication at the head of the rendez-vous
709  *  \param mbox The rendez-vous point
710  *  \return The communication or NULL if empty
711  */
712 smx_synchro_t simcall_mbox_get_head(smx_mailbox_t mbox)
713 {
714   return simcall_BODY_mbox_get_head(mbox);
715 }
716
717 void simcall_mbox_set_receiver(smx_mailbox_t mbox, smx_process_t process)
718 {
719   simcall_BODY_mbox_set_receiver(mbox, process);
720 }
721
722 smx_process_t simcall_mbox_get_receiver(smx_mailbox_t mbox)
723 {
724   return simcall_BODY_mbox_get_receiver(mbox);
725 }
726
727 /**
728  * \ingroup simix_comm_management
729  */
730 void simcall_comm_send(smx_process_t sender, smx_mailbox_t mbox, double task_size, double rate,
731                          void *src_buff, size_t src_buff_size,
732                          int (*match_fun)(void *, void *, smx_synchro_t),
733                          void (*copy_data_fun)(smx_synchro_t, void*, size_t), void *data,
734                          double timeout)
735 {
736   /* checking for infinite values */
737   xbt_assert(std::isfinite(task_size), "task_size is not finite!");
738   xbt_assert(std::isfinite(rate), "rate is not finite!");
739   xbt_assert(std::isfinite(timeout), "timeout is not finite!");
740
741   xbt_assert(mbox, "No rendez-vous point defined for send");
742
743   if (MC_is_active() || MC_record_replay_is_active()) {
744     /* the model-checker wants two separate simcalls */
745     smx_synchro_t comm = NULL; /* MC needs the comm to be set to NULL during the simcall */
746     comm = simcall_comm_isend(sender, mbox, task_size, rate,
747         src_buff, src_buff_size, match_fun, NULL, copy_data_fun, data, 0);
748     simcall_comm_wait(comm, timeout);
749     comm = NULL;
750   }
751   else {
752     simcall_BODY_comm_send(sender, mbox, task_size, rate, src_buff, src_buff_size,
753                          match_fun, copy_data_fun, data, timeout);
754   }
755 }
756
757 /**
758  * \ingroup simix_comm_management
759  */
760 smx_synchro_t simcall_comm_isend(smx_process_t sender, smx_mailbox_t mbox, double task_size, double rate,
761                               void *src_buff, size_t src_buff_size,
762                               int (*match_fun)(void *, void *, smx_synchro_t),
763                               void (*clean_fun)(void *),
764                               void (*copy_data_fun)(smx_synchro_t, void*, size_t),
765                               void *data,
766                               int detached)
767 {
768   /* checking for infinite values */
769   xbt_assert(std::isfinite(task_size), "task_size is not finite!");
770   xbt_assert(std::isfinite(rate), "rate is not finite!");
771
772   xbt_assert(mbox, "No rendez-vous point defined for isend");
773
774   return simcall_BODY_comm_isend(sender, mbox, task_size, rate, src_buff,
775                                  src_buff_size, match_fun,
776                                  clean_fun, copy_data_fun, data, detached);
777 }
778
779 /**
780  * \ingroup simix_comm_management
781  */
782 void simcall_comm_recv(smx_process_t receiver, smx_mailbox_t mbox, void *dst_buff, size_t * dst_buff_size,
783                        int (*match_fun)(void *, void *, smx_synchro_t),
784                        void (*copy_data_fun)(smx_synchro_t, void*, size_t),
785                        void *data, double timeout, double rate)
786 {
787   xbt_assert(std::isfinite(timeout), "timeout is not finite!");
788   xbt_assert(mbox, "No rendez-vous point defined for recv");
789
790   if (MC_is_active() || MC_record_replay_is_active()) {
791     /* the model-checker wants two separate simcalls */
792     smx_synchro_t comm = NULL; /* MC needs the comm to be set to NULL during the simcall */
793     comm = simcall_comm_irecv(receiver, mbox, dst_buff, dst_buff_size,
794                               match_fun, copy_data_fun, data, rate);
795     simcall_comm_wait(comm, timeout);
796     comm = NULL;
797   }
798   else {
799     simcall_BODY_comm_recv(receiver, mbox, dst_buff, dst_buff_size,
800                            match_fun, copy_data_fun, data, timeout, rate);
801   }
802 }
803 /**
804  * \ingroup simix_comm_management
805  */
806 smx_synchro_t simcall_comm_irecv(smx_process_t receiver, smx_mailbox_t mbox, void *dst_buff, size_t *dst_buff_size,
807                                 int (*match_fun)(void *, void *, smx_synchro_t),
808                                 void (*copy_data_fun)(smx_synchro_t, void*, size_t),
809                                 void *data, double rate)
810 {
811   xbt_assert(mbox, "No rendez-vous point defined for irecv");
812
813   return simcall_BODY_comm_irecv(receiver, mbox, dst_buff, dst_buff_size,
814                                  match_fun, copy_data_fun, data, rate);
815 }
816
817 /**
818  * \ingroup simix_comm_management
819  */
820 smx_synchro_t simcall_comm_iprobe(smx_mailbox_t mbox, int type, int src, int tag,
821                                 int (*match_fun)(void *, void *, smx_synchro_t), void *data)
822 {
823   xbt_assert(mbox, "No rendez-vous point defined for iprobe");
824
825   return simcall_BODY_comm_iprobe(mbox, type, src, tag, match_fun, data);
826 }
827
828 /**
829  * \ingroup simix_comm_management
830  */
831 void simcall_comm_cancel(smx_synchro_t comm)
832 {
833   simcall_BODY_comm_cancel(comm);
834 }
835
836 /**
837  * \ingroup simix_comm_management
838  */
839 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
840 {
841   return simcall_BODY_comm_waitany(comms);
842 }
843
844 /**
845  * \ingroup simix_comm_management
846  */
847 int simcall_comm_testany(xbt_dynar_t comms)
848 {
849   if (xbt_dynar_is_empty(comms))
850     return -1;
851   return simcall_BODY_comm_testany(comms);
852 }
853
854 /**
855  * \ingroup simix_comm_management
856  */
857 void simcall_comm_wait(smx_synchro_t comm, double timeout)
858 {
859   xbt_assert(std::isfinite(timeout), "timeout is not finite!");
860   simcall_BODY_comm_wait(comm, timeout);
861 }
862
863 /**
864  * \brief Set the category of an synchro.
865  *
866  * This functions changes the category only. It calls a surf function.
867  * \param execution The execution synchro
868  * \param category The tracing category
869  */
870 void simcall_set_category(smx_synchro_t synchro, const char *category)
871 {
872   if (category == NULL) {
873     return;
874   }
875   simcall_BODY_set_category(synchro, category);
876 }
877
878 /**
879  * \ingroup simix_comm_management
880  *
881  */
882 int simcall_comm_test(smx_synchro_t comm)
883 {
884   return simcall_BODY_comm_test(comm);
885 }
886
887 /**
888  * \ingroup simix_comm_management
889  *
890  */
891 double simcall_comm_get_remains(smx_synchro_t comm)
892 {
893   return simcall_BODY_comm_get_remains(comm);
894 }
895
896 /**
897  * \ingroup simix_comm_management
898  *
899  */
900 void *simcall_comm_get_src_data(smx_synchro_t comm)
901 {
902   return simcall_BODY_comm_get_src_data(comm);
903 }
904
905 /**
906  * \ingroup simix_comm_management
907  *
908  */
909 void *simcall_comm_get_dst_data(smx_synchro_t comm)
910 {
911   return simcall_BODY_comm_get_dst_data(comm);
912 }
913
914 /**
915  * \ingroup simix_comm_management
916  *
917  */
918 smx_process_t simcall_comm_get_src_proc(smx_synchro_t comm)
919 {
920   return simcall_BODY_comm_get_src_proc(comm);
921 }
922
923 /**
924  * \ingroup simix_comm_management
925  *
926  */
927 smx_process_t simcall_comm_get_dst_proc(smx_synchro_t comm)
928 {
929   return simcall_BODY_comm_get_dst_proc(comm);
930 }
931
932 /**
933  * \ingroup simix_synchro_management
934  *
935  */
936 smx_mutex_t simcall_mutex_init(void)
937 {
938   if(!simix_global) {
939     fprintf(stderr,"You must run MSG_init before using MSG\n"); // We can't use xbt_die since we may get there before the initialization
940     xbt_abort();
941   }
942   return simcall_BODY_mutex_init();
943 }
944
945 /**
946  * \ingroup simix_synchro_management
947  *
948  */
949 void simcall_mutex_lock(smx_mutex_t mutex)
950 {
951   simcall_BODY_mutex_lock(mutex);
952 }
953
954 /**
955  * \ingroup simix_synchro_management
956  *
957  */
958 int simcall_mutex_trylock(smx_mutex_t mutex)
959 {
960   return simcall_BODY_mutex_trylock(mutex);
961 }
962
963 /**
964  * \ingroup simix_synchro_management
965  *
966  */
967 void simcall_mutex_unlock(smx_mutex_t mutex)
968 {
969   simcall_BODY_mutex_unlock(mutex);
970 }
971
972 /**
973  * \ingroup simix_synchro_management
974  *
975  */
976 smx_cond_t simcall_cond_init(void)
977 {
978   return simcall_BODY_cond_init();
979 }
980
981 /**
982  * \ingroup simix_synchro_management
983  *
984  */
985 void simcall_cond_signal(smx_cond_t cond)
986 {
987   simcall_BODY_cond_signal(cond);
988 }
989
990 /**
991  * \ingroup simix_synchro_management
992  *
993  */
994 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
995 {
996   simcall_BODY_cond_wait(cond, mutex);
997 }
998
999 /**
1000  * \ingroup simix_synchro_management
1001  *
1002  */
1003 void simcall_cond_wait_timeout(smx_cond_t cond,
1004                                  smx_mutex_t mutex,
1005                                  double timeout)
1006 {
1007   xbt_assert(std::isfinite(timeout), "timeout is not finite!");
1008   simcall_BODY_cond_wait_timeout(cond, mutex, timeout);
1009 }
1010
1011 /**
1012  * \ingroup simix_synchro_management
1013  *
1014  */
1015 void simcall_cond_broadcast(smx_cond_t cond)
1016 {
1017   simcall_BODY_cond_broadcast(cond);
1018 }
1019
1020 /**
1021  * \ingroup simix_synchro_management
1022  *
1023  */
1024 smx_sem_t simcall_sem_init(int capacity)
1025 {
1026   return simcall_BODY_sem_init(capacity);
1027 }
1028
1029 /**
1030  * \ingroup simix_synchro_management
1031  *
1032  */
1033 void simcall_sem_release(smx_sem_t sem)
1034 {
1035   simcall_BODY_sem_release(sem);
1036 }
1037
1038 /**
1039  * \ingroup simix_synchro_management
1040  *
1041  */
1042 int simcall_sem_would_block(smx_sem_t sem)
1043 {
1044   return simcall_BODY_sem_would_block(sem);
1045 }
1046
1047 /**
1048  * \ingroup simix_synchro_management
1049  *
1050  */
1051 void simcall_sem_acquire(smx_sem_t sem)
1052 {
1053   simcall_BODY_sem_acquire(sem);
1054 }
1055
1056 /**
1057  * \ingroup simix_synchro_management
1058  *
1059  */
1060 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1061 {
1062   xbt_assert(std::isfinite(timeout), "timeout is not finite!");
1063   simcall_BODY_sem_acquire_timeout(sem, timeout);
1064 }
1065
1066 /**
1067  * \ingroup simix_synchro_management
1068  *
1069  */
1070 int simcall_sem_get_capacity(smx_sem_t sem)
1071 {
1072   return simcall_BODY_sem_get_capacity(sem);
1073 }
1074
1075 /**
1076  * \ingroup simix_file_management
1077  *
1078  */
1079 sg_size_t simcall_file_read(smx_file_t fd, sg_size_t size, sg_host_t host)
1080 {
1081   return simcall_BODY_file_read(fd, size, host);
1082 }
1083
1084 /**
1085  * \ingroup simix_file_management
1086  *
1087  */
1088 sg_size_t simcall_file_write(smx_file_t fd, sg_size_t size, sg_host_t host)
1089 {
1090   return simcall_BODY_file_write(fd, size, host);
1091 }
1092
1093 /**
1094  * \ingroup simix_file_management
1095  * \brief
1096  */
1097 smx_file_t simcall_file_open(const char* fullpath, sg_host_t host)
1098 {
1099   return simcall_BODY_file_open(fullpath, host);
1100 }
1101
1102 /**
1103  * \ingroup simix_file_management
1104  *
1105  */
1106 int simcall_file_close(smx_file_t fd, sg_host_t host)
1107 {
1108   return simcall_BODY_file_close(fd, host);
1109 }
1110
1111 /**
1112  * \ingroup simix_file_management
1113  *
1114  */
1115 int simcall_file_unlink(smx_file_t fd, sg_host_t host)
1116 {
1117   return simcall_BODY_file_unlink(fd, host);
1118 }
1119
1120 /**
1121  * \ingroup simix_file_management
1122  *
1123  */
1124 sg_size_t simcall_file_get_size(smx_file_t fd){
1125   return simcall_BODY_file_get_size(fd);
1126 }
1127
1128 /**
1129  * \ingroup simix_file_management
1130  *
1131  */
1132 sg_size_t simcall_file_tell(smx_file_t fd){
1133   return simcall_BODY_file_tell(fd);
1134 }
1135
1136 /**
1137  * \ingroup simix_file_management
1138  *
1139  */
1140 xbt_dynar_t simcall_file_get_info(smx_file_t fd)
1141 {
1142   return simcall_BODY_file_get_info(fd);
1143 }
1144
1145 /**
1146  * \ingroup simix_file_management
1147  *
1148  */
1149 int simcall_file_seek(smx_file_t fd, sg_offset_t offset, int origin){
1150   return simcall_BODY_file_seek(fd, offset, origin);
1151 }
1152
1153 /**
1154  * \ingroup simix_file_management
1155  * \brief Move a file to another location on the *same mount point*.
1156  *
1157  */
1158 int simcall_file_move(smx_file_t fd, const char* fullpath)
1159 {
1160   return simcall_BODY_file_move(fd, fullpath);
1161 }
1162
1163 /**
1164  * \ingroup simix_storage_management
1165  * \brief Returns the free space size on a given storage element.
1166  * \param storage a storage
1167  * \return Return the free space size on a given storage element (as sg_size_t)
1168  */
1169 sg_size_t simcall_storage_get_free_size (smx_storage_t storage){
1170   return simcall_BODY_storage_get_free_size(storage);
1171 }
1172
1173 /**
1174  * \ingroup simix_storage_management
1175  * \brief Returns the used space size on a given storage element.
1176  * \param storage a storage
1177  * \return Return the used space size on a given storage element (as sg_size_t)
1178  */
1179 sg_size_t simcall_storage_get_used_size (smx_storage_t storage){
1180   return simcall_BODY_storage_get_used_size(storage);
1181 }
1182
1183 /**
1184  * \ingroup simix_storage_management
1185  * \brief Returns a dict of the properties assigned to a storage element.
1186  *
1187  * \param storage A storage element
1188  * \return The properties of this storage element
1189  */
1190 xbt_dict_t simcall_storage_get_properties(smx_storage_t storage)
1191 {
1192   return simcall_BODY_storage_get_properties(storage);
1193 }
1194
1195 /**
1196  * \ingroup simix_storage_management
1197  * \brief Returns a dict containing the content of a storage element.
1198  *
1199  * \param storage A storage element
1200  * \return The content of this storage element as a dict (full path file => size)
1201  */
1202 xbt_dict_t simcall_storage_get_content(smx_storage_t storage)
1203 {
1204   return simcall_BODY_storage_get_content(storage);
1205 }
1206
1207 void simcall_run_kernel(std::function<void()> const& code)
1208 {
1209   return simcall_BODY_run_kernel((void*) &code);
1210 }
1211
1212 int simcall_mc_random(int min, int max) {
1213   return simcall_BODY_mc_random(min, max);
1214 }
1215
1216 /* ************************************************************************** */
1217
1218 /** @brief returns a printable string representing a simcall */
1219 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1220   return simcall_names[kind];
1221 }