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 "simcalls_generated_body.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 /* will jump to SIMIX_pre_vm_create() in src/simix/smx_smurf_private.h */
396 return simcall_BODY_vm_create(name, phys_host);
400 * \ingroup simix_vm_management
401 * \brief Start the given VM to the given physical host
405 void simcall_vm_start(smx_host_t vm)
407 /* will jump to SIMIX_pre_vm_start in src/simix/smx_smurf_private.h */
408 simcall_BODY_vm_start(vm);
412 * \ingroup simix_vm_management
413 * \brief Get the state of the given VM
416 * \return The state of the VM
418 int simcall_vm_get_state(smx_host_t vm)
420 /* will jump to SIMIX_pre_vm_get_state in src/simix/smx_smurf_private.h */
421 return simcall_BODY_vm_get_state(vm);
425 * \ingroup simix_vm_management
426 * \brief Get the name of the physical host on which the given VM runs.
429 * \return The name of the physical host
431 void *simcall_vm_get_pm(smx_host_t vm)
433 /* will jump to SIMIX_pre_vm_get_pm in src/simix/smx_smurf_private.h */
434 return simcall_BODY_vm_get_pm(vm);
437 void simcall_vm_set_bound(smx_host_t vm, double bound)
439 /* will jump to SIMIX_pre_vm_set_bound in src/simix/smx_smurf_private.h */
440 simcall_BODY_vm_set_bound(vm, bound);
443 void simcall_vm_set_affinity(smx_host_t vm, smx_host_t pm, unsigned long mask)
445 /* will jump to SIMIX_pre_vm_set_affinity in src/simix/smx_smurf_private.h */
446 simcall_BODY_vm_set_affinity(vm, pm, mask);
449 void simcall_host_get_params(smx_host_t vm, ws_params_t params)
451 /* will jump to SIMIX_pre_host_get_params in src/simix/smx_smurf_private.h */
452 simcall_BODY_host_get_params(vm, params);
455 void simcall_host_set_params(smx_host_t vm, ws_params_t params)
457 /* will jump to SIMIX_pre_host_set_params in src/simix/smx_smurf_private.h */
458 simcall_BODY_host_set_params(vm, params);
462 * \ingroup simix_vm_management
463 * \brief Migrate the given VM to the given physical host
466 * \param host Destination physical host
468 void simcall_vm_migrate(smx_host_t vm, smx_host_t host)
470 /* will jump to SIMIX_pre_vm_migrate in src/simix/smx_smurf_private.h */
471 simcall_BODY_vm_migrate(vm, host);
475 * \ingroup simix_vm_management
476 * \brief Suspend the given VM
480 void simcall_vm_suspend(smx_host_t vm)
482 /* will jump to SIMIX_pre_vm_suspend in src/simix/smx_smurf_private.h */
483 simcall_BODY_vm_suspend(vm);
487 * \ingroup simix_vm_management
488 * \brief Resume the given VM
492 void simcall_vm_resume(smx_host_t vm)
494 /* will jump to SIMIX_pre_vm_resume in src/simix/smx_smurf_private.h */
495 simcall_BODY_vm_resume(vm);
499 * \ingroup simix_vm_management
500 * \brief Save the given VM
504 void simcall_vm_save(smx_host_t vm)
506 /* will jump to SIMIX_pre_vm_save in src/simix/smx_smurf_private.h */
507 simcall_BODY_vm_save(vm);
511 * \ingroup simix_vm_management
512 * \brief Restore the given VM
516 void simcall_vm_restore(smx_host_t vm)
518 /* will jump to SIMIX_pre_vm_restore in src/simix/smx_smurf_private.h */
519 simcall_BODY_vm_restore(vm);
523 * \ingroup simix_vm_management
524 * \brief Shutdown the given VM
528 void simcall_vm_shutdown(smx_host_t vm)
530 /* will jump to SIMIX_pre_vm_shutdown in src/simix/smx_smurf_private.h */
531 simcall_BODY_vm_shutdown(vm);
535 * \ingroup simix_vm_management
536 * \brief Destroy the given VM
540 void simcall_vm_destroy(smx_host_t vm)
542 /* will jump to SIMIX_pre_vm_destroy in src/simix/smx_smurf_private.h */
543 simcall_BODY_vm_destroy(vm);
548 * \ingroup simix_process_management
549 * \brief Creates and runs a new SIMIX process.
551 * The structure and the corresponding thread are created and put in the list of ready processes.
553 * \param process the process created will be stored in this pointer
554 * \param name a name for the process. It is for user-level information and can be NULL.
555 * \param code the main function of the process
556 * \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.
557 * It can be retrieved with the function \ref simcall_process_get_data.
558 * \param hostname name of the host where the new agent is executed.
559 * \param kill_time time when the process is killed
560 * \param argc first argument passed to \a code
561 * \param argv second argument passed to \a code
562 * \param properties the properties of the process
563 * \param auto_restart either it is autorestarting or not.
565 void simcall_process_create(smx_process_t *process, const char *name,
566 xbt_main_func_t code,
568 const char *hostname,
570 int argc, char **argv,
571 xbt_dict_t properties,
574 simcall_BODY_process_create(process, name, code, data, hostname,
575 kill_time, argc, argv, properties,
580 * \ingroup simix_process_management
581 * \brief Kills a SIMIX process.
583 * This function simply kills a process.
585 * \param process poor victim
587 void simcall_process_kill(smx_process_t process)
589 simcall_BODY_process_kill(process);
593 * \ingroup simix_process_management
594 * \brief Kills all SIMIX processes.
596 void simcall_process_killall(int reset_pid)
598 simcall_BODY_process_killall(reset_pid);
602 * \ingroup simix_process_management
603 * \brief Cleans up a SIMIX process.
604 * \param process poor victim (must have already been killed)
606 void simcall_process_cleanup(smx_process_t process)
608 simcall_BODY_process_cleanup(process);
612 * \ingroup simix_process_management
613 * \brief Migrates an agent to another location.
615 * This function changes the value of the host on which \a process is running.
617 * \param process the process to migrate
618 * \param dest name of the new host
620 void simcall_process_change_host(smx_process_t process, smx_host_t dest)
622 simcall_BODY_process_change_host(process, dest);
625 void simcall_process_join(smx_process_t process, double timeout)
627 simcall_BODY_process_join(process, timeout);
631 * \ingroup simix_process_management
632 * \brief Suspends a process.
634 * This function suspends the process by suspending the action
635 * it was waiting for completion.
637 * \param process a SIMIX process
639 void simcall_process_suspend(smx_process_t process)
641 xbt_assert(process, "Invalid parameters");
643 simcall_BODY_process_suspend(process);
647 * \ingroup simix_process_management
648 * \brief Resumes a suspended process.
650 * This function resumes a suspended process by resuming the action
651 * it was waiting for completion.
653 * \param process a SIMIX process
655 void simcall_process_resume(smx_process_t process)
657 simcall_BODY_process_resume(process);
661 * \ingroup simix_process_management
662 * \brief Returns the amount of SIMIX processes in the system
664 * Maestro internal process is not counted, only user code processes are
666 int simcall_process_count(void)
668 return simcall_BODY_process_count();
672 * \ingroup simix_process_management
673 * \brief Return the PID of a #smx_process_t.
674 * \param process a SIMIX process
675 * \return the PID of this process
677 int simcall_process_get_PID(smx_process_t process)
679 if (process == SIMIX_process_self()) {
680 /* avoid a simcall if this function is called by the process itself */
681 return SIMIX_process_get_PID(process);
684 return simcall_BODY_process_get_PID(process);
688 * \ingroup simix_process_management
689 * \brief Return the parent PID of a #smx_process_t.
690 * \param process a SIMIX process
691 * \return the PID of this process parenrt
693 int simcall_process_get_PPID(smx_process_t process)
695 if (process == SIMIX_process_self()) {
696 /* avoid a simcall if this function is called by the process itself */
697 return SIMIX_process_get_PPID(process);
700 return simcall_BODY_process_get_PPID(process);
704 * \ingroup simix_process_management
705 * \brief Return the user data of a #smx_process_t.
706 * \param process a SIMIX process
707 * \return the user data of this process
709 void* simcall_process_get_data(smx_process_t process)
711 if (process == SIMIX_process_self()) {
712 /* avoid a simcall if this function is called by the process itself */
713 return SIMIX_process_get_data(process);
716 return simcall_BODY_process_get_data(process);
720 * \ingroup simix_process_management
721 * \brief Set the user data of a #smx_process_t.
723 * This functions sets the user data associated to \a process.
724 * \param process SIMIX process
725 * \param data User data
727 void simcall_process_set_data(smx_process_t process, void *data)
729 if (process == SIMIX_process_self()) {
730 /* avoid a simcall if this function is called by the process itself */
731 SIMIX_process_self_set_data(process, data);
734 simcall_BODY_process_set_data(process, data);
739 * \ingroup simix_process_management
740 * \brief Set the kill time of a process.
741 * \param process a process
742 * \param kill_time a double
744 void simcall_process_set_kill_time(smx_process_t process, double kill_time)
747 if (kill_time > SIMIX_get_clock()) {
748 if (simix_global->kill_process_function) {
749 XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name,
750 sg_host_name(process->smx_host));
751 SIMIX_timer_set(kill_time, simix_global->kill_process_function, process);
757 * \ingroup simix_process_management
758 * \brief Return the location on which an agent is running.
760 * This functions returns the smx_host_t corresponding to the location on which
761 * \a process is running.
762 * \param process SIMIX process
765 smx_host_t simcall_process_get_host(smx_process_t process)
767 return simcall_BODY_process_get_host(process);
771 * \ingroup simix_process_management
772 * \brief Return the name of an agent.
774 * This functions checks whether \a process is a valid pointer or not and return its name.
775 * \param process SIMIX process
776 * \return The process name
778 const char* simcall_process_get_name(smx_process_t process)
780 if (process == SIMIX_process_self()) {
781 /* avoid a simcall if this function is called by the process itself */
782 return process->name;
784 return simcall_BODY_process_get_name(process);
788 * \ingroup simix_process_management
789 * \brief Returns true if the process is suspended .
791 * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
792 * \param process SIMIX process
793 * \return 1, if the process is suspended, else 0.
795 int simcall_process_is_suspended(smx_process_t process)
797 return simcall_BODY_process_is_suspended(process);
801 * \ingroup simix_process_management
802 * \brief Return the properties
804 * This functions returns the properties associated with this process
806 xbt_dict_t simcall_process_get_properties(smx_process_t process)
808 return simcall_BODY_process_get_properties(process);
811 * \ingroup simix_process_management
812 * \brief Add an on_exit function
813 * Add an on_exit function which will be executed when the process exits/is killed.
815 XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_pvoid_t fun, void *data)
817 simcall_BODY_process_on_exit(process, fun, data);
820 * \ingroup simix_process_management
821 * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up.
822 * Will restart the process when the host comes back up if auto_restart is set to 1.
825 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart)
827 simcall_BODY_process_auto_restart_set(process, auto_restart);
831 * \ingroup simix_process_management
832 * \brief Restarts the process, killing it and starting it again from scratch.
834 XBT_PUBLIC(smx_process_t) simcall_process_restart(smx_process_t process)
836 return simcall_BODY_process_restart(process);
839 * \ingroup simix_process_management
840 * \brief Creates a new sleep SIMIX action.
842 * This function creates a SURF action and allocates the data necessary
843 * to create the SIMIX action. It can raise a host_error exception if the
844 * host crashed. The default SIMIX name of the action is "sleep".
846 * \param duration Time duration of the sleep.
847 * \return A result telling whether the sleep was successful
849 e_smx_state_t simcall_process_sleep(double duration)
851 /* checking for infinite values */
852 xbt_assert(isfinite(duration), "duration is not finite!");
853 return simcall_BODY_process_sleep(duration);
857 * \ingroup simix_rdv_management
858 * \brief Creates a new rendez-vous point
859 * \param name The name of the rendez-vous point
860 * \return The created rendez-vous point
862 smx_rdv_t simcall_rdv_create(const char *name)
864 return simcall_BODY_rdv_create(name);
869 * \ingroup simix_rdv_management
870 * \brief Destroy a rendez-vous point
871 * \param rdv The rendez-vous point to destroy
873 void simcall_rdv_destroy(smx_rdv_t rdv)
875 simcall_BODY_rdv_destroy(rdv);
878 * \ingroup simix_rdv_management
879 * \brief Returns a rendez-vous point knowing its name
881 smx_rdv_t simcall_rdv_get_by_name(const char *name)
883 xbt_assert(name != NULL, "Invalid parameter for simcall_rdv_get_by_name (name is NULL)");
885 /* FIXME: this is a horrible loss of performance, so we hack it out by
886 * skipping the simcall (for now). It works in parallel, it won't work on
887 * distributed but probably we will change MSG for that. */
889 return SIMIX_rdv_get_by_name(name);
893 * \ingroup simix_rdv_management
894 * \brief Counts the number of communication actions of a given host pending
895 * on a rendez-vous point.
896 * \param rdv The rendez-vous point
897 * \param host The host to be counted
898 * \return The number of comm actions pending in the rdv
900 int simcall_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
902 return simcall_BODY_rdv_comm_count_by_host(rdv, host);
906 * \ingroup simix_rdv_management
907 * \brief returns the communication at the head of the rendez-vous
908 * \param rdv The rendez-vous point
909 * \return The communication or NULL if empty
911 smx_action_t simcall_rdv_get_head(smx_rdv_t rdv)
913 return simcall_BODY_rdv_get_head(rdv);
916 void simcall_rdv_set_receiver(smx_rdv_t rdv, smx_process_t process)
918 simcall_BODY_rdv_set_receiver(rdv, process);
921 smx_process_t simcall_rdv_get_receiver(smx_rdv_t rdv)
923 return simcall_BODY_rdv_get_receiver(rdv);
927 * \ingroup simix_comm_management
929 void simcall_comm_send(smx_process_t src, smx_rdv_t rdv, double task_size, double rate,
930 void *src_buff, size_t src_buff_size,
931 int (*match_fun)(void *, void *, smx_action_t),
932 void (*copy_data_fun)(smx_action_t, void*, size_t), void *data,
935 /* checking for infinite values */
936 xbt_assert(isfinite(task_size), "task_size is not finite!");
937 xbt_assert(isfinite(rate), "rate is not finite!");
938 xbt_assert(isfinite(timeout), "timeout is not finite!");
940 xbt_assert(rdv, "No rendez-vous point defined for send");
942 if (MC_is_active()) {
943 /* the model-checker wants two separate simcalls */
944 smx_action_t comm = NULL; /* MC needs the comm to be set to NULL during the simcall */
945 comm = simcall_comm_isend(src, rdv, task_size, rate,
946 src_buff, src_buff_size, match_fun, NULL, copy_data_fun, data, 0);
947 simcall_comm_wait(comm, timeout);
951 simcall_BODY_comm_send(src, rdv, task_size, rate, src_buff, src_buff_size,
952 match_fun, copy_data_fun, data, timeout);
957 * \ingroup simix_comm_management
959 smx_action_t simcall_comm_isend(smx_process_t src, smx_rdv_t rdv, double task_size, double rate,
960 void *src_buff, size_t src_buff_size,
961 int (*match_fun)(void *, void *, smx_action_t),
962 void (*clean_fun)(void *),
963 void (*copy_data_fun)(smx_action_t, void*, size_t),
967 /* checking for infinite values */
968 xbt_assert(isfinite(task_size), "task_size is not finite!");
969 xbt_assert(isfinite(rate), "rate is not finite!");
971 xbt_assert(rdv, "No rendez-vous point defined for isend");
973 return simcall_BODY_comm_isend(src, rdv, task_size, rate, src_buff,
974 src_buff_size, match_fun,
975 clean_fun, copy_data_fun, data, detached);
979 * \ingroup simix_comm_management
981 void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
982 int (*match_fun)(void *, void *, smx_action_t),
983 void (*copy_data_fun)(smx_action_t, void*, size_t),
984 void *data, double timeout, double rate)
986 xbt_assert(isfinite(timeout), "timeout is not finite!");
987 xbt_assert(rdv, "No rendez-vous point defined for recv");
989 if (MC_is_active()) {
990 /* the model-checker wants two separate simcalls */
991 smx_action_t comm = NULL; /* MC needs the comm to be set to NULL during the simcall */
992 comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
993 match_fun, copy_data_fun, data, rate);
994 simcall_comm_wait(comm, timeout);
998 simcall_BODY_comm_recv(rdv, dst_buff, dst_buff_size,
999 match_fun, copy_data_fun, data, timeout, rate);
1003 * \ingroup simix_comm_management
1005 smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t *dst_buff_size,
1006 int (*match_fun)(void *, void *, smx_action_t),
1007 void (*copy_data_fun)(smx_action_t, void*, size_t),
1008 void *data, double rate)
1010 xbt_assert(rdv, "No rendez-vous point defined for irecv");
1012 return simcall_BODY_comm_irecv(rdv, dst_buff, dst_buff_size,
1013 match_fun, copy_data_fun, data, rate);
1017 * \ingroup simix_comm_management
1019 smx_action_t simcall_comm_iprobe(smx_rdv_t rdv, int type, int src, int tag,
1020 int (*match_fun)(void *, void *, smx_action_t), void *data)
1022 xbt_assert(rdv, "No rendez-vous point defined for iprobe");
1024 return simcall_BODY_comm_iprobe(rdv, type, src, tag, match_fun, data);
1028 * \ingroup simix_comm_management
1030 void simcall_comm_cancel(smx_action_t comm)
1032 simcall_BODY_comm_cancel(comm);
1036 * \ingroup simix_comm_management
1038 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
1040 return simcall_BODY_comm_waitany(comms);
1044 * \ingroup simix_comm_management
1046 int simcall_comm_testany(xbt_dynar_t comms)
1048 if (xbt_dynar_is_empty(comms))
1050 return simcall_BODY_comm_testany(comms);
1054 * \ingroup simix_comm_management
1056 void simcall_comm_wait(smx_action_t comm, double timeout)
1058 xbt_assert(isfinite(timeout), "timeout is not finite!");
1059 simcall_BODY_comm_wait(comm, timeout);
1064 * \brief Set the category of an action.
1066 * This functions changes the category only. It calls a surf function.
1067 * \param execution The execution action
1068 * \param category The tracing category
1070 void simcall_set_category(smx_action_t action, const char *category)
1072 if (category == NULL) {
1075 simcall_BODY_set_category(action, category);
1080 * \ingroup simix_comm_management
1083 int simcall_comm_test(smx_action_t comm)
1085 return simcall_BODY_comm_test(comm);
1089 * \ingroup simix_comm_management
1092 double simcall_comm_get_remains(smx_action_t comm)
1094 return simcall_BODY_comm_get_remains(comm);
1098 * \ingroup simix_comm_management
1101 e_smx_state_t simcall_comm_get_state(smx_action_t comm)
1103 return simcall_BODY_comm_get_state(comm);
1107 * \ingroup simix_comm_management
1110 void *simcall_comm_get_src_data(smx_action_t comm)
1112 return simcall_BODY_comm_get_src_data(comm);
1116 * \ingroup simix_comm_management
1119 void *simcall_comm_get_dst_data(smx_action_t comm)
1121 return simcall_BODY_comm_get_dst_data(comm);
1125 * \ingroup simix_comm_management
1128 smx_process_t simcall_comm_get_src_proc(smx_action_t comm)
1130 return simcall_BODY_comm_get_src_proc(comm);
1134 * \ingroup simix_comm_management
1137 smx_process_t simcall_comm_get_dst_proc(smx_action_t comm)
1139 return simcall_BODY_comm_get_dst_proc(comm);
1142 #ifdef HAVE_LATENCY_BOUND_TRACKING
1143 int simcall_comm_is_latency_bounded(smx_action_t comm)
1145 return simcall_BODY_comm_is_latency_bounded(comm);
1150 * \ingroup simix_synchro_management
1153 smx_mutex_t simcall_mutex_init(void)
1156 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
1159 return simcall_BODY_mutex_init();
1163 * \ingroup simix_synchro_management
1166 void simcall_mutex_destroy(smx_mutex_t mutex)
1168 simcall_BODY_mutex_destroy(mutex);
1172 * \ingroup simix_synchro_management
1175 void simcall_mutex_lock(smx_mutex_t mutex)
1177 simcall_BODY_mutex_lock(mutex);
1181 * \ingroup simix_synchro_management
1184 int simcall_mutex_trylock(smx_mutex_t mutex)
1186 return simcall_BODY_mutex_trylock(mutex);
1190 * \ingroup simix_synchro_management
1193 void simcall_mutex_unlock(smx_mutex_t mutex)
1195 simcall_BODY_mutex_unlock(mutex);
1199 * \ingroup simix_synchro_management
1202 smx_cond_t simcall_cond_init(void)
1204 return simcall_BODY_cond_init();
1208 * \ingroup simix_synchro_management
1211 void simcall_cond_destroy(smx_cond_t cond)
1213 simcall_BODY_cond_destroy(cond);
1217 * \ingroup simix_synchro_management
1220 void simcall_cond_signal(smx_cond_t cond)
1222 simcall_BODY_cond_signal(cond);
1226 * \ingroup simix_synchro_management
1229 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1231 simcall_BODY_cond_wait(cond, mutex);
1235 * \ingroup simix_synchro_management
1238 void simcall_cond_wait_timeout(smx_cond_t cond,
1242 xbt_assert(isfinite(timeout), "timeout is not finite!");
1243 simcall_BODY_cond_wait_timeout(cond, mutex, timeout);
1247 * \ingroup simix_synchro_management
1250 void simcall_cond_broadcast(smx_cond_t cond)
1252 simcall_BODY_cond_broadcast(cond);
1256 * \ingroup simix_synchro_management
1259 smx_sem_t simcall_sem_init(int capacity)
1261 return simcall_BODY_sem_init(capacity);
1265 * \ingroup simix_synchro_management
1268 void simcall_sem_destroy(smx_sem_t sem)
1270 simcall_BODY_sem_destroy(sem);
1274 * \ingroup simix_synchro_management
1277 void simcall_sem_release(smx_sem_t sem)
1279 simcall_BODY_sem_release(sem);
1283 * \ingroup simix_synchro_management
1286 int simcall_sem_would_block(smx_sem_t sem)
1288 return simcall_BODY_sem_would_block(sem);
1292 * \ingroup simix_synchro_management
1295 void simcall_sem_acquire(smx_sem_t sem)
1297 simcall_BODY_sem_acquire(sem);
1301 * \ingroup simix_synchro_management
1304 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1306 xbt_assert(isfinite(timeout), "timeout is not finite!");
1307 simcall_BODY_sem_acquire_timeout(sem, timeout);
1311 * \ingroup simix_synchro_management
1314 int simcall_sem_get_capacity(smx_sem_t sem)
1316 return simcall_BODY_sem_get_capacity(sem);
1320 * \ingroup simix_file_management
1323 sg_size_t simcall_file_read(smx_file_t fd, sg_size_t size, smx_host_t host)
1325 return simcall_BODY_file_read(fd, size, host);
1329 * \ingroup simix_file_management
1332 sg_size_t simcall_file_write(smx_file_t fd, sg_size_t size, smx_host_t host)
1334 return simcall_BODY_file_write(fd, size, host);
1338 * \ingroup simix_file_management
1341 smx_file_t simcall_file_open(const char* fullpath, smx_host_t host)
1343 return simcall_BODY_file_open(fullpath, host);
1347 * \ingroup simix_file_management
1350 int simcall_file_close(smx_file_t fd, smx_host_t host)
1352 return simcall_BODY_file_close(fd, host);
1356 * \ingroup simix_file_management
1359 int simcall_file_unlink(smx_file_t fd, smx_host_t host)
1361 return simcall_BODY_file_unlink(fd, host);
1365 * \ingroup simix_file_management
1368 sg_size_t simcall_file_get_size(smx_file_t fd){
1369 return simcall_BODY_file_get_size(fd);
1373 * \ingroup simix_file_management
1376 sg_size_t simcall_file_tell(smx_file_t fd){
1377 return simcall_BODY_file_tell(fd);
1381 * \ingroup simix_file_management
1384 xbt_dynar_t simcall_file_get_info(smx_file_t fd)
1386 return simcall_BODY_file_get_info(fd);
1390 * \ingroup simix_file_management
1393 int simcall_file_seek(smx_file_t fd, sg_offset_t offset, int origin){
1394 return simcall_BODY_file_seek(fd, offset, origin);
1398 * \ingroup simix_file_management
1399 * \brief Move a file to another location on the *same mount point*.
1402 int simcall_file_move(smx_file_t fd, const char* fullpath)
1404 return simcall_BODY_file_move(fd, fullpath);
1408 * \ingroup simix_storage_management
1409 * \brief Returns the free space size on a given storage element.
1410 * \param storage a storage
1411 * \return Return the free space size on a given storage element (as sg_size_t)
1413 sg_size_t simcall_storage_get_free_size (smx_storage_t storage){
1414 return simcall_BODY_storage_get_free_size(storage);
1418 * \ingroup simix_storage_management
1419 * \brief Returns the used space size on a given storage element.
1420 * \param storage a storage
1421 * \return Return the used space size on a given storage element (as sg_size_t)
1423 sg_size_t simcall_storage_get_used_size (smx_storage_t storage){
1424 return simcall_BODY_storage_get_used_size(storage);
1428 * \ingroup simix_storage_management
1429 * \brief Returns the list of storages mounted on an host.
1430 * \param host A SIMIX host
1431 * \return a dict containing all storages mounted on the host
1433 xbt_dict_t simcall_host_get_mounted_storage_list(smx_host_t host)
1435 return simcall_BODY_host_get_mounted_storage_list(host);
1439 * \ingroup simix_storage_management
1440 * \brief Returns the list of storages attached to an host.
1441 * \param host A SIMIX host
1442 * \return a dict containing all storages attached to the host
1444 xbt_dynar_t simcall_host_get_attached_storage_list(smx_host_t host)
1446 return simcall_BODY_host_get_attached_storage_list(host);
1450 * \ingroup simix_storage_management
1451 * \brief Returns a dict of the properties assigned to a storage element.
1453 * \param storage A storage element
1454 * \return The properties of this storage element
1456 xbt_dict_t simcall_storage_get_properties(smx_storage_t storage)
1458 return simcall_BODY_storage_get_properties(storage);
1462 * \ingroup simix_storage_management
1463 * \brief Returns a dict containing the content of a storage element.
1465 * \param storage A storage element
1466 * \return The content of this storage element as a dict (full path file => size)
1468 xbt_dict_t simcall_storage_get_content(smx_storage_t storage)
1470 return simcall_BODY_storage_get_content(storage);
1475 void *simcall_mc_snapshot(void)
1477 return simcall_BODY_mc_snapshot();
1480 int simcall_mc_compare_snapshots(void *s1, void *s2){
1481 return simcall_BODY_mc_compare_snapshots(s1, s2);
1484 int simcall_mc_random(int min, int max)
1486 return simcall_BODY_mc_random(min, max);
1490 #endif /* HAVE_MC */
1492 /* ****************************************************************************************** */
1493 /* TUTORIAL: New API */
1494 /* All functions for simcall */
1495 /* ****************************************************************************************** */
1496 int simcall_new_api_fct(const char* param1, double param2){
1497 smx_simcall_t simcall = SIMIX_simcall_mine();
1498 simcall->call = SIMCALL_NEW_API_INIT;
1499 simcall->new_api.param1 = param1;
1500 simcall->new_api.param2 = param2;
1502 SIMIX_simcall_push(simcall->issuer);
1503 return simcall->new_api.result;
1506 /* ************************************************************************** */
1508 /** @brief returns a printable string representing a simcall */
1509 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1510 return simcall_names[kind];