Logo AND Algorithmique Numérique Distribuée

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