1 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef _SIMIX_SMURF_PRIVATE_H
8 #define _SIMIX_SMURF_PRIVATE_H
10 /********************************* Simcalls *********************************/
12 /* we want to build the e_smx_simcall_t enumeration, the table of the
13 * corresponding simcalls string names, and the simcall handlers table
14 * automatically, using macros.
15 * To add a new simcall follow the following syntax:
17 * SIMCALL_ENUM_ELEMENT(<simcall_enumeration_id>, <simcall_handler_function>)
21 #define SIMCALL_LIST1 \
22 SIMCALL_ENUM_ELEMENT(SIMCALL_NONE),\
23 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_BY_NAME),\
24 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_NAME),\
25 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_PROPERTIES),\
26 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_SPEED),\
27 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_AVAILABLE_SPEED),\
28 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_STATE),\
29 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_DATA),\
30 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_SET_DATA),\
31 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTE),\
32 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_PARALLEL_EXECUTE),\
33 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_DESTROY),\
34 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_CANCEL),\
35 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_GET_REMAINS),\
36 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_GET_STATE),\
37 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_SET_PRIORITY),\
38 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_WAIT),\
39 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_CREATE),\
40 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_KILL),\
41 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_KILLALL),\
42 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_CLEANUP),\
43 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_CHANGE_HOST),\
44 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_SUSPEND),\
45 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_RESUME),\
46 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_COUNT),\
47 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_GET_DATA),\
48 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_SET_DATA),\
49 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_GET_HOST),\
50 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_GET_NAME),\
51 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_IS_SUSPENDED),\
52 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_GET_PROPERTIES),\
53 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_SLEEP),\
54 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_ON_EXIT),\
55 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_AUTO_RESTART_SET),\
56 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_RESTART),\
57 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_CREATE),\
58 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_DESTROY),\
59 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_GEY_BY_NAME),\
60 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_COMM_COUNT_BY_HOST),\
61 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_GET_HEAD),\
62 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_SET_RECV),\
63 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_GET_RECV),\
64 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_SEND),\
65 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_ISEND),\
66 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_RECV),\
67 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_IRECV),\
68 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_DESTROY),\
69 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_CANCEL),\
70 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_WAITANY),\
71 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_WAIT),\
72 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_TEST),\
73 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_TESTANY),\
74 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_IPROBE),\
75 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_REMAINS),\
76 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_STATE),\
77 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_SRC_DATA),\
78 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_DST_DATA),\
79 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_SRC_PROC),\
80 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_DST_PROC),\
81 SIMCALL_ENUM_ELEMENT(SIMCALL_MUTEX_INIT),\
82 SIMCALL_ENUM_ELEMENT(SIMCALL_MUTEX_DESTROY),\
83 SIMCALL_ENUM_ELEMENT(SIMCALL_MUTEX_LOCK),\
84 SIMCALL_ENUM_ELEMENT(SIMCALL_MUTEX_TRYLOCK),\
85 SIMCALL_ENUM_ELEMENT(SIMCALL_MUTEX_UNLOCK),\
86 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_INIT),\
87 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_DESTROY),\
88 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_SIGNAL),\
89 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_WAIT),\
90 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_WAIT_TIMEOUT),\
91 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_BROADCAST),\
92 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_INIT),\
93 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_DESTROY),\
94 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_RELEASE),\
95 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_WOULD_BLOCK),\
96 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_ACQUIRE),\
97 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_ACQUIRE_TIMEOUT),\
98 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_GET_CAPACITY),\
99 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_READ),\
100 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_WRITE),\
101 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_OPEN),\
102 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_CLOSE),\
103 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_STAT), \
104 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_UNLINK),\
105 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_LS),\
106 SIMCALL_ENUM_ELEMENT(SIMCALL_ASR_GET_PROPERTIES), \
107 /* ****************************************************************************************** */ \
108 /* TUTORIAL: New API */ \
109 /* ****************************************************************************************** */ \
110 SIMCALL_ENUM_ELEMENT(SIMCALL_NEW_API_INIT)
112 /* SIMCALL_COMM_IS_LATENCY_BOUNDED and SIMCALL_SET_CATEGORY make things complicated
113 * because they are not always present */
114 #ifdef HAVE_LATENCY_BOUND_TRACKING
115 #define SIMCALL_LIST2 \
116 ,SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_IS_LATENCY_BOUNDED, SIMIX_comm_is_latency_bounded)
118 #define SIMCALL_LIST2
122 #define SIMCALL_LIST3 \
123 ,SIMCALL_ENUM_ELEMENT(SIMCALL_SET_CATEGORY, SIMIX_set_category)
125 #define SIMCALL_LIST3
129 #define SIMCALL_LIST4 \
130 ,SIMCALL_ENUM_ELEMENT(SIMCALL_MC_SNAPSHOT) \
131 ,SIMCALL_ENUM_ELEMENT(SIMCALL_MC_COMPARE_SNAPSHOTS)
133 #define SIMCALL_LIST4
136 /* SIMCALL_LIST is the final macro to use */
137 #define SIMCALL_LIST SIMCALL_LIST1 SIMCALL_LIST2 SIMCALL_LIST3 SIMCALL_LIST4
139 /* you can redefine the following macro differently to generate something else
140 * with the list of enumeration values (e.g. a table of strings or a table of function pointers) */
141 #define SIMCALL_ENUM_ELEMENT(x, y) x
144 * \brief All possible simcalls.
151 * \brief Represents a simcall to the kernel.
153 typedef struct s_smx_simcall {
154 e_smx_simcall_t call;
155 smx_process_t issuer;
156 union u_smx_scalar *args;
157 //FIXME: union u_smx_scalar retval;
174 } host_get_properties;
184 } host_get_available_speed;
204 double computation_amount;
212 smx_host_t *host_list;
213 double *computation_amount;
214 double *communication_amount;
218 } host_parallel_execute;
221 smx_action_t execution;
222 } host_execution_destroy;
225 smx_action_t execution;
226 } host_execution_cancel;
229 smx_action_t execution;
231 } host_execution_get_remains;
234 smx_action_t execution;
235 e_smx_state_t result;
236 } host_execution_get_state;
239 smx_action_t execution;
241 } host_execution_set_priority;
244 smx_action_t execution;
245 struct s_smx_simcall *simcall;
246 e_smx_state_t result;
248 } host_execution_wait;
251 smx_process_t *process;
253 xbt_main_func_t code;
255 const char *hostname;
259 xbt_dict_t properties;
264 smx_process_t process;
268 smx_process_t process;
272 smx_process_t process;
274 } process_change_host;
277 smx_process_t process;
281 smx_process_t process;
289 smx_process_t process;
294 smx_process_t process;
299 smx_process_t process;
304 smx_process_t process;
309 smx_process_t process;
311 } process_is_suspended;
314 smx_process_t process;
316 } process_get_properties;
320 e_smx_state_t result;
324 smx_process_t process;
330 smx_process_t process;
332 } process_auto_restart;
335 smx_process_t process;
336 smx_process_t result;
357 } rdv_comm_count_by_host;
366 smx_process_t receiver;
371 smx_process_t result;
379 size_t src_buff_size;
380 int (*match_fun)(void *, void *, smx_action_t);
390 size_t src_buff_size;
391 int (*match_fun)(void *, void *, smx_action_t);
392 void (*clean_fun)(void *);
401 size_t *dst_buff_size;
402 int (*match_fun)(void *, void *, smx_action_t);
410 size_t *dst_buff_size;
411 int (*match_fun)(void *, void *, smx_action_t);
420 int (*match_fun)(void *, void *, smx_action_t);
460 e_smx_state_t result;
475 smx_process_t result;
480 smx_process_t result;
483 #ifdef HAVE_LATENCY_BOUND_TRACKING
487 } comm_is_latency_bounded;
493 const char *category;
570 } sem_acquire_timeout;
625 } asr_get_properties;
635 } mc_compare_snapshots;
637 /* ****************************************************************************************** */
638 /* TUTORIAL: New API */
639 /* ****************************************************************************************** */
647 } s_smx_simcall_t, *smx_simcall_t;
649 /******************************** General *************************************/
651 void SIMIX_simcall_push(smx_process_t self);
652 void SIMIX_simcall_answer(smx_simcall_t);
653 void SIMIX_simcall_pre(smx_simcall_t, int);
654 void SIMIX_simcall_post(smx_action_t);
655 smx_simcall_t SIMIX_simcall_mine(void);
656 const char *SIMIX_simcall_name(e_smx_simcall_t kind);
658 /*************************** New simcall interface ****************************/
660 /* Pack all possible scalar types in an union */
676 #define SIMIX_pack_args(...) (u_smx_scalar_t[]){MAP(INIT_FIELD, __VA_ARGS__)}
680 * Define scalar type wrappers to ease the use of simcalls.
681 * These are used to wrap the arguments in SIMIX_simcall macro.
683 #define CHAR(x) (c,x)
684 #define STRING(x) (cc,x)
685 #define SHORT(x) (s,x)
687 #define LONG(x) (l,x)
688 #define UCHAR(x) (uc,x)
689 #define USHORT(x) (us,x)
690 #define UINT(x) (ui,x)
691 #define ULONG(x) (ul,x)
692 #define FLOAT(x) (f,x)
693 #define DOUBLE(x) (d,x)
697 * Some macro machinery to get a MAP over the arguments of a variadic macro.
698 * It uses a FOLD to apply a macro to every argument, and because there is
699 * no recursion in the C preprocessor we must create a new macro for every
700 * depth of FOLD's recursion.
704 #define FE_1(WHAT, X) WHAT(X)
705 #define FE_2(WHAT, X, ...) WHAT(X), FE_1(WHAT, __VA_ARGS__)
706 #define FE_3(WHAT, X, ...) WHAT(X), FE_2(WHAT, __VA_ARGS__)
707 #define FE_4(WHAT, X, ...) WHAT(X), FE_3(WHAT, __VA_ARGS__)
708 #define FE_5(WHAT, X, ...) WHAT(X), FE_4(WHAT, __VA_ARGS__)
709 /* NOTE: add as many FE_n as needed (maximum number of simcall arguments )*/
711 /* Make a MAP macro usgin FOLD (will apply 'action' to the arguments.
712 * GET_MACRO is a smart hack that counts the number of arguments passed to
713 * the variadic macro, and it is used to invoke the right FOLD depth.
715 #define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
716 #define MAP(action,...) \
717 GET_MACRO(__VA_ARGS__,FE_5,FE_4,FE_3,FE_2,FE_1) (action, __VA_ARGS__)
720 /* Generate code to initialize the field 'x' with value 'y' of an structure or union */
721 #define INIT_FIELD_(x,y) {.x = y}
722 #define INIT_FIELD(t) INIT_FIELD_ t
724 /* Project the second element of a tuple */
725 #define SECOND_(x, y) y
726 #define SECOND(t) SECOND_ t
729 * \brief Simcall invocation macro
730 * It calls a dummy function that uses the format attribute to ensure typesafety (see
731 * gcc format attribute), then it invokes the real simcall function packing the
732 * user provided arguments in an array.
733 * \param id a simcall id (from the simcall enumeration ids)
736 #define SIMIX_simcall(id, ...) \
737 SIMIX_simcall_typecheck(simcall_types[id], MAP(SECOND, __VA_ARGS__)); \
738 __SIMIX_simcall(id, (u_smx_scalar_t[]){MAP(INIT_FIELD, __VA_ARGS__)})
740 void __SIMIX_simcall(e_smx_simcall_t simcall_id, u_smx_scalar_t *args);
743 * \biref Dummy variadic function used to typecheck the arguments of a simcall
744 * \param fmt A format string following printf style
746 void SIMIX_simcall_typecheck(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
748 typedef smx_action_t (*simcall_handler_t)(u_smx_scalar_t *);
750 extern const char *simcall_types[];
751 extern simcall_handler_t simcall_table[];