1 /* smx_user.c - public interface to simix */
3 /* Copyright (c) 2010-2013. 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"
12 #include <math.h> /* isfinite() */
14 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
16 /* generate strings from the enumeration values */
17 static const char* simcall_names[] = {
18 SIMCALL_LIST(SIMCALL_STRING_TYPE, SIMCALL_SEP_COMMA)
19 [SIMCALL_NONE] = "NONE"
22 SIMCALL_LIST(SIMCALL_FUNC, SIMCALL_SEP_NOTHING)
25 * \ingroup simix_host_management
26 * \brief Returns a host given its name.
28 * \param name The name of the host to get
29 * \return The corresponding host
31 smx_host_t simcall_host_get_by_name(const char *name)
33 return simcall_BODY_host_get_by_name(name);
37 * \ingroup simix_host_management
38 * \brief Returns the name of a host.
40 * \param host A SIMIX host
41 * \return The name of this host
43 const char* simcall_host_get_name(smx_host_t host)
45 return simcall_BODY_host_get_name(host);
49 * \ingroup simix_host_management
50 * \brief Start the host if it is off
52 * \param host A SIMIX host
54 void simcall_host_on(smx_host_t host)
56 simcall_BODY_host_on(host);
60 * \ingroup simix_host_management
61 * \brief Stop the host if it is on
63 * \param host A SIMIX host
65 void simcall_host_off(smx_host_t host)
67 simcall_BODY_host_off(host);
71 * \ingroup simix_host_management
72 * \brief Returns a dict of the properties assigned to a host.
75 * \return The properties of this host
77 xbt_dict_t simcall_host_get_properties(smx_host_t host)
79 return simcall_BODY_host_get_properties(host);
83 * \ingroup simix_host_management
84 * \brief Returns a dict of the properties assigned to a router or AS.
86 * \param name The name of the router or AS
87 * \return The properties
89 xbt_dict_t simcall_asr_get_properties(const char *name)
91 return simcall_BODY_asr_get_properties(name);
96 * \ingroup simix_host_management
97 * \brief Returns the speed of the processor.
99 * The speed returned does not take into account the current load on the machine.
100 * \param host A SIMIX host
101 * \return The speed of this host (in Mflop/s)
103 double simcall_host_get_speed(smx_host_t host)
105 return simcall_BODY_host_get_speed(host);
109 * \ingroup simix_host_management
110 * \brief Returns the number of core of the processor.
112 * \param host A SIMIX host
113 * \return The number of core
115 int simcall_host_get_core(smx_host_t host)
117 return simcall_BODY_host_get_core(host);
121 * \ingroup simix_host_management
122 * \brief Returns the list of processes attached to the host.
124 * \param host A SIMIX host
125 * \return the swag of attached processes
127 xbt_swag_t simcall_host_get_process_list(smx_host_t host)
129 return simcall_BODY_host_get_process_list(host);
134 * \ingroup simix_host_management
135 * \brief Returns the available speed of the processor.
137 * \return Speed currently available (in Mflop/s)
139 double simcall_host_get_available_speed(smx_host_t host)
141 return simcall_BODY_host_get_available_speed(host);
145 * \ingroup simix_host_management
146 * \brief Returns the state of a host.
148 * Two states are possible: 1 if the host is active or 0 if it has crashed.
149 * \param host A SIMIX host
150 * \return 1 if the host is available, 0 otherwise
152 int simcall_host_get_state(smx_host_t host)
154 return simcall_BODY_host_get_state(host);
158 * \ingroup simix_host_management
159 * \brief Returns the user data associated to a host.
161 * \param host SIMIX host
162 * \return the user data of this host
164 void* simcall_host_get_data(smx_host_t host)
166 return simcall_BODY_host_get_data(host);
170 * \ingroup simix_host_management
171 * \brief Sets the user data associated to a host.
173 * The host must not have previous user data associated to it.
174 * \param host A SIMIX host
175 * \param data The user data to set
177 void simcall_host_set_data(smx_host_t host, void *data)
179 simcall_host_set_data(host, data);
183 * \ingroup simix_host_management
184 * \brief Returns the power peak of a host.
186 * \param host A SIMIX host
187 * \return the current power peak value (double)
189 double simcall_host_get_current_power_peak(smx_host_t host)
191 return simcall_BODY_host_get_current_power_peak(host);
195 * \ingroup simix_host_management
196 * \brief Returns one power peak (in flops/s) of a host at a given pstate
198 * \param host A SIMIX host
199 * \param pstate_index pstate to test
200 * \return the current power peak value (double) for pstate_index
202 double simcall_host_get_power_peak_at(smx_host_t host, int pstate_index)
204 return simcall_BODY_host_get_power_peak_at(host, pstate_index);
208 * \ingroup simix_host_management
209 * \brief Returns the number of power states for a host.
211 * \param host A SIMIX host
212 * \return the number of power states
214 int simcall_host_get_nb_pstates(smx_host_t host)
216 return simcall_BODY_host_get_nb_pstates(host);
220 * \ingroup simix_host_management
221 * \brief Sets a new power peak for a host.
223 * \param host A SIMIX host
224 * \param pstate_index The pstate to which the CPU power will be set
227 void simcall_host_set_power_peak_at(smx_host_t host, int pstate_index)
229 simcall_BODY_host_set_power_peak_at(host, pstate_index);
233 * \ingroup simix_host_management
234 * \brief Returns the total energy consumed by the host (in Joules)
236 * \param host A SIMIX host
237 * \return the energy consumed by the host (double)
239 double simcall_host_get_consumed_energy(smx_host_t host)
241 return simcall_BODY_host_get_consumed_energy(host);
246 * \ingroup simix_host_management
247 * \brief Creates an action that executes some computation of an host.
249 * This function creates a SURF action and allocates the data necessary
250 * to create the SIMIX action. It can raise a host_error exception if the host crashed.
252 * \param name Name of the execution action to create
253 * \param host SIMIX host where the action will be executed
254 * \param computation_amount amount Computation amount (in bytes)
255 * \param priority computation priority
256 * \return A new SIMIX execution action
258 smx_action_t simcall_host_execute(const char *name, smx_host_t host,
259 double computation_amount,
260 double priority, double bound, unsigned long affinity_mask)
262 /* checking for infinite values */
263 xbt_assert(isfinite(computation_amount), "computation_amount is not finite!");
264 xbt_assert(isfinite(priority), "priority is not finite!");
266 return simcall_BODY_host_execute(name, host, computation_amount, priority, bound, affinity_mask);
270 * \ingroup simix_host_management
271 * \brief Creates an action that may involve parallel computation on
272 * several hosts and communication between them.
274 * \param name Name of the execution action to create
275 * \param host_nb Number of hosts where the action will be executed
276 * \param host_list Array (of size host_nb) of hosts where the action will be executed
277 * \param computation_amount Array (of size host_nb) of computation amount of hosts (in bytes)
278 * \param communication_amount Array (of size host_nb * host_nb) representing the communication
279 * amount between each pair of hosts
280 * \param amount the SURF action amount
281 * \param rate the SURF action rate
282 * \return A new SIMIX execution action
284 smx_action_t simcall_host_parallel_execute(const char *name,
286 smx_host_t *host_list,
287 double *computation_amount,
288 double *communication_amount,
293 /* checking for infinite values */
294 for (i = 0 ; i < host_nb ; ++i) {
295 xbt_assert(isfinite(computation_amount[i]), "computation_amount[%d] is not finite!", i);
296 for (j = 0 ; j < host_nb ; ++j) {
297 xbt_assert(isfinite(communication_amount[i + host_nb * j]),
298 "communication_amount[%d+%d*%d] is not finite!", i, host_nb, j);
302 xbt_assert(isfinite(amount), "amount is not finite!");
303 xbt_assert(isfinite(rate), "rate is not finite!");
305 return simcall_BODY_host_parallel_execute(name, host_nb, host_list,
307 communication_amount,
313 * \ingroup simix_host_management
314 * \brief Destroys an execution action.
316 * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
317 * \param execution The execution action to destroy
319 void simcall_host_execution_destroy(smx_action_t execution)
321 simcall_BODY_host_execution_destroy(execution);
325 * \ingroup simix_host_management
326 * \brief Cancels an execution action.
328 * This functions stops the execution. It calls a surf function.
329 * \param execution The execution action to cancel
331 void simcall_host_execution_cancel(smx_action_t execution)
333 simcall_BODY_host_execution_cancel(execution);
337 * \ingroup simix_host_management
338 * \brief Returns how much of an execution action remains to be done.
340 * \param execution The execution action
341 * \return The remaining amount
343 double simcall_host_execution_get_remains(smx_action_t execution)
345 return simcall_BODY_host_execution_get_remains(execution);
349 * \ingroup simix_host_management
350 * \brief Returns the state of an execution action.
352 * \param execution The execution action
355 e_smx_state_t simcall_host_execution_get_state(smx_action_t execution)
357 return simcall_BODY_host_execution_get_state(execution);
361 * \ingroup simix_host_management
362 * \brief Changes the priority of an execution action.
364 * This functions changes the priority only. It calls a surf function.
365 * \param execution The execution action
366 * \param priority The new priority
368 void simcall_host_execution_set_priority(smx_action_t execution, double priority)
370 /* checking for infinite values */
371 xbt_assert(isfinite(priority), "priority is not finite!");
373 simcall_BODY_host_execution_set_priority(execution, priority);
377 * \ingroup simix_host_management
378 * \brief Changes the capping (the maximum CPU utilization) of an execution action.
380 * This functions changes the capping only. It calls a surf function.
381 * \param execution The execution action
382 * \param bound The new bound
384 void simcall_host_execution_set_bound(smx_action_t execution, double bound)
386 simcall_BODY_host_execution_set_bound(execution, bound);
390 * \ingroup simix_host_management
391 * \brief Changes the CPU affinity of an execution action.
393 * This functions changes the CPU affinity of an execution action. See taskset(1) on Linux.
394 * \param execution The execution action
396 * \param mask Affinity mask
398 void simcall_host_execution_set_affinity(smx_action_t execution, smx_host_t host, unsigned long mask)
400 simcall_BODY_host_execution_set_affinity(execution, host, mask);
404 * \ingroup simix_host_management
405 * \brief Waits for the completion of an execution action and destroy it.
407 * \param execution The execution action
409 e_smx_state_t simcall_host_execution_wait(smx_action_t execution)
411 return simcall_BODY_host_execution_wait(execution);
416 * \ingroup simix_vm_management
417 * \brief Create a VM on the given physical host.
419 * \param name VM name
420 * \param host Physical host
422 * \return The host object of the VM
424 void* simcall_vm_create(const char *name, smx_host_t phys_host){
425 /* will jump to SIMIX_pre_vm_create() in src/simix/smx_smurf_private.h */
426 return simcall_BODY_vm_create(name, phys_host);
430 * \ingroup simix_vm_management
431 * \brief Start the given VM to the given physical host
435 void simcall_vm_start(smx_host_t vm)
437 /* will jump to SIMIX_pre_vm_start in src/simix/smx_smurf_private.h */
438 simcall_BODY_vm_start(vm);
442 * \ingroup simix_vm_management
443 * \brief Get the state of the given VM
446 * \return The state of the VM
448 int simcall_vm_get_state(smx_host_t vm)
450 /* will jump to SIMIX_pre_vm_get_state in src/simix/smx_smurf_private.h */
451 return simcall_BODY_vm_get_state(vm);
455 * \ingroup simix_vm_management
456 * \brief Get the name of the physical host on which the given VM runs.
459 * \return The name of the physical host
461 void *simcall_vm_get_pm(smx_host_t vm)
463 /* will jump to SIMIX_pre_vm_migrate in src/simix/smx_smurf_private.h */
464 return simcall_BODY_vm_get_pm(vm);
467 void simcall_vm_set_bound(smx_host_t vm, double bound)
469 /* will jump to SIMIX_pre_vm_set_bound in src/simix/smx_smurf_private.h */
470 simcall_BODY_vm_set_bound(vm, bound);
473 void simcall_vm_set_affinity(smx_host_t vm, smx_host_t pm, unsigned long mask)
475 /* will jump to SIMIX_pre_vm_set_affinity in src/simix/smx_smurf_private.h */
476 simcall_BODY_vm_set_affinity(vm, pm, mask);
479 void simcall_host_get_params(smx_host_t vm, ws_params_t params)
481 /* will jump to SIMIX_pre_host_get_params in src/simix/smx_smurf_private.h */
482 simcall_BODY_host_get_params(vm, params);
485 void simcall_host_set_params(smx_host_t vm, ws_params_t params)
487 /* will jump to SIMIX_pre_host_set_params in src/simix/smx_smurf_private.h */
488 simcall_BODY_host_set_params(vm, params);
492 * \ingroup simix_vm_management
493 * \brief Migrate the given VM to the given physical host
496 * \param host Destination physical host
498 void simcall_vm_migrate(smx_host_t vm, smx_host_t host)
500 /* will jump to SIMIX_pre_vm_migrate in src/simix/smx_smurf_private.h */
501 simcall_BODY_vm_migrate(vm, host);
505 * \ingroup simix_vm_management
506 * \brief Suspend the given VM
510 void simcall_vm_suspend(smx_host_t vm)
512 /* will jump to SIMIX_pre_vm_suspend in src/simix/smx_smurf_private.h */
513 simcall_BODY_vm_suspend(vm);
517 * \ingroup simix_vm_management
518 * \brief Resume the given VM
522 void simcall_vm_resume(smx_host_t vm)
524 /* will jump to SIMIX_pre_vm_resume in src/simix/smx_smurf_private.h */
525 simcall_BODY_vm_resume(vm);
529 * \ingroup simix_vm_management
530 * \brief Save the given VM
534 void simcall_vm_save(smx_host_t vm)
536 /* will jump to SIMIX_pre_vm_save in src/simix/smx_smurf_private.h */
537 simcall_BODY_vm_save(vm);
541 * \ingroup simix_vm_management
542 * \brief Restore the given VM
546 void simcall_vm_restore(smx_host_t vm)
548 /* will jump to SIMIX_pre_vm_restore in src/simix/smx_smurf_private.h */
549 simcall_BODY_vm_restore(vm);
553 * \ingroup simix_vm_management
554 * \brief Shutdown the given VM
558 void simcall_vm_shutdown(smx_host_t vm)
560 /* will jump to SIMIX_pre_vm_shutdown in src/simix/smx_smurf_private.h */
561 simcall_BODY_vm_shutdown(vm);
565 * \ingroup simix_vm_management
566 * \brief Destroy the given VM
570 void simcall_vm_destroy(smx_host_t vm)
572 /* will jump to SIMIX_pre_vm_destroy in src/simix/smx_smurf_private.h */
573 simcall_BODY_vm_destroy(vm);
578 * \ingroup simix_process_management
579 * \brief Creates and runs a new SIMIX process.
581 * The structure and the corresponding thread are created and put in the list of ready processes.
583 * \param process the process created will be stored in this pointer
584 * \param name a name for the process. It is for user-level information and can be NULL.
585 * \param code the main function of the process
586 * \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.
587 * It can be retrieved with the function \ref simcall_process_get_data.
588 * \param hostname name of the host where the new agent is executed.
589 * \param kill_time time when the process is killed
590 * \param argc first argument passed to \a code
591 * \param argv second argument passed to \a code
592 * \param properties the properties of the process
593 * \param auto_restart either it is autorestarting or not.
595 void simcall_process_create(smx_process_t *process, const char *name,
596 xbt_main_func_t code,
598 const char *hostname,
600 int argc, char **argv,
601 xbt_dict_t properties,
604 simcall_BODY_process_create(process, name, code, data, hostname,
605 kill_time, argc, argv, properties,
610 * \ingroup simix_process_management
611 * \brief Kills a SIMIX process.
613 * This function simply kills a process.
615 * \param process poor victim
617 void simcall_process_kill(smx_process_t process)
619 simcall_BODY_process_kill(process);
623 * \ingroup simix_process_management
624 * \brief Kills all SIMIX processes.
626 void simcall_process_killall(int reset_pid)
628 simcall_BODY_process_killall(reset_pid);
632 * \ingroup simix_process_management
633 * \brief Cleans up a SIMIX process.
634 * \param process poor victim (must have already been killed)
636 void simcall_process_cleanup(smx_process_t process)
638 simcall_BODY_process_cleanup(process);
642 * \ingroup simix_process_management
643 * \brief Migrates an agent to another location.
645 * This function changes the value of the host on which \a process is running.
647 * \param process the process to migrate
648 * \param dest name of the new host
650 void simcall_process_change_host(smx_process_t process, smx_host_t dest)
652 simcall_BODY_process_change_host(process, dest);
656 * \ingroup simix_process_management
657 * \brief Suspends a process.
659 * This function suspends the process by suspending the action
660 * it was waiting for completion.
662 * \param process a SIMIX process
664 void simcall_process_suspend(smx_process_t process)
666 xbt_assert(process, "Invalid parameters");
668 simcall_BODY_process_suspend(process);
672 * \ingroup simix_process_management
673 * \brief Resumes a suspended process.
675 * This function resumes a suspended process by resuming the action
676 * it was waiting for completion.
678 * \param process a SIMIX process
680 void simcall_process_resume(smx_process_t process)
682 simcall_BODY_process_resume(process);
686 * \ingroup simix_process_management
687 * \brief Returns the amount of SIMIX processes in the system
689 * Maestro internal process is not counted, only user code processes are
691 int simcall_process_count(void)
693 return simcall_BODY_process_count();
697 * \ingroup simix_process_management
698 * \brief Return the PID of a #smx_process_t.
699 * \param process a SIMIX process
700 * \return the PID of this process
702 int simcall_process_get_PID(smx_process_t process)
704 if (process == SIMIX_process_self()) {
705 /* avoid a simcall if this function is called by the process itself */
706 return SIMIX_process_get_PID(process);
709 return simcall_BODY_process_get_PID(process);
713 * \ingroup simix_process_management
714 * \brief Return the parent PID of a #smx_process_t.
715 * \param process a SIMIX process
716 * \return the PID of this process parenrt
718 int simcall_process_get_PPID(smx_process_t process)
720 if (process == SIMIX_process_self()) {
721 /* avoid a simcall if this function is called by the process itself */
722 return SIMIX_process_get_PPID(process);
725 return simcall_BODY_process_get_PPID(process);
729 * \ingroup simix_process_management
730 * \brief Return the user data of a #smx_process_t.
731 * \param process a SIMIX process
732 * \return the user data of this process
734 void* simcall_process_get_data(smx_process_t process)
736 if (process == SIMIX_process_self()) {
737 /* avoid a simcall if this function is called by the process itself */
738 return SIMIX_process_get_data(process);
741 return simcall_BODY_process_get_data(process);
745 * \ingroup simix_process_management
746 * \brief Set the user data of a #smx_process_t.
748 * This functions sets the user data associated to \a process.
749 * \param process SIMIX process
750 * \param data User data
752 void simcall_process_set_data(smx_process_t process, void *data)
754 if (process == SIMIX_process_self()) {
755 /* avoid a simcall if this function is called by the process itself */
756 SIMIX_process_self_set_data(process, data);
759 simcall_BODY_process_set_data(process, data);
764 * \ingroup simix_process_management
765 * \brief Set the kill time of a process.
766 * \param process a process
767 * \param kill_time a double
769 void simcall_process_set_kill_time(smx_process_t process, double kill_time)
772 if (kill_time > SIMIX_get_clock()) {
773 if (simix_global->kill_process_function) {
774 XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name,
775 sg_host_name(process->smx_host));
776 SIMIX_timer_set(kill_time, simix_global->kill_process_function, process);
782 * \ingroup simix_process_management
783 * \brief Return the location on which an agent is running.
785 * This functions returns the smx_host_t corresponding to the location on which
786 * \a process is running.
787 * \param process SIMIX process
790 smx_host_t simcall_process_get_host(smx_process_t process)
792 return simcall_BODY_process_get_host(process);
796 * \ingroup simix_process_management
797 * \brief Return the name of an agent.
799 * This functions checks whether \a process is a valid pointer or not and return its name.
800 * \param process SIMIX process
801 * \return The process name
803 const char* simcall_process_get_name(smx_process_t process)
805 if (process == SIMIX_process_self()) {
806 /* avoid a simcall if this function is called by the process itself */
807 return process->name;
809 return simcall_BODY_process_get_name(process);
813 * \ingroup simix_process_management
814 * \brief Returns true if the process is suspended .
816 * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
817 * \param process SIMIX process
818 * \return 1, if the process is suspended, else 0.
820 int simcall_process_is_suspended(smx_process_t process)
822 return simcall_BODY_process_is_suspended(process);
826 * \ingroup simix_process_management
827 * \brief Return the properties
829 * This functions returns the properties associated with this process
831 xbt_dict_t simcall_process_get_properties(smx_process_t process)
833 return simcall_BODY_process_get_properties(process);
836 * \ingroup simix_process_management
837 * \brief Add an on_exit function
838 * Add an on_exit function which will be executed when the process exits/is killed.
840 XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_t fun, void *data)
842 simcall_BODY_process_on_exit(process, fun, data);
845 * \ingroup simix_process_management
846 * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up.
847 * Will restart the process when the host comes back up if auto_restart is set to 1.
850 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart)
852 simcall_BODY_process_auto_restart_set(process, auto_restart);
856 * \ingroup simix_process_management
857 * \brief Restarts the process, killing it and starting it again from scratch.
859 XBT_PUBLIC(smx_process_t) simcall_process_restart(smx_process_t process)
861 return simcall_BODY_process_restart(process);
864 * \ingroup simix_process_management
865 * \brief Creates a new sleep SIMIX action.
867 * This function creates a SURF action and allocates the data necessary
868 * to create the SIMIX action. It can raise a host_error exception if the
869 * host crashed. The default SIMIX name of the action is "sleep".
871 * \param duration Time duration of the sleep.
872 * \return A result telling whether the sleep was successful
874 e_smx_state_t simcall_process_sleep(double duration)
876 /* checking for infinite values */
877 xbt_assert(isfinite(duration), "duration is not finite!");
878 return simcall_BODY_process_sleep(duration);
882 * \ingroup simix_rdv_management
883 * \brief Creates a new rendez-vous point
884 * \param name The name of the rendez-vous point
885 * \return The created rendez-vous point
887 smx_rdv_t simcall_rdv_create(const char *name)
889 return simcall_BODY_rdv_create(name);
894 * \ingroup simix_rdv_management
895 * \brief Destroy a rendez-vous point
896 * \param rdv The rendez-vous point to destroy
898 void simcall_rdv_destroy(smx_rdv_t rdv)
900 simcall_BODY_rdv_destroy(rdv);
903 * \ingroup simix_rdv_management
904 * \brief Returns a rendez-vous point knowing its name
906 smx_rdv_t simcall_rdv_get_by_name(const char *name)
908 xbt_assert(name != NULL, "Invalid parameter for simcall_rdv_get_by_name (name is NULL)");
910 /* FIXME: this is a horrible loss of performance, so we hack it out by
911 * skipping the simcall (for now). It works in parallel, it won't work on
912 * distributed but probably we will change MSG for that. */
915 smx_simcall_t simcall = simcall_mine();
916 simcall->call = SIMCALL_RDV_GEY_BY_NAME;
917 simcall->rdv_get_by_name.name = name;
918 SIMIX_simcall_push(simcall->issuer);
919 return simcall->rdv_get_by_name.result;*/
921 return SIMIX_rdv_get_by_name(name);
925 * \ingroup simix_rdv_management
926 * \brief Counts the number of communication actions of a given host pending
927 * on a rendez-vous point.
928 * \param rdv The rendez-vous point
929 * \param host The host to be counted
930 * \return The number of comm actions pending in the rdv
932 int simcall_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
934 return simcall_BODY_rdv_comm_count_by_host(rdv, host);
938 * \ingroup simix_rdv_management
939 * \brief returns the communication at the head of the rendez-vous
940 * \param rdv The rendez-vous point
941 * \return The communication or NULL if empty
943 smx_action_t simcall_rdv_get_head(smx_rdv_t rdv)
945 return simcall_BODY_rdv_get_head(rdv);
948 void simcall_rdv_set_receiver(smx_rdv_t rdv, smx_process_t process)
950 simcall_BODY_rdv_set_receiver(rdv, process);
953 smx_process_t simcall_rdv_get_receiver(smx_rdv_t rdv)
955 return simcall_BODY_rdv_get_receiver(rdv);
959 * \ingroup simix_comm_management
961 void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate,
962 void *src_buff, size_t src_buff_size,
963 int (*match_fun)(void *, void *, smx_action_t), void *data,
966 /* checking for infinite values */
967 xbt_assert(isfinite(task_size), "task_size is not finite!");
968 xbt_assert(isfinite(rate), "rate is not finite!");
969 xbt_assert(isfinite(timeout), "timeout is not finite!");
971 xbt_assert(rdv, "No rendez-vous point defined for send");
973 if (MC_is_active()) {
974 /* the model-checker wants two separate simcalls */
975 smx_action_t comm = NULL; /* MC needs the comm to be set to NULL during the simcall */
976 comm = simcall_comm_isend(rdv, task_size, rate,
977 src_buff, src_buff_size, match_fun, NULL, data, 0);
978 simcall_comm_wait(comm, timeout);
982 simcall_BODY_comm_send(rdv, task_size, rate, src_buff, src_buff_size,
983 match_fun, data, timeout);
988 * \ingroup simix_comm_management
990 smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate,
991 void *src_buff, size_t src_buff_size,
992 int (*match_fun)(void *, void *, smx_action_t),
993 void (*clean_fun)(void *),
997 /* checking for infinite values */
998 xbt_assert(isfinite(task_size), "task_size is not finite!");
999 xbt_assert(isfinite(rate), "rate is not finite!");
1001 xbt_assert(rdv, "No rendez-vous point defined for isend");
1003 return simcall_BODY_comm_isend(rdv, task_size, rate, src_buff,
1004 src_buff_size, match_fun,
1005 clean_fun, data, detached);
1008 * \ingroup simix_comm_management
1010 void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
1011 int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout)
1013 xbt_assert(isfinite(timeout), "timeout is not finite!");
1014 xbt_assert(rdv, "No rendez-vous point defined for recv");
1016 if (MC_is_active()) {
1017 /* the model-checker wants two separate simcalls */
1018 smx_action_t comm = NULL; /* MC needs the comm to be set to NULL during the simcall */
1019 comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
1021 simcall_comm_wait(comm, timeout);
1025 simcall_BODY_comm_recv(rdv, dst_buff, dst_buff_size,
1026 match_fun, data, timeout);
1030 * \ingroup simix_comm_management
1032 smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size,
1033 int (*match_fun)(void *, void *, smx_action_t), void *data)
1035 xbt_assert(rdv, "No rendez-vous point defined for irecv");
1037 return simcall_BODY_comm_irecv(rdv, dst_buff, dst_buff_size,
1043 * \ingroup simix_comm_management
1045 void simcall_comm_recv_bounded(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
1046 int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout, double rate)
1048 xbt_assert(isfinite(timeout), "timeout is not finite!");
1049 xbt_assert(rdv, "No rendez-vous point defined for recv");
1051 if (MC_is_active()) {
1052 /* the model-checker wants two separate simcalls */
1053 smx_action_t comm = simcall_comm_irecv_bounded(rdv, dst_buff, dst_buff_size,
1054 match_fun, data, rate);
1055 simcall_comm_wait(comm, timeout);
1058 simcall_BODY_comm_recv_bounded(rdv, dst_buff, dst_buff_size,
1059 match_fun, data, timeout, rate);
1063 * \ingroup simix_comm_management
1065 smx_action_t simcall_comm_irecv_bounded(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size,
1066 int (*match_fun)(void *, void *, smx_action_t), void *data, double rate)
1068 xbt_assert(rdv, "No rendez-vous point defined for irecv");
1070 return simcall_BODY_comm_irecv_bounded(rdv, dst_buff, dst_buff_size,
1071 match_fun, data, rate);
1076 * \ingroup simix_comm_management
1078 smx_action_t simcall_comm_iprobe(smx_rdv_t rdv, int src, int tag,
1079 int (*match_fun)(void *, void *, smx_action_t), void *data)
1081 xbt_assert(rdv, "No rendez-vous point defined for iprobe");
1083 return simcall_BODY_comm_iprobe(rdv, src, tag, match_fun, data);
1086 void simcall_comm_destroy(smx_action_t comm)
1088 xbt_assert(comm, "Invalid parameter");
1090 /* FIXME remove this simcall type: comms are auto-destroyed now */
1093 smx_simcall_t simcall = simcall_mine();
1095 simcall->call = SIMCALL_COMM_DESTROY;
1096 simcall->comm_destroy.comm = comm;
1098 SIMIX_simcall_push(simcall->issuer);
1103 * \ingroup simix_comm_management
1105 void simcall_comm_cancel(smx_action_t comm)
1107 simcall_BODY_comm_cancel(comm);
1111 * \ingroup simix_comm_management
1113 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
1115 return simcall_BODY_comm_waitany(comms);
1119 * \ingroup simix_comm_management
1121 int simcall_comm_testany(xbt_dynar_t comms)
1123 if (xbt_dynar_is_empty(comms))
1125 return simcall_BODY_comm_testany(comms);
1129 * \ingroup simix_comm_management
1131 void simcall_comm_wait(smx_action_t comm, double timeout)
1133 xbt_assert(isfinite(timeout), "timeout is not finite!");
1134 simcall_BODY_comm_wait(comm, timeout);
1139 * \brief Set the category of an action.
1141 * This functions changes the category only. It calls a surf function.
1142 * \param execution The execution action
1143 * \param category The tracing category
1145 void simcall_set_category(smx_action_t action, const char *category)
1147 if (category == NULL) {
1150 simcall_BODY_set_category(action, category);
1155 * \ingroup simix_comm_management
1158 int simcall_comm_test(smx_action_t comm)
1160 return simcall_BODY_comm_test(comm);
1164 * \ingroup simix_comm_management
1167 double simcall_comm_get_remains(smx_action_t comm)
1169 return simcall_BODY_comm_get_remains(comm);
1173 * \ingroup simix_comm_management
1176 e_smx_state_t simcall_comm_get_state(smx_action_t comm)
1178 return simcall_BODY_comm_get_state(comm);
1182 * \ingroup simix_comm_management
1185 void *simcall_comm_get_src_data(smx_action_t comm)
1187 return simcall_BODY_comm_get_src_data(comm);
1191 * \ingroup simix_comm_management
1194 void *simcall_comm_get_dst_data(smx_action_t comm)
1196 return simcall_BODY_comm_get_dst_data(comm);
1200 * \ingroup simix_comm_management
1203 smx_process_t simcall_comm_get_src_proc(smx_action_t comm)
1205 return simcall_BODY_comm_get_src_proc(comm);
1209 * \ingroup simix_comm_management
1212 smx_process_t simcall_comm_get_dst_proc(smx_action_t comm)
1214 return simcall_BODY_comm_get_dst_proc(comm);
1217 #ifdef HAVE_LATENCY_BOUND_TRACKING
1218 int simcall_comm_is_latency_bounded(smx_action_t comm)
1220 return simcall_BODY_comm_is_latency_bounded(comm);
1225 * \ingroup simix_synchro_management
1228 smx_mutex_t simcall_mutex_init(void)
1231 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
1234 return simcall_BODY_mutex_init();
1238 * \ingroup simix_synchro_management
1241 void simcall_mutex_destroy(smx_mutex_t mutex)
1243 simcall_BODY_mutex_destroy(mutex);
1247 * \ingroup simix_synchro_management
1250 void simcall_mutex_lock(smx_mutex_t mutex)
1252 simcall_BODY_mutex_lock(mutex);
1256 * \ingroup simix_synchro_management
1259 int simcall_mutex_trylock(smx_mutex_t mutex)
1261 return simcall_BODY_mutex_trylock(mutex);
1265 * \ingroup simix_synchro_management
1268 void simcall_mutex_unlock(smx_mutex_t mutex)
1270 simcall_BODY_mutex_unlock(mutex);
1274 * \ingroup simix_synchro_management
1277 smx_cond_t simcall_cond_init(void)
1279 return simcall_BODY_cond_init();
1283 * \ingroup simix_synchro_management
1286 void simcall_cond_destroy(smx_cond_t cond)
1288 simcall_BODY_cond_destroy(cond);
1292 * \ingroup simix_synchro_management
1295 void simcall_cond_signal(smx_cond_t cond)
1297 simcall_BODY_cond_signal(cond);
1301 * \ingroup simix_synchro_management
1304 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1306 simcall_BODY_cond_wait(cond, mutex);
1310 * \ingroup simix_synchro_management
1313 void simcall_cond_wait_timeout(smx_cond_t cond,
1317 xbt_assert(isfinite(timeout), "timeout is not finite!");
1318 simcall_BODY_cond_wait_timeout(cond, mutex, timeout);
1322 * \ingroup simix_synchro_management
1325 void simcall_cond_broadcast(smx_cond_t cond)
1327 simcall_BODY_cond_broadcast(cond);
1331 * \ingroup simix_synchro_management
1334 smx_sem_t simcall_sem_init(int capacity)
1336 return simcall_BODY_sem_init(capacity);
1340 * \ingroup simix_synchro_management
1343 void simcall_sem_destroy(smx_sem_t sem)
1345 simcall_sem_destroy(sem);
1349 * \ingroup simix_synchro_management
1352 void simcall_sem_release(smx_sem_t sem)
1354 simcall_BODY_sem_release(sem);
1358 * \ingroup simix_synchro_management
1361 int simcall_sem_would_block(smx_sem_t sem)
1363 return simcall_BODY_sem_would_block(sem);
1367 * \ingroup simix_synchro_management
1370 void simcall_sem_acquire(smx_sem_t sem)
1372 simcall_BODY_sem_acquire(sem);
1376 * \ingroup simix_synchro_management
1379 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1381 xbt_assert(isfinite(timeout), "timeout is not finite!");
1382 simcall_BODY_sem_acquire_timeout(sem, timeout);
1386 * \ingroup simix_synchro_management
1389 int simcall_sem_get_capacity(smx_sem_t sem)
1391 return simcall_BODY_sem_get_capacity(sem);
1395 * \ingroup simix_file_management
1396 * \brief Returns the user data associated to a file.
1398 * \param fd A simix file
1399 * \return the user data of this file
1401 void* simcall_file_get_data(smx_file_t fd)
1403 return simcall_BODY_file_get_data(fd);
1407 * \ingroup simix_file_management
1408 * \brief Sets the user data associated to a file.
1410 * \param fd A SIMIX file
1411 * \param data The user data to set
1413 void simcall_file_set_data(smx_file_t fd, void *data)
1415 simcall_file_set_data(fd, data);
1419 * \ingroup simix_file_management
1422 sg_storage_size_t simcall_file_read(smx_file_t fd, sg_storage_size_t size)
1424 return simcall_BODY_file_read(fd, size);
1428 * \ingroup simix_file_management
1431 sg_storage_size_t simcall_file_write(smx_file_t fd, sg_storage_size_t size)
1433 return simcall_BODY_file_write(fd, size);
1437 * \ingroup simix_file_management
1440 smx_file_t simcall_file_open(const char* mount, const char* path)
1442 return simcall_BODY_file_open(mount, path);
1446 * \ingroup simix_file_management
1449 int simcall_file_close(smx_file_t fd)
1451 return simcall_BODY_file_close(fd);
1455 * \ingroup simix_file_management
1458 int simcall_file_unlink(smx_file_t fd)
1460 return simcall_BODY_file_unlink(fd);
1464 * \ingroup simix_file_management
1467 xbt_dict_t simcall_file_ls(const char* mount, const char* path)
1469 return simcall_BODY_file_ls(mount, path);
1472 * \ingroup simix_file_management
1475 sg_storage_size_t simcall_file_get_size (smx_file_t fd){
1476 return simcall_BODY_file_get_size(fd);
1480 * \ingroup simix_file_management
1483 xbt_dynar_t simcall_file_get_info(smx_file_t fd)
1485 return simcall_BODY_file_get_info(fd);
1489 * \ingroup simix_file_management
1492 void simcall_storage_file_rename(smx_storage_t storage, const char* src, const char* dest)
1494 return simcall_BODY_storage_file_rename(storage, src, dest);
1498 * \ingroup simix_storage_management
1499 * \brief Returns the free space size on a given storage element.
1500 * \param storage name
1501 * \return Return the free space size on a given storage element (as sg_storage_size_t)
1503 sg_storage_size_t simcall_storage_get_free_size (const char* name){
1504 return simcall_BODY_storage_get_free_size(name);
1508 * \ingroup simix_storage_management
1509 * \brief Returns the used space size on a given storage element.
1510 * \param storage name
1511 * \return Return the used space size on a given storage element (as sg_storage_size_t)
1513 sg_storage_size_t simcall_storage_get_used_size (const char* name){
1514 return simcall_BODY_storage_get_used_size(name);
1518 * \ingroup simix_storage_management
1519 * \brief Returns the list of storages mounted on an host.
1520 * \param host A SIMIX host
1521 * \return a dict containing all storages mounted on the host
1523 xbt_dict_t simcall_host_get_storage_list(smx_host_t host)
1525 return simcall_BODY_host_get_storage_list(host);
1529 * \ingroup simix_storage_management
1530 * \brief Returns a dict of the properties assigned to a storage element.
1532 * \param storage A storage element
1533 * \return The properties of this storage element
1535 xbt_dict_t simcall_storage_get_properties(smx_storage_t storage)
1537 return simcall_BODY_storage_get_properties(storage);
1541 * \ingroup simix_storage_management
1542 * \brief Returns a dict containing the content of a storage element.
1544 * \param storage A storage element
1545 * \return The content of this storage element as a dict (full path file => size)
1547 xbt_dict_t simcall_storage_get_content(smx_storage_t storage)
1549 return simcall_BODY_storage_get_content(storage);
1554 void *simcall_mc_snapshot(void)
1556 return simcall_BODY_mc_snapshot();
1559 int simcall_mc_compare_snapshots(void *s1, void *s2){
1560 return simcall_BODY_mc_compare_snapshots(s1, s2);
1563 int simcall_mc_random(int min, int max)
1565 return simcall_BODY_mc_random(min, max);
1569 #endif /* HAVE_MC */
1571 /* ****************************************************************************************** */
1572 /* TUTORIAL: New API */
1573 /* All functions for simcall */
1574 /* ****************************************************************************************** */
1575 int simcall_new_api_fct(const char* param1, double param2){
1576 smx_simcall_t simcall = SIMIX_simcall_mine();
1577 simcall->call = SIMCALL_NEW_API_INIT;
1578 simcall->new_api.param1 = param1;
1579 simcall->new_api.param2 = param2;
1581 SIMIX_simcall_push(simcall->issuer);
1582 return simcall->new_api.result;
1585 /* ************************************************************************** */
1587 /** @brief returns a printable string representing a simcall */
1588 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1589 return simcall_names[kind];