1 /* smx_user.c - public interface to simix */
3 /* Copyright (c) 2010-2014. The SimGrid Team.
4 * All rights reserved. */
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. */
9 #include "smx_private.h"
10 #include "mc/mc_interface.h"
12 #include <math.h> /* isfinite() */
14 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
16 #include "popping_bodies.c"
19 * \ingroup simix_host_management
20 * \brief Returns a host given its name.
22 * \param name The name of the host to get
23 * \return The corresponding host
25 smx_host_t simcall_host_get_by_name(const char *name)
27 return simcall_BODY_host_get_by_name(name);
31 * \ingroup simix_host_management
32 * \brief Returns the name of a host.
34 * \param host A SIMIX host
35 * \return The name of this host
37 const char* simcall_host_get_name(smx_host_t host)
39 return simcall_BODY_host_get_name(host);
43 * \ingroup simix_host_management
44 * \brief Start the host if it is off
46 * \param host A SIMIX host
48 void simcall_host_on(smx_host_t host)
50 simcall_BODY_host_on(host);
54 * \ingroup simix_host_management
55 * \brief Stop the host if it is on
57 * \param host A SIMIX host
59 void simcall_host_off(smx_host_t host)
61 simcall_BODY_host_off(host);
65 * \ingroup simix_host_management
66 * \brief Returns a dict of the properties assigned to a host.
69 * \return The properties of this host
71 xbt_dict_t simcall_host_get_properties(smx_host_t host)
73 return simcall_BODY_host_get_properties(host);
77 * \ingroup simix_host_management
78 * \brief Returns a dict of the properties assigned to a router or AS.
80 * \param name The name of the router or AS
81 * \return The properties
83 xbt_dict_t simcall_asr_get_properties(const char *name)
85 return simcall_BODY_asr_get_properties(name);
90 * \ingroup simix_host_management
91 * \brief Returns the speed of the processor.
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)
97 double simcall_host_get_speed(smx_host_t host)
99 return simcall_BODY_host_get_speed(host);
103 * \ingroup simix_host_management
104 * \brief Returns the number of core of the processor.
106 * \param host A SIMIX host
107 * \return The number of core
109 int simcall_host_get_core(smx_host_t host)
111 return simcall_BODY_host_get_core(host);
115 * \ingroup simix_host_management
116 * \brief Returns the list of processes attached to the host.
118 * \param host A SIMIX host
119 * \return the swag of attached processes
121 xbt_swag_t simcall_host_get_process_list(smx_host_t host)
123 return simcall_BODY_host_get_process_list(host);
128 * \ingroup simix_host_management
129 * \brief Returns the available speed of the processor.
131 * \return Speed currently available (in Mflop/s)
133 double simcall_host_get_available_speed(smx_host_t host)
135 return simcall_BODY_host_get_available_speed(host);
139 * \ingroup simix_host_management
140 * \brief Returns the state of a host.
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
146 int simcall_host_get_state(smx_host_t host)
148 return simcall_BODY_host_get_state(host);
152 * \ingroup simix_host_management
153 * \brief Returns the power peak of a host.
155 * \param host A SIMIX host
156 * \return the current power peak value (double)
158 double simcall_host_get_current_power_peak(smx_host_t host)
160 return simcall_BODY_host_get_current_power_peak(host);
164 * \ingroup simix_host_management
165 * \brief Returns one power peak (in flops/s) of a host at a given pstate
167 * \param host A SIMIX host
168 * \param pstate_index pstate to test
169 * \return the current power peak value (double) for pstate_index
171 double simcall_host_get_power_peak_at(smx_host_t host, int pstate_index)
173 return simcall_BODY_host_get_power_peak_at(host, pstate_index);
177 * \ingroup simix_host_management
178 * \brief Returns the number of power states for a host.
180 * \param host A SIMIX host
181 * \return the number of power states
183 int simcall_host_get_nb_pstates(smx_host_t host)
185 return simcall_BODY_host_get_nb_pstates(host);
189 * \ingroup simix_host_management
190 * \brief Sets a new power peak for a host.
192 * \param host A SIMIX host
193 * \param pstate_index The pstate to which the CPU power will be set
195 void simcall_host_set_power_peak_at(smx_host_t host, int pstate_index)
197 simcall_BODY_host_set_power_peak_at(host, pstate_index);
201 * \ingroup simix_host_management
202 * \brief Returns the total energy consumed by the host (in Joules)
204 * \param host A SIMIX host
205 * \return the energy consumed by the host (double)
207 double simcall_host_get_consumed_energy(smx_host_t host)
209 return simcall_BODY_host_get_consumed_energy(host);
214 * \ingroup simix_host_management
215 * \brief Creates an action that executes some computation of an host.
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.
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
225 * \param affinity_mask
226 * \return A new SIMIX execution action
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)
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!");
236 return simcall_BODY_host_execute(name, host, computation_amount, priority, bound, affinity_mask);
240 * \ingroup simix_host_management
241 * \brief Creates an action that may involve parallel computation on
242 * several hosts and communication between them.
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
254 smx_action_t simcall_host_parallel_execute(const char *name,
256 smx_host_t *host_list,
257 double *computation_amount,
258 double *communication_amount,
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);
272 xbt_assert(isfinite(amount), "amount is not finite!");
273 xbt_assert(isfinite(rate), "rate is not finite!");
275 return simcall_BODY_host_parallel_execute(name, host_nb, host_list,
277 communication_amount,
283 * \ingroup simix_host_management
284 * \brief Destroys an execution action.
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
289 void simcall_host_execution_destroy(smx_action_t execution)
291 simcall_BODY_host_execution_destroy(execution);
295 * \ingroup simix_host_management
296 * \brief Cancels an execution action.
298 * This functions stops the execution. It calls a surf function.
299 * \param execution The execution action to cancel
301 void simcall_host_execution_cancel(smx_action_t execution)
303 simcall_BODY_host_execution_cancel(execution);
307 * \ingroup simix_host_management
308 * \brief Returns how much of an execution action remains to be done.
310 * \param execution The execution action
311 * \return The remaining amount
313 double simcall_host_execution_get_remains(smx_action_t execution)
315 return simcall_BODY_host_execution_get_remains(execution);
319 * \ingroup simix_host_management
320 * \brief Returns the state of an execution action.
322 * \param execution The execution action
325 e_smx_state_t simcall_host_execution_get_state(smx_action_t execution)
327 return simcall_BODY_host_execution_get_state(execution);
331 * \ingroup simix_host_management
332 * \brief Changes the priority of an execution action.
334 * This functions changes the priority only. It calls a surf function.
335 * \param execution The execution action
336 * \param priority The new priority
338 void simcall_host_execution_set_priority(smx_action_t execution, double priority)
340 /* checking for infinite values */
341 xbt_assert(isfinite(priority), "priority is not finite!");
343 simcall_BODY_host_execution_set_priority(execution, priority);
347 * \ingroup simix_host_management
348 * \brief Changes the capping (the maximum CPU utilization) of an execution action.
350 * This functions changes the capping only. It calls a surf function.
351 * \param execution The execution action
352 * \param bound The new bound
354 void simcall_host_execution_set_bound(smx_action_t execution, double bound)
356 simcall_BODY_host_execution_set_bound(execution, bound);
360 * \ingroup simix_host_management
361 * \brief Changes the CPU affinity of an execution action.
363 * This functions changes the CPU affinity of an execution action. See taskset(1) on Linux.
364 * \param execution The execution action
366 * \param mask Affinity mask
368 void simcall_host_execution_set_affinity(smx_action_t execution, smx_host_t host, unsigned long mask)
370 simcall_BODY_host_execution_set_affinity(execution, host, mask);
374 * \ingroup simix_host_management
375 * \brief Waits for the completion of an execution action and destroy it.
377 * \param execution The execution action
379 e_smx_state_t simcall_host_execution_wait(smx_action_t execution)
381 return simcall_BODY_host_execution_wait(execution);
386 * \ingroup simix_vm_management
387 * \brief Create a VM on the given physical host.
389 * \param name VM name
390 * \param host Physical host
392 * \return The host object of the VM
394 void* simcall_vm_create(const char *name, smx_host_t phys_host){
395 return simcall_BODY_vm_create(name, phys_host);
399 * \ingroup simix_vm_management
400 * \brief Start the given VM to the given physical host
404 void simcall_vm_start(smx_host_t vm)
406 simcall_BODY_vm_start(vm);
410 * \ingroup simix_vm_management
411 * \brief Get the state of the given VM
414 * \return The state of the VM
416 int simcall_vm_get_state(smx_host_t vm)
418 return simcall_BODY_vm_get_state(vm);
422 * \ingroup simix_vm_management
423 * \brief Get the name of the physical host on which the given VM runs.
426 * \return The name of the physical host
428 void *simcall_vm_get_pm(smx_host_t vm)
430 return simcall_BODY_vm_get_pm(vm);
433 void simcall_vm_set_bound(smx_host_t vm, double bound)
435 simcall_BODY_vm_set_bound(vm, bound);
438 void simcall_vm_set_affinity(smx_host_t vm, smx_host_t pm, unsigned long mask)
440 simcall_BODY_vm_set_affinity(vm, pm, mask);
443 void simcall_host_get_params(smx_host_t vm, ws_params_t params)
445 simcall_BODY_host_get_params(vm, params);
448 void simcall_host_set_params(smx_host_t vm, ws_params_t params)
450 simcall_BODY_host_set_params(vm, params);
454 * \ingroup simix_vm_management
455 * \brief Migrate the given VM to the given physical host
458 * \param host Destination physical host
460 void simcall_vm_migrate(smx_host_t vm, smx_host_t host)
462 simcall_BODY_vm_migrate(vm, host);
466 * \ingroup simix_vm_management
467 * \brief Suspend the given VM
471 void simcall_vm_suspend(smx_host_t vm)
473 simcall_BODY_vm_suspend(vm);
477 * \ingroup simix_vm_management
478 * \brief Resume the given VM
482 void simcall_vm_resume(smx_host_t vm)
484 simcall_BODY_vm_resume(vm);
488 * \ingroup simix_vm_management
489 * \brief Save the given VM
493 void simcall_vm_save(smx_host_t vm)
495 simcall_BODY_vm_save(vm);
499 * \ingroup simix_vm_management
500 * \brief Restore the given VM
504 void simcall_vm_restore(smx_host_t vm)
506 simcall_BODY_vm_restore(vm);
510 * \ingroup simix_vm_management
511 * \brief Shutdown the given VM
515 void simcall_vm_shutdown(smx_host_t vm)
517 simcall_BODY_vm_shutdown(vm);
521 * \ingroup simix_vm_management
522 * \brief Destroy the given VM
526 void simcall_vm_destroy(smx_host_t vm)
528 simcall_BODY_vm_destroy(vm);
533 * \ingroup simix_process_management
534 * \brief Creates and runs a new SIMIX process.
536 * The structure and the corresponding thread are created and put in the list of ready processes.
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.
550 void simcall_process_create(smx_process_t *process, const char *name,
551 xbt_main_func_t code,
553 const char *hostname,
555 int argc, char **argv,
556 xbt_dict_t properties,
559 simcall_BODY_process_create(process, name, code, data, hostname,
560 kill_time, argc, argv, properties,
565 * \ingroup simix_process_management
566 * \brief Kills a SIMIX process.
568 * This function simply kills a process.
570 * \param process poor victim
572 void simcall_process_kill(smx_process_t process)
574 simcall_BODY_process_kill(process);
578 * \ingroup simix_process_management
579 * \brief Kills all SIMIX processes.
581 void simcall_process_killall(int reset_pid)
583 simcall_BODY_process_killall(reset_pid);
587 * \ingroup simix_process_management
588 * \brief Cleans up a SIMIX process.
589 * \param process poor victim (must have already been killed)
591 void simcall_process_cleanup(smx_process_t process)
593 simcall_BODY_process_cleanup(process);
597 * \ingroup simix_process_management
598 * \brief Migrates an agent to another location.
600 * This function changes the value of the host on which \a process is running.
602 * \param process the process to migrate
603 * \param dest name of the new host
605 void simcall_process_change_host(smx_process_t process, smx_host_t dest)
607 simcall_BODY_process_change_host(process, dest);
610 void simcall_process_join(smx_process_t process, double timeout)
612 simcall_BODY_process_join(process, timeout);
616 * \ingroup simix_process_management
617 * \brief Suspends a process.
619 * This function suspends the process by suspending the action
620 * it was waiting for completion.
622 * \param process a SIMIX process
624 void simcall_process_suspend(smx_process_t process)
626 xbt_assert(process, "Invalid parameters");
628 simcall_BODY_process_suspend(process);
632 * \ingroup simix_process_management
633 * \brief Resumes a suspended process.
635 * This function resumes a suspended process by resuming the action
636 * it was waiting for completion.
638 * \param process a SIMIX process
640 void simcall_process_resume(smx_process_t process)
642 simcall_BODY_process_resume(process);
646 * \ingroup simix_process_management
647 * \brief Returns the amount of SIMIX processes in the system
649 * Maestro internal process is not counted, only user code processes are
651 int simcall_process_count(void)
653 return simcall_BODY_process_count();
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
662 int simcall_process_get_PID(smx_process_t process)
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);
669 return simcall_BODY_process_get_PID(process);
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
678 int simcall_process_get_PPID(smx_process_t process)
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);
685 return simcall_BODY_process_get_PPID(process);
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
694 void* simcall_process_get_data(smx_process_t process)
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);
701 return simcall_BODY_process_get_data(process);
705 * \ingroup simix_process_management
706 * \brief Set the user data of a #smx_process_t.
708 * This functions sets the user data associated to \a process.
709 * \param process SIMIX process
710 * \param data User data
712 void simcall_process_set_data(smx_process_t process, void *data)
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);
719 simcall_BODY_process_set_data(process, data);
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
729 void simcall_process_set_kill_time(smx_process_t process, double kill_time)
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);
742 * \ingroup simix_process_management
743 * \brief Return the location on which an agent is running.
745 * This functions returns the smx_host_t corresponding to the location on which
746 * \a process is running.
747 * \param process SIMIX process
750 smx_host_t simcall_process_get_host(smx_process_t process)
752 return simcall_BODY_process_get_host(process);
756 * \ingroup simix_process_management
757 * \brief Return the name of an agent.
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
763 const char* simcall_process_get_name(smx_process_t process)
765 if (process == SIMIX_process_self()) {
766 /* avoid a simcall if this function is called by the process itself */
767 return process->name;
769 return simcall_BODY_process_get_name(process);
773 * \ingroup simix_process_management
774 * \brief Returns true if the process is suspended .
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.
780 int simcall_process_is_suspended(smx_process_t process)
782 return simcall_BODY_process_is_suspended(process);
786 * \ingroup simix_process_management
787 * \brief Return the properties
789 * This functions returns the properties associated with this process
791 xbt_dict_t simcall_process_get_properties(smx_process_t process)
793 return simcall_BODY_process_get_properties(process);
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.
800 XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_pvoid_t fun, void *data)
802 simcall_BODY_process_on_exit(process, fun, data);
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.
810 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart)
812 simcall_BODY_process_auto_restart_set(process, auto_restart);
816 * \ingroup simix_process_management
817 * \brief Restarts the process, killing it and starting it again from scratch.
819 XBT_PUBLIC(smx_process_t) simcall_process_restart(smx_process_t process)
821 return simcall_BODY_process_restart(process);
824 * \ingroup simix_process_management
825 * \brief Creates a new sleep SIMIX action.
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".
831 * \param duration Time duration of the sleep.
832 * \return A result telling whether the sleep was successful
834 e_smx_state_t simcall_process_sleep(double duration)
836 /* checking for infinite values */
837 xbt_assert(isfinite(duration), "duration is not finite!");
838 return simcall_BODY_process_sleep(duration);
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
847 smx_rdv_t simcall_rdv_create(const char *name)
849 return simcall_BODY_rdv_create(name);
854 * \ingroup simix_rdv_management
855 * \brief Destroy a rendez-vous point
856 * \param rdv The rendez-vous point to destroy
858 void simcall_rdv_destroy(smx_rdv_t rdv)
860 simcall_BODY_rdv_destroy(rdv);
863 * \ingroup simix_rdv_management
864 * \brief Returns a rendez-vous point knowing its name
866 smx_rdv_t simcall_rdv_get_by_name(const char *name)
868 xbt_assert(name != NULL, "Invalid parameter for simcall_rdv_get_by_name (name is NULL)");
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. */
874 return SIMIX_rdv_get_by_name(name);
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
885 int simcall_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
887 return simcall_BODY_rdv_comm_count_by_host(rdv, host);
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
896 smx_action_t simcall_rdv_get_head(smx_rdv_t rdv)
898 return simcall_BODY_rdv_get_head(rdv);
901 void simcall_rdv_set_receiver(smx_rdv_t rdv, smx_process_t process)
903 simcall_BODY_rdv_set_receiver(rdv, process);
906 smx_process_t simcall_rdv_get_receiver(smx_rdv_t rdv)
908 return simcall_BODY_rdv_get_receiver(rdv);
912 * \ingroup simix_comm_management
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,
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!");
925 xbt_assert(rdv, "No rendez-vous point defined for send");
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);
936 simcall_BODY_comm_send(src, rdv, task_size, rate, src_buff, src_buff_size,
937 match_fun, copy_data_fun, data, timeout);
942 * \ingroup simix_comm_management
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),
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!");
956 xbt_assert(rdv, "No rendez-vous point defined for isend");
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);
964 * \ingroup simix_comm_management
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)
971 xbt_assert(isfinite(timeout), "timeout is not finite!");
972 xbt_assert(rdv, "No rendez-vous point defined for recv");
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);
983 simcall_BODY_comm_recv(rdv, dst_buff, dst_buff_size,
984 match_fun, copy_data_fun, data, timeout, rate);
988 * \ingroup simix_comm_management
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)
995 xbt_assert(rdv, "No rendez-vous point defined for irecv");
997 return simcall_BODY_comm_irecv(rdv, dst_buff, dst_buff_size,
998 match_fun, copy_data_fun, data, rate);
1002 * \ingroup simix_comm_management
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)
1007 xbt_assert(rdv, "No rendez-vous point defined for iprobe");
1009 return simcall_BODY_comm_iprobe(rdv, type, src, tag, match_fun, data);
1013 * \ingroup simix_comm_management
1015 void simcall_comm_cancel(smx_action_t comm)
1017 simcall_BODY_comm_cancel(comm);
1021 * \ingroup simix_comm_management
1023 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
1025 return simcall_BODY_comm_waitany(comms);
1029 * \ingroup simix_comm_management
1031 int simcall_comm_testany(xbt_dynar_t comms)
1033 if (xbt_dynar_is_empty(comms))
1035 return simcall_BODY_comm_testany(comms);
1039 * \ingroup simix_comm_management
1041 void simcall_comm_wait(smx_action_t comm, double timeout)
1043 xbt_assert(isfinite(timeout), "timeout is not finite!");
1044 simcall_BODY_comm_wait(comm, timeout);
1049 * \brief Set the category of an action.
1051 * This functions changes the category only. It calls a surf function.
1052 * \param execution The execution action
1053 * \param category The tracing category
1055 void simcall_set_category(smx_action_t action, const char *category)
1057 if (category == NULL) {
1060 simcall_BODY_set_category(action, category);
1065 * \ingroup simix_comm_management
1068 int simcall_comm_test(smx_action_t comm)
1070 return simcall_BODY_comm_test(comm);
1074 * \ingroup simix_comm_management
1077 double simcall_comm_get_remains(smx_action_t comm)
1079 return simcall_BODY_comm_get_remains(comm);
1083 * \ingroup simix_comm_management
1086 e_smx_state_t simcall_comm_get_state(smx_action_t comm)
1088 return simcall_BODY_comm_get_state(comm);
1092 * \ingroup simix_comm_management
1095 void *simcall_comm_get_src_data(smx_action_t comm)
1097 return simcall_BODY_comm_get_src_data(comm);
1101 * \ingroup simix_comm_management
1104 void *simcall_comm_get_dst_data(smx_action_t comm)
1106 return simcall_BODY_comm_get_dst_data(comm);
1110 * \ingroup simix_comm_management
1113 smx_process_t simcall_comm_get_src_proc(smx_action_t comm)
1115 return simcall_BODY_comm_get_src_proc(comm);
1119 * \ingroup simix_comm_management
1122 smx_process_t simcall_comm_get_dst_proc(smx_action_t comm)
1124 return simcall_BODY_comm_get_dst_proc(comm);
1127 #ifdef HAVE_LATENCY_BOUND_TRACKING
1128 int simcall_comm_is_latency_bounded(smx_action_t comm)
1130 return simcall_BODY_comm_is_latency_bounded(comm);
1135 * \ingroup simix_synchro_management
1138 smx_mutex_t simcall_mutex_init(void)
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
1144 return simcall_BODY_mutex_init();
1148 * \ingroup simix_synchro_management
1151 void simcall_mutex_destroy(smx_mutex_t mutex)
1153 simcall_BODY_mutex_destroy(mutex);
1157 * \ingroup simix_synchro_management
1160 void simcall_mutex_lock(smx_mutex_t mutex)
1162 simcall_BODY_mutex_lock(mutex);
1166 * \ingroup simix_synchro_management
1169 int simcall_mutex_trylock(smx_mutex_t mutex)
1171 return simcall_BODY_mutex_trylock(mutex);
1175 * \ingroup simix_synchro_management
1178 void simcall_mutex_unlock(smx_mutex_t mutex)
1180 simcall_BODY_mutex_unlock(mutex);
1184 * \ingroup simix_synchro_management
1187 smx_cond_t simcall_cond_init(void)
1189 return simcall_BODY_cond_init();
1193 * \ingroup simix_synchro_management
1196 void simcall_cond_destroy(smx_cond_t cond)
1198 simcall_BODY_cond_destroy(cond);
1202 * \ingroup simix_synchro_management
1205 void simcall_cond_signal(smx_cond_t cond)
1207 simcall_BODY_cond_signal(cond);
1211 * \ingroup simix_synchro_management
1214 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1216 simcall_BODY_cond_wait(cond, mutex);
1220 * \ingroup simix_synchro_management
1223 void simcall_cond_wait_timeout(smx_cond_t cond,
1227 xbt_assert(isfinite(timeout), "timeout is not finite!");
1228 simcall_BODY_cond_wait_timeout(cond, mutex, timeout);
1232 * \ingroup simix_synchro_management
1235 void simcall_cond_broadcast(smx_cond_t cond)
1237 simcall_BODY_cond_broadcast(cond);
1241 * \ingroup simix_synchro_management
1244 smx_sem_t simcall_sem_init(int capacity)
1246 return simcall_BODY_sem_init(capacity);
1250 * \ingroup simix_synchro_management
1253 void simcall_sem_destroy(smx_sem_t sem)
1255 simcall_BODY_sem_destroy(sem);
1259 * \ingroup simix_synchro_management
1262 void simcall_sem_release(smx_sem_t sem)
1264 simcall_BODY_sem_release(sem);
1268 * \ingroup simix_synchro_management
1271 int simcall_sem_would_block(smx_sem_t sem)
1273 return simcall_BODY_sem_would_block(sem);
1277 * \ingroup simix_synchro_management
1280 void simcall_sem_acquire(smx_sem_t sem)
1282 simcall_BODY_sem_acquire(sem);
1286 * \ingroup simix_synchro_management
1289 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1291 xbt_assert(isfinite(timeout), "timeout is not finite!");
1292 simcall_BODY_sem_acquire_timeout(sem, timeout);
1296 * \ingroup simix_synchro_management
1299 int simcall_sem_get_capacity(smx_sem_t sem)
1301 return simcall_BODY_sem_get_capacity(sem);
1305 * \ingroup simix_file_management
1308 sg_size_t simcall_file_read(smx_file_t fd, sg_size_t size, smx_host_t host)
1310 return simcall_BODY_file_read(fd, size, host);
1314 * \ingroup simix_file_management
1317 sg_size_t simcall_file_write(smx_file_t fd, sg_size_t size, smx_host_t host)
1319 return simcall_BODY_file_write(fd, size, host);
1323 * \ingroup simix_file_management
1326 smx_file_t simcall_file_open(const char* fullpath, smx_host_t host)
1328 return simcall_BODY_file_open(fullpath, host);
1332 * \ingroup simix_file_management
1335 int simcall_file_close(smx_file_t fd, smx_host_t host)
1337 return simcall_BODY_file_close(fd, host);
1341 * \ingroup simix_file_management
1344 int simcall_file_unlink(smx_file_t fd, smx_host_t host)
1346 return simcall_BODY_file_unlink(fd, host);
1350 * \ingroup simix_file_management
1353 sg_size_t simcall_file_get_size(smx_file_t fd){
1354 return simcall_BODY_file_get_size(fd);
1358 * \ingroup simix_file_management
1361 sg_size_t simcall_file_tell(smx_file_t fd){
1362 return simcall_BODY_file_tell(fd);
1366 * \ingroup simix_file_management
1369 xbt_dynar_t simcall_file_get_info(smx_file_t fd)
1371 return simcall_BODY_file_get_info(fd);
1375 * \ingroup simix_file_management
1378 int simcall_file_seek(smx_file_t fd, sg_offset_t offset, int origin){
1379 return simcall_BODY_file_seek(fd, offset, origin);
1383 * \ingroup simix_file_management
1384 * \brief Move a file to another location on the *same mount point*.
1387 int simcall_file_move(smx_file_t fd, const char* fullpath)
1389 return simcall_BODY_file_move(fd, fullpath);
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)
1398 sg_size_t simcall_storage_get_free_size (smx_storage_t storage){
1399 return simcall_BODY_storage_get_free_size(storage);
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)
1408 sg_size_t simcall_storage_get_used_size (smx_storage_t storage){
1409 return simcall_BODY_storage_get_used_size(storage);
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
1418 xbt_dict_t simcall_host_get_mounted_storage_list(smx_host_t host)
1420 return simcall_BODY_host_get_mounted_storage_list(host);
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
1429 xbt_dynar_t simcall_host_get_attached_storage_list(smx_host_t host)
1431 return simcall_BODY_host_get_attached_storage_list(host);
1435 * \ingroup simix_storage_management
1436 * \brief Returns a dict of the properties assigned to a storage element.
1438 * \param storage A storage element
1439 * \return The properties of this storage element
1441 xbt_dict_t simcall_storage_get_properties(smx_storage_t storage)
1443 return simcall_BODY_storage_get_properties(storage);
1447 * \ingroup simix_storage_management
1448 * \brief Returns a dict containing the content of a storage element.
1450 * \param storage A storage element
1451 * \return The content of this storage element as a dict (full path file => size)
1453 xbt_dict_t simcall_storage_get_content(smx_storage_t storage)
1455 return simcall_BODY_storage_get_content(storage);
1462 void *simcall_mc_snapshot(void) {
1463 return simcall_BODY_mc_snapshot();
1466 int simcall_mc_compare_snapshots(void *s1, void *s2) {
1467 return simcall_BODY_mc_compare_snapshots(s1, s2);
1470 int simcall_mc_random(int min, int max) {
1471 return simcall_BODY_mc_random(min, max);
1474 #endif /* HAVE_MC */
1476 /* ************************************************************************** */
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];