Logo AND Algorithmique Numérique Distribuée

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