Logo AND Algorithmique Numérique Distribuée

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