1 /* smx_user.c - public interface to simix */
3 /* Copyright (c) 2010-2012. Da SimGrid team. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "smx_private.h"
11 #include <math.h> /* isfinite() */
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
15 /* generate strings from the enumeration values */
16 static const char* simcall_names[] = {
17 SIMCALL_LIST(SIMCALL_STRING_TYPE, SIMCALL_SEP_COMMA)
18 [SIMCALL_NONE] = "NONE"
21 SIMCALL_LIST(SIMCALL_FUNC, SIMCALL_SEP_NOTHING)
24 * \ingroup simix_host_management
25 * \brief Returns a host given its name.
27 * \param name The name of the host to get
28 * \return The corresponding host
30 smx_host_t simcall_host_get_by_name(const char *name)
32 return simcall_BODY_host_get_by_name(name);
36 * \ingroup simix_host_management
37 * \brief Returns the name of a host.
39 * \param host A SIMIX host
40 * \return The name of this host
42 const char* simcall_host_get_name(smx_host_t host)
44 return simcall_BODY_host_get_name(host);
48 * \ingroup simix_host_management
49 * \brief Start the host if it is off
51 * \param host A SIMIX host
53 void simcall_host_on(smx_host_t host)
55 simcall_BODY_host_on(host);
59 * \ingroup simix_host_management
60 * \brief Stop the host if it is on
62 * \param host A SIMIX host
64 void simcall_host_off(smx_host_t host)
66 simcall_BODY_host_off(host);
70 * \ingroup simix_host_management
71 * \brief Returns a dict of the properties assigned to a host.
74 * \return The properties of this host
76 xbt_dict_t simcall_host_get_properties(smx_host_t host)
78 return simcall_BODY_host_get_properties(host);
82 * \ingroup simix_host_management
83 * \brief Returns a dict of the properties assigned to a router or AS.
85 * \param name The name of the router or AS
86 * \return The properties
88 xbt_dict_t simcall_asr_get_properties(const char *name)
90 return simcall_BODY_asr_get_properties(name);
95 * \ingroup simix_host_management
96 * \brief Returns the speed of the processor.
98 * The speed returned does not take into account the current load on the machine.
99 * \param host A SIMIX host
100 * \return The speed of this host (in Mflop/s)
102 double simcall_host_get_speed(smx_host_t host)
104 return simcall_BODY_host_get_speed(host);
108 * \ingroup simix_host_management
109 * \brief Returns the number of core of the processor.
111 * \param host A SIMIX host
112 * \return The number of core
114 int simcall_host_get_core(smx_host_t host)
116 return simcall_BODY_host_get_core(host);
122 * \ingroup simix_host_management
123 * \brief Returns the available speed of the processor.
125 * \return Speed currently available (in Mflop/s)
127 double simcall_host_get_available_speed(smx_host_t host)
129 return simcall_BODY_host_get_available_speed(host);
133 * \ingroup simix_host_management
134 * \brief Returns the state of a host.
136 * Two states are possible: 1 if the host is active or 0 if it has crashed.
137 * \param host A SIMIX host
138 * \return 1 if the host is available, 0 otherwise
140 int simcall_host_get_state(smx_host_t host)
142 return simcall_BODY_host_get_state(host);
146 * \ingroup simix_host_management
147 * \brief Returns the user data associated to a host.
149 * \param host SIMIX host
150 * \return the user data of this host
152 void* simcall_host_get_data(smx_host_t host)
154 return simcall_BODY_host_get_data(host);
158 * \ingroup simix_host_management
159 * \brief Sets the user data associated to a host.
161 * The host must not have previous user data associated to it.
162 * \param host A SIMIX host
163 * \param data The user data to set
165 void simcall_host_set_data(smx_host_t host, void *data)
167 simcall_host_set_data(host, data);
171 * \ingroup simix_host_management
172 * \brief Creates an action that executes some computation of an host.
174 * This function creates a SURF action and allocates the data necessary
175 * to create the SIMIX action. It can raise a host_error exception if the host crashed.
177 * \param name Name of the execution action to create
178 * \param host SIMIX host where the action will be executed
179 * \param computation_amount amount Computation amount (in bytes)
180 * \param priority computation priority
181 * \return A new SIMIX execution action
184 smx_action_t simcall_host_execute(const char *name, smx_host_t host,
185 double computation_amount,
186 double priority, double bound)
188 /* checking for infinite values */
189 xbt_assert(isfinite(computation_amount), "computation_amount is not finite!");
190 xbt_assert(isfinite(priority), "priority is not finite!");
192 return simcall_BODY_host_execute(name, host, computation_amount, priority, bound);
196 * \ingroup simix_host_management
197 * \brief Creates an action that may involve parallel computation on
198 * several hosts and communication between them.
200 * \param name Name of the execution action to create
201 * \param host_nb Number of hosts where the action will be executed
202 * \param host_list Array (of size host_nb) of hosts where the action will be executed
203 * \param computation_amount Array (of size host_nb) of computation amount of hosts (in bytes)
204 * \param communication_amount Array (of size host_nb * host_nb) representing the communication
205 * amount between each pair of hosts
206 * \param amount the SURF action amount
207 * \param rate the SURF action rate
208 * \return A new SIMIX execution action
210 smx_action_t simcall_host_parallel_execute(const char *name,
212 smx_host_t *host_list,
213 double *computation_amount,
214 double *communication_amount,
219 /* checking for infinite values */
220 for (i = 0 ; i < host_nb ; ++i) {
221 xbt_assert(isfinite(computation_amount[i]), "computation_amount[%d] is not finite!", i);
222 for (j = 0 ; j < host_nb ; ++j) {
223 xbt_assert(isfinite(communication_amount[i + host_nb * j]),
224 "communication_amount[%d+%d*%d] is not finite!", i, host_nb, j);
228 xbt_assert(isfinite(amount), "amount is not finite!");
229 xbt_assert(isfinite(rate), "rate is not finite!");
231 return simcall_BODY_host_parallel_execute(name, host_nb, host_list,
233 communication_amount,
239 * \ingroup simix_host_management
240 * \brief Destroys an execution action.
242 * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
243 * \param execution The execution action to destroy
245 void simcall_host_execution_destroy(smx_action_t execution)
247 simcall_BODY_host_execution_destroy(execution);
251 * \ingroup simix_host_management
252 * \brief Cancels an execution action.
254 * This functions stops the execution. It calls a surf function.
255 * \param execution The execution action to cancel
257 void simcall_host_execution_cancel(smx_action_t execution)
259 simcall_BODY_host_execution_cancel(execution);
263 * \ingroup simix_host_management
264 * \brief Returns how much of an execution action remains to be done.
266 * \param execution The execution action
267 * \return The remaining amount
269 double simcall_host_execution_get_remains(smx_action_t execution)
271 return simcall_BODY_host_execution_get_remains(execution);
275 * \ingroup simix_host_management
276 * \brief Returns the state of an execution action.
278 * \param execution The execution action
281 e_smx_state_t simcall_host_execution_get_state(smx_action_t execution)
283 return simcall_BODY_host_execution_get_state(execution);
287 * \ingroup simix_host_management
288 * \brief Changes the priority of an execution action.
290 * This functions changes the priority only. It calls a surf function.
291 * \param execution The execution action
292 * \param priority The new priority
294 void simcall_host_execution_set_priority(smx_action_t execution, double priority)
296 /* checking for infinite values */
297 xbt_assert(isfinite(priority), "priority is not finite!");
299 simcall_BODY_host_execution_set_priority(execution, priority);
303 * \ingroup simix_host_management
304 * \brief Changes the capping (the maximum CPU utilization) of an execution action.
306 * This functions changes the capping only. It calls a surf function.
307 * \param execution The execution action
308 * \param bound The new bound
310 void simcall_host_execution_set_bound(smx_action_t execution, double bound)
312 simcall_BODY_host_execution_set_bound(execution, bound);
316 * \ingroup simix_host_management
317 * \brief Changes the CPU affinity of an execution action.
319 * This functions changes the CPU affinity of an execution action. See taskset(1) on Linux.
320 * \param execution The execution action
322 * \param mask Affinity mask
324 void simcall_host_execution_set_affinity(smx_action_t execution, smx_host_t host, unsigned long mask)
326 simcall_BODY_host_execution_set_affinity(execution, host, mask);
330 * \ingroup simix_host_management
331 * \brief Waits for the completion of an execution action and destroy it.
333 * \param execution The execution action
335 e_smx_state_t simcall_host_execution_wait(smx_action_t execution)
337 return simcall_BODY_host_execution_wait(execution);
342 * \ingroup simix_vm_management
343 * \brief Create a VM on the given physical host.
345 * \param name VM name
346 * \param host Physical host
348 * \return The host object of the VM
350 void* simcall_vm_create(const char *name, smx_host_t phys_host){
351 /* will jump to SIMIX_pre_vm_create() in src/simix/smx_smurf_private.h */
352 return simcall_BODY_vm_create(name, phys_host);
356 * \ingroup simix_vm_management
357 * \brief Start the given VM to the given physical host
361 void simcall_vm_start(smx_host_t vm)
363 /* will jump to SIMIX_pre_vm_start in src/simix/smx_smurf_private.h */
364 simcall_BODY_vm_start(vm);
368 * \ingroup simix_vm_management
369 * \brief Get the state of the given VM
372 * \return The state of the VM
374 int simcall_vm_get_state(smx_host_t vm)
376 /* will jump to SIMIX_pre_vm_get_state in src/simix/smx_smurf_private.h */
377 return simcall_BODY_vm_get_state(vm);
381 * \ingroup simix_vm_management
382 * \brief Get the name of the physical host on which the given VM runs.
385 * \return The name of the physical host
387 void *simcall_vm_get_pm(smx_host_t vm)
389 /* will jump to SIMIX_pre_vm_migrate in src/simix/smx_smurf_private.h */
390 return simcall_BODY_vm_get_pm(vm);
393 void simcall_vm_set_bound(smx_host_t vm, double bound)
395 /* will jump to SIMIX_pre_vm_set_bound in src/simix/smx_smurf_private.h */
396 simcall_BODY_vm_set_bound(vm, bound);
399 void simcall_host_get_params(smx_host_t vm, ws_params_t params)
401 /* will jump to SIMIX_pre_host_get_params in src/simix/smx_smurf_private.h */
402 simcall_BODY_host_get_params(vm, params);
405 void simcall_host_set_params(smx_host_t vm, ws_params_t params)
407 /* will jump to SIMIX_pre_host_set_params in src/simix/smx_smurf_private.h */
408 simcall_BODY_host_set_params(vm, params);
412 * \ingroup simix_vm_management
413 * \brief Migrate the given VM to the given physical host
416 * \param host Destination physical host
418 void simcall_vm_migrate(smx_host_t vm, smx_host_t host)
420 /* will jump to SIMIX_pre_vm_migrate in src/simix/smx_smurf_private.h */
421 simcall_BODY_vm_migrate(vm, host);
425 * \ingroup simix_vm_management
426 * \brief Suspend the given VM
430 void simcall_vm_suspend(smx_host_t vm)
432 /* will jump to SIMIX_pre_vm_suspend in src/simix/smx_smurf_private.h */
433 simcall_BODY_vm_suspend(vm);
437 * \ingroup simix_vm_management
438 * \brief Resume the given VM
442 void simcall_vm_resume(smx_host_t vm)
444 /* will jump to SIMIX_pre_vm_resume in src/simix/smx_smurf_private.h */
445 simcall_BODY_vm_resume(vm);
449 * \ingroup simix_vm_management
450 * \brief Save the given VM
454 void simcall_vm_save(smx_host_t vm)
456 /* will jump to SIMIX_pre_vm_save in src/simix/smx_smurf_private.h */
457 simcall_BODY_vm_save(vm);
461 * \ingroup simix_vm_management
462 * \brief Restore the given VM
466 void simcall_vm_restore(smx_host_t vm)
468 /* will jump to SIMIX_pre_vm_restore in src/simix/smx_smurf_private.h */
469 simcall_BODY_vm_restore(vm);
473 * \ingroup simix_vm_management
474 * \brief Shutdown the given VM
478 void simcall_vm_shutdown(smx_host_t vm)
480 /* will jump to SIMIX_pre_vm_shutdown in src/simix/smx_smurf_private.h */
481 simcall_BODY_vm_shutdown(vm);
485 * \ingroup simix_vm_management
486 * \brief Destroy the given VM
490 void simcall_vm_destroy(smx_host_t vm)
492 /* will jump to SIMIX_pre_vm_destroy in src/simix/smx_smurf_private.h */
493 simcall_BODY_vm_destroy(vm);
498 * \ingroup simix_process_management
499 * \brief Creates and runs a new SIMIX process.
501 * The structure and the corresponding thread are created and put in the list of ready processes.
503 * \param process the process created will be stored in this pointer
504 * \param name a name for the process. It is for user-level information and can be NULL.
505 * \param code the main function of the process
506 * \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.
507 * It can be retrieved with the function \ref simcall_process_get_data.
508 * \param hostname name of the host where the new agent is executed.
509 * \param kill_time time when the process is killed
510 * \param argc first argument passed to \a code
511 * \param argv second argument passed to \a code
512 * \param properties the properties of the process
513 * \param auto_restart either it is autorestarting or not.
515 void simcall_process_create(smx_process_t *process, const char *name,
516 xbt_main_func_t code,
518 const char *hostname,
520 int argc, char **argv,
521 xbt_dict_t properties,
524 simcall_BODY_process_create(process, name, code, data, hostname,
525 kill_time, argc, argv, properties,
530 * \ingroup simix_process_management
531 * \brief Kills a SIMIX process.
533 * This function simply kills a process.
535 * \param process poor victim
537 void simcall_process_kill(smx_process_t process)
539 simcall_BODY_process_kill(process);
543 * \ingroup simix_process_management
544 * \brief Kills all SIMIX processes.
546 void simcall_process_killall(int reset_pid)
548 simcall_BODY_process_killall(reset_pid);
552 * \ingroup simix_process_management
553 * \brief Cleans up a SIMIX process.
554 * \param process poor victim (must have already been killed)
556 void simcall_process_cleanup(smx_process_t process)
558 simcall_BODY_process_cleanup(process);
562 * \ingroup simix_process_management
563 * \brief Migrates an agent to another location.
565 * This function changes the value of the host on which \a process is running.
567 * \param process the process to migrate
568 * \param dest name of the new host
570 void simcall_process_change_host(smx_process_t process, smx_host_t dest)
572 simcall_BODY_process_change_host(process, dest);
576 * \ingroup simix_process_management
577 * \brief Suspends a process.
579 * This function suspends the process by suspending the action
580 * it was waiting for completion.
582 * \param process a SIMIX process
584 void simcall_process_suspend(smx_process_t process)
586 xbt_assert(process, "Invalid parameters");
588 simcall_BODY_process_suspend(process);
592 * \ingroup simix_process_management
593 * \brief Resumes a suspended process.
595 * This function resumes a suspended process by resuming the action
596 * it was waiting for completion.
598 * \param process a SIMIX process
600 void simcall_process_resume(smx_process_t process)
602 simcall_BODY_process_resume(process);
606 * \ingroup simix_process_management
607 * \brief Returns the amount of SIMIX processes in the system
609 * Maestro internal process is not counted, only user code processes are
611 int simcall_process_count(void)
613 return simcall_BODY_process_count();
617 * \ingroup simix_process_management
618 * \brief Return the PID of a #smx_process_t.
619 * \param process a SIMIX process
620 * \return the PID of this process
622 int simcall_process_get_PID(smx_process_t process)
624 if (process == SIMIX_process_self()) {
625 /* avoid a simcall if this function is called by the process itself */
626 return SIMIX_process_get_PID(process);
629 return simcall_BODY_process_get_PID(process);
633 * \ingroup simix_process_management
634 * \brief Return the parent PID of a #smx_process_t.
635 * \param process a SIMIX process
636 * \return the PID of this process parenrt
638 int simcall_process_get_PPID(smx_process_t process)
640 if (process == SIMIX_process_self()) {
641 /* avoid a simcall if this function is called by the process itself */
642 return SIMIX_process_get_PPID(process);
645 return simcall_BODY_process_get_PPID(process);
649 * \ingroup simix_process_management
650 * \brief Return the user data of a #smx_process_t.
651 * \param process a SIMIX process
652 * \return the user data of this process
654 void* simcall_process_get_data(smx_process_t process)
656 if (process == SIMIX_process_self()) {
657 /* avoid a simcall if this function is called by the process itself */
658 return SIMIX_process_get_data(process);
661 return simcall_BODY_process_get_data(process);
665 * \ingroup simix_process_management
666 * \brief Set the user data of a #smx_process_t.
668 * This functions sets the user data associated to \a process.
669 * \param process SIMIX process
670 * \param data User data
672 void simcall_process_set_data(smx_process_t process, void *data)
674 if (process == SIMIX_process_self()) {
675 /* avoid a simcall if this function is called by the process itself */
676 SIMIX_process_self_set_data(process, data);
679 simcall_BODY_process_set_data(process, data);
684 * \ingroup simix_process_management
685 * \brief Set the kill time of a process.
686 * \param process a process
687 * \param kill_time a double
689 void simcall_process_set_kill_time(smx_process_t process, double kill_time)
692 if (kill_time > SIMIX_get_clock()) {
693 if (simix_global->kill_process_function) {
694 XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name,
695 sg_host_name(process->smx_host));
696 SIMIX_timer_set(kill_time, simix_global->kill_process_function, process);
702 * \ingroup simix_process_management
703 * \brief Return the location on which an agent is running.
705 * This functions returns the smx_host_t corresponding to the location on which
706 * \a process is running.
707 * \param process SIMIX process
710 smx_host_t simcall_process_get_host(smx_process_t process)
712 return simcall_BODY_process_get_host(process);
716 * \ingroup simix_process_management
717 * \brief Return the name of an agent.
719 * This functions checks whether \a process is a valid pointer or not and return its name.
720 * \param process SIMIX process
721 * \return The process name
723 const char* simcall_process_get_name(smx_process_t process)
725 if (process == SIMIX_process_self()) {
726 /* avoid a simcall if this function is called by the process itself */
727 return process->name;
729 return simcall_BODY_process_get_name(process);
733 * \ingroup simix_process_management
734 * \brief Returns true if the process is suspended .
736 * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
737 * \param process SIMIX process
738 * \return 1, if the process is suspended, else 0.
740 int simcall_process_is_suspended(smx_process_t process)
742 return simcall_BODY_process_is_suspended(process);
746 * \ingroup simix_process_management
747 * \brief Return the properties
749 * This functions returns the properties associated with this process
751 xbt_dict_t simcall_process_get_properties(smx_process_t process)
753 return simcall_BODY_process_get_properties(process);
756 * \ingroup simix_process_management
757 * \brief Add an on_exit function
758 * Add an on_exit function which will be executed when the process exits/is killed.
760 XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_t fun, void *data)
762 simcall_BODY_process_on_exit(process, fun, data);
765 * \ingroup simix_process_management
766 * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up.
767 * Will restart the process when the host comes back up if auto_restart is set to 1.
770 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart)
772 simcall_BODY_process_auto_restart_set(process, auto_restart);
776 * \ingroup simix_process_management
777 * \brief Restarts the process, killing it and starting it again from scratch.
779 XBT_PUBLIC(smx_process_t) simcall_process_restart(smx_process_t process)
781 return simcall_BODY_process_restart(process);
784 * \ingroup simix_process_management
785 * \brief Creates a new sleep SIMIX action.
787 * This function creates a SURF action and allocates the data necessary
788 * to create the SIMIX action. It can raise a host_error exception if the
789 * host crashed. The default SIMIX name of the action is "sleep".
791 * \param duration Time duration of the sleep.
792 * \return A result telling whether the sleep was successful
794 e_smx_state_t simcall_process_sleep(double duration)
796 /* checking for infinite values */
797 xbt_assert(isfinite(duration), "duration is not finite!");
798 return simcall_BODY_process_sleep(duration);
802 * \ingroup simix_rdv_management
803 * \brief Creates a new rendez-vous point
804 * \param name The name of the rendez-vous point
805 * \return The created rendez-vous point
807 smx_rdv_t simcall_rdv_create(const char *name)
809 return simcall_BODY_rdv_create(name);
814 * \ingroup simix_rdv_management
815 * \brief Destroy a rendez-vous point
816 * \param rdv The rendez-vous point to destroy
818 void simcall_rdv_destroy(smx_rdv_t rdv)
820 simcall_BODY_rdv_destroy(rdv);
823 * \ingroup simix_rdv_management
824 * \brief Returns a rendez-vous point knowing its name
826 smx_rdv_t simcall_rdv_get_by_name(const char *name)
828 xbt_assert(name != NULL, "Invalid parameter for simcall_rdv_get_by_name (name is NULL)");
830 /* FIXME: this is a horrible loss of performance, so we hack it out by
831 * skipping the simcall (for now). It works in parallel, it won't work on
832 * distributed but probably we will change MSG for that. */
835 smx_simcall_t simcall = simcall_mine();
836 simcall->call = SIMCALL_RDV_GEY_BY_NAME;
837 simcall->rdv_get_by_name.name = name;
838 SIMIX_simcall_push(simcall->issuer);
839 return simcall->rdv_get_by_name.result;*/
841 return SIMIX_rdv_get_by_name(name);
845 * \ingroup simix_rdv_management
846 * \brief Counts the number of communication actions of a given host pending
847 * on a rendez-vous point.
848 * \param rdv The rendez-vous point
849 * \param host The host to be counted
850 * \return The number of comm actions pending in the rdv
852 int simcall_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
854 return simcall_BODY_rdv_comm_count_by_host(rdv, host);
858 * \ingroup simix_rdv_management
859 * \brief returns the communication at the head of the rendez-vous
860 * \param rdv The rendez-vous point
861 * \return The communication or NULL if empty
863 smx_action_t simcall_rdv_get_head(smx_rdv_t rdv)
865 return simcall_BODY_rdv_get_head(rdv);
868 void simcall_rdv_set_receiver(smx_rdv_t rdv, smx_process_t process)
870 simcall_BODY_rdv_set_receiver(rdv, process);
873 smx_process_t simcall_rdv_get_receiver(smx_rdv_t rdv)
875 return simcall_BODY_rdv_get_receiver(rdv);
879 * \ingroup simix_comm_management
881 void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate,
882 void *src_buff, size_t src_buff_size,
883 int (*match_fun)(void *, void *, smx_action_t), void *data,
886 /* checking for infinite values */
887 xbt_assert(isfinite(task_size), "task_size is not finite!");
888 xbt_assert(isfinite(rate), "rate is not finite!");
889 xbt_assert(isfinite(timeout), "timeout is not finite!");
891 xbt_assert(rdv, "No rendez-vous point defined for send");
893 if (MC_is_active()) {
894 /* the model-checker wants two separate simcalls */
895 smx_action_t comm = simcall_comm_isend(rdv, task_size, rate,
896 src_buff, src_buff_size, match_fun, NULL, data, 0);
897 simcall_comm_wait(comm, timeout);
900 simcall_BODY_comm_send(rdv, task_size, rate, src_buff, src_buff_size,
901 match_fun, data, timeout);
906 * \ingroup simix_comm_management
908 smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate,
909 void *src_buff, size_t src_buff_size,
910 int (*match_fun)(void *, void *, smx_action_t),
911 void (*clean_fun)(void *),
915 /* checking for infinite values */
916 xbt_assert(isfinite(task_size), "task_size is not finite!");
917 xbt_assert(isfinite(rate), "rate is not finite!");
919 xbt_assert(rdv, "No rendez-vous point defined for isend");
921 return simcall_BODY_comm_isend(rdv, task_size, rate, src_buff,
922 src_buff_size, match_fun,
923 clean_fun, data, detached);
926 * \ingroup simix_comm_management
928 void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
929 int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout)
931 xbt_assert(isfinite(timeout), "timeout is not finite!");
932 xbt_assert(rdv, "No rendez-vous point defined for recv");
934 if (MC_is_active()) {
935 /* the model-checker wants two separate simcalls */
936 smx_action_t comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
938 simcall_comm_wait(comm, timeout);
941 simcall_BODY_comm_recv(rdv, dst_buff, dst_buff_size,
942 match_fun, data, timeout);
946 * \ingroup simix_comm_management
948 smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size,
949 int (*match_fun)(void *, void *, smx_action_t), void *data)
951 xbt_assert(rdv, "No rendez-vous point defined for irecv");
953 return simcall_BODY_comm_irecv(rdv, dst_buff, dst_buff_size,
959 * \ingroup simix_comm_management
961 void simcall_comm_recv_bounded(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
962 int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout, double rate)
964 xbt_assert(isfinite(timeout), "timeout is not finite!");
965 xbt_assert(rdv, "No rendez-vous point defined for recv");
967 if (MC_is_active()) {
968 /* the model-checker wants two separate simcalls */
969 smx_action_t comm = simcall_comm_irecv_bounded(rdv, dst_buff, dst_buff_size,
970 match_fun, data, rate);
971 simcall_comm_wait(comm, timeout);
974 simcall_BODY_comm_recv_bounded(rdv, dst_buff, dst_buff_size,
975 match_fun, data, timeout, rate);
979 * \ingroup simix_comm_management
981 smx_action_t simcall_comm_irecv_bounded(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size,
982 int (*match_fun)(void *, void *, smx_action_t), void *data, double rate)
984 xbt_assert(rdv, "No rendez-vous point defined for irecv");
986 return simcall_BODY_comm_irecv_bounded(rdv, dst_buff, dst_buff_size,
987 match_fun, data, rate);
992 * \ingroup simix_comm_management
994 smx_action_t simcall_comm_iprobe(smx_rdv_t rdv, int src, int tag,
995 int (*match_fun)(void *, void *, smx_action_t), void *data)
997 xbt_assert(rdv, "No rendez-vous point defined for iprobe");
999 return simcall_BODY_comm_iprobe(rdv, src, tag, match_fun, data);
1002 void simcall_comm_destroy(smx_action_t comm)
1004 xbt_assert(comm, "Invalid parameter");
1006 /* FIXME remove this simcall type: comms are auto-destroyed now */
1009 smx_simcall_t simcall = simcall_mine();
1011 simcall->call = SIMCALL_COMM_DESTROY;
1012 simcall->comm_destroy.comm = comm;
1014 SIMIX_simcall_push(simcall->issuer);
1019 * \ingroup simix_comm_management
1021 void simcall_comm_cancel(smx_action_t comm)
1023 simcall_BODY_comm_cancel(comm);
1027 * \ingroup simix_comm_management
1029 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
1031 return simcall_BODY_comm_waitany(comms);
1035 * \ingroup simix_comm_management
1037 int simcall_comm_testany(xbt_dynar_t comms)
1039 if (xbt_dynar_is_empty(comms))
1041 return simcall_BODY_comm_testany(comms);
1045 * \ingroup simix_comm_management
1047 void simcall_comm_wait(smx_action_t comm, double timeout)
1049 xbt_assert(isfinite(timeout), "timeout is not finite!");
1050 simcall_BODY_comm_wait(comm, timeout);
1055 * \brief Set the category of an action.
1057 * This functions changes the category only. It calls a surf function.
1058 * \param execution The execution action
1059 * \param category The tracing category
1061 void simcall_set_category(smx_action_t action, const char *category)
1063 if (category == NULL) {
1066 simcall_BODY_set_category(action, category);
1071 * \ingroup simix_comm_management
1074 int simcall_comm_test(smx_action_t comm)
1076 return simcall_BODY_comm_test(comm);
1080 * \ingroup simix_comm_management
1083 double simcall_comm_get_remains(smx_action_t comm)
1085 return simcall_BODY_comm_get_remains(comm);
1089 * \ingroup simix_comm_management
1092 e_smx_state_t simcall_comm_get_state(smx_action_t comm)
1094 return simcall_BODY_comm_get_state(comm);
1098 * \ingroup simix_comm_management
1101 void *simcall_comm_get_src_data(smx_action_t comm)
1103 return simcall_BODY_comm_get_src_data(comm);
1107 * \ingroup simix_comm_management
1110 void *simcall_comm_get_dst_data(smx_action_t comm)
1112 return simcall_BODY_comm_get_dst_data(comm);
1116 * \ingroup simix_comm_management
1119 smx_process_t simcall_comm_get_src_proc(smx_action_t comm)
1121 return simcall_BODY_comm_get_src_proc(comm);
1125 * \ingroup simix_comm_management
1128 smx_process_t simcall_comm_get_dst_proc(smx_action_t comm)
1130 return simcall_BODY_comm_get_dst_proc(comm);
1133 #ifdef HAVE_LATENCY_BOUND_TRACKING
1134 int simcall_comm_is_latency_bounded(smx_action_t comm)
1136 return simcall_BODY_comm_is_latency_bounded(comm);
1141 * \ingroup simix_synchro_management
1144 smx_mutex_t simcall_mutex_init(void)
1147 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
1150 return simcall_BODY_mutex_init();
1154 * \ingroup simix_synchro_management
1157 void simcall_mutex_destroy(smx_mutex_t mutex)
1159 simcall_BODY_mutex_destroy(mutex);
1163 * \ingroup simix_synchro_management
1166 void simcall_mutex_lock(smx_mutex_t mutex)
1168 simcall_BODY_mutex_lock(mutex);
1172 * \ingroup simix_synchro_management
1175 int simcall_mutex_trylock(smx_mutex_t mutex)
1177 return simcall_BODY_mutex_trylock(mutex);
1181 * \ingroup simix_synchro_management
1184 void simcall_mutex_unlock(smx_mutex_t mutex)
1186 simcall_BODY_mutex_unlock(mutex);
1190 * \ingroup simix_synchro_management
1193 smx_cond_t simcall_cond_init(void)
1195 return simcall_BODY_cond_init();
1199 * \ingroup simix_synchro_management
1202 void simcall_cond_destroy(smx_cond_t cond)
1204 simcall_BODY_cond_destroy(cond);
1208 * \ingroup simix_synchro_management
1211 void simcall_cond_signal(smx_cond_t cond)
1213 simcall_BODY_cond_signal(cond);
1217 * \ingroup simix_synchro_management
1220 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1222 simcall_BODY_cond_wait(cond, mutex);
1226 * \ingroup simix_synchro_management
1229 void simcall_cond_wait_timeout(smx_cond_t cond,
1233 xbt_assert(isfinite(timeout), "timeout is not finite!");
1234 simcall_BODY_cond_wait_timeout(cond, mutex, timeout);
1238 * \ingroup simix_synchro_management
1241 void simcall_cond_broadcast(smx_cond_t cond)
1243 simcall_BODY_cond_broadcast(cond);
1247 * \ingroup simix_synchro_management
1250 smx_sem_t simcall_sem_init(int capacity)
1252 return simcall_BODY_sem_init(capacity);
1256 * \ingroup simix_synchro_management
1259 void simcall_sem_destroy(smx_sem_t sem)
1261 simcall_sem_destroy(sem);
1265 * \ingroup simix_synchro_management
1268 void simcall_sem_release(smx_sem_t sem)
1270 simcall_BODY_sem_release(sem);
1274 * \ingroup simix_synchro_management
1277 int simcall_sem_would_block(smx_sem_t sem)
1279 return simcall_BODY_sem_would_block(sem);
1283 * \ingroup simix_synchro_management
1286 void simcall_sem_acquire(smx_sem_t sem)
1288 simcall_BODY_sem_acquire(sem);
1292 * \ingroup simix_synchro_management
1295 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1297 xbt_assert(isfinite(timeout), "timeout is not finite!");
1298 simcall_BODY_sem_acquire_timeout(sem, timeout);
1302 * \ingroup simix_synchro_management
1305 int simcall_sem_get_capacity(smx_sem_t sem)
1307 return simcall_BODY_sem_get_capacity(sem);
1311 * \ingroup simix_file_management
1314 size_t simcall_file_read(void* ptr, size_t size, smx_file_t fd)
1316 return simcall_BODY_file_read(ptr, size, fd);
1320 * \ingroup simix_file_management
1323 size_t simcall_file_write(const void* ptr, size_t size,
1326 return simcall_BODY_file_write(ptr, size, fd);
1330 * \ingroup simix_file_management
1333 smx_file_t simcall_file_open(const char* mount, const char* path)
1335 return simcall_BODY_file_open(mount, path);
1339 * \ingroup simix_file_management
1342 int simcall_file_close(smx_file_t fd)
1344 return simcall_BODY_file_close(fd);
1348 * \ingroup simix_file_management
1351 int simcall_file_unlink(smx_file_t fd)
1353 return simcall_BODY_file_unlink(fd);
1357 * \ingroup simix_file_management
1360 xbt_dict_t simcall_file_ls(const char* mount, const char* path)
1362 return simcall_BODY_file_ls(mount, path);
1365 * \ingroup simix_file_management
1368 size_t simcall_file_get_size (smx_file_t fd){
1369 return simcall_BODY_file_get_size(fd);
1374 void *simcall_mc_snapshot(void)
1376 return simcall_BODY_mc_snapshot();
1379 int simcall_mc_compare_snapshots(void *s1, void *s2){
1380 return simcall_BODY_mc_compare_snapshots(s1, s2);
1383 int simcall_mc_random(void)
1385 return simcall_BODY_mc_random();
1389 #endif /* HAVE_MC */
1391 /* ****************************************************************************************** */
1392 /* TUTORIAL: New API */
1393 /* All functions for simcall */
1394 /* ****************************************************************************************** */
1395 int simcall_new_api_fct(const char* param1, double param2){
1396 smx_simcall_t simcall = SIMIX_simcall_mine();
1397 simcall->call = SIMCALL_NEW_API_INIT;
1398 simcall->new_api.param1 = param1;
1399 simcall->new_api.param2 = param2;
1401 SIMIX_simcall_push(simcall->issuer);
1402 return simcall->new_api.result;
1405 /* ************************************************************************** */
1407 /** @brief returns a printable string representing a simcall */
1408 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1409 return simcall_names[kind];