Logo AND Algorithmique Numérique Distribuée

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