Logo AND Algorithmique Numérique Distribuée

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