Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change parameters order for msg_file_read, msg_file_write and in all their internal...
[simgrid.git] / src / simix / smx_smurf_private.h
1 /* Copyright (c) 2007-2010, 2012-2013. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #ifndef _SIMIX_SMURF_PRIVATE_H
8 #define _SIMIX_SMURF_PRIVATE_H
9
10 /********************************* Simcalls *********************************/
11
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:
16  *
17  * SIMCALL_ENUM_ELEMENT(<simcall_enumeration_id>, <simcall_handler_function>)
18  *
19  * */
20
21 /****************************
22  * SIMCALL GENERATING MACRO *
23  ****************************
24  *
25  * action(ENUM_NAME, func_name, result_type, params…) 
26  *
27  **/
28
29 /*
30  * Some macro machinery to get a MAP over the arguments of a variadic macro.
31  * It uses a FOLD to apply a macro to every argument, and because there is
32  * no recursion in the C preprocessor we must create a new macro for every
33  * depth of FOLD's recursion.
34  */
35
36 /* FOLD macro */
37 #define FE_0(WHAT, X, ...)
38 #define FE_1(I, WHAT, X) WHAT(I, X)
39 #define FE_2(I, WHAT, X, ...) WHAT(I, X), FE_1(I+1, WHAT, __VA_ARGS__)
40 #define FE_3(I, WHAT, X, ...) WHAT(I, X), FE_2(I+1, WHAT, __VA_ARGS__)
41 #define FE_4(I, WHAT, X, ...) WHAT(I, X), FE_3(I+1, WHAT, __VA_ARGS__)
42 #define FE_5(I, WHAT, X, ...) WHAT(I, X), FE_4(I+1, WHAT, __VA_ARGS__)
43 #define FE_6(I, WHAT, X, ...) WHAT(I, X), FE_5(I+1, WHAT, __VA_ARGS__)
44 #define FE_7(I, WHAT, X, ...) WHAT(I, X), FE_6(I+1, WHAT, __VA_ARGS__)
45 #define FE_8(I, WHAT, X, ...) WHAT(I, X), FE_7(I+1, WHAT, __VA_ARGS__)
46 #define FE_9(I, WHAT, X, ...) WHAT(I, X), FE_8(I+1, WHAT, __VA_ARGS__)
47 #define FE_10(I, WHAT, X, ...) WHAT(I, X), FE_9(I+1, WHAT, __VA_ARGS__)
48
49 /* NOTE: add as many FE_n as needed (maximum number of simcall arguments )*/
50
51 /* Make a MAP macro usgin FOLD (will apply 'action' to the arguments.
52  * GET_MACRO is a smart hack that counts the number of arguments passed to
53  * the variadic macro, and it is used to invoke the right FOLD depth.
54  */
55 #define GET_MACRO(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
56 #define MAP(action, ...) \
57   GET_MACRO(, ##__VA_ARGS__, FE_10,FE_9,FE_8,FE_7,FE_6,FE_5,FE_4,FE_3,FE_2,FE_1, FE_0) (0, action, __VA_ARGS__)
58
59 /* MAP with default arguments */
60 #define APPLY_MAP(WHAT, I, X, ...) WHAT(I, __VA_ARGS__, X)
61 #define FE_DA_0(I, WHAT, args, X, ...)
62 #define FE_DA_1(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args)
63 #define FE_DA_2(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_1(I+1, WHAT, args, __VA_ARGS__)
64 #define FE_DA_3(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_2(I+1, WHAT, args, __VA_ARGS__)
65 #define FE_DA_4(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_3(I+1, WHAT, args, __VA_ARGS__)
66 #define FE_DA_5(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_4(I+1, WHAT, args, __VA_ARGS__)
67 #define FE_DA_6(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_5(I+1, WHAT, args, __VA_ARGS__)
68 #define FE_DA_7(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_6(I+1, WHAT, args, __VA_ARGS__)
69 #define FE_DA_8(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_7(I+1, WHAT, args, __VA_ARGS__)
70 #define FE_DA_9(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_8(I+1, WHAT, args, __VA_ARGS__)
71 #define FE_DA_10(I, WHAT, args, X, ...) APPLY_MAP(WHAT, I, X, args) FE_DA_9(I+1, WHAT, args, __VA_ARGS__)
72
73 #define MAP_WITH_DEFAULT_ARGS(action, args, ...) \
74   GET_MACRO(, ##__VA_ARGS__, FE_DA_10,FE_DA_9,FE_DA_8,FE_DA_7,FE_DA_6,FE_DA_5,FE_DA_4,FE_DA_3,FE_DA_2,FE_DA_1, FE_DA_0) (0, action, args, __VA_ARGS__)
75
76 /*
77  * Define scalar type wrappers to ease the use of simcalls.
78  * These are used to wrap the arguments in SIMIX_simcall macro.
79  */
80 #define TCHAR(n) (n, char, c)
81 #define TSTRING(n) (n, const char*, cc)
82 #define TSHORT(n) (n, short, s)
83 #define TINT(n) (n, int, i)
84 #define TLONG(n) (n, long, l)
85 #define TUCHAR(n) (n, unsigned char, uc)
86 #define TUSHORT(n) (n, unsigned short, us)
87 #define TUINT(n) (n, unsigned int, ui)
88 #define TULONG(n) (n, unsigned long, ul)
89 #define TFLOAT(n) (n, float, f)
90 #define TDOUBLE(n) (n, double, d)
91 #define TPTR(n) (n, void*, p)
92 #define TCPTR(n) (n, const void*, cp)
93 #define TSIZE(n) (n, size_t, si)
94 #define TVOID(n) (n, void)
95 #define TSPEC(n,t) (n, t, p)
96
97 /* use comma or nothing to separate elements*/
98 #define SIMCALL_SEP_COMMA ,
99 #define SIMCALL_SEP_NOTHING
100
101 /* get the name of the parameter */
102 #define SIMCALL_NAME_(name, type, field) name
103 #define SIMCALL_NAME(i, v) SIMCALL_NAME_ v
104
105 /* get the %s format code of the parameter */
106 #define SIMCALL_FORMAT_(name, type, field) %field
107 #define SIMCALL_FORMAT(i, v) SIMCALL_FORMAT_ v
108
109 /* get the field of the parameter */
110 #define SIMCALL_FIELD_(name, type, field) field
111 #define SIMCALL_FIELD(i, v) SIMCALL_FIELD_ v
112
113 /* get the parameter declaration */
114 #define SIMCALL_ARG_(name, type, field) type name
115 #define SIMCALL_ARG(i, v) SIMCALL_ARG_ v
116
117 /* get the parameter initialisation field */
118 #define SIMCALL_INIT_FIELD_(name, type, field) .field = name
119 #define SIMCALL_INIT_FIELD(i, d, v) self->simcall.args[i]SIMCALL_INIT_FIELD_ v;
120
121 /* get the case of the parameter */
122 #define SIMCALL_CASE_PARAM_(name, type, field) field
123 #define SIMCALL_CASE_PARAM(i, v) simcall->args[i].SIMCALL_CASE_PARAM_ v
124
125 /* generate some code for SIMCALL_CASE if the simcall has an answer */
126 #define MAYBE2(_0, _1, func, ...) func
127
128 #define SIMCALL_WITH_RESULT_BEGIN(name, type, field) simcall->result.field =
129 #define SIMCALL_WITHOUT_RESULT_BEGIN(name, type, field)
130 #define SIMCALL_RESULT_BEGIN_(name, type, ...)\
131         MAYBE2(,##__VA_ARGS__, SIMCALL_WITH_RESULT_BEGIN, SIMCALL_WITHOUT_RESULT_BEGIN)\
132         (name, type, __VA_ARGS__)
133 #define SIMCALL_RESULT_BEGIN(answer, res) answer(SIMCALL_RESULT_BEGIN_ res)
134
135 #define SIMCALL_RESULT_END_(name, type, ...)\
136         SIMIX_simcall_answer(simcall);
137 #define SIMCALL_RESULT_END(answer, res) answer(SIMCALL_RESULT_END_ res)
138
139 /* generate some code for BODY function */
140 #define SIMCALL_FUNC_RETURN_TYPE_(name, type, ...) type
141 #define SIMCALL_FUNC_RETURN_TYPE(res) SIMCALL_FUNC_RETURN_TYPE_ res
142
143 #define SIMCALL_WITH_FUNC_SIMCALL(name, type, field) smx_simcall_t simcall = 
144 #define SIMCALL_WITHOUT_FUNC_SIMCALL(name, type, field)
145 #define SIMCALL_FUNC_SIMCALL_(name, type, ...)\
146         MAYBE2(,##__VA_ARGS__, SIMCALL_WITH_FUNC_SIMCALL, SIMCALL_WITHOUT_FUNC_SIMCALL)\
147         (name, type, __VA_ARGS__)
148 #define SIMCALL_FUNC_SIMCALL(res) SIMCALL_FUNC_SIMCALL_ res
149
150 #define SIMCALL_WITH_FUNC_RETURN(name, type, field) return self->simcall.result.field;
151 #define SIMCALL_WITHOUT_FUNC_RETURN(name, type, field)
152 #define SIMCALL_FUNC_RETURN_(name, type, ...)\
153         MAYBE2(,##__VA_ARGS__, SIMCALL_WITH_FUNC_RETURN, SIMCALL_WITHOUT_FUNC_RETURN)\
154         (name, type, __VA_ARGS__)
155 #define SIMCALL_FUNC_RETURN(res) SIMCALL_FUNC_RETURN_ res
156
157
158 /* generate the simcall enumeration */
159 #define SIMCALL_ENUM(type, ...)\
160         type
161
162 /* generate the strings name from the enumeration values */
163 #define SIMCALL_STRING_TYPE(type, name, answer, res, ...)\
164         [type] = STRINGIFY(type)
165
166 /* generate strings from the enumeration values */
167 #define SIMCALL_TYPE(type, name, answer, res, ...)\
168         [type] = STRINGIFY(MAP(SIMCALL_FORMAT, __VA_ARGS__))
169
170 /* generate the simcalls BODY functions */
171 #define SIMCALL_FUNC(TYPE, NAME, ANSWER, RES, ...)\
172   inline static SIMCALL_FUNC_RETURN_TYPE(RES) simcall_BODY_##NAME(MAP(SIMCALL_ARG, ##__VA_ARGS__)) { \
173     smx_process_t self = SIMIX_process_self(); \
174     self->simcall.call = TYPE; \
175     memset(&self->simcall.result, 0, sizeof(self->simcall.result)); \
176     memset(self->simcall.args, 0, sizeof(self->simcall.args)); \
177     MAP_WITH_DEFAULT_ARGS(SIMCALL_INIT_FIELD, (), ##__VA_ARGS__) \
178     if (self != simix_global->maestro_process) { \
179       XBT_DEBUG("Yield process '%s' on simcall %s (%d)", self->name, \
180                 SIMIX_simcall_name(self->simcall.call), (int)self->simcall.call); \
181       SIMIX_process_yield(self); \
182     } else { \
183       SIMIX_simcall_pre(&self->simcall, 0); \
184     } \
185     SIMCALL_FUNC_RETURN(RES) \
186   }
187
188 /* generate a comma if there is an argument*/
189 #define WITHOUT_COMMA 
190 #define WITH_COMMA ,
191 #define GET_CLEAN(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10, NAME,...) NAME
192 #define MAYBE_COMMA(...) GET_CLEAN(,##__VA_ARGS__,WITH_COMMA,WITH_COMMA,WITH_COMMA,WITH_COMMA,WITH_COMMA,WITH_COMMA,WITH_COMMA,WITH_COMMA,WITH_COMMA,WITH_COMMA,WITHOUT_COMMA)
193
194 /* generate the simcalls cases for the SIMIX_simcall_pre function */
195 #define WITH_ANSWER(...) __VA_ARGS__
196 #define WITHOUT_ANSWER(...) 
197 #define SIMCALL_CASE(type, name, answer, res, ...)\
198     case type:\
199       SIMCALL_RESULT_BEGIN(answer, res) SIMIX_pre_ ## name(simcall MAYBE_COMMA(__VA_ARGS__) MAP(SIMCALL_CASE_PARAM, ##__VA_ARGS__));\
200       SIMCALL_RESULT_END(answer, res)\
201       break;
202
203
204 /*
205  * Generate simcall args and result getter/setter
206  */
207 #define SIMCALL_GS_SC_NAME_(n) n
208 #define SIMCALL_GS_SC_NAME(n) SIMCALL_GS_SC_NAME_ n
209 #define SIMCALL_GS_ARG_NAME(n) SIMCALL_NAME_ n
210 #define JOIN2(_0, _1) _0 ##__## _1
211 #define JOIN3(_0, _1, _2) JOIN2(_0 ##__## _1, _2)
212 #define JOIN4(_0, _1, _2, _3) JOIN3(_0 ##_## _1, _2, _3)
213 #define SIMCALL_GS_FUNC(scname, setget, vname) \
214    JOIN4(simcall, scname, setget, vname)
215
216 /* generate the simcalls args getter/setter */
217 #define SIMCALL_ARG_GETSET_(i, name, v) \
218   static inline SIMCALL_FUNC_RETURN_TYPE(v) SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME(name), get, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall){\
219     return simcall->args[i].SIMCALL_FIELD_ v ;\
220   }\
221   static inline void SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME(name), set, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall, SIMCALL_ARG_ v){\
222     simcall->args[i].SIMCALL_FIELD_ v = SIMCALL_NAME_ v ;\
223   }
224
225 #define SIMCALL_ARG_GETSET(type, name, answer, res, ...)\
226     MAP_WITH_DEFAULT_ARGS(SIMCALL_ARG_GETSET_, (name), ##__VA_ARGS__)
227
228 /* generate the simcalls result getter/setter */
229 #define SIMCALL_WITH_RES_GETSET(name, v) \
230   static inline SIMCALL_FUNC_RETURN_TYPE(v) SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME((name)), get, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall){\
231     return simcall->result.SIMCALL_FIELD_ v ;\
232   }\
233   static inline void SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME((name)), set, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall, SIMCALL_ARG_ v){\
234     simcall->result.SIMCALL_FIELD_ v = SIMCALL_NAME_ v ;\
235   }
236 #define SIMCALL_WITHOUT_RES_GETSET(name, v)
237 #define SIMCALL_RES_GETSET__(name, type, ...)\
238         MAYBE2(,##__VA_ARGS__, SIMCALL_WITH_RES_GETSET, SIMCALL_WITHOUT_RES_GETSET)
239 #define SIMCALL_RES_GETSET_(scname, v)\
240         SIMCALL_RES_GETSET__ v (scname, v)
241 #define SIMCALL_RES_GETSET(type, name, answer, res, ...)\
242   SIMCALL_RES_GETSET_(name, res)
243
244 /* generate the simcalls result getter/setter protos*/
245 #define SIMCALL_WITH_RES_GETSET_PROTO(name, v) \
246   inline SIMCALL_FUNC_RETURN_TYPE(v) SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME((name)), get, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall);\
247   inline void SIMCALL_GS_FUNC(SIMCALL_GS_SC_NAME((name)), set, SIMCALL_GS_ARG_NAME(v))(smx_simcall_t simcall, SIMCALL_ARG_ v);
248 #define SIMCALL_WITHOUT_RES_GETSET_PROTO(name, v)
249 #define SIMCALL_RES_GETSET_PROTO__(name, type, ...)\
250         MAYBE2(,##__VA_ARGS__, SIMCALL_WITH_RES_GETSET_PROTO, SIMCALL_WITHOUT_RES_GETSET_PROTO)
251 #define SIMCALL_RES_GETSET_PROTO_(scname, v)\
252         SIMCALL_RES_GETSET_PROTO__ v (scname, v)
253 #define SIMCALL_RES_GETSET_PROTO(type, name, answer, res, ...)\
254   SIMCALL_RES_GETSET_PROTO_(name, res)
255
256 /* stringify arguments */
257 #define STRINGIFY_(...) #__VA_ARGS__
258 #define STRINGIFY(...) STRINGIFY_(__VA_ARGS__)
259
260 /* the list of simcalls definitions */
261 #define SIMCALL_LIST1(ACTION, sep) \
262 ACTION(SIMCALL_HOST_GET_BY_NAME, host_get_by_name, WITH_ANSWER, TSPEC(result, smx_host_t), TSTRING(name)) sep \
263 ACTION(SIMCALL_HOST_GET_NAME, host_get_name, WITH_ANSWER, TSTRING(result), TSPEC(host, smx_host_t)) sep \
264 ACTION(SIMCALL_HOST_GET_PROPERTIES, host_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(host, smx_host_t)) sep \
265 ACTION(SIMCALL_HOST_GET_CORE, host_get_core, WITH_ANSWER, TINT(result), TSPEC(host, smx_host_t)) sep \
266 ACTION(SIMCALL_HOST_GET_PROCESS_LIST, host_get_process_list, WITH_ANSWER, TSPEC(result, xbt_swag_t), TSPEC(host, smx_host_t)) sep \
267 ACTION(SIMCALL_HOST_GET_SPEED, host_get_speed, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t)) sep \
268 ACTION(SIMCALL_HOST_GET_AVAILABLE_SPEED, host_get_available_speed, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t)) sep \
269 ACTION(SIMCALL_HOST_GET_STATE, host_get_state, WITH_ANSWER, TINT(result), TSPEC(host, smx_host_t)) sep \
270 ACTION(SIMCALL_HOST_GET_DATA, host_get_data, WITH_ANSWER, TPTR(result), TSPEC(host, smx_host_t)) sep \
271 ACTION(SIMCALL_HOST_SET_DATA, host_set_data, WITH_ANSWER, TVOID(result), TSPEC(host, smx_host_t), TPTR(data)) sep \
272 ACTION(SIMCALL_HOST_GET_CURRENT_POWER_PEAK, host_get_current_power_peak, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t)) sep \
273 ACTION(SIMCALL_HOST_GET_POWER_PEAK_AT, host_get_power_peak_at, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t), TINT(pstate_index)) sep \
274 ACTION(SIMCALL_HOST_GET_NB_PSTATES, host_get_nb_pstates, WITH_ANSWER, TINT(result), TSPEC(host, smx_host_t)) sep \
275 ACTION(SIMCALL_HOST_SET_POWER_PEAK_AT, host_set_power_peak_at, WITH_ANSWER, TVOID(result), TSPEC(host, smx_host_t), TINT(pstate_index)) sep \
276 ACTION(SIMCALL_HOST_GET_CONSUMED_ENERGY, host_get_consumed_energy, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t)) sep \
277 ACTION(SIMCALL_HOST_EXECUTE, host_execute, WITH_ANSWER, TSPEC(result, smx_action_t), TSTRING(name), TSPEC(host, smx_host_t), TDOUBLE(computation_amount), TDOUBLE(priority)) sep \
278 ACTION(SIMCALL_HOST_PARALLEL_EXECUTE, host_parallel_execute, WITH_ANSWER, TSPEC(result, smx_action_t), TSTRING(name), TINT(host_nb), TSPEC(host_list, smx_host_t*), TSPEC(computation_amount, double*), TSPEC(communication_amount, double*), TDOUBLE(amount), TDOUBLE(rate)) sep \
279 ACTION(SIMCALL_HOST_EXECUTION_DESTROY, host_execution_destroy, WITH_ANSWER, TVOID(result), TSPEC(execution, smx_action_t)) sep \
280 ACTION(SIMCALL_HOST_EXECUTION_CANCEL, host_execution_cancel, WITH_ANSWER, TVOID(result), TSPEC(execution, smx_action_t)) sep \
281 ACTION(SIMCALL_HOST_EXECUTION_GET_REMAINS, host_execution_get_remains, WITH_ANSWER, TDOUBLE(result), TSPEC(execution, smx_action_t)) sep \
282 ACTION(SIMCALL_HOST_EXECUTION_GET_STATE, host_execution_get_state, WITH_ANSWER, TINT(result), TSPEC(execution, smx_action_t)) sep \
283 ACTION(SIMCALL_HOST_EXECUTION_SET_PRIORITY, host_execution_set_priority, WITH_ANSWER, TVOID(result), TSPEC(execution, smx_action_t), TDOUBLE(priority)) sep \
284 ACTION(SIMCALL_HOST_EXECUTION_WAIT, host_execution_wait, WITHOUT_ANSWER, TINT(result), TSPEC(execution, smx_action_t)) sep \
285 ACTION(SIMCALL_HOST_GET_STORAGE_LIST, host_get_storage_list, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(host, smx_host_t)) sep \
286 ACTION(SIMCALL_PROCESS_CREATE, process_create, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t*), TSTRING(name), TSPEC(code, xbt_main_func_t), TPTR(data), TSTRING(hostname), TDOUBLE(kill_time), TINT(argc), TSPEC(argv, char**), TSPEC(properties, xbt_dict_t), TINT(auto_restart)) sep \
287 ACTION(SIMCALL_PROCESS_KILL, process_kill, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
288 ACTION(SIMCALL_PROCESS_KILLALL, process_killall, WITH_ANSWER, TVOID(result), TINT(reset_pid)) sep \
289 ACTION(SIMCALL_PROCESS_CLEANUP, process_cleanup, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
290 ACTION(SIMCALL_PROCESS_CHANGE_HOST, process_change_host, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t), TSPEC(dest, smx_host_t)) sep \
291 ACTION(SIMCALL_PROCESS_SUSPEND, process_suspend, WITHOUT_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
292 ACTION(SIMCALL_PROCESS_RESUME, process_resume, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t)) sep \
293 ACTION(SIMCALL_PROCESS_COUNT, process_count, WITH_ANSWER, TINT(result)) sep \
294 ACTION(SIMCALL_PROCESS_GET_PID, process_get_PID, WITH_ANSWER, TINT(result), TSPEC(process, smx_process_t)) sep  \
295 ACTION(SIMCALL_PROCESS_GET_PPID, process_get_PPID, WITH_ANSWER, TINT(result), TSPEC(process, smx_process_t)) sep  \
296 ACTION(SIMCALL_PROCESS_GET_DATA, process_get_data, WITH_ANSWER, TPTR(result), TSPEC(process, smx_process_t)) sep \
297 ACTION(SIMCALL_PROCESS_SET_DATA, process_set_data, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t), TPTR(data)) sep \
298 ACTION(SIMCALL_PROCESS_GET_HOST, process_get_host, WITH_ANSWER, TSPEC(result, smx_host_t), TSPEC(process, smx_process_t)) sep \
299 ACTION(SIMCALL_PROCESS_GET_NAME, process_get_name, WITH_ANSWER, TSTRING(result), TSPEC(process, smx_process_t)) sep \
300 ACTION(SIMCALL_PROCESS_IS_SUSPENDED, process_is_suspended, WITH_ANSWER, TINT(result), TSPEC(process, smx_process_t)) sep \
301 ACTION(SIMCALL_PROCESS_GET_PROPERTIES, process_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(process, smx_process_t)) sep \
302 ACTION(SIMCALL_PROCESS_SLEEP, process_sleep, WITHOUT_ANSWER, TINT(result), TDOUBLE(duration)) sep \
303 ACTION(SIMCALL_PROCESS_ON_EXIT, process_on_exit, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t), TSPEC(fun, int_f_pvoid_t), TPTR(data)) sep \
304 ACTION(SIMCALL_PROCESS_AUTO_RESTART_SET, process_auto_restart_set, WITH_ANSWER, TVOID(result), TSPEC(process, smx_process_t), TINT(auto_restart)) sep \
305 ACTION(SIMCALL_PROCESS_RESTART, process_restart, WITH_ANSWER, TSPEC(result, smx_process_t), TSPEC(process, smx_process_t)) sep \
306 ACTION(SIMCALL_RDV_CREATE, rdv_create, WITH_ANSWER, TSPEC(result, smx_rdv_t), TSTRING(name)) sep \
307 ACTION(SIMCALL_RDV_DESTROY, rdv_destroy, WITH_ANSWER, TVOID(result), TSPEC(rdv, smx_rdv_t)) sep \
308 ACTION(SIMCALL_RDV_GET_BY_NAME, rdv_get_by_name, WITH_ANSWER, TSPEC(result, smx_host_t), TSTRING(name)) sep \
309 ACTION(SIMCALL_RDV_COMM_COUNT_BY_HOST, rdv_comm_count_by_host, WITH_ANSWER, TUINT(result), TSPEC(rdv, smx_rdv_t), TSPEC(host, smx_host_t)) sep \
310 ACTION(SIMCALL_RDV_GET_HEAD, rdv_get_head, WITH_ANSWER, TSPEC(result, smx_action_t), TSPEC(rdv, smx_rdv_t)) sep \
311 ACTION(SIMCALL_RDV_SET_RECV, rdv_set_receiver, WITH_ANSWER, TVOID(result), TSPEC(rdv, smx_rdv_t), TSPEC(receiver, smx_process_t)) sep \
312 ACTION(SIMCALL_RDV_GET_RECV, rdv_get_receiver, WITH_ANSWER, TSPEC(result, smx_process_t), TSPEC(rdv, smx_rdv_t)) sep \
313 ACTION(SIMCALL_COMM_IPROBE, comm_iprobe, WITH_ANSWER, TSPEC(result, smx_action_t), TSPEC(rdv, smx_rdv_t), TINT(src), TINT(tag), TSPEC(match_fun, simix_match_func_t), TPTR(data)) sep \
314 ACTION(SIMCALL_COMM_SEND, comm_send, WITHOUT_ANSWER, TVOID(result), TSPEC(rdv, smx_rdv_t), TDOUBLE(task_size), TDOUBLE(rate), TPTR(src_buff), TSIZE(src_buff_size), TSPEC(match_fun, simix_match_func_t), TPTR(data), TDOUBLE(timeout)) sep \
315 ACTION(SIMCALL_COMM_ISEND, comm_isend, WITH_ANSWER, TSPEC(result, smx_action_t), TSPEC(rdv, smx_rdv_t), TDOUBLE(task_size), TDOUBLE(rate), TPTR(src_buff), TSIZE(src_buff_size), TSPEC(match_fun, simix_match_func_t), TSPEC(clean_fun, simix_clean_func_t), TPTR(data), TINT(detached)) sep \
316 ACTION(SIMCALL_COMM_RECV, comm_recv, WITHOUT_ANSWER, TVOID(result), TSPEC(rdv, smx_rdv_t), TPTR(dst_buff), TSPEC(dst_buff_size, size_t*), TSPEC(match_fun, simix_match_func_t), TPTR(data), TDOUBLE(timeout)) sep \
317 ACTION(SIMCALL_COMM_IRECV, comm_irecv, WITH_ANSWER, TSPEC(result, smx_action_t), TSPEC(rdv, smx_rdv_t), TPTR(dst_buff), TSPEC(dst_buff_size, size_t*), TSPEC(match_fun, simix_match_func_t), TPTR(data)) sep \
318 ACTION(SIMCALL_COMM_RECV_BOUNDED, comm_recv_bounded, WITHOUT_ANSWER, TVOID(result), TSPEC(rdv, smx_rdv_t), TPTR(dst_buff), TSPEC(dst_buff_size, size_t*), TSPEC(match_fun, simix_match_func_t), TPTR(data), TDOUBLE(timeout), TDOUBLE(rate)) sep \
319 ACTION(SIMCALL_COMM_IRECV_BOUNDED, comm_irecv_bounded, WITH_ANSWER, TSPEC(result, smx_action_t), TSPEC(rdv, smx_rdv_t), TPTR(dst_buff), TSPEC(dst_buff_size, size_t*), TSPEC(match_fun, simix_match_func_t), TPTR(data), TDOUBLE(rate)) sep \
320 ACTION(SIMCALL_COMM_DESTROY, comm_destroy, WITH_ANSWER, TVOID(result), TSPEC(comm, smx_action_t)) sep \
321 ACTION(SIMCALL_COMM_CANCEL, comm_cancel, WITH_ANSWER, TVOID(result), TSPEC(comm, smx_action_t)) sep \
322 ACTION(SIMCALL_COMM_WAITANY, comm_waitany, WITHOUT_ANSWER, TINT(result), TSPEC(comms, xbt_dynar_t)) sep \
323 ACTION(SIMCALL_COMM_WAIT, comm_wait, WITHOUT_ANSWER, TVOID(result), TSPEC(comm, smx_action_t), TDOUBLE(timeout)) sep \
324 ACTION(SIMCALL_COMM_TEST, comm_test, WITHOUT_ANSWER, TINT(result), TSPEC(comm, smx_action_t)) sep \
325 ACTION(SIMCALL_COMM_TESTANY, comm_testany, WITHOUT_ANSWER, TINT(result), TSPEC(comms, xbt_dynar_t)) sep \
326 ACTION(SIMCALL_COMM_GET_REMAINS, comm_get_remains, WITH_ANSWER, TDOUBLE(result), TSPEC(comm, smx_action_t)) sep \
327 ACTION(SIMCALL_COMM_GET_STATE, comm_get_state, WITH_ANSWER, TINT(result), TSPEC(comm, smx_action_t)) sep \
328 ACTION(SIMCALL_COMM_GET_SRC_DATA, comm_get_src_data, WITH_ANSWER, TPTR(result), TSPEC(comm, smx_action_t)) sep \
329 ACTION(SIMCALL_COMM_GET_DST_DATA, comm_get_dst_data, WITH_ANSWER, TPTR(result), TSPEC(comm, smx_action_t)) sep \
330 ACTION(SIMCALL_COMM_GET_SRC_PROC, comm_get_src_proc, WITH_ANSWER, TSPEC(result, smx_process_t), TSPEC(comm, smx_action_t)) sep \
331 ACTION(SIMCALL_COMM_GET_DST_PROC, comm_get_dst_proc, WITH_ANSWER, TSPEC(result, smx_process_t), TSPEC(comm, smx_action_t)) sep \
332 ACTION(SIMCALL_MUTEX_INIT, mutex_init, WITH_ANSWER, TSPEC(result, smx_mutex_t)) sep \
333 ACTION(SIMCALL_MUTEX_DESTROY, mutex_destroy, WITH_ANSWER, TVOID(result), TSPEC(mutex, smx_mutex_t)) sep \
334 ACTION(SIMCALL_MUTEX_LOCK, mutex_lock, WITHOUT_ANSWER, TVOID(result), TSPEC(mutex, smx_mutex_t)) sep \
335 ACTION(SIMCALL_MUTEX_TRYLOCK, mutex_trylock, WITH_ANSWER, TINT(result), TSPEC(mutex, smx_mutex_t)) sep \
336 ACTION(SIMCALL_MUTEX_UNLOCK, mutex_unlock, WITH_ANSWER, TVOID(result), TSPEC(mutex, smx_mutex_t)) sep \
337 ACTION(SIMCALL_COND_INIT, cond_init, WITH_ANSWER, TSPEC(result, smx_cond_t)) sep \
338 ACTION(SIMCALL_COND_DESTROY, cond_destroy, WITH_ANSWER, TVOID(result), TSPEC(cond, smx_cond_t)) sep \
339 ACTION(SIMCALL_COND_SIGNAL, cond_signal, WITH_ANSWER, TVOID(result), TSPEC(cond, smx_cond_t)) sep \
340 ACTION(SIMCALL_COND_WAIT, cond_wait, WITHOUT_ANSWER, TVOID(result), TSPEC(cond, smx_cond_t), TSPEC(mutex, smx_mutex_t)) sep \
341 ACTION(SIMCALL_COND_WAIT_TIMEOUT, cond_wait_timeout, WITHOUT_ANSWER, TVOID(result), TSPEC(cond, smx_cond_t), TSPEC(mutex, smx_mutex_t), TDOUBLE(timeout)) sep \
342 ACTION(SIMCALL_COND_BROADCAST, cond_broadcast, WITH_ANSWER, TVOID(result), TSPEC(cond, smx_cond_t)) sep \
343 ACTION(SIMCALL_SEM_INIT, sem_init, WITH_ANSWER, TSPEC(result, smx_sem_t), TINT(capacity)) sep \
344 ACTION(SIMCALL_SEM_DESTROY, sem_destroy, WITH_ANSWER, TVOID(result), TSPEC(sem, smx_sem_t)) sep \
345 ACTION(SIMCALL_SEM_RELEASE, sem_release, WITH_ANSWER, TVOID(result), TSPEC(sem, smx_sem_t)) sep \
346 ACTION(SIMCALL_SEM_WOULD_BLOCK, sem_would_block, WITH_ANSWER, TINT(result), TSPEC(sem, smx_sem_t)) sep \
347 ACTION(SIMCALL_SEM_ACQUIRE, sem_acquire, WITHOUT_ANSWER, TVOID(result), TSPEC(sem, smx_sem_t)) sep \
348 ACTION(SIMCALL_SEM_ACQUIRE_TIMEOUT, sem_acquire_timeout, WITHOUT_ANSWER, TVOID(result), TSPEC(sem, smx_sem_t), TDOUBLE(timeout)) sep \
349 ACTION(SIMCALL_SEM_GET_CAPACITY, sem_get_capacity, WITH_ANSWER, TINT(result), TSPEC(sem, smx_sem_t)) sep \
350 ACTION(SIMCALL_FILE_GET_DATA, file_get_data, WITH_ANSWER, TPTR(result), TSPEC(fd, smx_file_t)) sep \
351 ACTION(SIMCALL_FILE_SET_DATA, file_set_data, WITH_ANSWER, TVOID(result), TSPEC(fd, smx_file_t), TPTR(data)) sep \
352 ACTION(SIMCALL_FILE_READ, file_read, WITHOUT_ANSWER, TSIZE(result), TSPEC(fd, smx_file_t), TSIZE(size)) sep \
353 ACTION(SIMCALL_FILE_WRITE, file_write, WITHOUT_ANSWER, TSIZE(result), TSPEC(fd, smx_file_t), TSIZE(size)) sep \
354 ACTION(SIMCALL_FILE_OPEN, file_open, WITHOUT_ANSWER, TSPEC(result, smx_file_t), TSTRING(mount), TSTRING(path)) sep \
355 ACTION(SIMCALL_FILE_CLOSE, file_close, WITHOUT_ANSWER, TINT(result), TSPEC(fd, smx_file_t)) sep \
356 ACTION(SIMCALL_FILE_UNLINK, file_unlink, WITH_ANSWER, TINT(result), TSPEC(fd, smx_file_t)) sep \
357 ACTION(SIMCALL_FILE_LS, file_ls, WITHOUT_ANSWER, TSPEC(result, xbt_dict_t), TSTRING(mount), TSTRING(path)) sep \
358 ACTION(SIMCALL_FILE_GET_SIZE, file_get_size, WITH_ANSWER, TSIZE(result), TSPEC(fd, smx_file_t)) sep \
359 ACTION(SIMCALL_FILE_GET_INFO, file_get_info, WITH_ANSWER, TSPEC(result, xbt_dynar_t), TSPEC(fd, smx_file_t)) sep \
360 ACTION(SIMCALL_STORAGE_GET_FREE_SIZE, storage_get_free_size, WITH_ANSWER, TSIZE(result), TSTRING(name)) sep \
361 ACTION(SIMCALL_STORAGE_GET_USED_SIZE, storage_get_used_size, WITH_ANSWER, TSIZE(result), TSTRING(name)) sep \
362 ACTION(SIMCALL_STORAGE_GET_PROPERTIES, storage_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(storage, smx_storage_t)) sep \
363 ACTION(SIMCALL_STORAGE_GET_CONTENT, storage_get_content, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(storage, smx_storage_t)) sep \
364 ACTION(SIMCALL_ASR_GET_PROPERTIES, asr_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSTRING(name)) sep 
365
366 /* SIMCALL_COMM_IS_LATENCY_BOUNDED and SIMCALL_SET_CATEGORY make things complicated
367  * because they are not always present */
368 #ifdef HAVE_LATENCY_BOUND_TRACKING
369 #define SIMCALL_LIST2(ACTION, sep) \
370 ACTION(SIMCALL_COMM_IS_LATENCY_BOUNDED, comm_is_latency_bounded, WITH_ANSWER, TINT(result), TSPEC(comm, smx_action_t)) sep
371 #else
372 #define SIMCALL_LIST2(ACTION, sep)
373 #endif
374
375 #ifdef HAVE_TRACING
376 #define SIMCALL_LIST3(ACTION, sep) \
377 ACTION(SIMCALL_SET_CATEGORY, set_category, WITH_ANSWER, TVOID(result), TSPEC(action, smx_action_t), TSTRING(category)) sep
378 #else
379 #define SIMCALL_LIST3(ACTION, sep)
380 #endif
381
382 #ifdef HAVE_MC
383 #define SIMCALL_LIST4(ACTION, sep) \
384 ACTION(SIMCALL_MC_SNAPSHOT, mc_snapshot, WITH_ANSWER, TPTR(result)) sep \
385 ACTION(SIMCALL_MC_COMPARE_SNAPSHOTS, mc_compare_snapshots, WITH_ANSWER, TINT(result), TPTR(s1), TPTR(s2)) sep \
386 ACTION(SIMCALL_MC_RANDOM, mc_random, WITH_ANSWER, TINT(result), TINT(min), TINT(max)) sep
387 #else
388 #define SIMCALL_LIST4(ACTION, sep)
389 #endif
390
391 /* SIMCALL_LIST is the final macro to use */
392 #define SIMCALL_LIST(ACTION, ...) \
393   SIMCALL_LIST1(ACTION, ##__VA_ARGS__)\
394   SIMCALL_LIST2(ACTION, ##__VA_ARGS__)\
395   SIMCALL_LIST3(ACTION, ##__VA_ARGS__)\
396   SIMCALL_LIST4(ACTION, ##__VA_ARGS__)
397
398
399 /* you can redefine the following macro differently to generate something else
400  * with the list of enumeration values (e.g. a table of strings or a table of function pointers) */
401 #define SIMCALL_ENUM_ELEMENT(x, y) x
402
403 /**
404  * \brief All possible simcalls.
405  */
406 typedef enum {
407 SIMCALL_NONE,
408 SIMCALL_LIST(SIMCALL_ENUM, SIMCALL_SEP_COMMA)
409 SIMCALL_NEW_API_INIT,
410 NUM_SIMCALLS
411 } e_smx_simcall_t;
412
413 typedef int (*simix_match_func_t)(void *, void *, smx_action_t);
414 typedef void (*simix_clean_func_t)(void *);
415
416 /* Pack all possible scalar types in an union */
417 union u_smx_scalar {
418   char            c;
419   const char*     cc;
420   short           s;
421   int             i;
422   long            l;
423   unsigned char   uc;
424   unsigned short  us;
425   unsigned int    ui;
426   unsigned long   ul;
427   float           f;
428   double          d;
429   size_t          si;
430   void*           p;
431   const void*     cp;
432 };
433
434 /**
435  * \brief Represents a simcall to the kernel.
436  */
437 typedef struct s_smx_simcall {
438   e_smx_simcall_t call;
439   smx_process_t issuer;
440   int mc_value;
441   union u_smx_scalar args[10];
442   union u_smx_scalar result;
443   //FIXME: union u_smx_scalar retval;
444   union {
445     struct {
446       const char* param1;
447       double param2;
448       int result;
449     } new_api;
450
451   };
452 } s_smx_simcall_t, *smx_simcall_t;
453
454 SIMCALL_LIST(SIMCALL_RES_GETSET, SIMCALL_SEP_NOTHING)
455 SIMCALL_LIST(SIMCALL_ARG_GETSET, SIMCALL_SEP_NOTHING)
456
457 /******************************** General *************************************/
458
459 void SIMIX_simcall_push(smx_process_t self);
460 void SIMIX_simcall_answer(smx_simcall_t);
461 void SIMIX_simcall_pre(smx_simcall_t, int);
462 void SIMIX_simcall_post(smx_action_t);
463 smx_simcall_t SIMIX_simcall_mine(void);
464 const char *SIMIX_simcall_name(e_smx_simcall_t kind);
465 //TOFIX put it in a better place
466 xbt_dict_t SIMIX_pre_asr_get_properties(smx_simcall_t simcall, const char *name);
467
468 /*************************** New simcall interface ****************************/
469
470 typedef smx_action_t (*simcall_handler_t)(u_smx_scalar_t *);
471
472 extern const char *simcall_types[];
473 extern simcall_handler_t simcall_table[];
474
475 #endif
476