Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
97cbbd83e6d50f9904561a13e88192ab1226ecbf
[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_CLEANUP),\
36 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_CHANGE_HOST),\
37 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_SUSPEND),\
38 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_RESUME),\
39 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_COUNT),\
40 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_DATA),\
41 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_SET_DATA),\
42 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_HOST),\
43 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_NAME),\
44 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_IS_SUSPENDED),\
45 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_GET_PROPERTIES),\
46 SIMIX_REQ_ENUM_ELEMENT(REQ_PROCESS_SLEEP),\
47 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_CREATE),\
48 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_DESTROY),\
49 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_GEY_BY_NAME),\
50 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_COMM_COUNT_BY_HOST),\
51 SIMIX_REQ_ENUM_ELEMENT(REQ_RDV_GET_HEAD),\
52 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_SEND),\
53 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_ISEND),\
54 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_RECV),\
55 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_IRECV),\
56 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_DESTROY),\
57 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_CANCEL),\
58 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_WAITANY),\
59 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_WAIT),\
60 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_TEST),\
61 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_TESTANY),\
62 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_REMAINS),\
63 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_STATE),\
64 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_SRC_DATA),\
65 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_DST_DATA),\
66 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_SRC_PROC),\
67 SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_GET_DST_PROC),\
68 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_INIT),\
69 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_DESTROY),\
70 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_LOCK),\
71 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_TRYLOCK),\
72 SIMIX_REQ_ENUM_ELEMENT(REQ_MUTEX_UNLOCK),\
73 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_INIT),\
74 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_DESTROY),\
75 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_SIGNAL),\
76 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_WAIT),\
77 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_WAIT_TIMEOUT),\
78 SIMIX_REQ_ENUM_ELEMENT(REQ_COND_BROADCAST),\
79 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_INIT),\
80 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_DESTROY),\
81 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_RELEASE),\
82 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_WOULD_BLOCK),\
83 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_ACQUIRE),\
84 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_ACQUIRE_TIMEOUT),\
85 SIMIX_REQ_ENUM_ELEMENT(REQ_SEM_GET_CAPACITY)
86
87 /* REQ_COMM_IS_LATENCY_BOUNDED and REQ_SET_CATEGORY make things complicated
88  * because they are not always present */
89 #ifdef HAVE_LATENCY_BOUND_TRACKING
90 #define SIMIX_REQ_LIST2 \
91 ,SIMIX_REQ_ENUM_ELEMENT(REQ_COMM_IS_LATENCY_BOUNDED)
92 #else
93 #define SIMIX_REQ_LIST2
94 #endif
95
96 #ifdef HAVE_TRACING
97 #define SIMIX_REQ_LIST3 \
98 ,SIMIX_REQ_ENUM_ELEMENT(REQ_SET_CATEGORY)
99 #else
100 #define SIMIX_REQ_LIST3
101 #endif
102
103 /* SIMIX_REQ_LIST is the final macro to use */
104 #define SIMIX_REQ_LIST SIMIX_REQ_LIST1 SIMIX_REQ_LIST2 SIMIX_REQ_LIST3
105
106 /* you can redefine the following macro differently to generate something else
107  * with the list of enumeration values (e.g. a table of strings or a table of function pointers) */
108 #define SIMIX_REQ_ENUM_ELEMENT(x) x
109
110 /**
111  * \brief All possible SIMIX requests.
112  */
113 typedef enum {
114 SIMIX_REQ_LIST
115 } e_smx_req_t;
116
117 /**
118  * \brief Represents a SIMIX request.
119  */
120 typedef struct s_smx_req {
121   s_xbt_swag_hookup_t reqtable_hookup;
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       const char *source;
236       const char *dest;
237     } process_change_host;
238
239     struct {
240       smx_process_t process;
241     } process_suspend;
242
243     struct {
244       smx_process_t process;
245     } process_resume;
246
247     struct {
248       int result;
249     } process_count;
250
251     struct {
252       smx_process_t process;
253       void* result;
254     } process_get_data;
255
256     struct {
257       smx_process_t process;
258       void* data;
259     } process_set_data;
260
261     struct {
262       smx_process_t process;
263       smx_host_t result;
264     } process_get_host;
265
266     struct {
267       smx_process_t process;
268       const char *result;
269     } process_get_name;
270
271     struct {
272       smx_process_t process;
273       int result;
274     } process_is_suspended;
275
276     struct {
277       smx_process_t process;
278       xbt_dict_t result;
279     } process_get_properties;
280
281     struct {
282       double duration;
283       e_smx_state_t result;
284     } process_sleep;
285
286     struct {
287       const char *name;
288       smx_rdv_t result;
289     } rdv_create;
290
291     struct {
292       smx_rdv_t rdv;
293     } rdv_destroy;
294
295     struct {
296       const char* name;
297       smx_rdv_t result;
298     } rdv_get_by_name;
299
300     struct {
301       smx_rdv_t rdv;
302       smx_host_t host;
303       unsigned int result; 
304     } rdv_comm_count_by_host;
305
306     struct {
307       smx_rdv_t rdv;
308       smx_action_t result;
309     } rdv_get_head;
310
311     struct {
312       smx_rdv_t rdv;
313       double task_size;
314       double rate;
315       void *src_buff;
316       size_t src_buff_size;
317       int (*match_fun)(void *, void *);
318       void *data;
319       double timeout;
320     } comm_send;
321
322     struct {
323       smx_rdv_t rdv;
324       double task_size;
325       double rate;
326       void *src_buff;
327       size_t src_buff_size;
328       int (*match_fun)(void *, void *);
329       void *data;
330       int detached;
331       smx_action_t result;
332     } comm_isend;
333
334     struct {
335       smx_rdv_t rdv;
336       void *dst_buff;
337       size_t *dst_buff_size;
338       int (*match_fun)(void *, void *);
339       void *data;
340       double timeout;
341     } comm_recv;
342
343     struct {
344       smx_rdv_t rdv;
345       void *dst_buff;
346       size_t *dst_buff_size;
347       int (*match_fun)(void *, void *);
348           void *data;
349       smx_action_t result;
350     } comm_irecv;
351
352     struct {
353       smx_action_t comm;
354     } comm_destroy;
355
356     struct {
357       smx_action_t comm;
358     } comm_cancel;
359
360     struct {
361       xbt_dynar_t comms;
362       unsigned int result;
363     } comm_waitany;
364
365     struct {
366       smx_action_t comm;
367       double timeout;
368     } comm_wait;
369
370     struct {
371       smx_action_t comm;
372       int result;
373     } comm_test;
374
375     struct {
376       xbt_dynar_t comms;
377       int result;
378     } comm_testany;
379
380     struct {
381       smx_action_t comm;
382       double result;
383     } comm_get_remains;
384
385     struct {
386       smx_action_t comm;
387       e_smx_state_t result;
388     } comm_get_state;
389
390     struct {
391       smx_action_t comm;
392       void *result;
393     } comm_get_src_data;
394
395     struct {
396       smx_action_t comm;
397       void *result;
398     } comm_get_dst_data;
399
400     struct {
401       smx_action_t comm;
402       smx_process_t result;
403     } comm_get_src_proc;
404
405     struct {
406       smx_action_t comm;
407       smx_process_t result;
408     } comm_get_dst_proc;
409
410 #ifdef HAVE_LATENCY_BOUND_TRACKING
411     struct {
412       smx_action_t comm;
413       int result;
414     } comm_is_latency_bounded;
415 #endif
416
417 #ifdef HAVE_TRACING
418     struct {
419       smx_action_t action;
420       const char *category;
421     } set_category;
422 #endif
423
424     struct {
425       smx_mutex_t result;
426     } mutex_init;
427
428     struct {
429       smx_mutex_t mutex;
430     } mutex_lock;
431
432     struct {
433       smx_mutex_t mutex;
434       int result;
435     } mutex_trylock;
436
437     struct {
438       smx_mutex_t mutex;
439     } mutex_unlock;
440
441     struct {
442       smx_mutex_t mutex;
443     } mutex_destroy;
444
445     struct {
446       smx_cond_t result;
447     } cond_init;
448
449     struct {
450       smx_cond_t cond;
451     } cond_destroy;
452
453     struct {
454       smx_cond_t cond;
455     } cond_signal;
456
457     struct {
458       smx_cond_t cond;
459       smx_mutex_t mutex;
460     } cond_wait;
461
462     struct {
463       smx_cond_t cond;
464       smx_mutex_t mutex;
465       double timeout;
466     } cond_wait_timeout;
467
468     struct {
469       smx_cond_t cond;
470     } cond_broadcast;
471
472     struct {
473       int capacity;
474       smx_sem_t result;
475     } sem_init;
476
477     struct {
478       smx_sem_t sem;
479     } sem_destroy;
480
481     struct {
482       smx_sem_t sem;
483     } sem_release;
484
485     struct {
486       smx_sem_t sem;
487       int result;
488     } sem_would_block;
489
490     struct {
491       smx_sem_t sem;
492     } sem_acquire;
493
494     struct {
495       smx_sem_t sem;
496       double timeout;
497     } sem_acquire_timeout;
498
499     struct {
500       smx_sem_t sem;
501       int result;
502     } sem_get_capacity;
503   };
504 } s_smx_req_t, *smx_req_t;
505
506 /******************************** General *************************************/
507
508 void SIMIX_request_init(void);
509 void SIMIX_request_destroy(void);
510 xbt_swag_t SIMIX_request_get_reqlist(int thread_pid);
511 void SIMIX_request_push(void);
512 smx_req_t SIMIX_request_pop(void);
513 void SIMIX_request_answer(smx_req_t);
514 void SIMIX_request_pre(smx_req_t, int);
515 void SIMIX_request_post(smx_action_t);
516 XBT_INLINE smx_req_t SIMIX_req_mine(void);
517
518 #endif
519