Logo AND Algorithmique Numérique Distribuée

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