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 static const char* simcall_names[] = {
16 #undef SIMCALL_ENUM_ELEMENT
17 #define SIMCALL_ENUM_ELEMENT(x,y) #x /* generate strings from the enumeration values */
19 #undef SIMCALL_ENUM_ELEMENT
23 * \ingroup simix_host_management
24 * \brief Returns a host given its name.
26 * \param name The name of the host to get
27 * \return The corresponding host
29 smx_host_t simcall_host_get_by_name(const char *name)
31 smx_simcall_t simcall = SIMIX_simcall_mine();
33 simcall->call = SIMCALL_HOST_GET_BY_NAME;
34 simcall->host_get_by_name.name = name;
35 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
36 simcall->host_get_by_name.result = NULL;
37 SIMIX_simcall_push(simcall->issuer);
38 return simcall->host_get_by_name.result;
42 * \ingroup simix_host_management
43 * \brief Returns the name of a host.
45 * \param host A SIMIX host
46 * \return The name of this host
48 const char* simcall_host_get_name(smx_host_t host)
50 smx_simcall_t simcall = SIMIX_simcall_mine();
52 simcall->call = SIMCALL_HOST_GET_NAME;
53 simcall->host_get_name.host = host;
54 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
55 simcall->host_get_name.result = NULL;
56 SIMIX_simcall_push(simcall->issuer);
57 return simcall->host_get_name.result;
61 * \ingroup simix_host_management
62 * \brief Returns a dict of the properties assigned to a host.
65 * \return The properties of this host
67 xbt_dict_t simcall_host_get_properties(smx_host_t host)
69 smx_simcall_t simcall = SIMIX_simcall_mine();
71 simcall->call = SIMCALL_HOST_GET_PROPERTIES;
72 simcall->host_get_properties.host = host;
73 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
74 simcall->host_get_properties.result = NULL;
75 SIMIX_simcall_push(simcall->issuer);
76 return simcall->host_get_properties.result;
80 * \ingroup simix_host_management
81 * \brief Returns a dict of the properties assigned to a router or AS.
83 * \param name The name of the router or AS
84 * \return The properties
86 xbt_dict_t simcall_asr_get_properties(const char *name)
88 smx_simcall_t simcall = SIMIX_simcall_mine();
90 simcall->call = SIMCALL_ASR_GET_PROPERTIES;
91 simcall->asr_get_properties.name = name;
92 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
93 simcall->asr_get_properties.result = NULL;
94 SIMIX_simcall_push(simcall->issuer);
95 return simcall->asr_get_properties.result;
100 * \ingroup simix_host_management
101 * \brief Returns the speed of the processor.
103 * The speed returned does not take into account the current load on the machine.
104 * \param host A SIMIX host
105 * \return The speed of this host (in Mflop/s)
107 double simcall_host_get_speed(smx_host_t host)
109 smx_simcall_t simcall = SIMIX_simcall_mine();
111 simcall->call = SIMCALL_HOST_GET_SPEED;
112 simcall->host_get_speed.host = host;
113 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
114 simcall->host_get_speed.result = 0.0;
115 SIMIX_simcall_push(simcall->issuer);
116 return simcall->host_get_speed.result;
120 * \ingroup simix_host_management
121 * \brief Returns the available speed of the processor.
123 * \return Speed currently available (in Mflop/s)
125 double simcall_host_get_available_speed(smx_host_t host)
127 smx_simcall_t simcall = SIMIX_simcall_mine();
129 simcall->call = SIMCALL_HOST_GET_AVAILABLE_SPEED;
130 simcall->host_get_available_speed.host = host;
131 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
132 simcall->host_get_available_speed.result = 0.0;
133 SIMIX_simcall_push(simcall->issuer);
134 return simcall->host_get_available_speed.result;
138 * \ingroup simix_host_management
139 * \brief Returns the state of a host.
141 * Two states are possible: 1 if the host is active or 0 if it has crashed.
142 * \param host A SIMIX host
143 * \return 1 if the host is available, 0 otherwise
145 int simcall_host_get_state(smx_host_t host)
147 smx_simcall_t simcall = SIMIX_simcall_mine();
149 simcall->call = SIMCALL_HOST_GET_STATE;
150 simcall->host_get_state.host = host;
151 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
152 simcall->host_get_state.result = -1;
153 SIMIX_simcall_push(simcall->issuer);
154 return simcall->host_get_state.result;
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 smx_simcall_t simcall = SIMIX_simcall_mine();
168 simcall->call = SIMCALL_HOST_GET_DATA;
169 simcall->host_get_data.host = host;
170 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
171 simcall->host_get_data.result = NULL;
172 SIMIX_simcall_push(simcall->issuer);
173 return simcall->host_get_data.result;
177 * \ingroup simix_host_management
178 * \brief Sets the user data associated to a host.
180 * The host must not have previous user data associated to it.
181 * \param host A SIMIX host
182 * \param data The user data to set
184 void simcall_host_set_data(smx_host_t host, void *data)
186 smx_simcall_t simcall = SIMIX_simcall_mine();
188 simcall->call = SIMCALL_HOST_SET_DATA;
189 simcall->host_set_data.host = host;
190 simcall->host_set_data.data = data;
191 SIMIX_simcall_push(simcall->issuer);
195 * \ingroup simix_host_management
196 * \brief Creates an action that executes some computation of an host.
198 * This function creates a SURF action and allocates the data necessary
199 * to create the SIMIX action. It can raise a host_error exception if the host crashed.
201 * \param name Name of the execution action to create
202 * \param host SIMIX host where the action will be executed
203 * \param computation_amount amount Computation amount (in bytes)
204 * \param priority computation priority
205 * \return A new SIMIX execution action
208 smx_action_t simcall_host_execute(const char *name, smx_host_t host,
209 double computation_amount,
212 /* checking for infinite values */
213 xbt_assert(isfinite(computation_amount), "computation_amount is not finite!");
214 xbt_assert(isfinite(priority), "priority is not finite!");
216 smx_simcall_t simcall = SIMIX_simcall_mine();
218 simcall->call = SIMCALL_HOST_EXECUTE;
219 simcall->host_execute.name = name;
220 simcall->host_execute.host = host;
221 simcall->host_execute.computation_amount = computation_amount;
222 simcall->host_execute.priority = priority;
224 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
225 simcall->host_execute.result = NULL;
227 SIMIX_simcall(SIMCALL_HOST_EXECUTE, PTR(name), PTR(host), DOUBLE(computation_amount), DOUBLE(priority));
229 return simcall->host_execute.result;
233 * \ingroup simix_host_management
234 * \brief Creates an action that may involve parallel computation on
235 * several hosts and communication between them.
237 * \param name Name of the execution action to create
238 * \param host_nb Number of hosts where the action will be executed
239 * \param host_list Array (of size host_nb) of hosts where the action will be executed
240 * \param computation_amount Array (of size host_nb) of computation amount of hosts (in bytes)
241 * \param communication_amount Array (of size host_nb * host_nb) representing the communication
242 * amount between each pair of hosts
243 * \param amount the SURF action amount
244 * \param rate the SURF action rate
245 * \return A new SIMIX execution action
247 smx_action_t simcall_host_parallel_execute(const char *name,
249 smx_host_t *host_list,
250 double *computation_amount,
251 double *communication_amount,
256 /* checking for infinite values */
257 for (i = 0 ; i < host_nb ; ++i) {
258 xbt_assert(isfinite(computation_amount[i]), "computation_amount[%d] is not finite!", i);
259 for (j = 0 ; j < host_nb ; ++j) {
260 xbt_assert(isfinite(communication_amount[i + host_nb * j]),
261 "communication_amount[%d+%d*%d] is not finite!", i, host_nb, j);
265 xbt_assert(isfinite(amount), "amount is not finite!");
266 xbt_assert(isfinite(rate), "rate is not finite!");
268 smx_simcall_t simcall = SIMIX_simcall_mine();
270 simcall->call = SIMCALL_HOST_PARALLEL_EXECUTE;
271 simcall->host_parallel_execute.name = name;
272 simcall->host_parallel_execute.host_nb = host_nb;
273 simcall->host_parallel_execute.host_list = host_list;
274 simcall->host_parallel_execute.computation_amount = computation_amount;
275 simcall->host_parallel_execute.communication_amount = communication_amount;
276 simcall->host_parallel_execute.amount = amount;
277 simcall->host_parallel_execute.rate = rate;
278 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
279 simcall->host_parallel_execute.result = NULL;
280 SIMIX_simcall_push(simcall->issuer);
281 return simcall->host_parallel_execute.result;
285 * \ingroup simix_host_management
286 * \brief Destroys an execution action.
288 * Destroys an action, freing its memory. This function cannot be called if there are a conditional waiting for it.
289 * \param execution The execution action to destroy
291 void simcall_host_execution_destroy(smx_action_t execution)
293 smx_simcall_t simcall = SIMIX_simcall_mine();
295 simcall->call = SIMCALL_HOST_EXECUTION_DESTROY;
296 simcall->host_execution_destroy.execution = execution;
297 SIMIX_simcall_push(simcall->issuer);
301 * \ingroup simix_host_management
302 * \brief Cancels an execution action.
304 * This functions stops the execution. It calls a surf function.
305 * \param execution The execution action to cancel
307 void simcall_host_execution_cancel(smx_action_t execution)
309 smx_simcall_t simcall = SIMIX_simcall_mine();
311 simcall->call = SIMCALL_HOST_EXECUTION_CANCEL;
312 simcall->host_execution_cancel.execution = execution;
313 SIMIX_simcall_push(simcall->issuer);
317 * \ingroup simix_host_management
318 * \brief Returns how much of an execution action remains to be done.
320 * \param execution The execution action
321 * \return The remaining amount
323 double simcall_host_execution_get_remains(smx_action_t execution)
325 smx_simcall_t simcall = SIMIX_simcall_mine();
327 simcall->call = SIMCALL_HOST_EXECUTION_GET_REMAINS;
328 simcall->host_execution_get_remains.execution = execution;
329 if(MC_is_active()) /* Initializeialize result to a default value for snapshot comparison done during simcall */
330 simcall->host_execution_get_remains.result = 0.0;
331 SIMIX_simcall_push(simcall->issuer);
332 return simcall->host_execution_get_remains.result;
336 * \ingroup simix_host_management
337 * \brief Returns the state of an execution action.
339 * \param execution The execution action
342 e_smx_state_t simcall_host_execution_get_state(smx_action_t execution)
344 smx_simcall_t simcall = SIMIX_simcall_mine();
346 simcall->call = SIMCALL_HOST_EXECUTION_GET_STATE;
347 simcall->host_execution_get_state.execution = execution;
348 simcall->host_execution_get_state.result = -1;
349 SIMIX_simcall_push(simcall->issuer);
350 return simcall->host_execution_get_state.result;
354 * \ingroup simix_host_management
355 * \brief Changes the priority of an execution action.
357 * This functions changes the priority only. It calls a surf function.
358 * \param execution The execution action
359 * \param priority The new priority
361 void simcall_host_execution_set_priority(smx_action_t execution, double priority)
363 /* checking for infinite values */
364 xbt_assert(isfinite(priority), "priority is not finite!");
366 smx_simcall_t simcall = SIMIX_simcall_mine();
368 simcall->call = SIMCALL_HOST_EXECUTION_SET_PRIORITY;
369 simcall->host_execution_set_priority.execution = execution;
370 simcall->host_execution_set_priority.priority = priority;
371 SIMIX_simcall_push(simcall->issuer);
375 * \ingroup simix_host_management
376 * \brief Waits for the completion of an execution action and destroy it.
378 * \param execution The execution action
380 e_smx_state_t simcall_host_execution_wait(smx_action_t execution)
382 smx_simcall_t simcall = SIMIX_simcall_mine();
384 simcall->call = SIMCALL_HOST_EXECUTION_WAIT;
385 simcall->host_execution_wait.execution = execution;
386 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
387 simcall->host_execution_wait.result = -1;
388 SIMIX_simcall_push(simcall->issuer);
389 return simcall->host_execution_wait.result;
393 * \ingroup simix_process_management
394 * \brief Creates and runs a new SIMIX process.
396 * The structure and the corresponding thread are created and put in the list of ready processes.
398 * \param process the process created will be stored in this pointer
399 * \param name a name for the process. It is for user-level information and can be NULL.
400 * \param code the main function of the process
401 * \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.
402 * It can be retrieved with the function \ref simcall_process_get_data.
403 * \param hostname name of the host where the new agent is executed.
404 * \param kill_time time when the process is killed
405 * \param argc first argument passed to \a code
406 * \param argv second argument passed to \a code
407 * \param properties the properties of the process
408 * \param auto_restart either it is autorestarting or not.
410 void simcall_process_create(smx_process_t *process, const char *name,
411 xbt_main_func_t code,
413 const char *hostname,
415 int argc, char **argv,
416 xbt_dict_t properties,
419 smx_simcall_t simcall = SIMIX_simcall_mine();
421 simcall->call = SIMCALL_PROCESS_CREATE;
422 simcall->process_create.process = process;
423 simcall->process_create.name = name;
424 simcall->process_create.code = code;
425 simcall->process_create.data = data;
426 simcall->process_create.hostname = hostname;
427 simcall->process_create.kill_time = kill_time;
428 simcall->process_create.argc = argc;
429 simcall->process_create.argv = argv;
430 simcall->process_create.properties = properties;
431 simcall->process_create.auto_restart = auto_restart;
432 SIMIX_simcall_push(simcall->issuer);
436 * \ingroup simix_process_management
437 * \brief Kills a SIMIX process.
439 * This function simply kills a process.
441 * \param process poor victim
443 void simcall_process_kill(smx_process_t process)
445 smx_simcall_t simcall = SIMIX_simcall_mine();
447 simcall->call = SIMCALL_PROCESS_KILL;
448 simcall->process_kill.process = process;
449 SIMIX_simcall_push(simcall->issuer);
453 * \ingroup simix_process_management
454 * \brief Kills all SIMIX processes.
456 void simcall_process_killall(void)
458 smx_simcall_t simcall = SIMIX_simcall_mine();
460 simcall->call = SIMCALL_PROCESS_KILLALL;
461 SIMIX_simcall_push(simcall->issuer);
465 * \ingroup simix_process_management
466 * \brief Cleans up a SIMIX process.
467 * \param process poor victim (must have already been killed)
469 void simcall_process_cleanup(smx_process_t process)
471 smx_simcall_t simcall = SIMIX_simcall_mine();
473 simcall->call = SIMCALL_PROCESS_CLEANUP;
474 simcall->process_cleanup.process = process;
475 SIMIX_simcall_push(simcall->issuer);
479 * \ingroup simix_process_management
480 * \brief Migrates an agent to another location.
482 * This function changes the value of the host on which \a process is running.
484 * \param process the process to migrate
485 * \param dest name of the new host
487 void simcall_process_change_host(smx_process_t process, smx_host_t dest)
489 smx_simcall_t simcall = SIMIX_simcall_mine();
491 simcall->call = SIMCALL_PROCESS_CHANGE_HOST;
492 simcall->process_change_host.process = process;
493 simcall->process_change_host.dest = dest;
494 SIMIX_simcall_push(simcall->issuer);
498 * \ingroup simix_process_management
499 * \brief Suspends a process.
501 * This function suspends the process by suspending the action
502 * it was waiting for completion.
504 * \param process a SIMIX process
506 void simcall_process_suspend(smx_process_t process)
508 xbt_assert(process, "Invalid parameters");
510 smx_simcall_t simcall = SIMIX_simcall_mine();
512 simcall->call = SIMCALL_PROCESS_SUSPEND;
513 simcall->process_suspend.process = process;
514 SIMIX_simcall_push(simcall->issuer);
518 * \ingroup simix_process_management
519 * \brief Resumes a suspended process.
521 * This function resumes a suspended process by resuming the action
522 * it was waiting for completion.
524 * \param process a SIMIX process
526 void simcall_process_resume(smx_process_t process)
528 smx_simcall_t simcall = SIMIX_simcall_mine();
530 simcall->call = SIMCALL_PROCESS_RESUME;
531 simcall->process_resume.process = process;
532 SIMIX_simcall_push(simcall->issuer);
536 * \ingroup simix_process_management
537 * \brief Returns the amount of SIMIX processes in the system
539 * Maestro internal process is not counted, only user code processes are
541 int simcall_process_count(void)
543 smx_simcall_t simcall = SIMIX_simcall_mine();
545 simcall->call = SIMCALL_PROCESS_COUNT;
546 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
547 simcall->process_count.result = -1;
548 SIMIX_simcall_push(simcall->issuer);
549 return simcall->process_count.result;
553 * \ingroup simix_process_management
554 * \brief Return the user data of a #smx_process_t.
555 * \param process a SIMIX process
556 * \return the user data of this process
558 void* simcall_process_get_data(smx_process_t process)
560 if (process == SIMIX_process_self()) {
561 /* avoid a simcall if this function is called by the process itself */
562 return SIMIX_process_get_data(process);
565 smx_simcall_t simcall = SIMIX_simcall_mine();
567 simcall->call = SIMCALL_PROCESS_GET_DATA;
568 simcall->process_get_data.process = process;
569 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
570 simcall->process_get_data.result = NULL;
571 SIMIX_simcall_push(simcall->issuer);
572 return simcall->process_get_data.result;
576 * \ingroup simix_process_management
577 * \brief Set the user data of a #smx_process_t.
579 * This functions sets the user data associated to \a process.
580 * \param process SIMIX process
581 * \param data User data
583 void simcall_process_set_data(smx_process_t process, void *data)
585 if (process == SIMIX_process_self()) {
586 /* avoid a simcall if this function is called by the process itself */
587 SIMIX_process_self_set_data(process, data);
591 smx_simcall_t simcall = SIMIX_simcall_mine();
593 simcall->call = SIMCALL_PROCESS_SET_DATA;
594 simcall->process_set_data.process = process;
595 simcall->process_set_data.data = data;
596 SIMIX_simcall_push(simcall->issuer);
601 * \ingroup simix_process_management
602 * \brief Set the kill time of a process.
603 * \param process a process
604 * \param kill_time a double
606 void simcall_process_set_kill_time(smx_process_t process, double kill_time)
609 if (kill_time > SIMIX_get_clock()) {
610 if (simix_global->kill_process_function) {
611 XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name,
612 process->smx_host->name);
613 SIMIX_timer_set(kill_time, simix_global->kill_process_function, process);
619 * \ingroup simix_process_management
620 * \brief Return the location on which an agent is running.
622 * This functions returns the smx_host_t corresponding to the location on which
623 * \a process is running.
624 * \param process SIMIX process
627 smx_host_t simcall_process_get_host(smx_process_t process)
629 smx_simcall_t simcall = SIMIX_simcall_mine();
631 simcall->call = SIMCALL_PROCESS_GET_HOST;
632 simcall->process_get_host.process = process;
633 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
634 simcall->process_get_host.result = NULL;
635 SIMIX_simcall_push(simcall->issuer);
636 return simcall->process_get_host.result;
640 * \ingroup simix_process_management
641 * \brief Return the name of an agent.
643 * This functions checks whether \a process is a valid pointer or not and return its name.
644 * \param process SIMIX process
645 * \return The process name
647 const char* simcall_process_get_name(smx_process_t process)
649 if (process == SIMIX_process_self()) {
650 /* avoid a simcall if this function is called by the process itself */
651 return process->name;
654 smx_simcall_t simcall = SIMIX_simcall_mine();
656 simcall->call = SIMCALL_PROCESS_GET_NAME;
657 simcall->process_get_name.process = process;
658 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
659 simcall->process_get_name.result = NULL;
660 SIMIX_simcall_push(simcall->issuer);
661 return simcall->process_get_name.result;
665 * \ingroup simix_process_management
666 * \brief Returns true if the process is suspended .
668 * This checks whether a process is suspended or not by inspecting the task on which it was waiting for the completion.
669 * \param process SIMIX process
670 * \return 1, if the process is suspended, else 0.
672 int simcall_process_is_suspended(smx_process_t process)
674 smx_simcall_t simcall = SIMIX_simcall_mine();
676 simcall->call = SIMCALL_PROCESS_IS_SUSPENDED;
677 simcall->process_is_suspended.process = process;
678 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
679 simcall->process_is_suspended.result = -1;
680 SIMIX_simcall_push(simcall->issuer);
681 return simcall->process_is_suspended.result;
685 * \ingroup simix_process_management
686 * \brief Return the properties
688 * This functions returns the properties associated with this process
690 xbt_dict_t simcall_process_get_properties(smx_process_t process)
692 smx_simcall_t simcall = SIMIX_simcall_mine();
694 simcall->call = SIMCALL_PROCESS_GET_PROPERTIES;
695 simcall->process_get_properties.process = process;
696 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
697 simcall->process_get_properties.result = NULL;
698 SIMIX_simcall_push(simcall->issuer);
699 return simcall->process_get_properties.result;
702 * \ingroup simix_process_management
703 * \brief Add an on_exit function
704 * Add an on_exit function which will be executed when the process exits/is killed.
706 XBT_PUBLIC(void) simcall_process_on_exit(smx_process_t process, int_f_pvoid_t fun, void *data)
708 smx_simcall_t simcall = SIMIX_simcall_mine();
710 simcall->call = SIMCALL_PROCESS_ON_EXIT;
711 simcall->process_on_exit.process = process;
712 simcall->process_on_exit.fun = fun;
713 simcall->process_on_exit.data = data;
715 SIMIX_simcall_push(simcall->issuer);
718 * \ingroup simix_process_management
719 * \brief Sets the process to be auto-restarted or not by SIMIX when its host comes back up.
720 * Will restart the process when the host comes back up if auto_restart is set to 1.
723 XBT_PUBLIC(void) simcall_process_auto_restart_set(smx_process_t process, int auto_restart)
725 smx_simcall_t simcall = SIMIX_simcall_mine();
727 simcall->call = SIMCALL_PROCESS_AUTO_RESTART_SET;
728 simcall->process_auto_restart.process = process;
729 simcall->process_auto_restart.auto_restart = auto_restart;
731 SIMIX_simcall_push(simcall->issuer);
735 * \ingroup simix_process_management
736 * \brief Restarts the process, killing it and starting it again from scratch.
738 XBT_PUBLIC(smx_process_t) simcall_process_restart(smx_process_t process)
740 smx_simcall_t simcall = SIMIX_simcall_mine();
742 simcall->call = SIMCALL_PROCESS_RESTART;
743 simcall->process_restart.process = process;
744 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
745 simcall->process_restart.result = NULL;
747 SIMIX_simcall_push(simcall->issuer);
749 return simcall->process_restart.result;
752 * \ingroup simix_process_management
753 * \brief Creates a new sleep SIMIX action.
755 * This function creates a SURF action and allocates the data necessary
756 * to create the SIMIX action. It can raise a host_error exception if the
757 * host crashed. The default SIMIX name of the action is "sleep".
759 * \param duration Time duration of the sleep.
760 * \return A result telling whether the sleep was successful
762 e_smx_state_t simcall_process_sleep(double duration)
764 /* checking for infinite values */
765 xbt_assert(isfinite(duration), "duration is not finite!");
767 smx_simcall_t simcall = SIMIX_simcall_mine();
769 simcall->call = SIMCALL_PROCESS_SLEEP;
770 simcall->process_sleep.duration = duration;
771 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
772 simcall->process_sleep.result = -1;
773 SIMIX_simcall_push(simcall->issuer);
774 return simcall->process_sleep.result;
778 * \ingroup simix_rdv_management
779 * \brief Creates a new rendez-vous point
780 * \param name The name of the rendez-vous point
781 * \return The created rendez-vous point
783 smx_rdv_t simcall_rdv_create(const char *name)
785 smx_simcall_t simcall = SIMIX_simcall_mine();
787 simcall->call = SIMCALL_RDV_CREATE;
788 simcall->rdv_create.name = name;
789 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
790 simcall->rdv_create.result = NULL;
792 SIMIX_simcall_push(simcall->issuer);
793 return simcall->rdv_create.result;
798 * \ingroup simix_rdv_management
799 * \brief Destroy a rendez-vous point
800 * \param rdv The rendez-vous point to destroy
802 void simcall_rdv_destroy(smx_rdv_t rdv)
804 smx_simcall_t simcall = SIMIX_simcall_mine();
806 simcall->call = SIMCALL_RDV_DESTROY;
807 simcall->rdv_destroy.rdv = rdv;
809 SIMIX_simcall_push(simcall->issuer);
812 * \ingroup simix_rdv_management
813 * \brief Returns a rendez-vous point knowing its name
815 smx_rdv_t simcall_rdv_get_by_name(const char *name)
817 xbt_assert(name != NULL, "Invalid parameter for simcall_rdv_get_by_name (name is NULL)");
819 /* FIXME: this is a horrible lost of performance, so we hack it out by
820 * skipping the simcall (for now). It works in parallel, it won't work on
821 * distributed but probably we will change MSG for that. */
824 smx_simcall_t simcall = simcall_mine();
825 simcall->call = SIMCALL_RDV_GEY_BY_NAME;
826 simcall->rdv_get_by_name.name = name;
827 SIMIX_simcall_push(simcall->issuer);
828 return simcall->rdv_get_by_name.result;*/
830 return SIMIX_rdv_get_by_name(name);
834 * \ingroup simix_rdv_management
835 * \brief Counts the number of communication actions of a given host pending
836 * on a rendez-vous point.
837 * \param rdv The rendez-vous point
838 * \param host The host to be counted
839 * \return The number of comm actions pending in the rdv
841 int simcall_rdv_comm_count_by_host(smx_rdv_t rdv, smx_host_t host)
843 smx_simcall_t simcall = SIMIX_simcall_mine();
845 simcall->call = SIMCALL_RDV_COMM_COUNT_BY_HOST;
846 simcall->rdv_comm_count_by_host.rdv = rdv;
847 simcall->rdv_comm_count_by_host.host = host;
848 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
849 simcall->rdv_comm_count_by_host.result = -1;
851 SIMIX_simcall_push(simcall->issuer);
852 return simcall->rdv_comm_count_by_host.result;
856 * \ingroup simix_rdv_management
857 * \brief returns the communication at the head of the rendez-vous
858 * \param rdv The rendez-vous point
859 * \return The communication or NULL if empty
861 smx_action_t simcall_rdv_get_head(smx_rdv_t rdv)
863 smx_simcall_t simcall = SIMIX_simcall_mine();
865 simcall->call = SIMCALL_RDV_GET_HEAD;
866 simcall->rdv_get_head.rdv = rdv;
867 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
868 simcall->rdv_get_head.result = NULL;
870 SIMIX_simcall_push(simcall->issuer);
871 return simcall->rdv_get_head.result;
874 void simcall_rdv_set_receiver(smx_rdv_t rdv , smx_process_t process)
876 smx_simcall_t simcall = SIMIX_simcall_mine();
878 simcall->call = SIMCALL_RDV_SET_RECV;
879 simcall->rdv_set_rcv_proc.rdv = rdv;
880 simcall->rdv_set_rcv_proc.receiver = process;
882 SIMIX_simcall_push(simcall->issuer);
885 smx_process_t simcall_rdv_get_receiver(smx_rdv_t rdv)
887 smx_simcall_t simcall = SIMIX_simcall_mine();
889 simcall->call = SIMCALL_RDV_GET_RECV;
890 simcall->rdv_get_rcv_proc.rdv = rdv;
891 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
892 simcall->rdv_get_rcv_proc.result = NULL;
894 SIMIX_simcall_push(simcall->issuer);
895 return simcall->rdv_get_rcv_proc.result;
899 * \ingroup simix_comm_management
901 void simcall_comm_send(smx_rdv_t rdv, double task_size, double rate,
902 void *src_buff, size_t src_buff_size,
903 int (*match_fun)(void *, void *, smx_action_t), void *data,
906 /* checking for infinite values */
907 xbt_assert(isfinite(task_size), "task_size is not finite!");
908 xbt_assert(isfinite(rate), "rate is not finite!");
909 xbt_assert(isfinite(timeout), "timeout is not finite!");
911 xbt_assert(rdv, "No rendez-vous point defined for send");
913 if (MC_is_active()) {
914 /* the model-checker wants two separate simcalls */
915 smx_action_t comm = simcall_comm_isend(rdv, task_size, rate,
916 src_buff, src_buff_size, match_fun, NULL, data, 0);
917 simcall_comm_wait(comm, timeout);
920 smx_simcall_t simcall = SIMIX_simcall_mine();
922 simcall->call = SIMCALL_COMM_SEND;
923 simcall->comm_send.rdv = rdv;
924 simcall->comm_send.task_size = task_size;
925 simcall->comm_send.rate = rate;
926 simcall->comm_send.src_buff = src_buff;
927 simcall->comm_send.src_buff_size = src_buff_size;
928 simcall->comm_send.match_fun = match_fun;
929 simcall->comm_send.data = data;
930 simcall->comm_send.timeout = timeout;
932 SIMIX_simcall_push(simcall->issuer);
936 * \ingroup simix_comm_management
938 smx_action_t simcall_comm_isend(smx_rdv_t rdv, double task_size, double rate,
939 void *src_buff, size_t src_buff_size,
940 int (*match_fun)(void *, void *, smx_action_t),
941 void (*clean_fun)(void *),
945 /* checking for infinite values */
946 xbt_assert(isfinite(task_size), "task_size is not finite!");
947 xbt_assert(isfinite(rate), "rate is not finite!");
949 xbt_assert(rdv, "No rendez-vous point defined for isend");
951 smx_simcall_t simcall = SIMIX_simcall_mine();
953 simcall->call = SIMCALL_COMM_ISEND;
954 simcall->comm_isend.rdv = rdv;
955 simcall->comm_isend.task_size = task_size;
956 simcall->comm_isend.rate = rate;
957 simcall->comm_isend.src_buff = src_buff;
958 simcall->comm_isend.src_buff_size = src_buff_size;
959 simcall->comm_isend.match_fun = match_fun;
960 simcall->comm_isend.clean_fun = clean_fun;
961 simcall->comm_isend.data = data;
962 simcall->comm_isend.detached = detached;
963 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
964 simcall->comm_isend.result = NULL;
966 SIMIX_simcall_push(simcall->issuer);
967 return simcall->comm_isend.result;
970 * \ingroup simix_comm_management
972 void simcall_comm_recv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
973 int (*match_fun)(void *, void *, smx_action_t), void *data, double timeout)
975 xbt_assert(isfinite(timeout), "timeout is not finite!");
976 xbt_assert(rdv, "No rendez-vous point defined for recv");
978 if (MC_is_active()) {
979 /* the model-checker wants two separate simcalls */
980 smx_action_t comm = simcall_comm_irecv(rdv, dst_buff, dst_buff_size,
982 simcall_comm_wait(comm, timeout);
985 smx_simcall_t simcall = SIMIX_simcall_mine();
987 simcall->call = SIMCALL_COMM_RECV;
988 simcall->comm_recv.rdv = rdv;
989 simcall->comm_recv.dst_buff = dst_buff;
990 simcall->comm_recv.dst_buff_size = dst_buff_size;
991 simcall->comm_recv.match_fun = match_fun;
992 simcall->comm_recv.data = data;
993 simcall->comm_recv.timeout = timeout;
995 SIMIX_simcall_push(simcall->issuer);
999 * \ingroup simix_comm_management
1001 smx_action_t simcall_comm_irecv(smx_rdv_t rdv, void *dst_buff, size_t * dst_buff_size,
1002 int (*match_fun)(void *, void *, smx_action_t), void *data)
1004 xbt_assert(rdv, "No rendez-vous point defined for irecv");
1006 smx_simcall_t simcall = SIMIX_simcall_mine();
1008 simcall->call = SIMCALL_COMM_IRECV;
1009 simcall->comm_irecv.rdv = rdv;
1010 simcall->comm_irecv.dst_buff = dst_buff;
1011 simcall->comm_irecv.dst_buff_size = dst_buff_size;
1012 simcall->comm_irecv.match_fun = match_fun;
1013 simcall->comm_irecv.data = data;
1014 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1015 simcall->comm_irecv.result = NULL;
1017 SIMIX_simcall_push(simcall->issuer);
1018 return simcall->comm_irecv.result;
1023 * \ingroup simix_comm_management
1025 smx_action_t simcall_comm_iprobe(smx_rdv_t rdv, int src, int tag,
1026 int (*match_fun)(void *, void *, smx_action_t), void *data)
1028 xbt_assert(rdv, "No rendez-vous point defined for iprobe");
1030 smx_simcall_t simcall = SIMIX_simcall_mine();
1032 simcall->call = SIMCALL_COMM_IPROBE;
1033 simcall->comm_iprobe.rdv = rdv;
1034 simcall->comm_iprobe.src = src;
1035 simcall->comm_iprobe.match_fun = match_fun;
1036 simcall->comm_iprobe.data = data;
1037 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1038 simcall->comm_iprobe.result = NULL;
1039 SIMIX_simcall_push(simcall->issuer);
1040 return simcall->comm_iprobe.result;
1044 void simcall_comm_destroy(smx_action_t comm)
1046 xbt_assert(comm, "Invalid parameter");
1048 /* FIXME remove this simcall type: comms are auto-destroyed now */
1051 smx_simcall_t simcall = simcall_mine();
1053 simcall->call = SIMCALL_COMM_DESTROY;
1054 simcall->comm_destroy.comm = comm;
1056 SIMIX_simcall_push(simcall->issuer);
1060 * \ingroup simix_comm_management
1062 void simcall_comm_cancel(smx_action_t comm)
1064 smx_simcall_t simcall = SIMIX_simcall_mine();
1066 simcall->call = SIMCALL_COMM_CANCEL;
1067 simcall->comm_cancel.comm = comm;
1069 SIMIX_simcall_push(simcall->issuer);
1072 * \ingroup simix_comm_management
1074 unsigned int simcall_comm_waitany(xbt_dynar_t comms)
1076 smx_simcall_t simcall = SIMIX_simcall_mine();
1078 simcall->call = SIMCALL_COMM_WAITANY;
1079 simcall->comm_waitany.comms = comms;
1080 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1081 simcall->comm_waitany.result = -1;
1083 SIMIX_simcall_push(simcall->issuer);
1084 return simcall->comm_waitany.result;
1087 * \ingroup simix_comm_management
1089 int simcall_comm_testany(xbt_dynar_t comms)
1091 smx_simcall_t simcall = SIMIX_simcall_mine();
1092 if (xbt_dynar_is_empty(comms))
1095 simcall->call = SIMCALL_COMM_TESTANY;
1096 simcall->comm_testany.comms = comms;
1097 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1098 simcall->comm_testany.result = -1;
1100 SIMIX_simcall_push(simcall->issuer);
1101 return simcall->comm_testany.result;
1104 * \ingroup simix_comm_management
1106 void simcall_comm_wait(smx_action_t comm, double timeout)
1108 xbt_assert(isfinite(timeout), "timeout is not finite!");
1110 smx_simcall_t simcall = SIMIX_simcall_mine();
1112 simcall->call = SIMCALL_COMM_WAIT;
1113 simcall->comm_wait.comm = comm;
1114 simcall->comm_wait.timeout = timeout;
1116 SIMIX_simcall_push(simcall->issuer);
1121 * \brief Set the category of an action.
1123 * This functions changes the category only. It calls a surf function.
1124 * \param execution The execution action
1125 * \param category The tracing category
1127 void simcall_set_category(smx_action_t action, const char *category)
1129 if (category == NULL) {
1133 smx_simcall_t simcall = SIMIX_simcall_mine();
1135 simcall->call = SIMCALL_SET_CATEGORY;
1136 simcall->set_category.action = action;
1137 simcall->set_category.category = category;
1139 SIMIX_simcall_push(simcall->issuer);
1143 * \ingroup simix_comm_management
1146 int simcall_comm_test(smx_action_t comm)
1148 smx_simcall_t simcall = SIMIX_simcall_mine();
1150 simcall->call = SIMCALL_COMM_TEST;
1151 simcall->comm_test.comm = comm;
1152 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1153 simcall->comm_test.result = -1;
1155 SIMIX_simcall_push(simcall->issuer);
1156 return simcall->comm_test.result;
1159 * \ingroup simix_comm_management
1162 double simcall_comm_get_remains(smx_action_t comm)
1164 smx_simcall_t simcall = SIMIX_simcall_mine();
1166 simcall->call = SIMCALL_COMM_GET_REMAINS;
1167 simcall->comm_get_remains.comm = comm;
1168 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1169 simcall->comm_get_remains.result = 0.0;
1171 SIMIX_simcall_push(simcall->issuer);
1172 return simcall->comm_get_remains.result;
1175 * \ingroup simix_comm_management
1178 e_smx_state_t simcall_comm_get_state(smx_action_t comm)
1180 smx_simcall_t simcall = SIMIX_simcall_mine();
1182 simcall->call = SIMCALL_COMM_GET_STATE;
1183 simcall->comm_get_state.comm = comm;
1184 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1185 simcall->comm_get_state.result = -1;
1187 SIMIX_simcall_push(simcall->issuer);
1188 return simcall->comm_get_state.result;
1191 * \ingroup simix_comm_management
1194 void *simcall_comm_get_src_data(smx_action_t comm)
1196 smx_simcall_t simcall = SIMIX_simcall_mine();
1198 simcall->call = SIMCALL_COMM_GET_SRC_DATA;
1199 simcall->comm_get_src_data.comm = comm;
1200 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1201 simcall->comm_get_src_data.result = NULL;
1203 SIMIX_simcall_push(simcall->issuer);
1204 return simcall->comm_get_src_data.result;
1207 * \ingroup simix_comm_management
1210 void *simcall_comm_get_dst_data(smx_action_t comm)
1212 smx_simcall_t simcall = SIMIX_simcall_mine();
1214 simcall->call = SIMCALL_COMM_GET_DST_DATA;
1215 simcall->comm_get_dst_data.comm = comm;
1216 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1217 simcall->comm_get_dst_data.result = NULL;
1219 SIMIX_simcall_push(simcall->issuer);
1220 return simcall->comm_get_dst_data.result;
1223 * \ingroup simix_comm_management
1226 smx_process_t simcall_comm_get_src_proc(smx_action_t comm)
1228 smx_simcall_t simcall = SIMIX_simcall_mine();
1230 simcall->call = SIMCALL_COMM_GET_SRC_PROC;
1231 simcall->comm_get_src_proc.comm = comm;
1232 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1233 simcall->comm_get_src_proc.result = NULL;
1235 SIMIX_simcall_push(simcall->issuer);
1236 return simcall->comm_get_src_proc.result;
1239 * \ingroup simix_comm_management
1242 smx_process_t simcall_comm_get_dst_proc(smx_action_t comm)
1244 smx_simcall_t simcall = SIMIX_simcall_mine();
1246 simcall->call = SIMCALL_COMM_GET_DST_PROC;
1247 simcall->comm_get_dst_proc.comm = comm;
1248 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1249 simcall->comm_get_dst_proc.result = NULL;
1251 SIMIX_simcall_push(simcall->issuer);
1252 return simcall->comm_get_dst_proc.result;
1255 #ifdef HAVE_LATENCY_BOUND_TRACKING
1256 int simcall_comm_is_latency_bounded(smx_action_t comm)
1258 smx_simcall_t simcall = SIMIX_simcall_mine();
1260 simcall->call = SIMCALL_COMM_IS_LATENCY_BOUNDED;
1261 simcall->comm_is_latency_bounded.comm = comm;
1262 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1263 simcall->comm_is_latency_bounded.result = -1;
1265 SIMIX_simcall_push(simcall->issuer);
1266 return simcall->comm_is_latency_bounded.result;
1270 * \ingroup simix_synchro_management
1273 smx_mutex_t simcall_mutex_init(void)
1276 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
1279 smx_simcall_t simcall = SIMIX_simcall_mine();
1281 simcall->call = SIMCALL_MUTEX_INIT;
1282 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1283 simcall->mutex_init.result = NULL;
1285 SIMIX_simcall_push(simcall->issuer);
1286 return simcall->mutex_init.result;
1289 * \ingroup simix_synchro_management
1292 void simcall_mutex_destroy(smx_mutex_t mutex)
1294 smx_simcall_t simcall = SIMIX_simcall_mine();
1296 simcall->call = SIMCALL_MUTEX_DESTROY;
1297 simcall->mutex_destroy.mutex = mutex;
1299 SIMIX_simcall_push(simcall->issuer);
1302 * \ingroup simix_synchro_management
1305 void simcall_mutex_lock(smx_mutex_t mutex)
1307 smx_simcall_t simcall = SIMIX_simcall_mine();
1309 simcall->call = SIMCALL_MUTEX_LOCK;
1310 simcall->mutex_lock.mutex = mutex;
1312 SIMIX_simcall_push(simcall->issuer);
1315 * \ingroup simix_synchro_management
1318 int simcall_mutex_trylock(smx_mutex_t mutex)
1320 smx_simcall_t simcall = SIMIX_simcall_mine();
1322 simcall->call = SIMCALL_MUTEX_TRYLOCK;
1323 simcall->mutex_trylock.mutex = mutex;
1324 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1325 simcall->mutex_trylock.result = -1;
1327 SIMIX_simcall_push(simcall->issuer);
1328 return simcall->mutex_trylock.result;
1331 * \ingroup simix_synchro_management
1334 void simcall_mutex_unlock(smx_mutex_t mutex)
1336 smx_simcall_t simcall = SIMIX_simcall_mine();
1338 simcall->call = SIMCALL_MUTEX_UNLOCK;
1339 simcall->mutex_unlock.mutex = mutex;
1341 SIMIX_simcall_push(simcall->issuer);
1344 * \ingroup simix_synchro_management
1347 smx_cond_t simcall_cond_init(void)
1349 smx_simcall_t simcall = SIMIX_simcall_mine();
1351 simcall->call = SIMCALL_COND_INIT;
1352 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1353 simcall->cond_init.result = NULL;
1355 SIMIX_simcall_push(simcall->issuer);
1356 return simcall->cond_init.result;
1359 * \ingroup simix_synchro_management
1362 void simcall_cond_destroy(smx_cond_t cond)
1364 smx_simcall_t simcall = SIMIX_simcall_mine();
1366 simcall->call = SIMCALL_COND_DESTROY;
1367 simcall->cond_destroy.cond = cond;
1369 SIMIX_simcall_push(simcall->issuer);
1372 * \ingroup simix_synchro_management
1375 void simcall_cond_signal(smx_cond_t cond)
1377 smx_simcall_t simcall = SIMIX_simcall_mine();
1379 simcall->call = SIMCALL_COND_SIGNAL;
1380 simcall->cond_signal.cond = cond;
1382 SIMIX_simcall_push(simcall->issuer);
1385 * \ingroup simix_synchro_management
1388 void simcall_cond_wait(smx_cond_t cond, smx_mutex_t mutex)
1390 smx_simcall_t simcall = SIMIX_simcall_mine();
1392 simcall->call = SIMCALL_COND_WAIT;
1393 simcall->cond_wait.cond = cond;
1394 simcall->cond_wait.mutex = mutex;
1396 SIMIX_simcall_push(simcall->issuer);
1399 * \ingroup simix_synchro_management
1402 void simcall_cond_wait_timeout(smx_cond_t cond,
1406 xbt_assert(isfinite(timeout), "timeout is not finite!");
1408 smx_simcall_t simcall = SIMIX_simcall_mine();
1410 simcall->call = SIMCALL_COND_WAIT_TIMEOUT;
1411 simcall->cond_wait_timeout.cond = cond;
1412 simcall->cond_wait_timeout.mutex = mutex;
1413 simcall->cond_wait_timeout.timeout = timeout;
1415 SIMIX_simcall_push(simcall->issuer);
1418 * \ingroup simix_synchro_management
1421 void simcall_cond_broadcast(smx_cond_t cond)
1423 smx_simcall_t simcall = SIMIX_simcall_mine();
1425 simcall->call = SIMCALL_COND_BROADCAST;
1426 simcall->cond_broadcast.cond = cond;
1428 SIMIX_simcall_push(simcall->issuer);
1431 * \ingroup simix_synchro_management
1434 smx_sem_t simcall_sem_init(int capacity)
1436 smx_simcall_t simcall = SIMIX_simcall_mine();
1438 simcall->call = SIMCALL_SEM_INIT;
1439 simcall->sem_init.capacity = capacity;
1440 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1441 simcall->sem_init.result = NULL;
1443 SIMIX_simcall_push(simcall->issuer);
1444 return simcall->sem_init.result;
1447 * \ingroup simix_synchro_management
1450 void simcall_sem_destroy(smx_sem_t sem)
1452 smx_simcall_t simcall = SIMIX_simcall_mine();
1454 simcall->call = SIMCALL_SEM_DESTROY;
1455 simcall->sem_destroy.sem = sem;
1457 SIMIX_simcall_push(simcall->issuer);
1460 * \ingroup simix_synchro_management
1463 void simcall_sem_release(smx_sem_t sem)
1465 smx_simcall_t simcall = SIMIX_simcall_mine();
1467 simcall->call = SIMCALL_SEM_RELEASE;
1468 simcall->sem_release.sem = sem;
1470 SIMIX_simcall_push(simcall->issuer);
1473 * \ingroup simix_synchro_management
1476 int simcall_sem_would_block(smx_sem_t sem)
1478 smx_simcall_t simcall = SIMIX_simcall_mine();
1480 simcall->call = SIMCALL_SEM_WOULD_BLOCK;
1481 simcall->sem_would_block.sem = sem;
1482 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1483 simcall->sem_would_block.result = -1;
1485 SIMIX_simcall_push(simcall->issuer);
1486 return simcall->sem_would_block.result;
1489 * \ingroup simix_synchro_management
1492 void simcall_sem_acquire(smx_sem_t sem)
1494 smx_simcall_t simcall = SIMIX_simcall_mine();
1496 simcall->call = SIMCALL_SEM_ACQUIRE;
1497 simcall->sem_acquire.sem = sem;
1499 SIMIX_simcall_push(simcall->issuer);
1502 * \ingroup simix_synchro_management
1505 void simcall_sem_acquire_timeout(smx_sem_t sem, double timeout)
1507 xbt_assert(isfinite(timeout), "timeout is not finite!");
1509 smx_simcall_t simcall = SIMIX_simcall_mine();
1511 simcall->call = SIMCALL_SEM_ACQUIRE_TIMEOUT;
1512 simcall->sem_acquire_timeout.sem = sem;
1513 simcall->sem_acquire_timeout.timeout = timeout;
1515 SIMIX_simcall_push(simcall->issuer);
1518 * \ingroup simix_synchro_management
1521 int simcall_sem_get_capacity(smx_sem_t sem)
1523 smx_simcall_t simcall = SIMIX_simcall_mine();
1525 simcall->call = SIMCALL_SEM_GET_CAPACITY;
1526 simcall->sem_get_capacity.sem = sem;
1527 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1528 simcall->sem_get_capacity.result = -1;
1530 SIMIX_simcall_push(simcall->issuer);
1531 return simcall->sem_get_capacity.result;
1534 * \ingroup simix_file_management
1537 double simcall_file_read(void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1539 smx_simcall_t simcall = SIMIX_simcall_mine();
1541 simcall->call = SIMCALL_FILE_READ;
1542 simcall->file_read.ptr = ptr;
1543 simcall->file_read.size = size;
1544 simcall->file_read.nmemb = nmemb;
1545 simcall->file_read.stream = stream;
1546 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1547 simcall->file_read.result = 0.0;
1548 SIMIX_simcall_push(simcall->issuer);
1550 return simcall->file_read.result;
1553 * \ingroup simix_file_management
1556 size_t simcall_file_write(const void* ptr, size_t size, size_t nmemb, smx_file_t stream)
1558 smx_simcall_t simcall = SIMIX_simcall_mine();
1560 simcall->call = SIMCALL_FILE_WRITE;
1561 simcall->file_write.ptr = ptr;
1562 simcall->file_write.size = size;
1563 simcall->file_write.nmemb = nmemb;
1564 simcall->file_write.stream = stream;
1565 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1566 simcall->file_write.result = 0;
1567 SIMIX_simcall_push(simcall->issuer);
1569 return simcall->file_write.result;
1572 * \ingroup simix_file_management
1575 smx_file_t simcall_file_open(const char* mount, const char* path, const char* mode)
1577 smx_simcall_t simcall = SIMIX_simcall_mine();
1579 simcall->call = SIMCALL_FILE_OPEN;
1580 simcall->file_open.mount = mount;
1581 simcall->file_open.path = path;
1582 simcall->file_open.mode = mode;
1583 if(MC_is_active()) /* Initialize result to NULL for snapshot comparison done during simcall */
1584 simcall->file_open.result = NULL;
1585 SIMIX_simcall_push(simcall->issuer);
1587 return simcall->file_open.result;
1590 * \ingroup simix_file_management
1593 int simcall_file_close(smx_file_t fp)
1595 smx_simcall_t simcall = SIMIX_simcall_mine();
1597 simcall->call = SIMCALL_FILE_CLOSE;
1598 simcall->file_close.fp = fp;
1599 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1600 simcall->file_close.result = -1;
1601 SIMIX_simcall_push(simcall->issuer);
1603 return simcall->file_close.result;
1606 * \ingroup simix_file_management
1609 int simcall_file_stat(smx_file_t fd, s_file_stat_t *buf)
1611 smx_simcall_t simcall = SIMIX_simcall_mine();
1612 simcall->call = SIMCALL_FILE_STAT;
1613 simcall->file_stat.fd = fd;
1614 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1615 simcall->file_stat.result = -1;
1617 SIMIX_simcall_push(simcall->issuer);
1619 *buf = simcall->file_stat.buf;
1621 return simcall->file_stat.result;
1625 * \ingroup simix_file_management
1628 int simcall_file_unlink(smx_file_t fd)
1630 smx_simcall_t simcall = SIMIX_simcall_mine();
1631 simcall->call = SIMCALL_FILE_UNLINK;
1632 simcall->file_unlink.fd = fd;
1633 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1634 simcall->file_unlink.result = -1;
1636 SIMIX_simcall_push(simcall->issuer);
1638 return simcall->file_unlink.result;
1642 * \ingroup simix_file_management
1645 xbt_dict_t simcall_file_ls(const char* mount, const char* path)
1647 smx_simcall_t simcall = SIMIX_simcall_mine();
1648 simcall->call = SIMCALL_FILE_LS;
1649 simcall->file_ls.mount = mount;
1650 simcall->file_ls.path = path;
1651 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1652 simcall->file_ls.result = NULL;
1654 SIMIX_simcall_push(simcall->issuer);
1656 return simcall->file_ls.result;
1661 void *simcall_mc_snapshot(void)
1663 smx_simcall_t simcall = SIMIX_simcall_mine();
1664 simcall->call = SIMCALL_MC_SNAPSHOT;
1666 SIMIX_simcall_push(simcall->issuer);
1668 return simcall->mc_snapshot.s;
1671 int simcall_mc_compare_snapshots(void *s1, void *s2){
1673 smx_simcall_t simcall = SIMIX_simcall_mine();
1674 simcall->call = SIMCALL_MC_COMPARE_SNAPSHOTS;
1675 simcall->mc_compare_snapshots.snapshot1 = s1;
1676 simcall->mc_compare_snapshots.snapshot2 = s2;
1678 if(MC_is_active()) /* Initialize result to a default value for snapshot comparison done during simcall */
1679 simcall->mc_compare_snapshots.result = -1;
1681 SIMIX_simcall_push(simcall->issuer);
1683 return simcall->mc_compare_snapshots.result;
1686 #endif /* HAVE_MC */
1688 /* ****************************************************************************************** */
1689 /* TUTORIAL: New API */
1690 /* All functions for simcall */
1691 /* ****************************************************************************************** */
1692 int simcall_new_api_fct(const char* param1, double param2){
1693 smx_simcall_t simcall = SIMIX_simcall_mine();
1694 simcall->call = SIMCALL_NEW_API_INIT;
1695 simcall->new_api.param1 = param1;
1696 simcall->new_api.param2 = param2;
1698 SIMIX_simcall_push(simcall->issuer);
1699 return simcall->new_api.result;
1702 /* ************************************************************************** */
1704 /** @brief returns a printable string representing a simcall */
1705 const char *SIMIX_simcall_name(e_smx_simcall_t kind) {
1706 return simcall_names[kind];