Logo AND Algorithmique Numérique Distribuée

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