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 e_smx_state_t result;
246 } host_execution_wait;
249 smx_process_t *process;
251 xbt_main_func_t code;
253 const char *hostname;
257 xbt_dict_t properties;
262 smx_process_t process;
266 smx_process_t process;
270 smx_process_t process;
272 } process_change_host;
275 smx_process_t process;
279 smx_process_t process;
287 smx_process_t process;
292 smx_process_t process;
297 smx_process_t process;
302 smx_process_t process;
307 smx_process_t process;
309 } process_is_suspended;
312 smx_process_t process;
314 } process_get_properties;
318 e_smx_state_t result;
322 smx_process_t process;
328 smx_process_t process;
330 } process_auto_restart;
333 smx_process_t process;
334 smx_process_t result;
355 } rdv_comm_count_by_host;
364 smx_process_t receiver;
369 smx_process_t result;
377 size_t src_buff_size;
378 int (*match_fun)(void *, void *, smx_action_t);
388 size_t src_buff_size;
389 int (*match_fun)(void *, void *, smx_action_t);
390 void (*clean_fun)(void *);
399 size_t *dst_buff_size;
400 int (*match_fun)(void *, void *, smx_action_t);
408 size_t *dst_buff_size;
409 int (*match_fun)(void *, void *, smx_action_t);
418 int (*match_fun)(void *, void *, smx_action_t);
458 e_smx_state_t result;
473 smx_process_t result;
478 smx_process_t result;
481 #ifdef HAVE_LATENCY_BOUND_TRACKING
485 } comm_is_latency_bounded;
491 const char *category;
568 } sem_acquire_timeout;
623 } asr_get_properties;
633 } mc_compare_snapshots;
635 /* ****************************************************************************************** */
636 /* TUTORIAL: New API */
637 /* ****************************************************************************************** */
645 } s_smx_simcall_t, *smx_simcall_t;
647 /******************************** General *************************************/
649 void SIMIX_simcall_push(smx_process_t self);
650 void SIMIX_simcall_answer(smx_simcall_t);
651 void SIMIX_simcall_pre(smx_simcall_t, int);
652 void SIMIX_simcall_post(smx_action_t);
653 smx_simcall_t SIMIX_simcall_mine(void);
654 const char *SIMIX_simcall_name(e_smx_simcall_t kind);
656 /*************************** New simcall interface ****************************/
658 /* Pack all possible scalar types in an union */
675 * Define scalar type wrappers to ease the use of simcalls.
676 * These are used to wrap the arguments in SIMIX_simcall macro.
678 #define CHAR(x) (c,x)
679 #define STRING(x) (cc,x)
680 #define SHORT(x) (s,x)
682 #define LONG(x) (l,x)
683 #define UCHAR(x) (uc,x)
684 #define USHORT(x) (us,x)
685 #define UINT(x) (ui,x)
686 #define ULONG(x) (ul,x)
687 #define FLOAT(x) (f,x)
688 #define DOUBLE(x) (d,x)
694 * Some macro machinery to get a MAP over the arguments of a variadic macro.
695 * It uses a FOLD to apply a macro to every argument, and because there is
696 * no recursion in the C preprocessor we must create a new macro for every
697 * depth of FOLD's recursion.
701 #define FE_1(WHAT, X) WHAT(X)
702 #define FE_2(WHAT, X, ...) WHAT(X), FE_1(WHAT, __VA_ARGS__)
703 #define FE_3(WHAT, X, ...) WHAT(X), FE_2(WHAT, __VA_ARGS__)
704 #define FE_4(WHAT, X, ...) WHAT(X), FE_3(WHAT, __VA_ARGS__)
705 #define FE_5(WHAT, X, ...) WHAT(X), FE_4(WHAT, __VA_ARGS__)
706 /* NOTE: add as many FE_n as needed (maximum number of simcall arguments )*/
708 /* Make a MAP macro usgin FOLD (will apply 'action' to the arguments.
709 * GET_MACRO is a smart hack that counts the number of arguments passed to
710 * the variadic macro, and it is used to invoke the right FOLD depth.
712 #define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
713 #define MAP(action,...) \
714 GET_MACRO(__VA_ARGS__,FE_5,FE_4,FE_3,FE_2,FE_1) (action, __VA_ARGS__)
717 /* Generate code to initialize the field 'x' with value 'y' of an structure or union */
718 #define INIT_FIELD_(x,y) {.x = y}
719 #define INIT_FIELD(t) INIT_FIELD_ t
721 /* Project the second element of a tuple */
722 #define SECOND_(x, y) y
723 #define SECOND(t) SECOND_ t
726 * \brief Simcall invocation macro
727 * It calls a dummy function that uses the format attribute to ensure typesafety (see
728 * gcc format attribute), then it invokes the real simcall function packing the
729 * user provided arguments in an array.
730 * \param id a simcall id (from the simcall enumeration ids)
733 #define SIMIX_simcall(id, ...) \
734 SIMIX_simcall_typecheck(simcall_types[id], MAP(SECOND, __VA_ARGS__)); \
735 __SIMIX_simcall(id, (u_smx_scalar_t[]){MAP(INIT_FIELD, __VA_ARGS__)})
737 void __SIMIX_simcall(e_smx_simcall_t simcall_id, u_smx_scalar_t *args);
740 * \biref Dummy variadic function used to typecheck the arguments of a simcall
741 * \param fmt A format string following printf style
743 void SIMIX_simcall_typecheck(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
745 typedef smx_action_t (*simcall_handler_t)(u_smx_scalar_t *);
747 extern const char *simcall_types[];
748 extern simcall_handler_t simcall_table[];