Logo AND Algorithmique Numérique Distribuée

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