Logo AND Algorithmique Numérique Distribuée

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