Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a simcall for process_on_exit
[simgrid.git] / src / simix / smx_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 /********************************* Simcalls *********************************/
11
12 /* we want to build the e_smx_simcall_t enumeration and the table of the
13  * corresponding strings automatically, using macros */
14
15 #define SIMCALL_LIST1 \
16 SIMCALL_ENUM_ELEMENT(SIMCALL_NONE),\
17 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_BY_NAME),\
18 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_NAME),\
19 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_PROPERTIES),\
20 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_SPEED),\
21 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_AVAILABLE_SPEED),\
22 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_STATE),\
23 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_GET_DATA),\
24 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_SET_DATA),\
25 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTE),\
26 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_PARALLEL_EXECUTE),\
27 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_DESTROY),\
28 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_CANCEL),\
29 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_GET_REMAINS),\
30 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_GET_STATE),\
31 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_SET_PRIORITY),\
32 SIMCALL_ENUM_ELEMENT(SIMCALL_HOST_EXECUTION_WAIT),\
33 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_CREATE),\
34 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_KILL),\
35 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_KILLALL),\
36 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_CLEANUP),\
37 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_CHANGE_HOST),\
38 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_SUSPEND),\
39 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_RESUME),\
40 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_COUNT),\
41 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_GET_DATA),\
42 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_SET_DATA),\
43 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_GET_HOST),\
44 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_GET_NAME),\
45 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_IS_SUSPENDED),\
46 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_GET_PROPERTIES),\
47 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_SLEEP),\
48 SIMCALL_ENUM_ELEMENT(SIMCALL_PROCESS_ON_EXIT),\
49 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_CREATE),\
50 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_DESTROY),\
51 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_GEY_BY_NAME),\
52 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_COMM_COUNT_BY_HOST),\
53 SIMCALL_ENUM_ELEMENT(SIMCALL_RDV_GET_HEAD),\
54 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_SEND),\
55 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_ISEND),\
56 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_RECV),\
57 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_IRECV),\
58 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_DESTROY),\
59 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_CANCEL),\
60 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_WAITANY),\
61 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_WAIT),\
62 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_TEST),\
63 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_TESTANY),\
64 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_REMAINS),\
65 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_STATE),\
66 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_SRC_DATA),\
67 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_DST_DATA),\
68 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_SRC_PROC),\
69 SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_GET_DST_PROC),\
70 SIMCALL_ENUM_ELEMENT(SIMCALL_MUTEX_INIT),\
71 SIMCALL_ENUM_ELEMENT(SIMCALL_MUTEX_DESTROY),\
72 SIMCALL_ENUM_ELEMENT(SIMCALL_MUTEX_LOCK),\
73 SIMCALL_ENUM_ELEMENT(SIMCALL_MUTEX_TRYLOCK),\
74 SIMCALL_ENUM_ELEMENT(SIMCALL_MUTEX_UNLOCK),\
75 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_INIT),\
76 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_DESTROY),\
77 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_SIGNAL),\
78 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_WAIT),\
79 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_WAIT_TIMEOUT),\
80 SIMCALL_ENUM_ELEMENT(SIMCALL_COND_BROADCAST),\
81 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_INIT),\
82 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_DESTROY),\
83 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_RELEASE),\
84 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_WOULD_BLOCK),\
85 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_ACQUIRE),\
86 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_ACQUIRE_TIMEOUT),\
87 SIMCALL_ENUM_ELEMENT(SIMCALL_SEM_GET_CAPACITY),\
88 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_READ),\
89 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_WRITE),\
90 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_OPEN),\
91 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_CLOSE),\
92 SIMCALL_ENUM_ELEMENT(SIMCALL_FILE_STAT)
93
94
95 /* SIMCALL_COMM_IS_LATENCY_BOUNDED and SIMCALL_SET_CATEGORY make things complicated
96  * because they are not always present */
97 #ifdef HAVE_LATENCY_BOUND_TRACKING
98 #define SIMCALL_LIST2 \
99 ,SIMCALL_ENUM_ELEMENT(SIMCALL_COMM_IS_LATENCY_BOUNDED)
100 #else
101 #define SIMCALL_LIST2
102 #endif
103
104 #ifdef HAVE_TRACING
105 #define SIMCALL_LIST3 \
106 ,SIMCALL_ENUM_ELEMENT(SIMCALL_SET_CATEGORY)
107 #else
108 #define SIMCALL_LIST3
109 #endif
110
111 /* SIMCALL_LIST is the final macro to use */
112 #define SIMCALL_LIST SIMCALL_LIST1 SIMCALL_LIST2 SIMCALL_LIST3
113
114 /* you can redefine the following macro differently to generate something else
115  * with the list of enumeration values (e.g. a table of strings or a table of function pointers) */
116 #define SIMCALL_ENUM_ELEMENT(x) x
117
118 /**
119  * \brief All possible simcalls.
120  */
121 typedef enum {
122 SIMCALL_LIST
123 } e_smx_simcall_t;
124
125 /**
126  * \brief Represents a simcall to the kernel.
127  */
128 typedef struct s_smx_simcall {
129   e_smx_simcall_t call;
130   smx_process_t issuer;
131
132   union {
133
134     struct {
135       const char *name;
136       smx_host_t result;
137     } host_get_by_name;
138
139     struct {
140       smx_host_t host;
141       const char* result;
142     } host_get_name;
143
144     struct {
145       smx_host_t host;
146       xbt_dict_t result;
147     } host_get_properties;
148
149     struct {
150       smx_host_t host;
151       double result;
152     } host_get_speed;
153
154     struct {
155       smx_host_t host;
156       double result;
157     } host_get_available_speed;
158
159     struct {
160       smx_host_t host;
161       int result;
162     } host_get_state;
163
164     struct {
165       smx_host_t host;
166       void* result;
167     } host_get_data;
168
169     struct {
170       smx_host_t host;
171       void* data;
172     } host_set_data;
173
174     struct {
175       const char* name;
176       smx_host_t host;
177       double computation_amount;
178       double priority;
179       smx_action_t result;
180     } host_execute;
181
182     struct {
183       const char *name;
184       int host_nb;
185       smx_host_t *host_list;
186       double *computation_amount;
187       double *communication_amount;
188       double amount;
189       double rate;
190       smx_action_t result;
191     } host_parallel_execute;
192
193     struct {
194       smx_action_t execution;
195     } host_execution_destroy;
196
197     struct {
198       smx_action_t execution;
199     } host_execution_cancel;
200
201     struct {
202       smx_action_t execution;
203       double result;
204     } host_execution_get_remains;
205
206     struct {
207       smx_action_t execution;
208       e_smx_state_t result;
209     } host_execution_get_state;
210
211     struct {
212       smx_action_t execution;
213       double priority;
214     } host_execution_set_priority;
215
216     struct {
217       smx_action_t execution;
218       e_smx_state_t result;
219     } host_execution_wait;
220
221     struct {
222       smx_process_t *process;
223       const char *name;
224       xbt_main_func_t code;
225       void *data;
226       const char *hostname;
227       double kill_time;
228       int argc;
229       char **argv;
230       xbt_dict_t properties;
231     } process_create;
232
233     struct {
234       smx_process_t process;
235     } process_kill;
236
237     struct {
238       smx_process_t process;
239     } process_cleanup;
240
241     struct {
242       smx_process_t process;
243       smx_host_t dest;
244     } process_change_host;
245
246     struct {
247       smx_process_t process;
248     } process_suspend;
249
250     struct {
251       smx_process_t process;
252     } process_resume;
253
254     struct {
255       int result;
256     } process_count;
257
258     struct {
259       smx_process_t process;
260       void* result;
261     } process_get_data;
262
263     struct {
264       smx_process_t process;
265       void* data;
266     } process_set_data;
267
268     struct {
269       smx_process_t process;
270       smx_host_t result;
271     } process_get_host;
272
273     struct {
274       smx_process_t process;
275       const char *result;
276     } process_get_name;
277
278     struct {
279       smx_process_t process;
280       int result;
281     } process_is_suspended;
282
283     struct {
284       smx_process_t process;
285       xbt_dict_t result;
286     } process_get_properties;
287
288     struct {
289       double duration;
290       e_smx_state_t result;
291     } process_sleep;
292
293     struct {
294       smx_process_t process;
295       int_f_pvoid_t fun;
296       void *data;
297     } process_on_exit;
298
299     struct {
300       const char *name;
301       smx_rdv_t result;
302     } rdv_create;
303
304     struct {
305       smx_rdv_t rdv;
306     } rdv_destroy;
307
308     struct {
309       const char* name;
310       smx_rdv_t result;
311     } rdv_get_by_name;
312
313     struct {
314       smx_rdv_t rdv;
315       smx_host_t host;
316       unsigned int result; 
317     } rdv_comm_count_by_host;
318
319     struct {
320       smx_rdv_t rdv;
321       smx_action_t result;
322     } rdv_get_head;
323
324     struct {
325       smx_rdv_t rdv;
326       double task_size;
327       double rate;
328       void *src_buff;
329       size_t src_buff_size;
330       int (*match_fun)(void *, void *, smx_action_t);
331       void *data;
332       double timeout;
333     } comm_send;
334
335     struct {
336       smx_rdv_t rdv;
337       double task_size;
338       double rate;
339       void *src_buff;
340       size_t src_buff_size;
341       int (*match_fun)(void *, void *, smx_action_t);
342       void (*clean_fun)(void *);
343       void *data;
344       int detached;
345       smx_action_t result;
346     } comm_isend;
347
348     struct {
349       smx_rdv_t rdv;
350       void *dst_buff;
351       size_t *dst_buff_size;
352       int (*match_fun)(void *, void *, smx_action_t);
353       void *data;
354       double timeout;
355     } comm_recv;
356
357     struct {
358       smx_rdv_t rdv;
359       void *dst_buff;
360       size_t *dst_buff_size;
361       int (*match_fun)(void *, void *, smx_action_t);
362       void *data;
363       smx_action_t result;
364     } comm_irecv;
365
366     struct {
367       smx_action_t comm;
368     } comm_destroy;
369
370     struct {
371       smx_action_t comm;
372     } comm_cancel;
373
374     struct {
375       xbt_dynar_t comms;
376       unsigned int result;
377     } comm_waitany;
378
379     struct {
380       smx_action_t comm;
381       double timeout;
382     } comm_wait;
383
384     struct {
385       smx_action_t comm;
386       int result;
387     } comm_test;
388
389     struct {
390       xbt_dynar_t comms;
391       int result;
392     } comm_testany;
393
394     struct {
395       smx_action_t comm;
396       double result;
397     } comm_get_remains;
398
399     struct {
400       smx_action_t comm;
401       e_smx_state_t result;
402     } comm_get_state;
403
404     struct {
405       smx_action_t comm;
406       void *result;
407     } comm_get_src_data;
408
409     struct {
410       smx_action_t comm;
411       void *result;
412     } comm_get_dst_data;
413
414     struct {
415       smx_action_t comm;
416       smx_process_t result;
417     } comm_get_src_proc;
418
419     struct {
420       smx_action_t comm;
421       smx_process_t result;
422     } comm_get_dst_proc;
423
424 #ifdef HAVE_LATENCY_BOUND_TRACKING
425     struct {
426       smx_action_t comm;
427       int result;
428     } comm_is_latency_bounded;
429 #endif
430
431 #ifdef HAVE_TRACING
432     struct {
433       smx_action_t action;
434       const char *category;
435     } set_category;
436 #endif
437
438     struct {
439       smx_mutex_t result;
440     } mutex_init;
441
442     struct {
443       smx_mutex_t mutex;
444     } mutex_lock;
445
446     struct {
447       smx_mutex_t mutex;
448       int result;
449     } mutex_trylock;
450
451     struct {
452       smx_mutex_t mutex;
453     } mutex_unlock;
454
455     struct {
456       smx_mutex_t mutex;
457     } mutex_destroy;
458
459     struct {
460       smx_cond_t result;
461     } cond_init;
462
463     struct {
464       smx_cond_t cond;
465     } cond_destroy;
466
467     struct {
468       smx_cond_t cond;
469     } cond_signal;
470
471     struct {
472       smx_cond_t cond;
473       smx_mutex_t mutex;
474     } cond_wait;
475
476     struct {
477       smx_cond_t cond;
478       smx_mutex_t mutex;
479       double timeout;
480     } cond_wait_timeout;
481
482     struct {
483       smx_cond_t cond;
484     } cond_broadcast;
485
486     struct {
487       int capacity;
488       smx_sem_t result;
489     } sem_init;
490
491     struct {
492       smx_sem_t sem;
493     } sem_destroy;
494
495     struct {
496       smx_sem_t sem;
497     } sem_release;
498
499     struct {
500       smx_sem_t sem;
501       int result;
502     } sem_would_block;
503
504     struct {
505       smx_sem_t sem;
506     } sem_acquire;
507
508     struct {
509       smx_sem_t sem;
510       double timeout;
511     } sem_acquire_timeout;
512
513     struct {
514       smx_sem_t sem;
515       int result;
516     } sem_get_capacity;
517
518     struct {
519       void *ptr;
520       size_t size;
521       size_t nmemb;
522       smx_file_t stream;
523       double result;
524     } file_read;
525
526     struct {
527       const void *ptr;
528       size_t size;
529       size_t nmemb;
530       smx_file_t stream;
531       size_t result;
532     } file_write;
533
534     struct {
535       const char* mount;
536       const char* path;
537       const char* mode;
538       smx_file_t result;
539     } file_open;
540
541     struct {
542       smx_file_t fp;
543       int result;
544     } file_close;
545
546     struct {
547       smx_file_t fd;
548       s_file_stat_t buf;
549       int result;
550     } file_stat;
551
552   };
553 } s_smx_simcall_t, *smx_simcall_t;
554
555 /******************************** General *************************************/
556
557 void SIMIX_simcall_push(smx_process_t self);
558 void SIMIX_simcall_answer(smx_simcall_t);
559 void SIMIX_simcall_pre(smx_simcall_t, int);
560 void SIMIX_simcall_post(smx_action_t);
561 smx_simcall_t SIMIX_simcall_mine(void);
562 const char *SIMIX_simcall_name(e_smx_simcall_t kind);
563
564 #endif
565