Logo AND Algorithmique Numérique Distribuée

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