Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
various fixups to the surf documentation
[simgrid.git] / src / simix / libsmx.c
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-2014. The SimGrid Team. All rights reserved.            */
9
10 /* This program is free software; you can redistribute it and/or modify it
11  * under the terms of the license (GNU LGPL) which comes with this package.   */
12
13 #include "mc/mc_replay.h"
14 #include "smx_private.h"
15 #include "mc/mc_forward.h"
16 #include "xbt/ex.h"
17 #include <math.h>         /* isfinite() */
18 #include "mc/mc.h"
19
20 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
21
22 #include "popping_bodies.c"
23
24 /**
25  * \ingroup simix_host_management
26  * \brief Returns the name of a host.
27  *
28  * \param host A SIMIX host
29  * \return The name of this host
30  */
31 const char* simcall_host_get_name(sg_host_t host)
32 {
33   return simcall_BODY_host_get_name(host);
34 }
35
36 /**
37  * \ingroup simix_host_management
38  * \brief Start the host if it is off
39  *
40  * \param host A SIMIX host
41  */
42 void simcall_host_on(sg_host_t host)
43 {
44   simcall_BODY_host_on(host);
45 }
46
47 /**
48  * \ingroup simix_host_management
49  * \brief Stop the host if it is on
50  *
51  * \param host A SIMIX host
52  */
53 void simcall_host_off(sg_host_t host)
54 {
55   simcall_BODY_host_off(host);
56 }
57
58 /**
59  * \ingroup simix_host_management
60  * \brief Returns a dict of the properties assigned to a host.
61  *
62  * \param host A host
63  * \return The properties of this host
64  */
65 xbt_dict_t simcall_host_get_properties(sg_host_t host)
66 {
67   return simcall_BODY_host_get_properties(host);
68 }
69
70 /**
71  * \ingroup simix_host_management
72  * \brief Returns a dict of the properties assigned to a router or AS.
73  *
74  * \param name The name of the router or AS
75  * \return The properties
76  */
77 xbt_dict_t simcall_asr_get_properties(const char *name)
78 {
79   return simcall_BODY_asr_get_properties(name);
80 }
81
82
83 /**
84  * \ingroup simix_host_management
85  * \brief Returns the speed of the processor.
86  *
87  * The speed returned does not take into account the current load on the machine.
88  * \param host A SIMIX host
89  * \return The speed of this host (in Mflop/s)
90  */
91 double simcall_host_get_speed(sg_host_t host)
92 {
93   return simcall_BODY_host_get_speed(host);
94 }
95
96 /**
97  * \ingroup simix_host_management
98  * \brief Returns the number of core of the processor.
99  *
100  * \param host A SIMIX host
101  * \return The number of core
102  */
103 int simcall_host_get_core(sg_host_t host)
104 {
105   return simcall_BODY_host_get_core(host);
106 }
107
108 /**
109  * \ingroup simix_host_management
110  * \brief Returns the list of processes attached to the host.
111  *
112  * \param host A SIMIX host
113  * \return the swag of attached processes
114  */
115 xbt_swag_t simcall_host_get_process_list(sg_host_t host)
116 {
117   return simcall_BODY_host_get_process_list(host);
118 }
119
120
121 /**
122  * \ingroup simix_host_management
123  * \brief Returns the available speed of the processor.
124  *
125  * \return Speed currently available (in Mflop/s)
126  */
127 double simcall_host_get_available_speed(sg_host_t host)
128 {
129   return simcall_BODY_host_get_available_speed(host);
130 }
131
132 /**
133  * \ingroup simix_host_management
134  * \brief Returns the state of a host.
135  *
136  * Two states are possible: 1 if the host is active or 0 if it has crashed.
137  * \param host A SIMIX host
138  * \return 1 if the host is available, 0 otherwise
139  */
140 int simcall_host_get_state(sg_host_t host)
141 {
142   return simcall_BODY_host_get_state(host);
143 }
144
145 /**
146  * \ingroup simix_host_management
147  * \brief Returns the power peak of a host.
148  *
149  * \param host A SIMIX host
150  * \return the current power peak value (double)
151  */
152 double simcall_host_get_current_power_peak(sg_host_t host)
153 {
154   return simcall_BODY_host_get_current_power_peak(host);
155 }
156
157 /**
158  * \ingroup simix_host_management
159  * \brief Returns one power peak (in flops/s) of a host at a given pstate
160  *
161  * \param host A SIMIX host
162  * \param pstate_index pstate to test
163  * \return the current power peak value (double) for pstate_index
164  */
165 double simcall_host_get_power_peak_at(sg_host_t host, int pstate_index)
166 {
167   return simcall_BODY_host_get_power_peak_at(host, pstate_index);
168 }
169
170 /**
171  * \ingroup simix_host_management
172  * \brief Returns the number of power states for a host.
173  *
174  * \param host A SIMIX host
175  * \return the number of power states
176  */
177 int simcall_host_get_nb_pstates(sg_host_t host)
178 {
179   return simcall_BODY_host_get_nb_pstates(host);
180 }
181
182 /**
183  * \ingroup simix_host_management
184  * \brief Sets the pstate at which the host should run
185  *
186  * \param host A SIMIX host
187  * \param pstate_index The pstate to which the CPU power will be set
188  */
189 void simcall_host_set_pstate(sg_host_t host, int pstate_index)
190 {
191         simcall_BODY_host_set_pstate(host, pstate_index);
192 }
193 /**
194  * \ingroup simix_host_management
195  * \brief Gets the pstate at which that host currently runs.
196  *
197  * \param host A SIMIX host
198  */
199 int simcall_host_get_pstate(sg_host_t host)
200 {
201         return simcall_BODY_host_get_pstate(host);
202 }
203
204 /**
205  * \ingroup simix_host_management
206  * \brief Returns the total energy consumed by the host (in Joules)
207  *
208  * \param host A SIMIX host
209  * \return the energy consumed by the host (double)
210  */
211 double simcall_host_get_consumed_energy(sg_host_t host)
212 {
213   return simcall_BODY_host_get_consumed_energy(host);
214 }
215 /** \ingroup simix_host_management
216  * \brief Returns the amount of watt dissipated at the given pstate when the host is idling
217  */
218 double simcall_host_get_wattmin_at(msg_host_t host, int pstate){
219         return simcall_BODY_host_get_wattmin_at(host, pstate);
220 }
221 /** \ingroup simix_host_management
222  * \brief Returns the amount of watt dissipated at the given pstate when the host burns CPU at 100%
223  */
224 double simcall_host_get_wattmax_at(msg_host_t host, int pstate){
225         return simcall_BODY_host_get_wattmax_at(host, pstate);
226 }
227
228
229
230 /**
231  * \ingroup simix_process_management
232  * \brief Creates a synchro that executes some computation of an host.
233  *
234  * This function creates a SURF action and allocates the data necessary
235  * to create the SIMIX synchro. It can raise a host_error exception if the host crashed.
236  *
237  * \param name Name of the execution synchro to create
238  * \param flops_amount amount Computation amount (in flops)
239  * \param priority computation priority
240  * \param bound
241  * \param affinity_mask
242  * \return A new SIMIX execution synchronization
243  */
244 smx_synchro_t simcall_process_execute(const char *name,
245                                     double flops_amount,
246                                     double priority, double bound, unsigned long affinity_mask)
247 {
248   /* checking for infinite values */
249   xbt_assert(isfinite(flops_amount), "flops_amount is not finite!");
250   xbt_assert(isfinite(priority), "priority is not finite!");
251
252   return simcall_BODY_process_execute(name, flops_amount, priority, bound, affinity_mask);
253 }
254
255 /**
256  * \ingroup simix_process_management
257  * \brief Creates a synchro that may involve parallel computation on
258  * several hosts and communication between them.
259  *
260  * \param name Name of the execution synchro to create
261  * \param host_nb Number of hosts where the synchro will be executed
262  * \param host_list Array (of size host_nb) of hosts where the synchro will be executed
263  * \param flops_amount Array (of size host_nb) of computation amount of hosts (in bytes)
264  * \param bytes_amount Array (of size host_nb * host_nb) representing the communication
265  * amount between each pair of hosts
266  * \param amount the SURF action amount
267  * \param rate the SURF action rate
268  * \return A new SIMIX execution synchronization
269  */
270 smx_synchro_t simcall_process_parallel_execute(const char *name,
271                                          int host_nb,
272                                          sg_host_t *host_list,
273                                          double *flops_amount,
274                                          double *bytes_amount,
275                                          double amount,
276                                          double rate)
277 {
278   int i,j;
279   /* checking for infinite values */
280   for (i = 0 ; i < host_nb ; ++i) {
281      xbt_assert(isfinite(flops_amount[i]), "flops_amount[%d] is not finite!", i);
282      for (j = 0 ; j < host_nb ; ++j) {
283         xbt_assert(isfinite(bytes_amount[i + host_nb * j]),
284              "bytes_amount[%d+%d*%d] is not finite!", i, host_nb, j);
285      }
286   }
287
288   xbt_assert(isfinite(amount), "amount is not finite!");
289   xbt_assert(isfinite(rate), "rate is not finite!");
290
291   return simcall_BODY_process_parallel_execute(name, host_nb, host_list,
292                                             flops_amount,
293                                             bytes_amount,
294                                             amount, rate);
295
296 }
297
298 /**
299  * \ingroup simix_process_management
300  * \brief Destroys an execution synchro.
301  *
302  * Destroys a synchro, freeing its memory. This function cannot be called if there are a conditional waiting for it.
303  * \param execution The execution synchro to destroy
304  */
305 void simcall_process_execution_destroy(smx_synchro_t execution)
306 {
307   simcall_BODY_process_execution_destroy(execution);
308 }
309
310 /**
311  * \ingroup simix_process_management
312  * \brief Cancels an execution synchro.
313  *
314  * This functions stops the execution. It calls a surf function.
315  * \param execution The execution synchro to cancel
316  */
317 void simcall_process_execution_cancel(smx_synchro_t execution)
318 {
319   simcall_BODY_process_execution_cancel(execution);
320 }
321
322 /**
323  * \ingroup simix_process_management
324  * \brief Returns how much of an execution synchro remains to be done.
325  *
326  * \param execution The execution synchro
327  * \return The remaining amount
328  */
329 double simcall_process_execution_get_remains(smx_synchro_t execution)
330 {
331   return simcall_BODY_process_execution_get_remains(execution);
332 }
333
334 /**
335  * \ingroup simix_process_management
336  * \brief Returns the state of an execution synchro.
337  *
338  * \param execution The execution synchro
339  * \return The state
340  */
341 e_smx_state_t simcall_process_execution_get_state(smx_synchro_t execution)
342 {
343   return simcall_BODY_process_execution_get_state(execution);
344 }
345
346 /**
347  * \ingroup simix_process_management
348  * \brief Changes the priority of an execution synchro.
349  *
350  * This functions changes the priority only. It calls a surf function.
351  * \param execution The execution synchro
352  * \param priority The new priority
353  */
354 void simcall_process_execution_set_priority(smx_synchro_t execution, double priority)
355 {
356   /* checking for infinite values */
357   xbt_assert(isfinite(priority), "priority is not finite!");
358
359   simcall_BODY_process_execution_set_priority(execution, priority);
360 }
361
362 /**
363  * \ingroup simix_process_management
364  * \brief Changes the capping (the maximum CPU utilization) of an execution synchro.
365  *
366  * This functions changes the capping only. It calls a surf function.
367  * \param execution The execution synchro
368  * \param bound The new bound
369  */
370 void simcall_process_execution_set_bound(smx_synchro_t execution, double bound)
371 {
372   simcall_BODY_process_execution_set_bound(execution, bound);
373 }
374
375 /**
376  * \ingroup simix_process_management
377  * \brief Changes the CPU affinity of an execution synchro.
378  *
379  * This functions changes the CPU affinity of an execution synchro. See taskset(1) on Linux.
380  * \param execution The execution synchro
381  * \param host Host
382  * \param mask Affinity mask
383  */
384 void simcall_process_execution_set_affinity(smx_synchro_t execution, sg_host_t host, unsigned long mask)
385 {
386   simcall_BODY_process_execution_set_affinity(execution, host, mask);
387 }
388
389 /**
390  * \ingroup simix_host_management
391  * \brief Waits for the completion of an execution synchro and destroy it.
392  *
393  * \param execution The execution synchro
394  */
395 e_smx_state_t simcall_process_execution_wait(smx_synchro_t execution)
396 {
397   return simcall_BODY_process_execution_wait(execution);
398 }
399
400
401 /**
402  * \ingroup simix_vm_management
403  * \brief Create a VM on the given physical host.
404  *
405  * \param name VM name
406  * \param host Physical host
407  *
408  * \return The host object of the VM
409  */
410 void* simcall_vm_create(const char *name, sg_host_t phys_host){
411   return simcall_BODY_vm_create(name, phys_host);
412 }
413
414 /**
415  * \ingroup simix_vm_management
416  * \brief Start the given VM to the given physical host
417  *
418  * \param vm VM
419  */
420 void simcall_vm_start(sg_host_t vm)
421 {
422   simcall_BODY_vm_start(vm);
423 }
424
425 /**
426  * \ingroup simix_vm_management
427  * \brief Get the state of the given VM
428  *
429  * \param vm VM
430  * \return The state of the VM
431  */
432 int simcall_vm_get_state(sg_host_t vm)
433 {
434   return simcall_BODY_vm_get_state(vm);
435 }
436
437 /**
438  * \ingroup simix_vm_management
439  * \brief Get the name of the physical host on which the given VM runs.
440  *
441  * \param vm VM
442  * \return The name of the physical host
443  */
444 void *simcall_vm_get_pm(sg_host_t vm)
445 {
446   return simcall_BODY_vm_get_pm(vm);
447 }
448
449 void simcall_vm_set_bound(sg_host_t vm, double bound)
450 {
451   simcall_BODY_vm_set_bound(vm, bound);
452 }
453
454 void simcall_vm_set_affinity(sg_host_t vm, sg_host_t pm, unsigned long mask)
455 {
456   simcall_BODY_vm_set_affinity(vm, pm, mask);
457 }
458
459 void simcall_host_get_params(sg_host_t vm, vm_params_t params)
460 {
461   simcall_BODY_host_get_params(vm, params);
462 }
463
464 void simcall_host_set_params(sg_host_t vm, vm_params_t params)
465 {
466   simcall_BODY_host_set_params(vm, params);
467 }
468
469 /**
470  * \ingroup simix_vm_management
471  * \brief Migrate the given VM to the given physical host
472  *
473  * \param vm VM
474  * \param host Destination physical host
475  */
476 void simcall_vm_migrate(sg_host_t vm, sg_host_t host)
477 {
478   simcall_BODY_vm_migrate(vm, host);
479 }
480
481 /**
482  * \ingroup simix_vm_management
483  * \brief Suspend the given VM
484  *
485  * \param vm VM
486  */
487 void simcall_vm_suspend(sg_host_t vm)
488 {
489   simcall_BODY_vm_suspend(vm);
490 }
491
492 /**
493  * \ingroup simix_vm_management
494  * \brief Resume the given VM
495  *
496  * \param vm VM
497  */
498 void simcall_vm_resume(sg_host_t vm)
499 {
500   simcall_BODY_vm_resume(vm);
501 }
502
503 /**
504  * \ingroup simix_vm_management
505  * \brief Save the given VM
506  *
507  * \param vm VM
508  */
509 void simcall_vm_save(sg_host_t vm)
510 {
511   simcall_BODY_vm_save(vm);
512 }
513
514 /**
515  * \ingroup simix_vm_management
516  * \brief Restore the given VM
517  *
518  * \param vm VM
519  */
520 void simcall_vm_restore(sg_host_t vm)
521 {
522   simcall_BODY_vm_restore(vm);
523 }
524
525 /**
526  * \ingroup simix_vm_management
527  * \brief Shutdown the given VM
528  *
529  * \param vm VM
530  */
531 void simcall_vm_shutdown(sg_host_t vm)
532 {
533   simcall_BODY_vm_shutdown(vm);
534 }
535
536 /**
537  * \ingroup simix_vm_management
538  * \brief Destroy the given VM
539  *
540  * \param vm VM
541  */
542 void simcall_vm_destroy(sg_host_t vm)
543 {
544   simcall_BODY_vm_destroy(vm);
545 }
546
547 /**
548  * \ingroup simix_vm_management
549  * \brief Encompassing simcall to prevent the removal of the src or the dst node at the end of a VM migration
550  *  The simcall actually invokes the following calls: 
551  *     simcall_vm_set_affinity(vm, src_pm, 0); 
552  *     simcall_vm_migrate(vm, dst_pm); 
553  *     simcall_vm_resume(vm);
554  *
555  * It is called at the end of the migration_rx_fun function from msg/msg_vm.c
556  *
557  * \param vm VM to migrate
558  * \param src_pm  Source physical host
559  * \param dst_pmt Destination physical host
560  */
561 void simcall_vm_migratefrom_resumeto(sg_host_t vm, sg_host_t src_pm, sg_host_t dst_pm)
562 {
563   simcall_BODY_vm_migratefrom_resumeto(vm, src_pm, dst_pm);
564 }
565
566 /**
567  * \ingroup simix_process_management
568  * \brief Creates and runs a new SIMIX process.
569  *
570  * The structure and the corresponding thread are created and put in the list of ready processes.
571  *
572  * \param name a name for the process. It is for user-level information and can be NULL.
573  * \param code the main function of the process
574  * \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.
575  * It can be retrieved with the function \ref simcall_process_get_data.
576  * \param hostname name of the host where the new agent is executed.
577  * \param kill_time time when the process is killed
578  * \param argc first argument passed to \a code
579  * \param argv second argument passed to \a code
580  * \param properties the properties of the process
581  * \param auto_restart either it is autorestarting or not.
582  */
583 smx_process_t simcall_process_create(const char *name,
584                               xbt_main_func_t code,
585                               void *data,
586                               const char *hostname,
587                               double kill_time,
588                               int argc, char **argv,
589                               xbt_dict_t properties,
590                               int auto_restart)
591 {
592   return (smx_process_t) simcall_BODY_process_create(name, code, data, hostname,
593                               kill_time, argc, argv, properties,
594                               auto_restart);
595 }
596
597 /**
598  * \ingroup simix_process_management
599  * \brief Kills a SIMIX process.
600  *
601  * This function simply kills a  process.
602  *
603  * \param process poor victim
604  */
605 void simcall_process_kill(smx_process_t process)
606 {
607   simcall_BODY_process_kill(process);
608 }
609
610 /**
611  * \ingroup simix_process_management
612  * \brief Kills all SIMIX processes.
613  */
614 void simcall_process_killall(int reset_pid)
615 {
616   simcall_BODY_process_killall(reset_pid);
617 }
618
619 /**
620  * \ingroup simix_process_management
621  * \brief Cleans up a SIMIX process.
622  * \param process poor victim (must have already been killed)
623  */
624 void simcall_process_cleanup(smx_process_t process)
625 {
626   simcall_BODY_process_cleanup(process);
627 }
628
629 /**
630  * \ingroup simix_process_management
631  * \brief Migrates an agent to another location.
632  *
633  * This function changes the value of the host on which \a process is running.
634  *
635  * \param process the process to migrate
636  * \param dest name of the new host
637  */
638 void simcall_process_change_host(smx_process_t process, sg_host_t dest)
639 {
640   simcall_BODY_process_change_host(process, dest);
641 }
642
643 void simcall_process_join(smx_process_t process, double timeout)
644 {
645   simcall_BODY_process_join(process, timeout);
646 }
647
648 /**
649  * \ingroup simix_process_management
650  * \brief Suspends a process.
651  *
652  * This function suspends the process by suspending the synchro
653  * it was waiting for completion.
654  *
655  * \param process a SIMIX process
656  */
657 void simcall_process_suspend(smx_process_t process)
658 {
659   xbt_assert(process, "Invalid parameters");
660
661   simcall_BODY_process_suspend(process);
662 }
663
664 /**
665  * \ingroup simix_process_management
666  * \brief Resumes a suspended process.
667  *
668  * This function resumes a suspended process by resuming the synchro
669  * it was waiting for completion.
670  *
671  * \param process a SIMIX process
672  */
673 void simcall_process_resume(smx_process_t process)
674 {
675   simcall_BODY_process_resume(process);
676 }
677
678 /**
679  * \ingroup simix_process_management
680  * \brief Returns the amount of SIMIX processes in the system
681  *
682  * Maestro internal process is not counted, only user code processes are
683  */
684 int simcall_process_count(void)
685 {
686   return simcall_BODY_process_count();
687 }
688
689 /**
690  * \ingroup simix_process_management
691  * \brief Return the PID of a #smx_process_t.
692  * \param process a SIMIX process
693  * \return the PID of this process
694  */
695 int simcall_process_get_PID(smx_process_t process)
696 {
697   if (process == SIMIX_process_self()) {
698     /* avoid a simcall if this function is called by the process itself */
699     return SIMIX_process_get_PID(process);
700   }
701
702   return simcall_BODY_process_get_PID(process);
703 }
704
705 /**
706  * \ingroup simix_process_management
707  * \brief Return the parent PID of a #smx_process_t.
708  * \param process a SIMIX process
709  * \return the PID of this process parenrt
710  */
711 int simcall_process_get_PPID(smx_process_t process)
712 {
713   if (process == SIMIX_process_self()) {
714     /* avoid a simcall if this function is called by the process itself */
715     return SIMIX_process_get_PPID(process);
716   }
717
718   return simcall_BODY_process_get_PPID(process);
719 }
720
721 /**
722  * \ingroup simix_process_management
723  * \brief Return the user data of a #smx_process_t.
724  * \param process a SIMIX process
725  * \return the user data of this process
726  */
727 void* simcall_process_get_data(smx_process_t process)
728 {
729   if (process == SIMIX_process_self()) {
730     /* avoid a simcall if this function is called by the process itself */
731     return SIMIX_process_get_data(process);
732   }
733
734   return simcall_BODY_process_get_data(process);
735 }
736
737 /**
738  * \ingroup simix_process_management
739  * \brief Set the user data of a #smx_process_t.
740  *
741  * This functions sets the user data associated to \a process.
742  * \param process SIMIX process
743  * \param data User data
744  */
745 void simcall_process_set_data(smx_process_t process, void *data)
746 {
747   if (process == SIMIX_process_self()) {
748     /* avoid a simcall if this function is called by the process itself */
749     SIMIX_process_self_set_data(process, data);
750   }
751   else {
752     simcall_BODY_process_set_data(process, data);
753   }
754 }
755
756 /**
757  * \ingroup simix_process_management
758  * \brief Set the kill time of a process.
759  */
760 void simcall_process_set_kill_time(smx_process_t process, double kill_time)
761 {
762
763   if (kill_time > SIMIX_get_clock()) {
764     if (simix_global->kill_process_function) {
765       XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name,
766           sg_host_name(process->host));
767       process->kill_timer = SIMIX_timer_set(kill_time, simix_global->kill_process_function, process);
768     }
769   }
770 }
771 /**
772  * \ingroup simix_process_management
773  * \brief Get the kill time of a process (or 0 if unset).
774  */
775 double simcall_process_get_kill_time(smx_process_t process) {
776         return SIMIX_timer_get_date(process->kill_timer);
777 }
778
779 /**
780  * \ingroup simix_process_management
781  * \brief Return the location on which an agent is running.
782  *
783  * This functions returns the sg_host_t corresponding to the location on which
784  * \a process is running.
785  * \param process SIMIX process
786  * \return SIMIX host
787  */
788 sg_host_t simcall_process_get_host(smx_process_t process)
789 {
790   return simcall_BODY_process_get_host(process);
791 }
792
793 /**
794  * \ingroup simix_process_management
795  * \brief Return the name of an agent.
796  *
797  * This functions checks whether \a process is a valid pointer or not and return its name.
798  * \param process SIMIX process
799  * \return The process name
800  */
801 const char* simcall_process_get_name(smx_process_t process)
802 {
803   if (process == SIMIX_process_self()) {
804     /* avoid a simcall if this function is called by the process itself */
805     return process->name;
806   }
807   return simcall_BODY_process_get_name(process);
808 }
809
810 /**
811  * \ingroup simix_process_management
812  * \brief Returns true if the process is suspended .
813  *
814  * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
815  * \param process SIMIX process
816  * \return 1, if the process is suspended, else 0.
817  */
818 int simcall_process_is_suspended(smx_process_t process)
819 {
820   return  simcall_BODY_process_is_suspended(process);
821 }
822
823 /**
824  * \ingroup simix_process_management
825  * \brief Return the properties
826  *
827  * This functions returns the properties associated with this process
828  */
829 xbt_dict_t simcall_process_get_properties(smx_process_t process)
830 {
831   return simcall_BODY_process_get_properties(process);
832 }
833 /**
834  * \ingroup simix_process_management
835  * \brief Add an on_exit function
836  * Add an on_exit function which will be executed when the process exits/is killed.
837  */
838 XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_pvoid_t fun, void *data)
839 {
840   simcall_BODY_process_on_exit(process, fun, data);
841 }
842 /**
843  * \ingroup simix_process_management
844  * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up.
845  * Will restart the process when the host comes back up if auto_restart is set to 1.
846  */
847
848 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart)
849 {
850   simcall_BODY_process_auto_restart_set(process, auto_restart);
851 }
852
853 /**
854  * \ingroup simix_process_management
855  * \brief Restarts the process, killing it and starting it again from scratch.
856  */
857 XBT_PUBLIC(smx_process_t) simcall_process_restart(smx_process_t process)
858 {
859   return simcall_BODY_process_restart(process);
860 }
861 /**
862  * \ingroup simix_process_management
863  * \brief Creates a new sleep SIMIX synchro.
864  *
865  * This function creates a SURF action and allocates the data necessary
866  * to create the SIMIX synchro. It can raise a host_error exception if the
867  * host crashed. The default SIMIX name of the synchro is "sleep".
868  *
869  *   \param duration Time duration of the sleep.
870  *   \return A result telling whether the sleep was successful
871  */
872 e_smx_state_t simcall_process_sleep(double duration)
873 {
874   /* checking for infinite values */
875   xbt_assert(isfinite(duration), "duration is not finite!");
876   return simcall_BODY_process_sleep(duration);
877 }
878
879 /**
880  *  \ingroup simix_rdv_management
881  *  \brief Creates a new rendez-vous point
882  *  \param name The name of the rendez-vous point
883  *  \return The created rendez-vous point
884  */
885 smx_rdv_t simcall_rdv_create(const char *name)
886 {
887   return simcall_BODY_rdv_create(name);
888 }
889
890
891 /**
892  *  \ingroup simix_rdv_management
893  *  \brief Destroy a rendez-vous point
894  *  \param rdv The rendez-vous point to destroy
895  */
896 void simcall_rdv_destroy(smx_rdv_t rdv)
897 {
898   simcall_BODY_rdv_destroy(rdv);
899 }
900 /**
901  *  \ingroup simix_rdv_management
902  *  \brief Returns a rendez-vous point knowing its name
903  */
904 smx_rdv_t simcall_rdv_get_by_name(const char *name)
905 {
906   xbt_assert(name != NULL, "Invalid parameter for simcall_rdv_get_by_name (name is NULL)");
907
908   /* FIXME: this is a horrible loss of performance, so we hack it out by
909    * skipping the simcall (for now). It works in parallel, it won't work on
910    * distributed but probably we will change MSG for that. */
911
912   return SIMIX_rdv_get_by_name(name);
913 }
914
915 /**
916  *  \ingroup simix_rdv_management
917  *  \brief Counts the number of communication synchros of a given host pending
918  *         on a rendez-vous point.
919  *  \param rdv The rendez-vous point
920  *  \param host The host to be counted
921  *  \return The number of comm synchros pending in the rdv
922  */
923 int simcall_rdv_comm_count_by_host(smx_rdv_t rdv, sg_host_t host)
924 {
925   return simcall_BODY_rdv_comm_count_by_host(rdv, host);
926 }
927
928 /**
929  *  \ingroup simix_rdv_management
930  *  \brief returns the communication at the head of the rendez-vous
931  *  \param rdv The rendez-vous point
932  *  \return The communication or NULL if empty
933  */
934 smx_synchro_t simcall_rdv_get_head(smx_rdv_t rdv)
935 {
936   return simcall_BODY_rdv_get_head(rdv);
937 }
938
939 void simcall_rdv_set_receiver(smx_rdv_t rdv, smx_process_t process)
940 {
941   simcall_BODY_rdv_set_receiver(rdv, process);
942 }
943
944 smx_process_t simcall_rdv_get_receiver(smx_rdv_t rdv)
945 {
946   return simcall_BODY_rdv_get_receiver(rdv);
947 }
948
949 /**
950  * \ingroup simix_comm_management
951  */
952 void simcall_comm_send(smx_process_t src, smx_rdv_t rdv, double task_size, double rate,
953                          void *src_buff, size_t src_buff_size,
954                          int (*match_fun)(void *, void *, smx_synchro_t),
955                          void (*copy_data_fun)(smx_synchro_t, void*, size_t), void *data,
956                          double timeout)
957 {
958   /* checking for infinite values */
959   xbt_assert(isfinite(task_size), "task_size is not finite!");
960   xbt_assert(isfinite(rate), "rate is not finite!");
961   xbt_assert(isfinite(timeout), "timeout is not finite!");
962
963   xbt_assert(rdv, "No rendez-vous point defined for send");
964
965   if (MC_is_active() || MC_record_replay_is_active()) {
966     /* the model-checker wants two separate simcalls */
967     smx_synchro_t comm = NULL; /* MC needs the comm to be set to NULL during the simcall */
968     comm = simcall_comm_isend(src, rdv, task_size, rate,
969         src_buff, src_buff_size, match_fun, NULL, copy_data_fun, data, 0);
970     simcall_comm_wait(comm, timeout);
971     comm = NULL;
972   }
973   else {
974     simcall_BODY_comm_send(src, rdv, task_size, rate, src_buff, src_buff_size,
975                          match_fun, copy_data_fun, data, timeout);
976   }
977 }
978
979 /**
980  * \ingroup simix_comm_management
981  */
982 smx_synchro_t simcall_comm_isend(smx_process_t src, smx_rdv_t rdv, double task_size, double rate,
983                               void *src_buff, size_t src_buff_size,
984                               int (*match_fun)(void *, void *, smx_synchro_t),
985                               void (*clean_fun)(void *),
986                               void (*copy_data_fun)(smx_synchro_t, void*, size_t),
987                               void *data,
988                               int detached)
989 {
990   /* checking for infinite values */
991   xbt_assert(isfinite(task_size), "task_size is not finite!");
992   xbt_assert(isfinite(rate), "rate is not finite!");
993
994   xbt_assert(rdv, "No rendez-vous point defined for isend");
995
996   return simcall_BODY_comm_isend(src, rdv, task_size, rate, src_buff,
997                                  src_buff_size, match_fun,
998                                  clean_fun, copy_data_fun, data, detached);
999 }
1000
1001 /**
1002  * \ingroup simix_comm_management
1003  */
1004 void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
1005                        int (*match_fun)(void *, void *, smx_synchro_t),
1006                        void (*copy_data_fun)(smx_synchro_t, void*, size_t),
1007                        void *data, double timeout, double rate)
1008 {
1009   xbt_assert(isfinite(timeout), "timeout is not finite!");
1010   xbt_assert(rdv, "No rendez-vous point defined for recv");
1011
1012   if (MC_is_active() || MC_record_replay_is_active()) {
1013     /* the model-checker wants two separate simcalls */
1014     smx_synchro_t comm = NULL; /* MC needs the comm to be set to NULL during the simcall */
1015     comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
1016                               match_fun, copy_data_fun, data, rate);
1017     simcall_comm_wait(comm, timeout);
1018     comm = NULL;
1019   }
1020   else {
1021     simcall_BODY_comm_recv(rdv, dst_buff, dst_buff_size,
1022                            match_fun, copy_data_fun, data, timeout, rate);
1023   }
1024 }
1025 /**
1026  * \ingroup simix_comm_management
1027  */
1028 smx_synchro_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size,
1029                                 int (*match_fun)(void *, void *, smx_synchro_t),
1030                                 void (*copy_data_fun)(smx_synchro_t, void*, size_t),
1031                                 void *data, double rate)
1032 {
1033   xbt_assert(rdv, "No rendez-vous point defined for irecv");
1034
1035   return simcall_BODY_comm_irecv(rdv, dst_buff, dst_buff_size,
1036                                  match_fun, copy_data_fun, data, rate);
1037 }
1038
1039 /**
1040  * \ingroup simix_comm_management
1041  */
1042 smx_synchro_t simcall_comm_iprobe(smx_rdv_t rdv, int type, int src, int tag,
1043                                 int (*match_fun)(void *, void *, smx_synchro_t), void *data)
1044 {
1045   xbt_assert(rdv, "No rendez-vous point defined for iprobe");
1046
1047   return simcall_BODY_comm_iprobe(rdv, type, src, tag, match_fun, data);
1048 }
1049
1050 /**
1051  * \ingroup simix_comm_management
1052  */
1053 void simcall_comm_cancel(smx_synchro_t comm)
1054 {
1055   simcall_BODY_comm_cancel(comm);
1056 }
1057
1058 /**
1059  * \ingroup simix_comm_management
1060  */
1061 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
1062 {
1063   return simcall_BODY_comm_waitany(comms);
1064 }
1065
1066 /**
1067  * \ingroup simix_comm_management
1068  */
1069 int simcall_comm_testany(xbt_dynar_t comms)
1070 {
1071   if (xbt_dynar_is_empty(comms))
1072     return -1;
1073   return simcall_BODY_comm_testany(comms);
1074 }
1075
1076 /**
1077  * \ingroup simix_comm_management
1078  */
1079 void simcall_comm_wait(smx_synchro_t comm, double timeout)
1080 {
1081   xbt_assert(isfinite(timeout), "timeout is not finite!");
1082   simcall_BODY_comm_wait(comm, timeout);
1083 }
1084
1085 /**
1086  * \brief Set the category of an synchro.
1087  *
1088  * This functions changes the category only. It calls a surf function.
1089  * \param execution The execution synchro
1090  * \param category The tracing category
1091  */
1092 void simcall_set_category(smx_synchro_t synchro, const char *category)
1093 {
1094   if (category == NULL) {
1095     return;
1096   }
1097   simcall_BODY_set_category(synchro, category);
1098 }
1099
1100 /**
1101  * \ingroup simix_comm_management
1102  *
1103  */
1104 int simcall_comm_test(smx_synchro_t comm)
1105 {
1106   return simcall_BODY_comm_test(comm);
1107 }
1108
1109 /**
1110  * \ingroup simix_comm_management
1111  *
1112  */
1113 double simcall_comm_get_remains(smx_synchro_t comm)
1114 {
1115   return simcall_BODY_comm_get_remains(comm);
1116 }
1117
1118 /**
1119  * \ingroup simix_comm_management
1120  *
1121  */
1122 e_smx_state_t simcall_comm_get_state(smx_synchro_t comm)
1123 {
1124   return simcall_BODY_comm_get_state(comm);
1125 }
1126
1127 /**
1128  * \ingroup simix_comm_management
1129  *
1130  */
1131 void *simcall_comm_get_src_data(smx_synchro_t comm)
1132 {
1133   return simcall_BODY_comm_get_src_data(comm);
1134 }
1135
1136 /**
1137  * \ingroup simix_comm_management
1138  *
1139  */
1140 void *simcall_comm_get_dst_data(smx_synchro_t comm)
1141 {
1142   return simcall_BODY_comm_get_dst_data(comm);
1143 }
1144
1145 /**
1146  * \ingroup simix_comm_management
1147  *
1148  */
1149 smx_process_t simcall_comm_get_src_proc(smx_synchro_t comm)
1150 {
1151   return simcall_BODY_comm_get_src_proc(comm);
1152 }
1153
1154 /**
1155  * \ingroup simix_comm_management
1156  *
1157  */
1158 smx_process_t simcall_comm_get_dst_proc(smx_synchro_t comm)
1159 {
1160   return simcall_BODY_comm_get_dst_proc(comm);
1161 }
1162
1163 #ifdef HAVE_LATENCY_BOUND_TRACKING
1164 int simcall_comm_is_latency_bounded(smx_synchro_t comm)
1165 {
1166   return simcall_BODY_comm_is_latency_bounded(comm);
1167 }
1168 #endif
1169
1170 /**
1171  * \ingroup simix_synchro_management
1172  *
1173  */
1174 smx_mutex_t simcall_mutex_init(void)
1175 {
1176   if(!simix_global) {
1177     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
1178     xbt_abort();
1179   }
1180   return simcall_BODY_mutex_init();
1181 }
1182
1183 /**
1184  * \ingroup simix_synchro_management
1185  *
1186  */
1187 void simcall_mutex_destroy(smx_mutex_t mutex)
1188 {
1189   simcall_BODY_mutex_destroy(mutex);
1190 }
1191
1192 /**
1193  * \ingroup simix_synchro_management
1194  *
1195  */
1196 void simcall_mutex_lock(smx_mutex_t mutex)
1197 {
1198   simcall_BODY_mutex_lock(mutex);
1199 }
1200
1201 /**
1202  * \ingroup simix_synchro_management
1203  *
1204  */
1205 int simcall_mutex_trylock(smx_mutex_t mutex)
1206 {
1207   return simcall_BODY_mutex_trylock(mutex);
1208 }
1209
1210 /**
1211  * \ingroup simix_synchro_management
1212  *
1213  */
1214 void simcall_mutex_unlock(smx_mutex_t mutex)
1215 {
1216   simcall_BODY_mutex_unlock(mutex);
1217 }
1218
1219 /**
1220  * \ingroup simix_synchro_management
1221  *
1222  */
1223 smx_cond_t simcall_cond_init(void)
1224 {
1225   return simcall_BODY_cond_init();
1226 }
1227
1228 /**
1229  * \ingroup simix_synchro_management
1230  *
1231  */
1232 void simcall_cond_destroy(smx_cond_t cond)
1233 {
1234   simcall_BODY_cond_destroy(cond);
1235 }
1236
1237 /**
1238  * \ingroup simix_synchro_management
1239  *
1240  */
1241 void simcall_cond_signal(smx_cond_t cond)
1242 {
1243   simcall_BODY_cond_signal(cond);
1244 }
1245
1246 /**
1247  * \ingroup simix_synchro_management
1248  *
1249  */
1250 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1251 {
1252   simcall_BODY_cond_wait(cond, mutex);
1253 }
1254
1255 /**
1256  * \ingroup simix_synchro_management
1257  *
1258  */
1259 void simcall_cond_wait_timeout(smx_cond_t cond,
1260                                  smx_mutex_t mutex,
1261                                  double timeout)
1262 {
1263   xbt_assert(isfinite(timeout), "timeout is not finite!");
1264   simcall_BODY_cond_wait_timeout(cond, mutex, timeout);
1265 }
1266
1267 /**
1268  * \ingroup simix_synchro_management
1269  *
1270  */
1271 void simcall_cond_broadcast(smx_cond_t cond)
1272 {
1273   simcall_BODY_cond_broadcast(cond);
1274 }
1275
1276 /**
1277  * \ingroup simix_synchro_management
1278  *
1279  */
1280 smx_sem_t simcall_sem_init(int capacity)
1281 {
1282   return simcall_BODY_sem_init(capacity);
1283 }
1284
1285 /**
1286  * \ingroup simix_synchro_management
1287  *
1288  */
1289 void simcall_sem_destroy(smx_sem_t sem)
1290 {
1291   simcall_BODY_sem_destroy(sem);
1292 }
1293
1294 /**
1295  * \ingroup simix_synchro_management
1296  *
1297  */
1298 void simcall_sem_release(smx_sem_t sem)
1299 {
1300   simcall_BODY_sem_release(sem);
1301 }
1302
1303 /**
1304  * \ingroup simix_synchro_management
1305  *
1306  */
1307 int simcall_sem_would_block(smx_sem_t sem)
1308 {
1309   return simcall_BODY_sem_would_block(sem);
1310 }
1311
1312 /**
1313  * \ingroup simix_synchro_management
1314  *
1315  */
1316 void simcall_sem_acquire(smx_sem_t sem)
1317 {
1318   simcall_BODY_sem_acquire(sem);
1319 }
1320
1321 /**
1322  * \ingroup simix_synchro_management
1323  *
1324  */
1325 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1326 {
1327   xbt_assert(isfinite(timeout), "timeout is not finite!");
1328   simcall_BODY_sem_acquire_timeout(sem, timeout);
1329 }
1330
1331 /**
1332  * \ingroup simix_synchro_management
1333  *
1334  */
1335 int simcall_sem_get_capacity(smx_sem_t sem)
1336 {
1337   return simcall_BODY_sem_get_capacity(sem);
1338 }
1339
1340 /**
1341  * \ingroup simix_file_management
1342  *
1343  */
1344 sg_size_t simcall_file_read(smx_file_t fd, sg_size_t size, sg_host_t host)
1345 {
1346   return simcall_BODY_file_read(fd, size, host);
1347 }
1348
1349 /**
1350  * \ingroup simix_file_management
1351  *
1352  */
1353 sg_size_t simcall_file_write(smx_file_t fd, sg_size_t size, sg_host_t host)
1354 {
1355   return simcall_BODY_file_write(fd, size, host);
1356 }
1357
1358 /**
1359  * \ingroup simix_file_management
1360  * \brief
1361  */
1362 smx_file_t simcall_file_open(const char* fullpath, sg_host_t host)
1363 {
1364   return simcall_BODY_file_open(fullpath, host);
1365 }
1366
1367 /**
1368  * \ingroup simix_file_management
1369  *
1370  */
1371 int simcall_file_close(smx_file_t fd, sg_host_t host)
1372 {
1373   return simcall_BODY_file_close(fd, host);
1374 }
1375
1376 /**
1377  * \ingroup simix_file_management
1378  *
1379  */
1380 int simcall_file_unlink(smx_file_t fd, sg_host_t host)
1381 {
1382   return simcall_BODY_file_unlink(fd, host);
1383 }
1384
1385 /**
1386  * \ingroup simix_file_management
1387  *
1388  */
1389 sg_size_t simcall_file_get_size(smx_file_t fd){
1390   return simcall_BODY_file_get_size(fd);
1391 }
1392
1393 /**
1394  * \ingroup simix_file_management
1395  *
1396  */
1397 sg_size_t simcall_file_tell(smx_file_t fd){
1398   return simcall_BODY_file_tell(fd);
1399 }
1400
1401 /**
1402  * \ingroup simix_file_management
1403  *
1404  */
1405 xbt_dynar_t simcall_file_get_info(smx_file_t fd)
1406 {
1407   return simcall_BODY_file_get_info(fd);
1408 }
1409
1410 /**
1411  * \ingroup simix_file_management
1412  *
1413  */
1414 int simcall_file_seek(smx_file_t fd, sg_offset_t offset, int origin){
1415   return simcall_BODY_file_seek(fd, offset, origin);
1416 }
1417
1418 /**
1419  * \ingroup simix_file_management
1420  * \brief Move a file to another location on the *same mount point*.
1421  *
1422  */
1423 int simcall_file_move(smx_file_t fd, const char* fullpath)
1424 {
1425   return simcall_BODY_file_move(fd, fullpath);
1426 }
1427
1428 /**
1429  * \ingroup simix_storage_management
1430  * \brief Returns the free space size on a given storage element.
1431  * \param storage a storage
1432  * \return Return the free space size on a given storage element (as sg_size_t)
1433  */
1434 sg_size_t simcall_storage_get_free_size (smx_storage_t storage){
1435   return simcall_BODY_storage_get_free_size(storage);
1436 }
1437
1438 /**
1439  * \ingroup simix_storage_management
1440  * \brief Returns the used space size on a given storage element.
1441  * \param storage a storage
1442  * \return Return the used space size on a given storage element (as sg_size_t)
1443  */
1444 sg_size_t simcall_storage_get_used_size (smx_storage_t storage){
1445   return simcall_BODY_storage_get_used_size(storage);
1446 }
1447
1448 /**
1449  * \ingroup simix_storage_management
1450  * \brief Returns the list of storages mounted on an host.
1451  * \param host A SIMIX host
1452  * \return a dict containing all storages mounted on the host
1453  */
1454 xbt_dict_t simcall_host_get_mounted_storage_list(sg_host_t host)
1455 {
1456   return simcall_BODY_host_get_mounted_storage_list(host);
1457 }
1458
1459 /**
1460  * \ingroup simix_storage_management
1461  * \brief Returns the list of storages attached to an host.
1462  * \param host A SIMIX host
1463  * \return a dict containing all storages attached to the host
1464  */
1465 xbt_dynar_t simcall_host_get_attached_storage_list(sg_host_t host)
1466 {
1467   return simcall_BODY_host_get_attached_storage_list(host);
1468 }
1469
1470 /**
1471  * \ingroup simix_storage_management
1472  * \brief Returns a dict of the properties assigned to a storage element.
1473  *
1474  * \param storage A storage element
1475  * \return The properties of this storage element
1476  */
1477 xbt_dict_t simcall_storage_get_properties(smx_storage_t storage)
1478 {
1479   return simcall_BODY_storage_get_properties(storage);
1480 }
1481
1482 /**
1483  * \ingroup simix_storage_management
1484  * \brief Returns a dict containing the content of a storage element.
1485  *
1486  * \param storage A storage element
1487  * \return The content of this storage element as a dict (full path file => size)
1488  */
1489 xbt_dict_t simcall_storage_get_content(smx_storage_t storage)
1490 {
1491   return simcall_BODY_storage_get_content(storage);
1492 }
1493
1494
1495
1496 #ifdef HAVE_MC
1497
1498 void *simcall_mc_snapshot(void) {
1499   return simcall_BODY_mc_snapshot();
1500 }
1501
1502 int simcall_mc_compare_snapshots(void *s1, void *s2) {
1503   return simcall_BODY_mc_compare_snapshots(s1, s2);
1504 }
1505
1506 #endif /* HAVE_MC */
1507
1508 int simcall_mc_random(int min, int max) {
1509   return simcall_BODY_mc_random(min, max);
1510 }
1511
1512 /* ************************************************************************** */
1513
1514 /** @brief returns a printable string representing a simcall */
1515 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1516   return simcall_names[kind];
1517 }