Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge back master branch.
[simgrid.git] / src / simix / smurf_private.h
1 /* Copyright (c) 2007, 2008, 2009, 2010. 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 /********************************* Requests ***********************************/
11
12 /* we want to build the e_smx_t enumeration and the table of the corresponding
13  * strings automatically, using macros */
14
15 #define SIMIX_REQ_LIST1 \
16 SIMIX_REQ_ENUM_ELEMENT(REQ_NO_REQ),\
17 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_BY_NAME),\
18 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_NAME),\
19 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_PROPERTIES),\
20 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_SPEED),\
21 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_AVAILABLE_SPEED),\
22 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_STATE),\
23 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_GET_DATA),\
24 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_SET_DATA),\
25 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTE),\
26 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_PARALLEL_EXECUTE),\
27 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_DESTROY),\
28 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_CANCEL),\
29 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_GET_REMAINS),\
30 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_GET_STATE),\
31 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_SET_PRIORITY),\
32 SIMIX_REQ_ENUM_ELEMENT(REQ_HOST_EXECUTION_WAIT),\
33 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_CREATE),\
34 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_KILL),\
35 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_KILLALL),\
36 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_CLEANUP),\
37 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_CHANGE_HOST),\
38 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_SUSPEND),\
39 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_RESUME),\
40 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_COUNT),\
41 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_DATA),\
42 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_SET_DATA),\
43 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_HOST),\
44 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_NAME),\
45 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_IS_SUSPENDED),\
46 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_PROPERTIES),\
47 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_SLEEP),\
48 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_CREATE),\
49 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_DESTROY),\
50 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_GEY_BY_NAME),\
51 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_COMM_COUNT_BY_HOST),\
52 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_GET_HEAD),\
53 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_SEND),\
54 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_ISEND),\
55 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_RECV),\
56 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_IRECV),\
57 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_DESTROY),\
58 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_CANCEL),\
59 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_WAITANY),\
60 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_WAIT),\
61 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_TEST),\
62 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_TESTANY),\
63 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_REMAINS),\
64 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_STATE),\
65 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_SRC_DATA),\
66 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_DST_DATA),\
67 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_SRC_PROC),\
68 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_DST_PROC),\
69 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_INIT),\
70 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_DESTROY),\
71 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_LOCK),\
72 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_TRYLOCK),\
73 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_UNLOCK),\
74 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_INIT),\
75 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_DESTROY),\
76 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_SIGNAL),\
77 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_WAIT),\
78 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_WAIT_TIMEOUT),\
79 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_BROADCAST),\
80 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_INIT),\
81 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_DESTROY),\
82 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_RELEASE),\
83 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_WOULD_BLOCK),\
84 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_ACQUIRE),\
85 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_ACQUIRE_TIMEOUT),\
86 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_GET_CAPACITY)
87
88 /* REQ_COMM_IS_LATENCY_BOUNDED and REQ_SET_CATEGORY make things complicated
89  * because they are not always present */
90 #ifdef HAVE_LATENCY_BOUND_TRACKING
91 #define SIMIX_REQ_LIST2 \
92 ,SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_IS_LATENCY_BOUNDED)
93 #else
94 #define SIMIX_REQ_LIST2
95 #endif
96
97 #ifdef HAVE_TRACING
98 #define SIMIX_REQ_LIST3 \
99 ,SIMIX_REQ_ENUM_ELEMENT(REQ_SET_CATEGORY)
100 #else
101 #define SIMIX_REQ_LIST3
102 #endif
103
104 /* SIMIX_REQ_LIST is the final macro to use */
105 #define SIMIX_REQ_LIST SIMIX_REQ_LIST1 SIMIX_REQ_LIST2 SIMIX_REQ_LIST3
106
107 /* you can redefine the following macro differently to generate something else
108  * with the list of enumeration values (e.g. a table of strings or a table of function pointers) */
109 #define SIMIX_REQ_ENUM_ELEMENT(x) x
110
111 /**
112  * \brief All possible SIMIX requests.
113  */
114 typedef enum {
115 SIMIX_REQ_LIST
116 } e_smx_req_t;
117
118 /**
119  * \brief Represents a SIMIX request.
120  */
121 typedef struct s_smx_req {
122   e_smx_req_t call;
123   smx_process_t issuer;
124
125   union {
126
127     struct {
128       const char *name;
129       smx_host_t result;
130     } host_get_by_name;
131
132     struct {
133       smx_host_t host;
134       const char* result;
135     } host_get_name;
136
137     struct {
138       smx_host_t host;
139       xbt_dict_t result;
140     } host_get_properties;
141
142     struct {
143       smx_host_t host;
144       double result;
145     } host_get_speed;
146
147     struct {
148       smx_host_t host;
149       double result;
150     } host_get_available_speed;
151
152     struct {
153       smx_host_t host;
154       int result;
155     } host_get_state;
156
157     struct {
158       smx_host_t host;
159       void* result;
160     } host_get_data;
161
162     struct {
163       smx_host_t host;
164       void* data;
165     } host_set_data;
166
167     struct {
168       const char* name;
169       smx_host_t host;
170       double computation_amount;
171       double priority;
172       smx_action_t result;
173     } host_execute;
174
175     struct {
176       const char *name;
177       int host_nb;
178       smx_host_t *host_list;
179       double *computation_amount;
180       double *communication_amount;
181       double amount;
182       double rate;
183       smx_action_t result;
184     } host_parallel_execute;
185
186     struct {
187       smx_action_t execution;
188     } host_execution_destroy;
189
190     struct {
191       smx_action_t execution;
192     } host_execution_cancel;
193
194     struct {
195       smx_action_t execution;
196       double result;
197     } host_execution_get_remains;
198
199     struct {
200       smx_action_t execution;
201       e_smx_state_t result;
202     } host_execution_get_state;
203
204     struct {
205       smx_action_t execution;
206       double priority;
207     } host_execution_set_priority;
208
209     struct {
210       smx_action_t execution;
211       e_smx_state_t result;
212     } host_execution_wait;
213
214     struct {
215       smx_process_t *process;
216       const char *name;
217       xbt_main_func_t code;
218       void *data;
219       const char *hostname;
220       int argc;
221       char **argv;
222       xbt_dict_t properties;
223     } process_create;
224
225     struct {
226       smx_process_t process;
227     } process_kill;
228
229     struct {
230       smx_process_t process;
231     } process_cleanup;
232
233     struct {
234       smx_process_t process;
235       smx_host_t dest;
236     } process_change_host;
237
238     struct {
239       smx_process_t process;
240     } process_suspend;
241
242     struct {
243       smx_process_t process;
244     } process_resume;
245
246     struct {
247       int result;
248     } process_count;
249
250     struct {
251       smx_process_t process;
252       void* result;
253     } process_get_data;
254
255     struct {
256       smx_process_t process;
257       void* data;
258     } process_set_data;
259
260     struct {
261       smx_process_t process;
262       smx_host_t result;
263     } process_get_host;
264
265     struct {
266       smx_process_t process;
267       const char *result;
268     } process_get_name;
269
270     struct {
271       smx_process_t process;
272       int result;
273     } process_is_suspended;
274
275     struct {
276       smx_process_t process;
277       xbt_dict_t result;
278     } process_get_properties;
279
280     struct {
281       double duration;
282       e_smx_state_t result;
283     } process_sleep;
284
285     struct {
286       const char *name;
287       smx_rdv_t result;
288     } rdv_create;
289
290     struct {
291       smx_rdv_t rdv;
292     } rdv_destroy;
293
294     struct {
295       const char* name;
296       smx_rdv_t result;
297     } rdv_get_by_name;
298
299     struct {
300       smx_rdv_t rdv;
301       smx_host_t host;
302       unsigned int result; 
303     } rdv_comm_count_by_host;
304
305     struct {
306       smx_rdv_t rdv;
307       smx_action_t result;
308     } rdv_get_head;
309
310     struct {
311       smx_rdv_t rdv;
312       double task_size;
313       double rate;
314       void *src_buff;
315       size_t src_buff_size;
316       int (*match_fun)(void *, void *);
317       void *data;
318       double timeout;
319     } comm_send;
320
321     struct {
322       smx_rdv_t rdv;
323       double task_size;
324       double rate;
325       void *src_buff;
326       size_t src_buff_size;
327       int (*match_fun)(void *, void *);
328       void *data;
329       int detached;
330       smx_action_t result;
331     } comm_isend;
332
333     struct {
334       smx_rdv_t rdv;
335       void *dst_buff;
336       size_t *dst_buff_size;
337       int (*match_fun)(void *, void *);
338       void *data;
339       double timeout;
340     } comm_recv;
341
342     struct {
343       smx_rdv_t rdv;
344       void *dst_buff;
345       size_t *dst_buff_size;
346       int (*match_fun)(void *, void *);
347           void *data;
348       smx_action_t result;
349     } comm_irecv;
350
351     struct {
352       smx_action_t comm;
353     } comm_destroy;
354
355     struct {
356       smx_action_t comm;
357     } comm_cancel;
358
359     struct {
360       xbt_dynar_t comms;
361       unsigned int result;
362     } comm_waitany;
363
364     struct {
365       smx_action_t comm;
366       double timeout;
367     } comm_wait;
368
369     struct {
370       smx_action_t comm;
371       int result;
372     } comm_test;
373
374     struct {
375       xbt_dynar_t comms;
376       int result;
377     } comm_testany;
378
379     struct {
380       smx_action_t comm;
381       double result;
382     } comm_get_remains;
383
384     struct {
385       smx_action_t comm;
386       e_smx_state_t result;
387     } comm_get_state;
388
389     struct {
390       smx_action_t comm;
391       void *result;
392     } comm_get_src_data;
393
394     struct {
395       smx_action_t comm;
396       void *result;
397     } comm_get_dst_data;
398
399     struct {
400       smx_action_t comm;
401       smx_process_t result;
402     } comm_get_src_proc;
403
404     struct {
405       smx_action_t comm;
406       smx_process_t result;
407     } comm_get_dst_proc;
408
409 #ifdef HAVE_LATENCY_BOUND_TRACKING
410     struct {
411       smx_action_t comm;
412       int result;
413     } comm_is_latency_bounded;
414 #endif
415
416 #ifdef HAVE_TRACING
417     struct {
418       smx_action_t action;
419       const char *category;
420     } set_category;
421 #endif
422
423     struct {
424       smx_mutex_t result;
425     } mutex_init;
426
427     struct {
428       smx_mutex_t mutex;
429     } mutex_lock;
430
431     struct {
432       smx_mutex_t mutex;
433       int result;
434     } mutex_trylock;
435
436     struct {
437       smx_mutex_t mutex;
438     } mutex_unlock;
439
440     struct {
441       smx_mutex_t mutex;
442     } mutex_destroy;
443
444     struct {
445       smx_cond_t result;
446     } cond_init;
447
448     struct {
449       smx_cond_t cond;
450     } cond_destroy;
451
452     struct {
453       smx_cond_t cond;
454     } cond_signal;
455
456     struct {
457       smx_cond_t cond;
458       smx_mutex_t mutex;
459     } cond_wait;
460
461     struct {
462       smx_cond_t cond;
463       smx_mutex_t mutex;
464       double timeout;
465     } cond_wait_timeout;
466
467     struct {
468       smx_cond_t cond;
469     } cond_broadcast;
470
471     struct {
472       int capacity;
473       smx_sem_t result;
474     } sem_init;
475
476     struct {
477       smx_sem_t sem;
478     } sem_destroy;
479
480     struct {
481       smx_sem_t sem;
482     } sem_release;
483
484     struct {
485       smx_sem_t sem;
486       int result;
487     } sem_would_block;
488
489     struct {
490       smx_sem_t sem;
491     } sem_acquire;
492
493     struct {
494       smx_sem_t sem;
495       double timeout;
496     } sem_acquire_timeout;
497
498     struct {
499       smx_sem_t sem;
500       int result;
501     } sem_get_capacity;
502   };
503 } s_smx_req_t, *smx_req_t;
504
505 /******************************** General *************************************/
506
507 void SIMIX_request_push(void);
508 void SIMIX_request_answer(smx_req_t);
509 void SIMIX_request_pre(smx_req_t, int);
510 void SIMIX_request_post(smx_action_t);
511 XBT_INLINE smx_req_t SIMIX_req_mine(void);
512
513 #endif
514