Logo AND Algorithmique Numérique Distribuée

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