Logo AND Algorithmique Numérique Distribuée

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