Logo AND Algorithmique Numérique Distribuée

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